Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
5bc7f67e
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5bc7f67e
编写于
6月 05, 2020
作者:
A
alesapin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better metadata for select query and renames
上级
5c07970f
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
103 addition
and
193 deletion
+103
-193
src/DataStreams/PushingToViewsBlockOutputStream.cpp
src/DataStreams/PushingToViewsBlockOutputStream.cpp
+1
-1
src/Storages/IStorage.cpp
src/Storages/IStorage.cpp
+33
-8
src/Storages/IStorage.h
src/Storages/IStorage.h
+26
-12
src/Storages/LiveView/StorageLiveView.h
src/Storages/LiveView/StorageLiveView.h
+1
-0
src/Storages/MergeTree/MergeTreeData.cpp
src/Storages/MergeTree/MergeTreeData.cpp
+12
-11
src/Storages/MergeTree/MergeTreeData.h
src/Storages/MergeTree/MergeTreeData.h
+0
-2
src/Storages/StorageInMemoryMetadata.cpp
src/Storages/StorageInMemoryMetadata.cpp
+0
-34
src/Storages/StorageInMemoryMetadata.h
src/Storages/StorageInMemoryMetadata.h
+0
-30
src/Storages/StorageMaterializedView.cpp
src/Storages/StorageMaterializedView.cpp
+18
-80
src/Storages/StorageMaterializedView.h
src/Storages/StorageMaterializedView.h
+0
-7
src/Storages/StorageView.cpp
src/Storages/StorageView.cpp
+7
-3
src/Storages/StorageView.h
src/Storages/StorageView.h
+0
-3
src/Storages/TTLDescription.cpp
src/Storages/TTLDescription.cpp
+1
-1
src/Storages/TTLDescription.h
src/Storages/TTLDescription.h
+2
-1
src/Storages/ya.make
src/Storages/ya.make
+2
-0
未找到文件。
src/DataStreams/PushingToViewsBlockOutputStream.cpp
浏览文件 @
5bc7f67e
...
...
@@ -72,7 +72,7 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
StoragePtr
inner_table
=
materialized_view
->
getTargetTable
();
auto
inner_table_id
=
inner_table
->
getStorageID
();
query
=
materialized_view
->
get
InnerQuery
()
;
query
=
materialized_view
->
get
SelectQuery
().
inner_query
;
std
::
unique_ptr
<
ASTInsertQuery
>
insert
=
std
::
make_unique
<
ASTInsertQuery
>
();
insert
->
table_id
=
inner_table_id
;
...
...
src/Storages/IStorage.cpp
浏览文件 @
5bc7f67e
...
...
@@ -421,12 +421,12 @@ NamesAndTypesList IStorage::getVirtuals() const
return
{};
}
const
StorageMetadataKeyField
&
IStorage
::
getPartitionKey
()
const
const
KeyDescription
&
IStorage
::
getPartitionKey
()
const
{
return
partition_key
;
}
void
IStorage
::
setPartitionKey
(
const
StorageMetadataKeyField
&
partition_key_
)
void
IStorage
::
setPartitionKey
(
const
KeyDescription
&
partition_key_
)
{
partition_key
=
partition_key_
;
}
...
...
@@ -448,12 +448,12 @@ Names IStorage::getColumnsRequiredForPartitionKey() const
return
{};
}
const
StorageMetadataKeyField
&
IStorage
::
getSortingKey
()
const
const
KeyDescription
&
IStorage
::
getSortingKey
()
const
{
return
sorting_key
;
}
void
IStorage
::
setSortingKey
(
const
StorageMetadataKeyField
&
sorting_key_
)
void
IStorage
::
setSortingKey
(
const
KeyDescription
&
sorting_key_
)
{
sorting_key
=
sorting_key_
;
}
...
...
@@ -482,12 +482,12 @@ Names IStorage::getSortingKeyColumns() const
return
{};
}
const
StorageMetadataKeyField
&
IStorage
::
getPrimaryKey
()
const
const
KeyDescription
&
IStorage
::
getPrimaryKey
()
const
{
return
primary_key
;
}
void
IStorage
::
setPrimaryKey
(
const
StorageMetadataKeyField
&
primary_key_
)
void
IStorage
::
setPrimaryKey
(
const
KeyDescription
&
primary_key_
)
{
primary_key
=
primary_key_
;
}
...
...
@@ -516,12 +516,12 @@ Names IStorage::getPrimaryKeyColumns() const
return
{};
}
const
StorageMetadataKeyField
&
IStorage
::
getSamplingKey
()
const
const
KeyDescription
&
IStorage
::
getSamplingKey
()
const
{
return
sampling_key
;
}
void
IStorage
::
setSamplingKey
(
const
StorageMetadataKeyField
&
sampling_key_
)
void
IStorage
::
setSamplingKey
(
const
KeyDescription
&
sampling_key_
)
{
sampling_key
=
sampling_key_
;
}
...
...
@@ -654,4 +654,29 @@ ColumnDependencies IStorage::getColumnDependencies(const NameSet & updated_colum
}
ASTPtr
IStorage
::
getSettingsChanges
()
const
{
return
settings_changes
->
clone
();
}
void
IStorage
::
setSettingsChanges
(
const
ASTPtr
&
settings_changes_
)
{
settings_changes
=
settings_changes_
->
clone
();
}
const
SelectQueryDescription
&
IStorage
::
getSelectQuery
()
const
{
return
select
;
}
void
IStorage
::
setSelectQuery
(
const
SelectQueryDescription
&
select_
)
{
select
=
select_
;
}
bool
IStorage
::
hasSelectQuery
()
const
{
return
select
.
select_query
!=
nullptr
;
}
}
src/Storages/IStorage.h
浏览文件 @
5bc7f67e
...
...
@@ -15,7 +15,9 @@
#include <Storages/ConstraintsDescription.h>
#include <Storages/StorageInMemoryMetadata.h>
#include <Storages/TTLDescription.h>
#include <Storages/KeyDescription.h>
#include <Storages/ColumnDependency.h>
#include <Storages/SelectQueryDescription.h>
#include <Common/ActionLock.h>
#include <Common/Exception.h>
#include <Common/RWLock.h>
...
...
@@ -152,6 +154,15 @@ public: /// thread-unsafe part. lockStructure must be acquired
const
ConstraintsDescription
&
getConstraints
()
const
;
void
setConstraints
(
ConstraintsDescription
constraints_
);
/// Storage settings
ASTPtr
getSettingsChanges
()
const
;
void
setSettingsChanges
(
const
ASTPtr
&
settings_changes_
);
bool
hasSettingsChanges
()
const
{
return
settings_changes
!=
nullptr
;
}
const
SelectQueryDescription
&
getSelectQuery
()
const
;
void
setSelectQuery
(
const
SelectQueryDescription
&
select_
);
bool
hasSelectQuery
()
const
;
/// Returns storage metadata copy. Direct modification of
/// result structure doesn't affect storage.
virtual
StorageInMemoryMetadata
getInMemoryMetadata
()
const
;
...
...
@@ -203,14 +214,17 @@ private:
IndicesDescription
secondary_indices
;
ConstraintsDescription
constraints
;
StorageMetadataKeyField
partition_key
;
StorageMetadataKeyField
primary_key
;
StorageMetadataKeyField
sorting_key
;
StorageMetadataKeyField
sampling_key
;
KeyDescription
partition_key
;
KeyDescription
primary_key
;
KeyDescription
sorting_key
;
KeyDescription
sampling_key
;
TTLColumnsDescription
column_ttls_by_name
;
TTLTableDescription
table_ttl
;
ASTPtr
settings_changes
;
SelectQueryDescription
select
;
private:
RWLockImpl
::
LockHolder
tryLockTimed
(
const
RWLock
&
rwlock
,
RWLockImpl
::
Type
type
,
const
String
&
query_id
,
const
SettingSeconds
&
acquire_timeout
)
const
;
...
...
@@ -443,10 +457,10 @@ public:
virtual
Strings
getDataPaths
()
const
{
return
{};
}
/// Returns structure with partition key.
const
StorageMetadataKeyField
&
getPartitionKey
()
const
;
const
KeyDescription
&
getPartitionKey
()
const
;
/// Set partition key for storage (methods bellow, are just wrappers for this
/// struct).
void
setPartitionKey
(
const
StorageMetadataKeyField
&
partition_key_
);
void
setPartitionKey
(
const
KeyDescription
&
partition_key_
);
/// Returns ASTExpressionList of partition key expression for storage or nullptr if there is none.
ASTPtr
getPartitionKeyAST
()
const
{
return
partition_key
.
definition_ast
;
}
/// Storage has user-defined (in CREATE query) partition key.
...
...
@@ -458,10 +472,10 @@ public:
/// Returns structure with sorting key.
const
StorageMetadataKeyField
&
getSortingKey
()
const
;
const
KeyDescription
&
getSortingKey
()
const
;
/// Set sorting key for storage (methods bellow, are just wrappers for this
/// struct).
void
setSortingKey
(
const
StorageMetadataKeyField
&
sorting_key_
);
void
setSortingKey
(
const
KeyDescription
&
sorting_key_
);
/// Returns ASTExpressionList of sorting key expression for storage or nullptr if there is none.
ASTPtr
getSortingKeyAST
()
const
{
return
sorting_key
.
definition_ast
;
}
/// Storage has user-defined (in CREATE query) sorting key.
...
...
@@ -475,10 +489,10 @@ public:
Names
getSortingKeyColumns
()
const
;
/// Returns structure with primary key.
const
StorageMetadataKeyField
&
getPrimaryKey
()
const
;
const
KeyDescription
&
getPrimaryKey
()
const
;
/// Set primary key for storage (methods bellow, are just wrappers for this
/// struct).
void
setPrimaryKey
(
const
StorageMetadataKeyField
&
primary_key_
);
void
setPrimaryKey
(
const
KeyDescription
&
primary_key_
);
/// Returns ASTExpressionList of primary key expression for storage or nullptr if there is none.
ASTPtr
getPrimaryKeyAST
()
const
{
return
primary_key
.
definition_ast
;
}
/// Storage has user-defined (in CREATE query) sorting key.
...
...
@@ -493,10 +507,10 @@ public:
Names
getPrimaryKeyColumns
()
const
;
/// Returns structure with sampling key.
const
StorageMetadataKeyField
&
getSamplingKey
()
const
;
const
KeyDescription
&
getSamplingKey
()
const
;
/// Set sampling key for storage (methods bellow, are just wrappers for this
/// struct).
void
setSamplingKey
(
const
StorageMetadataKeyField
&
sampling_key_
);
void
setSamplingKey
(
const
KeyDescription
&
sampling_key_
);
/// Returns sampling expression AST for storage or nullptr if there is none.
ASTPtr
getSamplingKeyAST
()
const
{
return
sampling_key
.
definition_ast
;
}
/// Storage has user-defined (in CREATE query) sampling key.
...
...
src/Storages/LiveView/StorageLiveView.h
浏览文件 @
5bc7f67e
...
...
@@ -165,6 +165,7 @@ public:
const
Context
&
context
);
private:
/// TODO move to common struct SelectQueryDescription
StorageID
select_table_id
=
StorageID
::
createEmpty
();
/// Will be initialized in constructor
ASTPtr
inner_query
;
/// stored query : SELECT * FROM ( SELECT a FROM A)
ASTPtr
inner_subquery
;
/// stored query's innermost subquery if any
...
...
src/Storages/MergeTree/MergeTreeData.cpp
浏览文件 @
5bc7f67e
...
...
@@ -131,7 +131,6 @@ MergeTreeData::MergeTreeData(
:
IStorage
(
table_id_
)
,
global_context
(
context_
)
,
merging_params
(
merging_params_
)
,
settings_ast
(
metadata
.
settings_ast
)
,
require_part_metadata
(
require_part_metadata_
)
,
relative_data_path
(
relative_data_path_
)
,
broken_part_callback
(
broken_part_callback_
)
...
...
@@ -145,6 +144,7 @@ MergeTreeData::MergeTreeData(
if
(
relative_data_path
.
empty
())
throw
Exception
(
"MergeTree storages require data path"
,
ErrorCodes
::
INCORRECT_FILE_NAME
);
setSettingsChanges
(
metadata
.
settings_ast
);
const
auto
settings
=
getSettings
();
setProperties
(
metadata
,
/*only_check*/
false
,
attach
);
...
...
@@ -153,7 +153,7 @@ MergeTreeData::MergeTreeData(
if
(
metadata
.
sample_by_ast
!=
nullptr
)
{
StorageMetadataKeyField
candidate_sampling_key
=
StorageMetadataKeyField
::
getKeyFromAST
(
metadata
.
sample_by_ast
,
getColumns
(),
global_context
);
KeyDescription
candidate_sampling_key
=
KeyDescription
::
getKeyFromAST
(
metadata
.
sample_by_ast
,
getColumns
(),
global_context
);
const
auto
&
pk_sample_block
=
getPrimaryKey
().
sample_block
;
if
(
!
pk_sample_block
.
has
(
candidate_sampling_key
.
column_names
[
0
])
&&
!
attach
...
...
@@ -265,8 +265,8 @@ StorageInMemoryMetadata MergeTreeData::getInMemoryMetadata() const
if
(
isSamplingKeyDefined
())
metadata
.
sample_by_ast
=
getSamplingKeyAST
()
->
clone
();
if
(
settings_ast
)
metadata
.
settings_ast
=
settings_ast
->
clone
();
if
(
hasSettingsChanges
()
)
metadata
.
settings_ast
=
getSettingsChanges
();
return
metadata
;
}
...
...
@@ -444,7 +444,7 @@ void MergeTreeData::setProperties(const StorageInMemoryMetadata & metadata, bool
{
setColumns
(
std
::
move
(
metadata
.
columns
));
StorageMetadataKeyField
new_sorting_key
;
KeyDescription
new_sorting_key
;
new_sorting_key
.
definition_ast
=
metadata
.
order_by_ast
;
new_sorting_key
.
column_names
=
std
::
move
(
new_sorting_key_columns
);
new_sorting_key
.
expression_list_ast
=
std
::
move
(
new_sorting_key_expr_list
);
...
...
@@ -453,7 +453,7 @@ void MergeTreeData::setProperties(const StorageInMemoryMetadata & metadata, bool
new_sorting_key
.
data_types
=
std
::
move
(
new_sorting_key_data_types
);
setSortingKey
(
new_sorting_key
);
StorageMetadataKeyField
new_primary_key
;
KeyDescription
new_primary_key
;
new_primary_key
.
definition_ast
=
metadata
.
primary_key_ast
;
new_primary_key
.
column_names
=
std
::
move
(
new_primary_key_columns
);
new_primary_key
.
expression_list_ast
=
std
::
move
(
new_primary_key_expr_list
);
...
...
@@ -472,7 +472,7 @@ namespace
{
ExpressionActionsPtr
getCombinedIndicesExpression
(
const
StorageMetadataKeyField
&
key
,
const
KeyDescription
&
key
,
const
IndicesDescription
&
indices
,
const
ColumnsDescription
&
columns
,
const
Context
&
context
)
...
...
@@ -523,7 +523,7 @@ ASTPtr MergeTreeData::extractKeyExpressionList(const ASTPtr & node)
void
MergeTreeData
::
initPartitionKey
(
ASTPtr
partition_by_ast
)
{
StorageMetadataKeyField
new_partition_key
=
StorageMetadataKeyField
::
getKeyFromAST
(
partition_by_ast
,
getColumns
(),
global_context
);
KeyDescription
new_partition_key
=
KeyDescription
::
getKeyFromAST
(
partition_by_ast
,
getColumns
(),
global_context
);
if
(
new_partition_key
.
expression_list_ast
->
children
.
empty
())
return
;
...
...
@@ -1460,9 +1460,10 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, const S
setTTLExpressions
(
metadata
.
columns
,
metadata
.
ttl_for_table_ast
,
/* only_check = */
true
);
if
(
settings_ast
)
if
(
hasSettingsChanges
()
)
{
const
auto
&
current_changes
=
settings_ast
->
as
<
const
ASTSetQuery
&>
().
changes
;
const
auto
&
current_changes
=
getSettingsChanges
()
->
as
<
const
ASTSetQuery
&>
().
changes
;
const
auto
&
new_changes
=
metadata
.
settings_ast
->
as
<
const
ASTSetQuery
&>
().
changes
;
for
(
const
auto
&
changed_setting
:
new_changes
)
{
...
...
@@ -1601,7 +1602,7 @@ void MergeTreeData::changeSettings(
MergeTreeSettings
copy
=
*
getSettings
();
copy
.
applyChanges
(
new_changes
);
storage_settings
.
set
(
std
::
make_unique
<
const
MergeTreeSettings
>
(
copy
));
set
tings_ast
=
new_settings
;
set
SettingsChanges
(
new_settings
)
;
}
}
...
...
src/Storages/MergeTree/MergeTreeData.h
浏览文件 @
5bc7f67e
...
...
@@ -677,8 +677,6 @@ protected:
friend
struct
ReplicatedMergeTreeTableMetadata
;
friend
class
StorageReplicatedMergeTree
;
ASTPtr
settings_ast
;
bool
require_part_metadata
;
String
relative_data_path
;
...
...
src/Storages/StorageInMemoryMetadata.cpp
浏览文件 @
5bc7f67e
#include <Storages/StorageInMemoryMetadata.h>
#include <Functions/IFunction.h>
#include <Interpreters/ExpressionActions.h>
#include <Interpreters/ExpressionAnalyzer.h>
#include <Interpreters/SyntaxAnalyzer.h>
#include <Parsers/ASTExpressionList.h>
#include <Parsers/ASTFunction.h>
#include <Storages/extractKeyExpressionList.h>
namespace
DB
{
...
...
@@ -89,30 +81,4 @@ StorageInMemoryMetadata & StorageInMemoryMetadata::operator=(const StorageInMemo
return
*
this
;
}
StorageMetadataKeyField
StorageMetadataKeyField
::
getKeyFromAST
(
const
ASTPtr
&
definition_ast
,
const
ColumnsDescription
&
columns
,
const
Context
&
context
)
{
StorageMetadataKeyField
result
;
result
.
definition_ast
=
definition_ast
;
result
.
expression_list_ast
=
extractKeyExpressionList
(
definition_ast
);
if
(
result
.
expression_list_ast
->
children
.
empty
())
return
result
;
const
auto
&
children
=
result
.
expression_list_ast
->
children
;
for
(
const
auto
&
child
:
children
)
result
.
column_names
.
emplace_back
(
child
->
getColumnName
());
{
auto
expr
=
result
.
expression_list_ast
->
clone
();
auto
syntax_result
=
SyntaxAnalyzer
(
context
).
analyze
(
expr
,
columns
.
getAllPhysical
());
result
.
expression
=
ExpressionAnalyzer
(
expr
,
syntax_result
,
context
).
getActions
(
true
);
result
.
sample_block
=
result
.
expression
->
getSampleBlock
();
}
for
(
size_t
i
=
0
;
i
<
result
.
sample_block
.
columns
();
++
i
)
result
.
data_types
.
emplace_back
(
result
.
sample_block
.
getByPosition
(
i
).
type
);
return
result
;
}
}
src/Storages/StorageInMemoryMetadata.h
浏览文件 @
5bc7f67e
...
...
@@ -3,7 +3,6 @@
#include <Storages/ColumnsDescription.h>
#include <Storages/IndicesDescription.h>
#include <Storages/ConstraintsDescription.h>
#include <Core/Field.h>
#include <Parsers/IAST_fwd.h>
namespace
DB
...
...
@@ -44,33 +43,4 @@ struct StorageInMemoryMetadata
StorageInMemoryMetadata
&
operator
=
(
const
StorageInMemoryMetadata
&
other
);
};
/// Common structure for primary, partition and other storage keys
struct
StorageMetadataKeyField
{
/// User defined AST in CREATE/ALTER query. This field may be empty, but key
/// can exists because some of them maybe set implicitly (for example,
/// primary key in merge tree can be part of sorting key)
ASTPtr
definition_ast
;
/// ASTExpressionList with key fields, example: (x, toStartOfMonth(date))).
ASTPtr
expression_list_ast
;
/// Expression from expression_list_ast created by ExpressionAnalyzer. Useful,
/// when you need to get required columns for key, example: a, date, b.
ExpressionActionsPtr
expression
;
/// Sample block with key columns (names, types, empty column)
Block
sample_block
;
/// Column names in key definition, example: x, toStartOfMonth(date), a * b.
Names
column_names
;
/// Types from sample block ordered in columns order.
DataTypes
data_types
;
/// Parse key structure from key definition. Requires all columns, available
/// in storage.
static
StorageMetadataKeyField
getKeyFromAST
(
const
ASTPtr
&
definition_ast
,
const
ColumnsDescription
&
columns
,
const
Context
&
context
);
};
}
src/Storages/StorageMaterializedView.cpp
浏览文件 @
5bc7f67e
...
...
@@ -18,6 +18,7 @@
#include <Storages/AlterCommands.h>
#include <Storages/StorageFactory.h>
#include <Storages/ReadInOrderOptimizer.h>
#include <Storages/SelectQueryDescription.h>
#include <Common/typeid_cast.h>
#include <Processors/Sources/SourceFromInputStream.h>
...
...
@@ -41,58 +42,6 @@ static inline String generateInnerTableName(const StorageID & view_id)
return
".inner."
+
view_id
.
getTableName
();
}
static
StorageID
extractDependentTableFromSelectQuery
(
ASTSelectQuery
&
query
,
const
Context
&
context
,
bool
add_default_db
=
true
)
{
if
(
add_default_db
)
{
AddDefaultDatabaseVisitor
visitor
(
context
.
getCurrentDatabase
(),
nullptr
);
visitor
.
visit
(
query
);
}
if
(
auto
db_and_table
=
getDatabaseAndTable
(
query
,
0
))
{
return
StorageID
(
db_and_table
->
database
,
db_and_table
->
table
/*, db_and_table->uuid*/
);
}
else
if
(
auto
subquery
=
extractTableExpression
(
query
,
0
))
{
auto
*
ast_select
=
subquery
->
as
<
ASTSelectWithUnionQuery
>
();
if
(
!
ast_select
)
throw
Exception
(
"Logical error while creating StorageMaterializedView. "
"Could not retrieve table name from select query."
,
DB
::
ErrorCodes
::
LOGICAL_ERROR
);
if
(
ast_select
->
list_of_selects
->
children
.
size
()
!=
1
)
throw
Exception
(
"UNION is not supported for MATERIALIZED VIEW"
,
ErrorCodes
::
QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW
);
auto
&
inner_query
=
ast_select
->
list_of_selects
->
children
.
at
(
0
);
return
extractDependentTableFromSelectQuery
(
inner_query
->
as
<
ASTSelectQuery
&>
(),
context
,
false
);
}
else
return
StorageID
::
createEmpty
();
}
static
void
checkAllowedQueries
(
const
ASTSelectQuery
&
query
)
{
if
(
query
.
prewhere
()
||
query
.
final
()
||
query
.
sampleSize
())
throw
Exception
(
"MATERIALIZED VIEW cannot have PREWHERE, SAMPLE or FINAL."
,
DB
::
ErrorCodes
::
QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW
);
ASTPtr
subquery
=
extractTableExpression
(
query
,
0
);
if
(
!
subquery
)
return
;
if
(
const
auto
*
ast_select
=
subquery
->
as
<
ASTSelectWithUnionQuery
>
())
{
if
(
ast_select
->
list_of_selects
->
children
.
size
()
!=
1
)
throw
Exception
(
"UNION is not supported for MATERIALIZED VIEW"
,
ErrorCodes
::
QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW
);
const
auto
&
inner_query
=
ast_select
->
list_of_selects
->
children
.
at
(
0
);
checkAllowedQueries
(
inner_query
->
as
<
ASTSelectQuery
&>
());
}
}
StorageMaterializedView
::
StorageMaterializedView
(
const
StorageID
&
table_id_
,
...
...
@@ -117,13 +66,8 @@ StorageMaterializedView::StorageMaterializedView(
if
(
query
.
select
->
list_of_selects
->
children
.
size
()
!=
1
)
throw
Exception
(
"UNION is not supported for MATERIALIZED VIEW"
,
ErrorCodes
::
QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW
);
select
=
query
.
select
->
clone
();
inner_query
=
query
.
select
->
list_of_selects
->
children
.
at
(
0
);
auto
&
select_query
=
inner_query
->
as
<
ASTSelectQuery
&>
();
checkAllowedQueries
(
select_query
);
select_table_id
=
extractDependentTableFromSelectQuery
(
select_query
,
local_context
);
auto
select
=
SelectQueryDescription
::
getSelectQueryFromASTForMatView
(
query
.
select
->
clone
(),
local_context
);
setSelectQuery
(
select
);
if
(
!
has_inner_table
)
target_table_id
=
query
.
to_table_id
;
...
...
@@ -152,14 +96,14 @@ StorageMaterializedView::StorageMaterializedView(
target_table_id
=
DatabaseCatalog
::
instance
().
getTable
({
manual_create_query
->
database
,
manual_create_query
->
table
},
global_context
)
->
getStorageID
();
}
if
(
!
select_table_id
.
empty
())
DatabaseCatalog
::
instance
().
addDependency
(
select_table_id
,
getStorageID
());
if
(
!
select
.
select
_table_id
.
empty
())
DatabaseCatalog
::
instance
().
addDependency
(
select
.
select
_table_id
,
getStorageID
());
}
StorageInMemoryMetadata
StorageMaterializedView
::
getInMemoryMetadata
()
const
{
StorageInMemoryMetadata
result
(
getColumns
(),
getSecondaryIndices
(),
getConstraints
());
result
.
select
=
getSelectQuery
();
result
.
select
=
getSelectQuery
()
.
select_query
;
return
result
;
}
...
...
@@ -222,8 +166,9 @@ static void executeDropQuery(ASTDropQuery::Kind kind, Context & global_context,
void
StorageMaterializedView
::
drop
()
{
auto
table_id
=
getStorageID
();
if
(
!
select_table_id
.
empty
())
DatabaseCatalog
::
instance
().
removeDependency
(
select_table_id
,
table_id
);
const
auto
&
select_query
=
getSelectQuery
();
if
(
!
select_query
.
select_table_id
.
empty
())
DatabaseCatalog
::
instance
().
removeDependency
(
select_query
.
select_table_id
,
table_id
);
if
(
has_inner_table
&&
tryGetTargetTable
())
executeDropQuery
(
ASTDropQuery
::
Kind
::
Drop
,
global_context
,
target_table_id
);
...
...
@@ -262,21 +207,12 @@ void StorageMaterializedView::alter(
/// start modify query
if
(
context
.
getSettingsRef
().
allow_experimental_alter_materialized_view_structure
)
{
auto
&
new_select
=
metadata
.
select
->
as
<
ASTSelectWithUnionQuery
&>
();
if
(
new_select
.
list_of_selects
->
children
.
size
()
!=
1
)
throw
Exception
(
"UNION is not supported for MATERIALIZED VIEW"
,
ErrorCodes
::
QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW
);
auto
&
new_inner_query
=
new_select
.
list_of_selects
->
children
.
at
(
0
);
auto
&
select_query
=
new_inner_query
->
as
<
ASTSelectQuery
&>
();
checkAllowedQueries
(
select_query
);
auto
new_select
=
SelectQueryDescription
::
getSelectQueryFromASTForMatView
(
metadata
.
select
,
context
);
const
auto
&
old_select
=
getSelectQuery
();
auto
new_select_table_id
=
extractDependentTableFromSelectQuery
(
select_query
,
context
);
DatabaseCatalog
::
instance
().
updateDependency
(
select_table_id
,
table_id
,
new_select_table_id
,
table_id
);
DatabaseCatalog
::
instance
().
updateDependency
(
old_select
.
select_table_id
,
table_id
,
new_select
.
select_table_id
,
table_id
);
select_table_id
=
new_select_table_id
;
select
=
metadata
.
select
;
inner_query
=
new_inner_query
;
setSelectQuery
(
new_select
);
}
/// end modify query
...
...
@@ -349,15 +285,17 @@ void StorageMaterializedView::renameInMemory(const StorageID & new_table_id)
}
IStorage
::
renameInMemory
(
new_table_id
);
const
auto
&
select_query
=
getSelectQuery
();
// TODO Actually we don't need to update dependency if MV has UUID, but then db and table name will be outdated
DatabaseCatalog
::
instance
().
updateDependency
(
select_
table_id
,
old_table_id
,
select_table_id
,
getStorageID
());
DatabaseCatalog
::
instance
().
updateDependency
(
select_
query
.
select_table_id
,
old_table_id
,
select_query
.
select_table_id
,
getStorageID
());
}
void
StorageMaterializedView
::
shutdown
()
{
const
auto
&
select_query
=
getSelectQuery
();
/// Make sure the dependency is removed after DETACH TABLE
if
(
!
select_table_id
.
empty
())
DatabaseCatalog
::
instance
().
removeDependency
(
select_table_id
,
getStorageID
());
if
(
!
select_
query
.
select_
table_id
.
empty
())
DatabaseCatalog
::
instance
().
removeDependency
(
select_
query
.
select_
table_id
,
getStorageID
());
}
StoragePtr
StorageMaterializedView
::
getTargetTable
()
const
...
...
src/Storages/StorageMaterializedView.h
浏览文件 @
5bc7f67e
...
...
@@ -19,8 +19,6 @@ public:
std
::
string
getName
()
const
override
{
return
"MaterializedView"
;
}
bool
isView
()
const
override
{
return
true
;
}
ASTPtr
getSelectQuery
()
const
{
return
select
->
clone
();
}
ASTPtr
getInnerQuery
()
const
{
return
inner_query
->
clone
();
}
bool
hasInnerTable
()
const
{
return
has_inner_table
;
}
StorageInMemoryMetadata
getInMemoryMetadata
()
const
override
;
...
...
@@ -76,14 +74,9 @@ public:
Strings
getDataPaths
()
const
override
;
private:
/// Can be empty if SELECT query doesn't contain table
StorageID
select_table_id
=
StorageID
::
createEmpty
();
/// Will be initialized in constructor
StorageID
target_table_id
=
StorageID
::
createEmpty
();
ASTPtr
select
;
ASTPtr
inner_query
;
Context
&
global_context
;
bool
has_inner_table
=
false
;
...
...
src/Storages/StorageView.cpp
浏览文件 @
5bc7f67e
...
...
@@ -12,6 +12,7 @@
#include <Storages/StorageView.h>
#include <Storages/StorageFactory.h>
#include <Storages/SelectQueryDescription.h>
#include <Common/typeid_cast.h>
...
...
@@ -45,7 +46,10 @@ StorageView::StorageView(
if
(
!
query
.
select
)
throw
Exception
(
"SELECT query is not specified for "
+
getName
(),
ErrorCodes
::
INCORRECT_QUERY
);
inner_query
=
query
.
select
->
ptr
();
SelectQueryDescription
description
;
description
.
inner_query
=
query
.
select
->
ptr
();
setSelectQuery
(
description
);
}
...
...
@@ -59,7 +63,7 @@ Pipes StorageView::read(
{
Pipes
pipes
;
ASTPtr
current_inner_query
=
inner_query
;
ASTPtr
current_inner_query
=
getSelectQuery
().
inner_query
;
if
(
context
.
getSettings
().
enable_optimize_predicate_expression
)
current_inner_query
=
getRuntimeViewQuery
(
*
query_info
.
query
->
as
<
const
ASTSelectQuery
>
(),
context
);
...
...
@@ -119,7 +123,7 @@ static void replaceTableNameWithSubquery(ASTSelectQuery * select_query, ASTPtr &
ASTPtr
StorageView
::
getRuntimeViewQuery
(
ASTSelectQuery
*
outer_query
,
const
Context
&
context
,
bool
normalize
)
{
auto
runtime_view_query
=
inner_query
->
clone
();
auto
runtime_view_query
=
getSelectQuery
().
inner_query
->
clone
();
/// TODO: remove getTableExpressions and getTablesWithColumns
{
...
...
src/Storages/StorageView.h
浏览文件 @
5bc7f67e
...
...
@@ -33,9 +33,6 @@ public:
ASTPtr
getRuntimeViewQuery
(
ASTSelectQuery
*
outer_query
,
const
Context
&
context
,
bool
normalize
);
private:
ASTPtr
inner_query
;
protected:
StorageView
(
const
StorageID
&
table_id_
,
...
...
src/Storages/TTLDescription.cpp
浏览文件 @
5bc7f67e
...
...
@@ -59,7 +59,7 @@ TTLDescription TTLDescription::getTTLFromAST(
const
ASTPtr
&
definition_ast
,
const
ColumnsDescription
&
columns
,
const
Context
&
context
,
const
StorageMetadataKeyField
&
primary_key
)
const
KeyDescription
&
primary_key
)
{
TTLDescription
result
;
const
auto
*
ttl_element
=
definition_ast
->
as
<
ASTTTLElement
>
();
...
...
src/Storages/TTLDescription.h
浏览文件 @
5bc7f67e
...
...
@@ -2,6 +2,7 @@
#include <Parsers/IAST_fwd.h>
#include <Storages/DataDestinationType.h>
#include <Storages/ColumnsDescription.h>
#include <Storages/KeyDescription.h>
#include <Interpreters/ExpressionActions.h>
#include <Interpreters/AggregateDescription.h>
#include <Storages/StorageInMemoryMetadata.h>
...
...
@@ -73,7 +74,7 @@ struct TTLDescription
/// Parse TTL structure from definition. Able to parse both column and table
/// TTLs.
static
TTLDescription
getTTLFromAST
(
const
ASTPtr
&
definition_ast
,
const
ColumnsDescription
&
columns
,
const
Context
&
context
,
const
StorageMetadataKeyField
&
primary_key
);
static
TTLDescription
getTTLFromAST
(
const
ASTPtr
&
definition_ast
,
const
ColumnsDescription
&
columns
,
const
Context
&
context
,
const
KeyDescription
&
primary_key
);
};
/// Mapping from column name to column TTL
...
...
src/Storages/ya.make
浏览文件 @
5bc7f67e
...
...
@@ -176,6 +176,8 @@ SRCS(
VirtualColumnUtils.cpp
extractKeyExpressionList.cpp
TTLDescription.cpp
KeyDescription.cpp
SelectQueryDescription.cpp
)
END()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录