Skip to content

Commit

Permalink
override date comparision
Browse files Browse the repository at this point in the history
  • Loading branch information
lgbo-ustc committed Nov 2, 2023
1 parent 81fae1e commit d21168d
Show file tree
Hide file tree
Showing 3 changed files with 363 additions and 15 deletions.
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,9 @@ class CHSparkPlanExecApi extends SparkPlanExecApi {
* @return
*/
override def genExtendedAnalyzers(): List[SparkSession => Rule[LogicalPlan]] = {
List(spark => new ClickHouseAnalysis(spark, spark.sessionState.conf))
List(
spark => new ClickHouseAnalysis(spark, spark.sessionState.conf),
spark => new RewriteDateTimestampComparisonRule(spark, spark.sessionState.conf))
}

/**
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", LongType, 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 = false) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) <= '2019-01-02'",
noFallBack = false) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) > '2019-01-02'",
noFallBack = false) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) >= '2019-01-02'",
noFallBack = false) { _ => }
runQueryAndCompare(
"select * from date_table where to_date(from_unixtime(ts)) = '2019-01-01'",
noFallBack = false) { _ => }
}
}
Loading

0 comments on commit d21168d

Please sign in to comment.