mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 10:02:01 +00:00
added EPHEMERAL default for column (preliminary)
This commit is contained in:
parent
22de534fdc
commit
4d5fb56c29
@ -19,7 +19,7 @@ ASTPtr processColumnTransformers(
|
|||||||
ASTPtr query_columns)
|
ASTPtr query_columns)
|
||||||
{
|
{
|
||||||
const auto & columns = metadata_snapshot->getColumns();
|
const auto & columns = metadata_snapshot->getColumns();
|
||||||
auto names_and_types = columns.getOrdinary();
|
auto names_and_types = columns.getInsertable();
|
||||||
removeDuplicateColumns(names_and_types);
|
removeDuplicateColumns(names_and_types);
|
||||||
|
|
||||||
TablesWithColumns tables_with_columns;
|
TablesWithColumns tables_with_columns;
|
||||||
|
@ -124,6 +124,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
|||||||
ParserKeyword s_null{"NULL"};
|
ParserKeyword s_null{"NULL"};
|
||||||
ParserKeyword s_not{"NOT"};
|
ParserKeyword s_not{"NOT"};
|
||||||
ParserKeyword s_materialized{"MATERIALIZED"};
|
ParserKeyword s_materialized{"MATERIALIZED"};
|
||||||
|
ParserKeyword s_ephemeral{"EPHEMERAL"};
|
||||||
ParserKeyword s_alias{"ALIAS"};
|
ParserKeyword s_alias{"ALIAS"};
|
||||||
ParserKeyword s_comment{"COMMENT"};
|
ParserKeyword s_comment{"COMMENT"};
|
||||||
ParserKeyword s_codec{"CODEC"};
|
ParserKeyword s_codec{"CODEC"};
|
||||||
@ -171,6 +172,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
|||||||
|
|
||||||
if (!s_default.checkWithoutMoving(pos, expected)
|
if (!s_default.checkWithoutMoving(pos, expected)
|
||||||
&& !s_materialized.checkWithoutMoving(pos, expected)
|
&& !s_materialized.checkWithoutMoving(pos, expected)
|
||||||
|
&& !s_ephemeral.checkWithoutMoving(pos, expected)
|
||||||
&& !s_alias.checkWithoutMoving(pos, expected)
|
&& !s_alias.checkWithoutMoving(pos, expected)
|
||||||
&& (require_type
|
&& (require_type
|
||||||
|| (!s_comment.checkWithoutMoving(pos, expected)
|
|| (!s_comment.checkWithoutMoving(pos, expected)
|
||||||
@ -190,6 +192,9 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
|||||||
/// should be followed by an expression
|
/// should be followed by an expression
|
||||||
if (!expr_parser.parse(pos, default_expression, expected))
|
if (!expr_parser.parse(pos, default_expression, expected))
|
||||||
return false;
|
return false;
|
||||||
|
} else if (s_ephemeral.ignore(pos, expected)) {
|
||||||
|
default_specifier = Poco::toUpper(std::string{pos_before_specifier->begin, pos_before_specifier->end});
|
||||||
|
expr_parser.parse(pos, default_expression, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require_type && !type && !default_expression)
|
if (require_type && !type && !default_expression)
|
||||||
|
@ -26,20 +26,20 @@ namespace
|
|||||||
|
|
||||||
const std::unordered_set<std::string_view> keywords
|
const std::unordered_set<std::string_view> keywords
|
||||||
{
|
{
|
||||||
"CREATE", "DATABASE", "IF", "NOT", "EXISTS", "TEMPORARY", "TABLE", "ON", "CLUSTER", "DEFAULT",
|
"CREATE", "DATABASE", "IF", "NOT", "EXISTS", "TEMPORARY", "TABLE", "ON", "CLUSTER", "DEFAULT",
|
||||||
"MATERIALIZED", "ALIAS", "ENGINE", "AS", "VIEW", "POPULATE", "SETTINGS", "ATTACH", "DETACH", "DROP",
|
"MATERIALIZED", "EPHEMERAL", "ALIAS", "ENGINE", "AS", "VIEW", "POPULATE", "SETTINGS", "ATTACH", "DETACH",
|
||||||
"RENAME", "TO", "ALTER", "ADD", "MODIFY", "CLEAR", "COLUMN", "AFTER", "COPY", "PROJECT",
|
"DROP", "RENAME", "TO", "ALTER", "ADD", "MODIFY", "CLEAR", "COLUMN", "AFTER", "COPY",
|
||||||
"PRIMARY", "KEY", "CHECK", "PARTITION", "PART", "FREEZE", "FETCH", "FROM", "SHOW", "INTO",
|
"PROJECT", "PRIMARY", "KEY", "CHECK", "PARTITION", "PART", "FREEZE", "FETCH", "FROM", "SHOW",
|
||||||
"OUTFILE", "FORMAT", "TABLES", "DATABASES", "LIKE", "PROCESSLIST", "CASE", "WHEN", "THEN", "ELSE",
|
"INTO", "OUTFILE", "FORMAT", "TABLES", "DATABASES", "LIKE", "PROCESSLIST", "CASE", "WHEN", "THEN",
|
||||||
"END", "DESCRIBE", "DESC", "USE", "SET", "OPTIMIZE", "FINAL", "DEDUPLICATE", "INSERT", "VALUES",
|
"ELSE", "END", "DESCRIBE", "DESC", "USE", "SET", "OPTIMIZE", "FINAL", "DEDUPLICATE", "INSERT",
|
||||||
"SELECT", "DISTINCT", "SAMPLE", "ARRAY", "JOIN", "GLOBAL", "LOCAL", "ANY", "ALL", "INNER",
|
"VALUES", "SELECT", "DISTINCT", "SAMPLE", "ARRAY", "JOIN", "GLOBAL", "LOCAL", "ANY", "ALL",
|
||||||
"LEFT", "RIGHT", "FULL", "OUTER", "CROSS", "USING", "PREWHERE", "WHERE", "GROUP", "BY",
|
"INNER", "LEFT", "RIGHT", "FULL", "OUTER", "CROSS", "USING", "PREWHERE", "WHERE", "GROUP",
|
||||||
"WITH", "TOTALS", "HAVING", "ORDER", "COLLATE", "LIMIT", "UNION", "AND", "OR", "ASC",
|
"BY", "WITH", "TOTALS", "HAVING", "ORDER", "COLLATE", "LIMIT", "UNION", "AND", "OR",
|
||||||
"IN", "KILL", "QUERY", "SYNC", "ASYNC", "TEST", "BETWEEN", "TRUNCATE", "USER", "ROLE",
|
"ASC", "IN", "KILL", "QUERY", "SYNC", "ASYNC", "TEST", "BETWEEN", "TRUNCATE", "USER",
|
||||||
"PROFILE", "QUOTA", "POLICY", "ROW", "GRANT", "REVOKE", "OPTION", "ADMIN", "EXCEPT", "REPLACE",
|
"ROLE", "PROFILE", "QUOTA", "POLICY", "ROW", "GRANT", "REVOKE", "OPTION", "ADMIN", "EXCEPT",
|
||||||
"IDENTIFIED", "HOST", "NAME", "READONLY", "WRITABLE", "PERMISSIVE", "FOR", "RESTRICTIVE", "RANDOMIZED",
|
"REPLACE", "IDENTIFIED", "HOST", "NAME", "READONLY", "WRITABLE", "PERMISSIVE", "FOR", "RESTRICTIVE", "RANDOMIZED",
|
||||||
"INTERVAL", "LIMITS", "ONLY", "TRACKING", "IP", "REGEXP", "ILIKE", "DICTIONARY", "OFFSET",
|
"INTERVAL", "LIMITS", "ONLY", "TRACKING", "IP", "REGEXP", "ILIKE", "DICTIONARY", "OFFSET", "TRIM",
|
||||||
"TRIM", "LTRIM", "RTRIM", "BOTH", "LEADING", "TRAILING"
|
"LTRIM", "RTRIM", "BOTH", "LEADING", "TRAILING"
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::unordered_set<std::string_view> keep_words
|
const std::unordered_set<std::string_view> keep_words
|
||||||
|
@ -9,6 +9,7 @@ struct AliasNames
|
|||||||
static constexpr const char * DEFAULT = "DEFAULT";
|
static constexpr const char * DEFAULT = "DEFAULT";
|
||||||
static constexpr const char * MATERIALIZED = "MATERIALIZED";
|
static constexpr const char * MATERIALIZED = "MATERIALIZED";
|
||||||
static constexpr const char * ALIAS = "ALIAS";
|
static constexpr const char * ALIAS = "ALIAS";
|
||||||
|
static constexpr const char * EPHEMERAL = "EPHEMERAL";
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -27,7 +28,8 @@ ColumnDefaultKind columnDefaultKindFromString(const std::string & str)
|
|||||||
static const std::unordered_map<std::string, ColumnDefaultKind> map{
|
static const std::unordered_map<std::string, ColumnDefaultKind> map{
|
||||||
{ AliasNames::DEFAULT, ColumnDefaultKind::Default },
|
{ AliasNames::DEFAULT, ColumnDefaultKind::Default },
|
||||||
{ AliasNames::MATERIALIZED, ColumnDefaultKind::Materialized },
|
{ AliasNames::MATERIALIZED, ColumnDefaultKind::Materialized },
|
||||||
{ AliasNames::ALIAS, ColumnDefaultKind::Alias }
|
{ AliasNames::ALIAS, ColumnDefaultKind::Alias },
|
||||||
|
{ AliasNames::EPHEMERAL, ColumnDefaultKind::Ephemeral }
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto it = map.find(str);
|
const auto it = map.find(str);
|
||||||
@ -43,7 +45,8 @@ std::string toString(const ColumnDefaultKind kind)
|
|||||||
static const std::unordered_map<ColumnDefaultKind, std::string> map{
|
static const std::unordered_map<ColumnDefaultKind, std::string> map{
|
||||||
{ ColumnDefaultKind::Default, AliasNames::DEFAULT },
|
{ ColumnDefaultKind::Default, AliasNames::DEFAULT },
|
||||||
{ ColumnDefaultKind::Materialized, AliasNames::MATERIALIZED },
|
{ ColumnDefaultKind::Materialized, AliasNames::MATERIALIZED },
|
||||||
{ ColumnDefaultKind::Alias, AliasNames::ALIAS }
|
{ ColumnDefaultKind::Alias, AliasNames::ALIAS },
|
||||||
|
{ ColumnDefaultKind::Ephemeral, AliasNames::EPHEMERAL }
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto it = map.find(kind);
|
const auto it = map.find(kind);
|
||||||
|
@ -13,7 +13,8 @@ enum class ColumnDefaultKind
|
|||||||
{
|
{
|
||||||
Default,
|
Default,
|
||||||
Materialized,
|
Materialized,
|
||||||
Alias
|
Alias,
|
||||||
|
Ephemeral
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -340,6 +340,15 @@ NamesAndTypesList ColumnsDescription::getOrdinary() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NamesAndTypesList ColumnsDescription::getInsertable() const
|
||||||
|
{
|
||||||
|
NamesAndTypesList ret;
|
||||||
|
for (const auto & col : columns)
|
||||||
|
if (col.default_desc.kind == ColumnDefaultKind::Default || col.default_desc.kind == ColumnDefaultKind::Ephemeral)
|
||||||
|
ret.emplace_back(col.name, col.type);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
NamesAndTypesList ColumnsDescription::getMaterialized() const
|
NamesAndTypesList ColumnsDescription::getMaterialized() const
|
||||||
{
|
{
|
||||||
NamesAndTypesList ret;
|
NamesAndTypesList ret;
|
||||||
@ -358,6 +367,15 @@ NamesAndTypesList ColumnsDescription::getAliases() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NamesAndTypesList ColumnsDescription::getEphemeral() const
|
||||||
|
{
|
||||||
|
NamesAndTypesList ret;
|
||||||
|
for (const auto & col : columns)
|
||||||
|
if (col.default_desc.kind == ColumnDefaultKind::Ephemeral)
|
||||||
|
ret.emplace_back(col.name, col.type);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
NamesAndTypesList ColumnsDescription::getAll() const
|
NamesAndTypesList ColumnsDescription::getAll() const
|
||||||
{
|
{
|
||||||
NamesAndTypesList ret;
|
NamesAndTypesList ret;
|
||||||
@ -402,6 +420,8 @@ static ColumnsDescription::GetFlags defaultKindToGetFlag(ColumnDefaultKind kind)
|
|||||||
return ColumnsDescription::Materialized;
|
return ColumnsDescription::Materialized;
|
||||||
case ColumnDefaultKind::Alias:
|
case ColumnDefaultKind::Alias:
|
||||||
return ColumnsDescription::Aliases;
|
return ColumnsDescription::Aliases;
|
||||||
|
case ColumnDefaultKind::Ephemeral:
|
||||||
|
return ColumnsDescription::Ephemeral;
|
||||||
}
|
}
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
@ -84,18 +84,21 @@ public:
|
|||||||
Ordinary = 1,
|
Ordinary = 1,
|
||||||
Materialized = 2,
|
Materialized = 2,
|
||||||
Aliases = 4,
|
Aliases = 4,
|
||||||
|
Ephemeral = 8,
|
||||||
|
|
||||||
AllPhysical = Ordinary | Materialized,
|
AllPhysical = Ordinary | Materialized,
|
||||||
All = AllPhysical | Aliases,
|
All = AllPhysical | Aliases | Ephemeral,
|
||||||
};
|
};
|
||||||
|
|
||||||
NamesAndTypesList getByNames(GetFlags flags, const Names & names, bool with_subcolumns) const;
|
NamesAndTypesList getByNames(GetFlags flags, const Names & names, bool with_subcolumns) const;
|
||||||
|
|
||||||
NamesAndTypesList getOrdinary() const;
|
NamesAndTypesList getOrdinary() const;
|
||||||
NamesAndTypesList getMaterialized() const;
|
NamesAndTypesList getMaterialized() const;
|
||||||
|
NamesAndTypesList getInsertable() const;
|
||||||
NamesAndTypesList getAliases() const;
|
NamesAndTypesList getAliases() const;
|
||||||
|
NamesAndTypesList getEphemeral() const;
|
||||||
NamesAndTypesList getAllPhysical() const; /// ordinary + materialized.
|
NamesAndTypesList getAllPhysical() const; /// ordinary + materialized.
|
||||||
NamesAndTypesList getAll() const; /// ordinary + materialized + aliases
|
NamesAndTypesList getAll() const; /// ordinary + materialized + aliases + ephemeral
|
||||||
NamesAndTypesList getAllWithSubcolumns() const;
|
NamesAndTypesList getAllWithSubcolumns() const;
|
||||||
NamesAndTypesList getAllPhysicalWithSubcolumns() const;
|
NamesAndTypesList getAllPhysicalWithSubcolumns() const;
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ Block StorageInMemoryMetadata::getSampleBlockNonMaterialized() const
|
|||||||
{
|
{
|
||||||
Block res;
|
Block res;
|
||||||
|
|
||||||
for (const auto & column : getColumns().getOrdinary())
|
for (const auto & column : getColumns().getInsertable())
|
||||||
res.insert({column.type->createColumn(), column.type, column.name});
|
res.insert({column.type->createColumn(), column.type, column.name});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user