Skip to content

Commit

Permalink
[GLUTEN-5910] [CH] add custom type to ASTLiteral (#5911)
Browse files Browse the repository at this point in the history
What changes were proposed in this pull request?
This pr based on ClickHouse/ClickHouse#64562, Type of Literal DateTime32 will be lost during parsing plan of CH as it will be convert to Int16.

(Fixes: #5910)

How was this patch tested?
This patch was tested manually.
  • Loading branch information
shuai-xu authored Jun 7, 2024
1 parent 17697fa commit 4b5f2c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2612,5 +2612,23 @@ class GlutenClickHouseTPCHSaltNullParquetSuite extends GlutenClickHouseTPCHAbstr
spark.sql("drop table ineq_join_t2")
}
}

test("GLUTEN-5910: Fix ASTLiteral type is lost in CH") {
spark.sql("create table test_tbl_5910_0(c_time bigint, type int) using parquet")
spark.sql("create table test_tbl_5910_1(type int) using parquet")
spark.sql("insert into test_tbl_5910_0 values(1717209159, 12)")
spark.sql("insert into test_tbl_5910_1 values(12)")
val select_sql =
"""
| select t1.cday, t2.type from (
| select type, to_date(from_unixtime(c_time)) as cday from test_tbl_5910_0 ) t1
| left join (
| select type, "2024-06-01" as cday from test_tbl_5910_1 ) t2
| on t1.cday = t2.cday and t1.type = t2.type
|""".stripMargin
compareResultsAgainstVanillaSpark(select_sql, true, { _ => })
spark.sql("drop table test_tbl_5910_0")
spark.sql("drop table test_tbl_5910_1")
}
}
// scalastyle:on line.size.limit
4 changes: 2 additions & 2 deletions cpp-ch/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,8 +1888,8 @@ ASTPtr ASTParser::parseArgumentToAST(const Names & names, const substrait::Expre
case substrait::Expression::RexTypeCase::kLiteral: {
DataTypePtr type;
Field field;
std::tie(std::ignore, field) = SerializedPlanParser::parseLiteral(rel.literal());
return std::make_shared<ASTLiteral>(field);
std::tie(type, field) = SerializedPlanParser::parseLiteral(rel.literal());
return std::make_shared<ASTLiteral>(field, type);
}
case substrait::Expression::RexTypeCase::kSelection: {
if (!rel.selection().has_direct_reference() || !rel.selection().direct_reference().has_struct_field())
Expand Down

0 comments on commit 4b5f2c3

Please sign in to comment.