Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
f2ebffb7
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,发现更多精彩内容 >>
提交
f2ebffb7
编写于
10月 30, 2017
作者:
A
Alexey Zatelepin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
save TO table of a materialized view to the ATTACH query [#CLICKHOUSE-2]
上级
b0f1227e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
59 addition
and
32 deletion
+59
-32
dbms/src/Databases/DatabasesCommon.cpp
dbms/src/Databases/DatabasesCommon.cpp
+2
-7
dbms/src/Interpreters/InterpreterCreateQuery.cpp
dbms/src/Interpreters/InterpreterCreateQuery.cpp
+4
-1
dbms/src/Parsers/ASTCreateQuery.h
dbms/src/Parsers/ASTCreateQuery.h
+12
-3
dbms/src/Parsers/ParserCreateQuery.cpp
dbms/src/Parsers/ParserCreateQuery.cpp
+10
-8
dbms/src/Storages/StorageFactory.cpp
dbms/src/Storages/StorageFactory.cpp
+4
-4
dbms/src/Storages/StorageMaterializedView.cpp
dbms/src/Storages/StorageMaterializedView.cpp
+7
-5
dbms/tests/queries/0_stateless/00508_materialized_view_to.reference
.../queries/0_stateless/00508_materialized_view_to.reference
+6
-0
dbms/tests/queries/0_stateless/00508_materialized_view_to.sql
.../tests/queries/0_stateless/00508_materialized_view_to.sql
+14
-4
未找到文件。
dbms/src/Databases/DatabasesCommon.cpp
浏览文件 @
f2ebffb7
...
...
@@ -27,6 +27,8 @@ String getTableDefinitionFromCreateQuery(const ASTPtr & query)
/// We remove everything that is not needed for ATTACH from the query.
create
.
attach
=
true
;
create
.
database
.
clear
();
create
.
as_database
.
clear
();
create
.
as_table
.
clear
();
create
.
if_not_exists
=
false
;
create
.
is_populate
=
false
;
...
...
@@ -34,13 +36,6 @@ String getTableDefinitionFromCreateQuery(const ASTPtr & query)
if
(
!
create
.
is_view
&&
!
create
.
is_materialized_view
)
create
.
select
=
nullptr
;
/// For "MATERIALIZED VIEW x TO y" it's necessary to save destination table
if
(
!
create
.
is_materialized_view
||
create
.
storage
)
{
create
.
as_database
.
clear
();
create
.
as_table
.
clear
();
}
std
::
ostringstream
statement_stream
;
formatAST
(
create
,
statement_stream
,
0
,
false
);
statement_stream
<<
'\n'
;
...
...
dbms/src/Interpreters/InterpreterCreateQuery.cpp
浏览文件 @
f2ebffb7
...
...
@@ -480,12 +480,15 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
create
.
attach
=
true
;
}
if
(
create
.
to_database
.
empty
())
create
.
to_database
=
current_database
;
std
::
unique_ptr
<
InterpreterSelectQuery
>
interpreter_select
;
Block
as_select_sample
;
/// For `view` type tables, you may need `sample_block` to get the columns.
if
(
create
.
select
&&
(
!
create
.
attach
||
(
!
create
.
columns
&&
(
create
.
is_view
||
create
.
is_materialized_view
))))
{
create
.
select
->
setDatabaseIfNeeded
(
database_nam
e
);
create
.
select
->
setDatabaseIfNeeded
(
current_databas
e
);
interpreter_select
=
std
::
make_unique
<
InterpreterSelectQuery
>
(
create
.
select
->
ptr
(),
context
);
as_select_sample
=
interpreter_select
->
getSampleBlock
();
}
...
...
dbms/src/Parsers/ASTCreateQuery.h
浏览文件 @
f2ebffb7
...
...
@@ -88,6 +88,8 @@ public:
String
database
;
String
table
;
ASTExpressionList
*
columns
=
nullptr
;
String
to_database
;
/// For CREATE MATERIALIZED VIEW mv TO table.
String
to_table
;
ASTStorage
*
storage
=
nullptr
;
String
as_database
;
String
as_table
;
...
...
@@ -166,11 +168,18 @@ protected:
formatOnCluster
(
settings
);
}
if
(
!
to_table
.
empty
())
{
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
" TO "
<<
(
settings
.
hilite
?
hilite_none
:
""
)
<<
(
!
to_database
.
empty
()
?
backQuoteIfNeed
(
to_database
)
+
"."
:
""
)
<<
backQuoteIfNeed
(
to_table
);
}
if
(
!
as_table
.
empty
())
{
s
td
::
string
what
=
(
!
is_materialized_view
?
" AS "
:
" TO "
);
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
what
<<
(
settings
.
hilite
?
hilite_none
:
""
)
<<
(
!
as_database
.
empty
()
?
backQuoteIfNeed
(
as_database
)
+
"."
:
""
)
<<
backQuoteIfNeed
(
as_table
);
s
ettings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
" AS "
<<
(
settings
.
hilite
?
hilite_none
:
""
)
<<
(
!
as_database
.
empty
()
?
backQuoteIfNeed
(
as_database
)
+
"."
:
""
)
<<
backQuoteIfNeed
(
as_table
);
}
if
(
columns
)
...
...
dbms/src/Parsers/ParserCreateQuery.cpp
浏览文件 @
f2ebffb7
...
...
@@ -208,6 +208,8 @@ bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
ASTPtr
database
;
ASTPtr
table
;
ASTPtr
columns
;
ASTPtr
to_database
;
ASTPtr
to_table
;
ASTPtr
storage
;
ASTPtr
as_database
;
ASTPtr
as_table
;
...
...
@@ -219,7 +221,6 @@ bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
bool
is_materialized_view
=
false
;
bool
is_populate
=
false
;
bool
is_temporary
=
false
;
bool
to_table
=
false
;
if
(
!
s_create
.
ignore
(
pos
,
expected
))
{
...
...
@@ -362,17 +363,13 @@ bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
// TO [db.]table
if
(
ParserKeyword
{
"TO"
}.
ignore
(
pos
,
expected
))
{
to_table
=
true
;
/// FIXME: as_table is ambiguous, it is set in AS clause also
if
(
!
name_p
.
parse
(
pos
,
as_table
,
expected
))
if
(
!
name_p
.
parse
(
pos
,
to_table
,
expected
))
return
false
;
if
(
s_dot
.
ignore
(
pos
,
expected
))
{
as_database
=
as
_table
;
if
(
!
name_p
.
parse
(
pos
,
as
_table
,
expected
))
to_database
=
to
_table
;
if
(
!
name_p
.
parse
(
pos
,
to
_table
,
expected
))
return
false
;
}
}
...
...
@@ -422,6 +419,11 @@ bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
query
->
table
=
typeid_cast
<
ASTIdentifier
&>
(
*
table
).
name
;
query
->
cluster
=
cluster_str
;
if
(
to_database
)
query
->
to_database
=
typeid_cast
<
ASTIdentifier
&>
(
*
to_database
).
name
;
if
(
to_table
)
query
->
to_table
=
typeid_cast
<
ASTIdentifier
&>
(
*
to_table
).
name
;
query
->
set
(
query
->
columns
,
columns
);
query
->
set
(
query
->
storage
,
storage
);
if
(
as_database
)
...
...
dbms/src/Storages/StorageFactory.cpp
浏览文件 @
f2ebffb7
...
...
@@ -388,9 +388,6 @@ StoragePtr StorageFactory::get(
checkAllTypesAreAllowedInTable
(
materialized_columns
);
checkAllTypesAreAllowedInTable
(
alias_columns
);
if
(
!
query
.
storage
)
throw
Exception
(
"Incorrect CREATE query: ENGINE required"
,
ErrorCodes
::
ENGINE_REQUIRED
);
if
(
query
.
is_materialized_view
)
{
/// Pass local_context here to convey setting for inner table
...
...
@@ -400,6 +397,9 @@ StoragePtr StorageFactory::get(
attach
);
}
if
(
!
query
.
storage
)
throw
Exception
(
"Incorrect CREATE query: ENGINE required"
,
ErrorCodes
::
ENGINE_REQUIRED
);
ASTStorage
&
storage_def
=
*
query
.
storage
;
const
ASTFunction
&
engine_def
=
*
storage_def
.
engine
;
...
...
@@ -423,7 +423,7 @@ StoragePtr StorageFactory::get(
auto
check_arguments_empty
=
[
&
]
{
if
(
args_ptr
)
if
(
args_ptr
&&
!
args_ptr
->
empty
()
)
throw
Exception
(
"Engine "
+
name
+
" doesn't support any arguments ("
+
toString
(
args_ptr
->
size
())
+
" given)"
,
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
);
...
...
dbms/src/Storages/StorageMaterializedView.cpp
浏览文件 @
f2ebffb7
...
...
@@ -70,8 +70,10 @@ StorageMaterializedView::StorageMaterializedView(
if
(
!
query
.
select
)
throw
Exception
(
"SELECT query is not specified for "
+
getName
(),
ErrorCodes
::
INCORRECT_QUERY
);
if
(
!
query
.
storage
&&
query
.
as_table
.
empty
())
throw
Exception
(
"ENGINE of MaterializedView should be specified explicitly"
,
ErrorCodes
::
INCORRECT_QUERY
);
if
(
!
query
.
storage
&&
query
.
to_table
.
empty
())
throw
Exception
(
"You must specify where to save results of a MaterializedView query: either ENGINE or an existing table in a TO clause"
,
ErrorCodes
::
INCORRECT_QUERY
);
extractDependentTable
(
*
query
.
select
,
select_database_name
,
select_table_name
);
...
...
@@ -81,10 +83,10 @@ StorageMaterializedView::StorageMaterializedView(
DatabaseAndTableName
(
database_name
,
table_name
));
// If the destination table is not set, use inner table
if
(
!
query
.
as
_table
.
empty
())
if
(
!
query
.
to
_table
.
empty
())
{
target_database_name
=
query
.
as
_database
;
target_table_name
=
query
.
as
_table
;
target_database_name
=
query
.
to
_database
;
target_table_name
=
query
.
to
_table
;
}
else
{
...
...
dbms/tests/queries/0_stateless/00508_materialized_view_to.reference
浏览文件 @
f2ebffb7
...
...
@@ -2,3 +2,9 @@
2
1
2
1
2
3
1
2
3
dbms/tests/queries/0_stateless/00508_materialized_view_to.sql
浏览文件 @
f2ebffb7
...
...
@@ -5,16 +5,26 @@ DROP TABLE IF EXISTS test.mv;
CREATE
TABLE
test
.
src
(
x
UInt8
)
ENGINE
=
Null
;
CREATE
TABLE
test
.
dst
(
x
UInt8
)
ENGINE
=
Memory
;
CREATE
MATERIALIZED
VIEW
test
.
mv
TO
test
.
dst
AS
SELECT
*
FROM
test
.
src
;
INSERT
INTO
test
.
src
VALUES
(
1
),
(
2
);
USE
test
;
CREATE
MATERIALIZED
VIEW
mv
TO
dst
AS
SELECT
*
FROM
src
;
INSERT
INTO
src
VALUES
(
1
),
(
2
);
SELECT
*
FROM
mv
;
-- Detach MV and see if the data is still readable
DETACH
TABLE
test
.
mv
;
SELECT
*
FROM
test
.
dst
;
DETACH
TABLE
mv
;
SELECT
*
FROM
dst
;
USE
default
;
-- Reattach MV (shortcut)
ATTACH
TABLE
test
.
mv
;
INSERT
INTO
test
.
src
VALUES
(
3
);
SELECT
*
FROM
test
.
mv
;
-- Drop the MV and see if the data is still readable
DROP
TABLE
test
.
mv
;
SELECT
*
FROM
test
.
dst
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录