add test for variant subcolumn

This commit is contained in:
Anton Popov 2024-02-06 15:52:19 +00:00
parent 66b39b11a2
commit bac29c0bba
3 changed files with 35 additions and 0 deletions

View File

@ -124,6 +124,12 @@ void RewriteFunctionToSubcolumnFirstPassMatcher::visit(const ASTFunction & funct
if (value_type == Field::Types::UInt64 || value_type == Field::Types::String) if (value_type == Field::Types::UInt64 || value_type == Field::Types::String)
++data.optimized_identifiers_count[column->name]; ++data.optimized_identifiers_count[column->name];
} }
else if (function.name == "variantElement" && column_type_id == TypeIndex::Variant)
{
const auto * literal = arguments[1]->as<ASTLiteral>();
if (literal && literal->value.getType() == Field::Types::String)
++data.optimized_identifiers_count[column->name];
}
else if (function.name == "mapContains" && column_type_id == TypeIndex::Map) else if (function.name == "mapContains" && column_type_id == TypeIndex::Map)
{ {
++data.optimized_identifiers_count[column->name]; ++data.optimized_identifiers_count[column->name];

View File

@ -0,0 +1,8 @@
SELECT `v.String` AS `variantElement(v, \'String\')`
FROM t_func_to_subcolumns_variant
foo
\N
SELECT __table1.`v.String` AS `variantElement(v, \'String\')`
FROM default.t_func_to_subcolumns_variant AS __table1
foo
\N

View File

@ -0,0 +1,21 @@
DROP TABLE IF EXISTS t_func_to_subcolumns_variant;
SET allow_experimental_variant_type = 1;
CREATE TABLE t_func_to_subcolumns_variant (id UInt64, v Variant(String, UInt64)) ENGINE = MergeTree ORDER BY id;
INSERT INTO t_func_to_subcolumns_variant VALUES (1, 'foo') (2, 111);
SET optimize_functions_to_subcolumns = 1;
SET allow_experimental_analyzer = 0;
EXPLAIN SYNTAX SELECT variantElement(v, 'String') FROM t_func_to_subcolumns_variant;
SELECT variantElement(v, 'String') FROM t_func_to_subcolumns_variant;
SET optimize_functions_to_subcolumns = 1;
SET allow_experimental_analyzer = 1;
EXPLAIN QUERY TREE dump_tree = 0, dump_ast = 1 SELECT variantElement(v, 'String') FROM t_func_to_subcolumns_variant;
SELECT variantElement(v, 'String') FROM t_func_to_subcolumns_variant;
DROP TABLE t_func_to_subcolumns_variant;