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-3861][CH] Fix parse exception when join postJoinFilter contains singularOrList #3862

Merged
merged 1 commit into from
Dec 12, 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 @@ -2186,6 +2186,27 @@ 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, t1.l_year, t2.o_orderkey, 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, t1.l_year, t2.o_orderkey, t2.o_year
|""".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
12 changes: 9 additions & 3 deletions cpp-ch/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <Interpreters/ActionsVisitor.h>
#include <Interpreters/CollectJoinOnKeysVisitor.h>
#include <Interpreters/Context.h>
#include <Interpreters/PreparedSets.h>
#include <Interpreters/ProcessList.h>
#include <Interpreters/QueryPriorities.h>
#include <Join/StorageJoinFromReadBuffer.h>
Expand Down Expand Up @@ -1883,7 +1884,7 @@ ActionsDAGPtr ASTParser::convertToActions(const NamesAndTypesList & name_and_typ
size_t(0),
name_and_types,
std::make_shared<ActionsDAG>(name_and_types),
nullptr /* prepared_sets */,
std::make_shared<PreparedSets>(),
false /* no_subqueries */,
false /* no_makeset */,
false /* only_consts */,
Expand All @@ -1895,6 +1896,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 @@ -2000,7 +2003,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 @@ -2023,8 +2027,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
Loading