-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23727][SQL] Support for pushing down filters for DateType in parquet #20851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
079af71
59d8483
1f2b450
4df29df
8f36d1e
82c5a73
784b625
7946bea
423a938
a58eec8
b43e36c
b70def0
759f468
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -353,6 +353,13 @@ object SQLConf { | |
| .booleanConf | ||
| .createWithDefault(true) | ||
|
|
||
| val PARQUET_FILTER_PUSHDOWN_DATE_ENABLED = buildConf("spark.sql.parquet.filterPushdown.date") | ||
| .doc("If true, enables Parquet filter push-down optimization for Date. " + | ||
| "This configuration only has an effect when 'spark.sql.parquet.filterPushdown' is enabled.") | ||
| .internal() | ||
| .booleanConf | ||
| .createWithDefault(true) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this kind of thing, we had better start with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
|
||
| val PARQUET_WRITE_LEGACY_FORMAT = buildConf("spark.sql.parquet.writeLegacyFormat") | ||
| .doc("Whether to be compatible with the legacy Parquet format adopted by Spark 1.4 and prior " + | ||
| "versions, when converting Parquet schema to Spark SQL schema and vice versa.") | ||
|
|
@@ -1319,6 +1326,8 @@ class SQLConf extends Serializable with Logging { | |
|
|
||
| def parquetFilterPushDown: Boolean = getConf(PARQUET_FILTER_PUSHDOWN_ENABLED) | ||
|
|
||
| def parquetFilterPushDownDate: Boolean = getConf(PARQUET_FILTER_PUSHDOWN_DATE_ENABLED) | ||
|
|
||
| def orcFilterPushDown: Boolean = getConf(ORC_FILTER_PUSHDOWN_ENABLED) | ||
|
|
||
| def verifyPartitionPath: Boolean = getConf(HIVE_VERIFY_PARTITION_PATH) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,15 @@ | |
|
|
||
| package org.apache.spark.sql.execution.datasources.parquet | ||
|
|
||
| import java.sql.Date | ||
|
|
||
| import org.apache.parquet.filter2.predicate._ | ||
| import org.apache.parquet.filter2.predicate.FilterApi._ | ||
| import org.apache.parquet.io.api.Binary | ||
|
|
||
| import org.apache.spark.sql.catalyst.util.DateTimeUtils | ||
| import org.apache.spark.sql.catalyst.util.DateTimeUtils.SQLDate | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.sources | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
|
|
@@ -29,6 +34,10 @@ import org.apache.spark.sql.types._ | |
| */ | ||
| private[parquet] object ParquetFilters { | ||
|
|
||
| private def dateToDays(date: Date): SQLDate = { | ||
| DateTimeUtils.fromJavaDate(date) | ||
| } | ||
|
|
||
| private val makeEq: PartialFunction[DataType, (String, Any) => FilterPredicate] = { | ||
| case BooleanType => | ||
| (n: String, v: Any) => FilterApi.eq(booleanColumn(n), v.asInstanceOf[java.lang.Boolean]) | ||
|
|
@@ -50,6 +59,10 @@ private[parquet] object ParquetFilters { | |
| (n: String, v: Any) => FilterApi.eq( | ||
| binaryColumn(n), | ||
| Option(v).map(b => Binary.fromReusedByteArray(v.asInstanceOf[Array[Byte]])).orNull) | ||
| case DateType if SQLConf.get.parquetFilterPushDownDate => | ||
| (n: String, v: Any) => FilterApi.eq( | ||
| intColumn(n), | ||
| Option(v).map(date => dateToDays(date.asInstanceOf[Date]).asInstanceOf[Integer]).orNull) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry I was wrong. I took a look at how these dates get created, in |
||
| } | ||
|
|
||
| private val makeNotEq: PartialFunction[DataType, (String, Any) => FilterPredicate] = { | ||
|
|
@@ -72,6 +85,10 @@ private[parquet] object ParquetFilters { | |
| (n: String, v: Any) => FilterApi.notEq( | ||
| binaryColumn(n), | ||
| Option(v).map(b => Binary.fromReusedByteArray(v.asInstanceOf[Array[Byte]])).orNull) | ||
| case DateType if SQLConf.get.parquetFilterPushDownDate => | ||
| (n: String, v: Any) => FilterApi.notEq( | ||
| intColumn(n), | ||
| Option(v).map(date => dateToDays(date.asInstanceOf[Date]).asInstanceOf[Integer]).orNull) | ||
| } | ||
|
|
||
| private val makeLt: PartialFunction[DataType, (String, Any) => FilterPredicate] = { | ||
|
|
@@ -91,6 +108,10 @@ private[parquet] object ParquetFilters { | |
| case BinaryType => | ||
| (n: String, v: Any) => | ||
| FilterApi.lt(binaryColumn(n), Binary.fromReusedByteArray(v.asInstanceOf[Array[Byte]])) | ||
| case DateType if SQLConf.get.parquetFilterPushDownDate => | ||
| (n: String, v: Any) => FilterApi.lt( | ||
| intColumn(n), | ||
| Option(v).map(date => dateToDays(date.asInstanceOf[Date]).asInstanceOf[Integer]).orNull) | ||
| } | ||
|
|
||
| private val makeLtEq: PartialFunction[DataType, (String, Any) => FilterPredicate] = { | ||
|
|
@@ -110,6 +131,10 @@ private[parquet] object ParquetFilters { | |
| case BinaryType => | ||
| (n: String, v: Any) => | ||
| FilterApi.ltEq(binaryColumn(n), Binary.fromReusedByteArray(v.asInstanceOf[Array[Byte]])) | ||
| case DateType if SQLConf.get.parquetFilterPushDownDate => | ||
| (n: String, v: Any) => FilterApi.ltEq( | ||
| intColumn(n), | ||
| Option(v).map(date => dateToDays(date.asInstanceOf[Date]).asInstanceOf[Integer]).orNull) | ||
| } | ||
|
|
||
| private val makeGt: PartialFunction[DataType, (String, Any) => FilterPredicate] = { | ||
|
|
@@ -129,6 +154,10 @@ private[parquet] object ParquetFilters { | |
| case BinaryType => | ||
| (n: String, v: Any) => | ||
| FilterApi.gt(binaryColumn(n), Binary.fromReusedByteArray(v.asInstanceOf[Array[Byte]])) | ||
| case DateType if SQLConf.get.parquetFilterPushDownDate => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should refactor it, so that adding a new data type doesn't need to touch so many places. This can be done later. |
||
| (n: String, v: Any) => FilterApi.gt( | ||
| intColumn(n), | ||
| Option(v).map(date => dateToDays(date.asInstanceOf[Date]).asInstanceOf[Integer]).orNull) | ||
| } | ||
|
|
||
| private val makeGtEq: PartialFunction[DataType, (String, Any) => FilterPredicate] = { | ||
|
|
@@ -148,6 +177,10 @@ private[parquet] object ParquetFilters { | |
| case BinaryType => | ||
| (n: String, v: Any) => | ||
| FilterApi.gtEq(binaryColumn(n), Binary.fromReusedByteArray(v.asInstanceOf[Array[Byte]])) | ||
| case DateType if SQLConf.get.parquetFilterPushDownDate => | ||
| (n: String, v: Any) => FilterApi.gtEq( | ||
| intColumn(n), | ||
| Option(v).map(date => dateToDays(date.asInstanceOf[Date]).asInstanceOf[Integer]).orNull) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be an internal conf, i.e.,
.internal()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be an internal conf. In Spark 3.0 release, we will revisit all the internal confs and remove all the unnecessary confs.