Skip to content

Commit

Permalink
[GLUTEN-3861][CH] Fix parse exception when join postJoinFilter contai…
Browse files Browse the repository at this point in the history
…ns singularOrList
  • Loading branch information
exmy committed Nov 29, 2023
1 parent e0f197f commit 80e2229
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,28 @@ class GlutenClickHouseTPCHParquetSuite extends GlutenClickHouseTPCHAbstractSuite
}
}

test("GLUTEN-3861: Fix parse exception when join postJoinFilter contains singularOrList") {
withSQLConf(("spark.sql.autoBroadcastJoinThreshold", "-1")) {
val sql =
"""
|select t1.l_orderkey, t2.o_orderkey, t1.l_year, t2.o_year
|from (
| select l_orderkey, extract(year from l_shipdate) as l_year, count(1) as l_cnt
| from lineitem
| group by l_orderkey, l_shipdate) t1
|left join (
| select o_orderkey, extract(year from o_orderdate) as o_year, count(1) as o_cnt
| from orders
| group by o_orderkey, o_orderdate) t2
|on t1.l_orderkey = t2.o_orderkey
| and l_year in (1997, 1995, 1993)
|order by t1.l_orderkey, t2.o_orderkey, t1.l_year, t2.o_year
|limit 100
|""".stripMargin
compareResultsAgainstVanillaSpark(sql, true, { _ => })
}
}

test("GLUTEN-3467: Fix 'Names of tuple elements must be unique' error for ch backend") {
val sql =
"""
Expand Down
2 changes: 1 addition & 1 deletion cpp-ch/local-engine/Parser/JoinRelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ bool JoinRelParser::tryAddPushDownFilter(
}
}
}
// if ch not support the join type or join conditions, it will throw an exception like 'not support'.
// if ch does not support the join type or join conditions, it will throw an exception like 'not support'.
catch (Poco::Exception & e)
{
// CH not support join condition has 'or' and has different table in each side.
Expand Down
9 changes: 7 additions & 2 deletions cpp-ch/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,8 @@ ActionsDAGPtr ASTParser::convertToActions(const NamesAndTypesList & name_and_typ
ASTPtr ASTParser::parseToAST(const Names & names, const substrait::Expression & rel)
{
LOG_DEBUG(&Poco::Logger::get("ASTParser"), "substrait plan:\n{}", rel.DebugString());
if (rel.has_singular_or_list())
return parseArgumentToAST(names, rel);
if (!rel.has_scalar_function())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "the root of expression should be a scalar function:\n {}", rel.DebugString());

Expand Down Expand Up @@ -2021,7 +2023,8 @@ ASTPtr ASTParser::parseArgumentToAST(const Names & names, const substrait::Expre

bool nullable = false;
size_t options_len = options.size();
args.reserve(options_len);
ASTs in_args;
in_args.reserve(options_len);

for (int i = 0; i < static_cast<int>(options_len); ++i)
{
Expand All @@ -2044,8 +2047,10 @@ ASTPtr ASTParser::parseArgumentToAST(const Names & names, const substrait::Expre
elem_type->getName(),
option_type->getName());

args.emplace_back(std::make_shared<ASTLiteral>(type_and_field.second));
in_args.emplace_back(std::make_shared<ASTLiteral>(type_and_field.second));
}
auto array_ast = makeASTFunction("array", in_args);
args.emplace_back(array_ast);

auto ast = makeASTFunction("in", args);
if (nullable)
Expand Down

0 comments on commit 80e2229

Please sign in to comment.