From d52430103889f8fb90706a1ed286e4789bad6459 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Fri, 19 Jun 2020 00:11:23 +0800 Subject: [PATCH] add scalars in time --- src/Interpreters/InterpreterSelectQuery.cpp | 10 +++++----- .../01323_add_scalars_in_time.reference | 2 ++ .../0_stateless/01323_add_scalars_in_time.sql | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 tests/queries/0_stateless/01323_add_scalars_in_time.reference create mode 100644 tests/queries/0_stateless/01323_add_scalars_in_time.sql diff --git a/src/Interpreters/InterpreterSelectQuery.cpp b/src/Interpreters/InterpreterSelectQuery.cpp index 523e467261b..d036211d65d 100644 --- a/src/Interpreters/InterpreterSelectQuery.cpp +++ b/src/Interpreters/InterpreterSelectQuery.cpp @@ -309,6 +309,11 @@ InterpreterSelectQuery::InterpreterSelectQuery( query_ptr, SyntaxAnalyzerResult(source_header.getNamesAndTypesList(), storage), options, joined_tables.tablesWithColumns(), required_result_column_names, table_join); + /// Save scalar sub queries's results in the query context + if (!options.only_analyze && context->hasQueryContext()) + for (const auto & it : syntax_analyzer_result->getScalars()) + context->getQueryContext().addScalar(it.first, it.second); + if (view) { /// Restore original view name. Save rewritten subquery for future usage in StorageView. @@ -329,11 +334,6 @@ InterpreterSelectQuery::InterpreterSelectQuery( } } - /// Save scalar sub queries's results in the query context - if (!options.only_analyze && context->hasQueryContext()) - for (const auto & it : syntax_analyzer_result->getScalars()) - context->getQueryContext().addScalar(it.first, it.second); - query_analyzer = std::make_unique( query_ptr, syntax_analyzer_result, *context, NameSet(required_result_column_names.begin(), required_result_column_names.end()), diff --git a/tests/queries/0_stateless/01323_add_scalars_in_time.reference b/tests/queries/0_stateless/01323_add_scalars_in_time.reference new file mode 100644 index 00000000000..85d56962cdb --- /dev/null +++ b/tests/queries/0_stateless/01323_add_scalars_in_time.reference @@ -0,0 +1,2 @@ +[0,3,2] id2 +[3,1,2] id1 diff --git a/tests/queries/0_stateless/01323_add_scalars_in_time.sql b/tests/queries/0_stateless/01323_add_scalars_in_time.sql new file mode 100644 index 00000000000..9a71b0075d4 --- /dev/null +++ b/tests/queries/0_stateless/01323_add_scalars_in_time.sql @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS tags; + +CREATE TABLE tags ( + id String, + seqs Array(UInt8), + create_time DateTime DEFAULT now() +) engine=ReplacingMergeTree() +ORDER BY (id); + +INSERT INTO tags(id, seqs) VALUES ('id1', [1,2,3]), ('id2', [0,2,3]), ('id1', [1,3]); + +WITH + (SELECT [0, 1, 2, 3]) AS arr1 +SELECT arrayIntersect(argMax(seqs, create_time), arr1) AS common, id +FROM tags +WHERE id LIKE 'id%' +GROUP BY id; + +DROP TABLE tags;