1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.sql.sources
////////////////////////////////////////////////////////////////////////////////////////////////////
// This file defines all the filters that we can push down to the data sources.
////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A filter predicate for data sources.
*
* @since 1.3.0
*/
abstract class Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to a value
* equal to `value`.
*
* @since 1.3.0
*/
case class EqualTo(attribute: String, value: Any) extends Filter
/**
* Performs equality comparison, similar to [[EqualTo]]. However, this differs from [[EqualTo]]
* in that it returns `true` (rather than NULL) if both inputs are NULL, and `false`
* (rather than NULL) if one of the input is NULL and the other is not NULL.
*
* @since 1.5.0
*/
case class EqualNullSafe(attribute: String, value: Any) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to a value
* greater than `value`.
*
* @since 1.3.0
*/
case class GreaterThan(attribute: String, value: Any) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to a value
* greater than or equal to `value`.
*
* @since 1.3.0
*/
case class GreaterThanOrEqual(attribute: String, value: Any) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to a value
* less than `value`.
*
* @since 1.3.0
*/
case class LessThan(attribute: String, value: Any) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to a value
* less than or equal to `value`.
*
* @since 1.3.0
*/
case class LessThanOrEqual(attribute: String, value: Any) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to one of the values in the array.
*
* @since 1.3.0
*/
case class In(attribute: String, values: Array[Any]) extends Filter {
override def hashCode(): Int = {
var h = attribute.hashCode
values.foreach { v =>
h *= 41
h += v.hashCode()
}
h
}
override def equals(o: Any): Boolean = o match {
case In(a, vs) =>
a == attribute && vs.length == values.length && vs.zip(values).forall(x => x._1 == x._2)
case _ => false
}
override def toString: String = {
s"In($attribute, [${values.mkString(",")}]"
}
}
/**
* A filter that evaluates to `true` iff the attribute evaluates to null.
*
* @since 1.3.0
*/
case class IsNull(attribute: String) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to a non-null value.
*
* @since 1.3.0
*/
case class IsNotNull(attribute: String) extends Filter
/**
* A filter that evaluates to `true` iff both `left` or `right` evaluate to `true`.
*
* @since 1.3.0
*/
case class And(left: Filter, right: Filter) extends Filter
/**
* A filter that evaluates to `true` iff at least one of `left` or `right` evaluates to `true`.
*
* @since 1.3.0
*/
case class Or(left: Filter, right: Filter) extends Filter
/**
* A filter that evaluates to `true` iff `child` is evaluated to `false`.
*
* @since 1.3.0
*/
case class Not(child: Filter) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to
* a string that starts with `value`.
*
* @since 1.3.1
*/
case class StringStartsWith(attribute: String, value: String) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to
* a string that starts with `value`.
*
* @since 1.3.1
*/
case class StringEndsWith(attribute: String, value: String) extends Filter
/**
* A filter that evaluates to `true` iff the attribute evaluates to
* a string that contains the string `value`.
*
* @since 1.3.1
*/
case class StringContains(attribute: String, value: String) extends Filter
|