add scalars in time

This commit is contained in:
Amos Bird 2020-06-19 00:11:23 +08:00
parent 7011401cd4
commit d524301038
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 26 additions and 5 deletions

View File

@ -309,6 +309,11 @@ InterpreterSelectQuery::InterpreterSelectQuery(
query_ptr, SyntaxAnalyzerResult(source_header.getNamesAndTypesList(), storage), query_ptr, SyntaxAnalyzerResult(source_header.getNamesAndTypesList(), storage),
options, joined_tables.tablesWithColumns(), required_result_column_names, table_join); 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) if (view)
{ {
/// Restore original view name. Save rewritten subquery for future usage in StorageView. /// 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<SelectQueryExpressionAnalyzer>( query_analyzer = std::make_unique<SelectQueryExpressionAnalyzer>(
query_ptr, syntax_analyzer_result, *context, query_ptr, syntax_analyzer_result, *context,
NameSet(required_result_column_names.begin(), required_result_column_names.end()), NameSet(required_result_column_names.begin(), required_result_column_names.end()),

View File

@ -0,0 +1,2 @@
[0,3,2] id2
[3,1,2] id1

View File

@ -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;