Support function to subcolumns optimization for Variant, better text priority for reading Bool

This commit is contained in:
avogar 2023-12-27 20:04:14 +00:00
parent 4b2a0b99fc
commit 275fbe3e98
3 changed files with 36 additions and 0 deletions

View File

@ -176,6 +176,23 @@ public:
node = std::make_shared<ColumnNode>(column, column_source);
}
else if (function_name == "variantElement" && isVariant(column_type) && second_argument_constant_node)
{
/// Replace `variantElement(variant_argument, type_name)` with `variant_argument.type_name`.
const auto & variant_element_constant_value = second_argument_constant_node->getValue();
String subcolumn_name;
if (variant_element_constant_value.getType() != Field::Types::String)
return;
subcolumn_name = variant_element_constant_value.get<const String &>();
column.name += '.';
column.name += subcolumn_name;
column.type = function_node->getResultType();
node = std::make_shared<ColumnNode>(column, column_source);
}
else if (function_name == "mapContains" && column_type.isMap())
{
const auto & data_type_map = assert_cast<const DataTypeMap &>(*column.type);

View File

@ -534,6 +534,10 @@ std::tuple<size_t, size_t, size_t> getTypeTextDeserializePriority(const DataType
return {max_depth, max_priority, max_simple_nested_depth};
}
/// Bool type should have priority higher then all integers.
if (isBool(type))
return {nested_depth, priority_map[TypeIndex::Int8] + 1 , simple_nested_depth};
return {nested_depth, priority_map[type->getTypeId()], simple_nested_depth};
}

View File

@ -122,6 +122,21 @@ void RewriteFunctionToSubcolumnData::visit(ASTFunction & function, ASTPtr & ast)
ast = transformToSubcolumn(name_in_storage, subcolumn_name);
ast->setAlias(alias);
}
else if (function.name == "variantElement" && column_type_id == TypeIndex::Variant)
{
const auto * literal = arguments[1]->as<ASTLiteral>();
if (!literal)
return;
String subcolumn_name;
auto value_type = literal->value.getType();
if (value_type != Field::Types::String)
return;
subcolumn_name = literal->value.get<const String &>();
ast = transformToSubcolumn(name_in_storage, subcolumn_name);
ast->setAlias(alias);
}
else
{
auto it = binary_function_to_subcolumn.find(function.name);