17
17
18
18
package org .apache .spark .sql .execution .datasources .parquet
19
19
20
+ import java .sql .Date
21
+
20
22
import org .apache .parquet .filter2 .predicate ._
21
23
import org .apache .parquet .filter2 .predicate .FilterApi ._
22
24
import org .apache .parquet .io .api .Binary
23
25
26
+ import org .apache .spark .sql .catalyst .util .DateTimeUtils
27
+ import org .apache .spark .sql .catalyst .util .DateTimeUtils .SQLDate
28
+ import org .apache .spark .sql .internal .SQLConf
24
29
import org .apache .spark .sql .sources
25
30
import org .apache .spark .sql .types ._
26
31
@@ -29,6 +34,10 @@ import org.apache.spark.sql.types._
29
34
*/
30
35
private [parquet] object ParquetFilters {
31
36
37
+ private def dateToDays (date : Date ): SQLDate = {
38
+ DateTimeUtils .fromJavaDate(date)
39
+ }
40
+
32
41
private val makeEq : PartialFunction [DataType , (String , Any ) => FilterPredicate ] = {
33
42
case BooleanType =>
34
43
(n : String , v : Any ) => FilterApi .eq(booleanColumn(n), v.asInstanceOf [java.lang.Boolean ])
@@ -50,6 +59,10 @@ private[parquet] object ParquetFilters {
50
59
(n : String , v : Any ) => FilterApi .eq(
51
60
binaryColumn(n),
52
61
Option (v).map(b => Binary .fromReusedByteArray(v.asInstanceOf [Array [Byte ]])).orNull)
62
+ case DateType if SQLConf .get.parquetFilterPushDownDate =>
63
+ (n : String , v : Any ) => FilterApi .eq(
64
+ intColumn(n),
65
+ Option (v).map(date => dateToDays(date.asInstanceOf [Date ]).asInstanceOf [Integer ]).orNull)
53
66
}
54
67
55
68
private val makeNotEq : PartialFunction [DataType , (String , Any ) => FilterPredicate ] = {
@@ -72,6 +85,10 @@ private[parquet] object ParquetFilters {
72
85
(n : String , v : Any ) => FilterApi .notEq(
73
86
binaryColumn(n),
74
87
Option (v).map(b => Binary .fromReusedByteArray(v.asInstanceOf [Array [Byte ]])).orNull)
88
+ case DateType if SQLConf .get.parquetFilterPushDownDate =>
89
+ (n : String , v : Any ) => FilterApi .notEq(
90
+ intColumn(n),
91
+ Option (v).map(date => dateToDays(date.asInstanceOf [Date ]).asInstanceOf [Integer ]).orNull)
75
92
}
76
93
77
94
private val makeLt : PartialFunction [DataType , (String , Any ) => FilterPredicate ] = {
@@ -91,6 +108,10 @@ private[parquet] object ParquetFilters {
91
108
case BinaryType =>
92
109
(n : String , v : Any ) =>
93
110
FilterApi .lt(binaryColumn(n), Binary .fromReusedByteArray(v.asInstanceOf [Array [Byte ]]))
111
+ case DateType if SQLConf .get.parquetFilterPushDownDate =>
112
+ (n : String , v : Any ) => FilterApi .lt(
113
+ intColumn(n),
114
+ Option (v).map(date => dateToDays(date.asInstanceOf [Date ]).asInstanceOf [Integer ]).orNull)
94
115
}
95
116
96
117
private val makeLtEq : PartialFunction [DataType , (String , Any ) => FilterPredicate ] = {
@@ -110,6 +131,10 @@ private[parquet] object ParquetFilters {
110
131
case BinaryType =>
111
132
(n : String , v : Any ) =>
112
133
FilterApi .ltEq(binaryColumn(n), Binary .fromReusedByteArray(v.asInstanceOf [Array [Byte ]]))
134
+ case DateType if SQLConf .get.parquetFilterPushDownDate =>
135
+ (n : String , v : Any ) => FilterApi .ltEq(
136
+ intColumn(n),
137
+ Option (v).map(date => dateToDays(date.asInstanceOf [Date ]).asInstanceOf [Integer ]).orNull)
113
138
}
114
139
115
140
private val makeGt : PartialFunction [DataType , (String , Any ) => FilterPredicate ] = {
@@ -129,6 +154,10 @@ private[parquet] object ParquetFilters {
129
154
case BinaryType =>
130
155
(n : String , v : Any ) =>
131
156
FilterApi .gt(binaryColumn(n), Binary .fromReusedByteArray(v.asInstanceOf [Array [Byte ]]))
157
+ case DateType if SQLConf .get.parquetFilterPushDownDate =>
158
+ (n : String , v : Any ) => FilterApi .gt(
159
+ intColumn(n),
160
+ Option (v).map(date => dateToDays(date.asInstanceOf [Date ]).asInstanceOf [Integer ]).orNull)
132
161
}
133
162
134
163
private val makeGtEq : PartialFunction [DataType , (String , Any ) => FilterPredicate ] = {
@@ -148,6 +177,10 @@ private[parquet] object ParquetFilters {
148
177
case BinaryType =>
149
178
(n : String , v : Any ) =>
150
179
FilterApi .gtEq(binaryColumn(n), Binary .fromReusedByteArray(v.asInstanceOf [Array [Byte ]]))
180
+ case DateType if SQLConf .get.parquetFilterPushDownDate =>
181
+ (n : String , v : Any ) => FilterApi .gtEq(
182
+ intColumn(n),
183
+ Option (v).map(date => dateToDays(date.asInstanceOf [Date ]).asInstanceOf [Integer ]).orNull)
151
184
}
152
185
153
186
/**
0 commit comments