From 35a736f811626a6b9db84bdc64bda551d7da3fa0 Mon Sep 17 00:00:00 2001 From: ongkong Date: Thu, 20 Apr 2023 23:12:37 -0700 Subject: [PATCH 1/2] use sanitizeBlock --- src/Interpreters/ExpressionAnalyzer.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Interpreters/ExpressionAnalyzer.cpp b/src/Interpreters/ExpressionAnalyzer.cpp index cc54e7620f6..e444a9b3a2b 100644 --- a/src/Interpreters/ExpressionAnalyzer.cpp +++ b/src/Interpreters/ExpressionAnalyzer.cpp @@ -1066,13 +1066,6 @@ static std::shared_ptr chooseJoinAlgorithm( { const auto & settings = context->getSettings(); - Block left_sample_block(left_sample_columns); - for (auto & column : left_sample_block) - { - if (!column.column) - column.column = column.type->createColumn(); - } - Block right_sample_block = joined_plan->getCurrentDataStream().header; std::vector tried_algorithms; @@ -1115,7 +1108,7 @@ static std::shared_ptr chooseJoinAlgorithm( return std::make_shared(analyzed_join, right_sample_block); } - if (analyzed_join->isEnabledAlgorithm(JoinAlgorithm::GRACE_HASH)) + if (Block left_sample_block(left_sample_columns); analyzed_join->isEnabledAlgorithm(JoinAlgorithm::GRACE_HASH) && sanitizeBlock(left_sample_block, false)) { tried_algorithms.push_back(toString(JoinAlgorithm::GRACE_HASH)); if (GraceHashJoin::isSupported(analyzed_join)) From 1bffb28adc995f828998df8c51841cf763ab6b11 Mon Sep 17 00:00:00 2001 From: ongkong Date: Tue, 25 Apr 2023 00:40:54 -0700 Subject: [PATCH 2/2] add comment, change check location --- src/Interpreters/ExpressionAnalyzer.cpp | 7 +++++-- ...2724_function_in_left_table_clause_asof_join.reference | 1 + .../02724_function_in_left_table_clause_asof_join.sql | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.reference create mode 100644 tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.sql diff --git a/src/Interpreters/ExpressionAnalyzer.cpp b/src/Interpreters/ExpressionAnalyzer.cpp index e444a9b3a2b..9e3951e80a4 100644 --- a/src/Interpreters/ExpressionAnalyzer.cpp +++ b/src/Interpreters/ExpressionAnalyzer.cpp @@ -1108,10 +1108,13 @@ static std::shared_ptr chooseJoinAlgorithm( return std::make_shared(analyzed_join, right_sample_block); } - if (Block left_sample_block(left_sample_columns); analyzed_join->isEnabledAlgorithm(JoinAlgorithm::GRACE_HASH) && sanitizeBlock(left_sample_block, false)) + if (analyzed_join->isEnabledAlgorithm(JoinAlgorithm::GRACE_HASH)) { tried_algorithms.push_back(toString(JoinAlgorithm::GRACE_HASH)); - if (GraceHashJoin::isSupported(analyzed_join)) + + // Grace hash join requires that columns exist in left_sample_block. + Block left_sample_block(left_sample_columns); + if (sanitizeBlock(left_sample_block, false) && GraceHashJoin::isSupported(analyzed_join)) return std::make_shared(context, analyzed_join, left_sample_block, right_sample_block, context->getTempDataOnDisk()); } diff --git a/tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.reference b/tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.sql b/tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.sql new file mode 100644 index 00000000000..13dfb5debe7 --- /dev/null +++ b/tests/queries/0_stateless/02724_function_in_left_table_clause_asof_join.sql @@ -0,0 +1,8 @@ +select count(*) +from ( + select 1 as id, [1, 2, 3] as arr +) as sessions +ASOF LEFT JOIN ( + select 1 as session_id, 4 as id +) as visitors +ON visitors.session_id <= sessions.id AND arrayFirst(a -> a, arrayMap((a) -> a, sessions.arr)) = visitors.id