mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 18:12:02 +00:00
Merge pull request #55060 from vitlibar/fix-detecting-column-default-for-dist-table
Fix detecting DEFAULT for columns of a Distributed table created without AS
This commit is contained in:
commit
d841b8179e
@ -149,6 +149,12 @@ ASTPtr getCreateQueryFromStorage(const StoragePtr & storage, const ASTPtr & ast_
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
ast_column_declaration->type = ast_type;
|
ast_column_declaration->type = ast_type;
|
||||||
|
|
||||||
|
if (auto column_default = metadata_ptr->columns.getDefault(column_name_and_type.name))
|
||||||
|
{
|
||||||
|
ast_column_declaration->default_specifier = toString(column_default->kind);
|
||||||
|
ast_column_declaration->default_expression = column_default->expression;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast_expression_list->children.emplace_back(ast_column_declaration);
|
ast_expression_list->children.emplace_back(ast_column_declaration);
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ CREATE TABLE system.clusters
|
|||||||
`database_shard_name` String,
|
`database_shard_name` String,
|
||||||
`database_replica_name` String,
|
`database_replica_name` String,
|
||||||
`is_active` Nullable(UInt8),
|
`is_active` Nullable(UInt8),
|
||||||
`name` String
|
`name` String ALIAS cluster
|
||||||
)
|
)
|
||||||
ENGINE = SystemClusters
|
ENGINE = SystemClusters
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -134,7 +134,7 @@ CREATE TABLE system.databases
|
|||||||
`uuid` UUID,
|
`uuid` UUID,
|
||||||
`engine_full` String,
|
`engine_full` String,
|
||||||
`comment` String,
|
`comment` String,
|
||||||
`database` String
|
`database` String ALIAS name
|
||||||
)
|
)
|
||||||
ENGINE = SystemDatabases
|
ENGINE = SystemDatabases
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -265,7 +265,7 @@ CREATE TABLE system.events
|
|||||||
`event` String,
|
`event` String,
|
||||||
`value` UInt64,
|
`value` UInt64,
|
||||||
`description` String,
|
`description` String,
|
||||||
`name` String
|
`name` String ALIAS event
|
||||||
)
|
)
|
||||||
ENGINE = SystemEvents
|
ENGINE = SystemEvents
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -376,7 +376,7 @@ CREATE TABLE system.metrics
|
|||||||
`metric` String,
|
`metric` String,
|
||||||
`value` Int64,
|
`value` Int64,
|
||||||
`description` String,
|
`description` String,
|
||||||
`name` String
|
`name` String ALIAS metric
|
||||||
)
|
)
|
||||||
ENGINE = SystemMetrics
|
ENGINE = SystemMetrics
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -513,9 +513,9 @@ CREATE TABLE system.parts
|
|||||||
`has_lightweight_delete` UInt8,
|
`has_lightweight_delete` UInt8,
|
||||||
`last_removal_attempt_time` DateTime,
|
`last_removal_attempt_time` DateTime,
|
||||||
`removal_state` String,
|
`removal_state` String,
|
||||||
`bytes` UInt64,
|
`bytes` UInt64 ALIAS bytes_on_disk,
|
||||||
`marks_size` UInt64,
|
`marks_size` UInt64 ALIAS marks_bytes,
|
||||||
`part_name` String
|
`part_name` String ALIAS name
|
||||||
)
|
)
|
||||||
ENGINE = SystemParts
|
ENGINE = SystemParts
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -569,9 +569,9 @@ CREATE TABLE system.parts_columns
|
|||||||
`subcolumns.data_compressed_bytes` Array(UInt64),
|
`subcolumns.data_compressed_bytes` Array(UInt64),
|
||||||
`subcolumns.data_uncompressed_bytes` Array(UInt64),
|
`subcolumns.data_uncompressed_bytes` Array(UInt64),
|
||||||
`subcolumns.marks_bytes` Array(UInt64),
|
`subcolumns.marks_bytes` Array(UInt64),
|
||||||
`bytes` UInt64,
|
`bytes` UInt64 ALIAS bytes_on_disk,
|
||||||
`marks_size` UInt64,
|
`marks_size` UInt64 ALIAS marks_bytes,
|
||||||
`part_name` String
|
`part_name` String ALIAS name
|
||||||
)
|
)
|
||||||
ENGINE = SystemPartsColumns
|
ENGINE = SystemPartsColumns
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -616,10 +616,10 @@ CREATE TABLE system.processes
|
|||||||
`ProfileEvents` Map(String, UInt64),
|
`ProfileEvents` Map(String, UInt64),
|
||||||
`Settings` Map(String, String),
|
`Settings` Map(String, String),
|
||||||
`current_database` String,
|
`current_database` String,
|
||||||
`ProfileEvents.Names` Array(String),
|
`ProfileEvents.Names` Array(String) ALIAS mapKeys(ProfileEvents),
|
||||||
`ProfileEvents.Values` Array(UInt64),
|
`ProfileEvents.Values` Array(UInt64) ALIAS mapValues(ProfileEvents),
|
||||||
`Settings.Names` Array(String),
|
`Settings.Names` Array(String) ALIAS mapKeys(Settings),
|
||||||
`Settings.Values` Array(String)
|
`Settings.Values` Array(String) ALIAS mapValues(Settings)
|
||||||
)
|
)
|
||||||
ENGINE = SystemProcesses
|
ENGINE = SystemProcesses
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -682,9 +682,9 @@ CREATE TABLE system.projection_parts
|
|||||||
`rows_where_ttl_info.expression` Array(String),
|
`rows_where_ttl_info.expression` Array(String),
|
||||||
`rows_where_ttl_info.min` Array(DateTime),
|
`rows_where_ttl_info.min` Array(DateTime),
|
||||||
`rows_where_ttl_info.max` Array(DateTime),
|
`rows_where_ttl_info.max` Array(DateTime),
|
||||||
`bytes` UInt64,
|
`bytes` UInt64 ALIAS bytes_on_disk,
|
||||||
`marks_size` UInt64,
|
`marks_size` UInt64 ALIAS marks_bytes,
|
||||||
`part_name` String
|
`part_name` String ALIAS name
|
||||||
)
|
)
|
||||||
ENGINE = SystemProjectionParts
|
ENGINE = SystemProjectionParts
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -738,9 +738,9 @@ CREATE TABLE system.projection_parts_columns
|
|||||||
`column_data_uncompressed_bytes` UInt64,
|
`column_data_uncompressed_bytes` UInt64,
|
||||||
`column_marks_bytes` UInt64,
|
`column_marks_bytes` UInt64,
|
||||||
`column_modification_time` Nullable(DateTime),
|
`column_modification_time` Nullable(DateTime),
|
||||||
`bytes` UInt64,
|
`bytes` UInt64 ALIAS bytes_on_disk,
|
||||||
`marks_size` UInt64,
|
`marks_size` UInt64 ALIAS marks_bytes,
|
||||||
`part_name` String
|
`part_name` String ALIAS name
|
||||||
)
|
)
|
||||||
ENGINE = SystemProjectionPartsColumns
|
ENGINE = SystemProjectionPartsColumns
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
@ -1094,7 +1094,7 @@ CREATE TABLE system.tables
|
|||||||
`loading_dependencies_table` Array(String),
|
`loading_dependencies_table` Array(String),
|
||||||
`loading_dependent_database` Array(String),
|
`loading_dependent_database` Array(String),
|
||||||
`loading_dependent_table` Array(String),
|
`loading_dependent_table` Array(String),
|
||||||
`table` String
|
`table` String ALIAS name
|
||||||
)
|
)
|
||||||
ENGINE = SystemTables
|
ENGINE = SystemTables
|
||||||
COMMENT 'SYSTEM TABLE is built on the fly.'
|
COMMENT 'SYSTEM TABLE is built on the fly.'
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE default.dist_tbl\n(\n `key` UInt32,\n `value` UInt32 DEFAULT 42\n)\nENGINE = Distributed(\'test_shard_localhost\', \'default\', \'local_tbl\', rand())
|
||||||
|
local_tbl
|
||||||
|
99 42
|
||||||
|
dist_tbl
|
||||||
|
99 42
|
@ -0,0 +1,16 @@
|
|||||||
|
-- Here a Distributed table without AS must detect its structure.
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS dist_tbl;
|
||||||
|
DROP TABLE IF EXISTS local_tbl;
|
||||||
|
|
||||||
|
CREATE TABLE local_tbl (`key` UInt32, `value` UInt32 DEFAULT 42) ENGINE = MergeTree ORDER BY key;
|
||||||
|
CREATE TABLE dist_tbl ENGINE = Distributed('test_shard_localhost', currentDatabase(), 'local_tbl', rand());
|
||||||
|
SHOW CREATE TABLE dist_tbl;
|
||||||
|
INSERT INTO dist_tbl (key) SETTINGS insert_distributed_sync=1 VALUES (99);
|
||||||
|
SELECT 'local_tbl';
|
||||||
|
SELECT * FROM local_tbl;
|
||||||
|
SELECT 'dist_tbl';
|
||||||
|
SELECT * FROM dist_tbl;
|
||||||
|
|
||||||
|
DROP TABLE dist_tbl;
|
||||||
|
DROP TABLE local_tbl;
|
Loading…
Reference in New Issue
Block a user