Skip to content
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

[GLUTEN-3141][CH] Rewrite date comparison expression into a more efficient way #3592

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.apache.spark.sql.execution.joins.{BuildSideRelation, ClickHouseBuildS
import org.apache.spark.sql.execution.metric.SQLMetric
import org.apache.spark.sql.execution.utils.CHExecUtil
import org.apache.spark.sql.extension.ClickHouseAnalysis
import org.apache.spark.sql.extension.RewriteDateTimestampComparisonRule
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.vectorized.ColumnarBatch

Expand Down Expand Up @@ -328,7 +329,12 @@ class CHSparkPlanExecApi extends SparkPlanExecApi {
* @return
*/
override def genExtendedAnalyzers(): List[SparkSession => Rule[LogicalPlan]] = {
List(spark => new ClickHouseAnalysis(spark, spark.sessionState.conf))
val analyzers = List(spark => new ClickHouseAnalysis(spark, spark.sessionState.conf))
if (GlutenConfig.getConf.enableDateTimestampComparison) {
analyzers :+ (spark => new RewriteDateTimestampComparisonRule(spark, spark.sessionState.conf))
} else {
analyzers
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,27 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS

val dateSchema = StructType(
Array(
StructField("ts", IntegerType, true),
StructField("day", DateType, true),
StructField("weekday_abbr", StringType, true)
)
)
val dateRows = sparkContext.parallelize(
Seq(
Row(Date.valueOf("2019-01-01"), "MO"),
Row(Date.valueOf("2019-01-01"), "TU"),
Row(Date.valueOf("2019-01-01"), "TH"),
Row(Date.valueOf("2019-01-01"), "WE"),
Row(Date.valueOf("2019-01-01"), "FR"),
Row(Date.valueOf("2019-01-01"), "SA"),
Row(Date.valueOf("2019-01-01"), "SU"),
Row(Date.valueOf("2019-01-01"), "MO"),
Row(Date.valueOf("2019-01-02"), "MM"),
Row(Date.valueOf("2019-01-03"), "TH"),
Row(Date.valueOf("2019-01-04"), "WE"),
Row(Date.valueOf("2019-01-05"), "FR"),
Row(null, "SA"),
Row(Date.valueOf("2019-01-07"), null)
Row(1546309380, Date.valueOf("2019-01-01"), "MO"),
Row(1546273380, Date.valueOf("2019-01-01"), "TU"),
Row(1546358340, Date.valueOf("2019-01-01"), "TH"),
Row(1546311540, Date.valueOf("2019-01-01"), "WE"),
Row(1546308540, Date.valueOf("2019-01-01"), "FR"),
Row(1546319340, Date.valueOf("2019-01-01"), "SA"),
Row(1546319940, Date.valueOf("2019-01-01"), "SU"),
Row(1546323545, Date.valueOf("2019-01-01"), "MO"),
Row(1546409940, Date.valueOf("2019-01-02"), "MM"),
Row(1546496340, Date.valueOf("2019-01-03"), "TH"),
Row(1546586340, Date.valueOf("2019-01-04"), "WE"),
Row(1546676341, Date.valueOf("2019-01-05"), "FR"),
Row(null, null, "SA"),
Row(1546849141, Date.valueOf("2019-01-07"), null)
)
)
val dateTableFile = Files.createTempFile("", ".parquet").toFile
Expand Down Expand Up @@ -466,4 +467,22 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS
"select round(0.41875f * id , 4) from range(10);"
)(checkOperatorMatch[ProjectExecTransformer])
}

test("test date comparision expression override") {
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) < '2019-01-02'",
noFallBack = true) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) <= '2019-01-02'",
noFallBack = true) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) > '2019-01-02'",
noFallBack = true) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) >= '2019-01-02'",
noFallBack = true) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) = '2019-01-01'",
noFallBack = true) { _ => }
}
}
Loading
Loading