Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
70dc82f9
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,发现更多精彩内容 >>
提交
70dc82f9
编写于
3月 02, 2020
作者:
A
Alexander Tokmakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add StorageID to ASTInsertQuery
上级
fa27ecf3
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
42 addition
and
52 deletion
+42
-52
dbms/programs/server/MySQLHandler.cpp
dbms/programs/server/MySQLHandler.cpp
+1
-1
dbms/programs/server/TCPHandler.cpp
dbms/programs/server/TCPHandler.cpp
+3
-3
dbms/src/DataStreams/CheckConstraintsBlockOutputStream.cpp
dbms/src/DataStreams/CheckConstraintsBlockOutputStream.cpp
+3
-3
dbms/src/DataStreams/CheckConstraintsBlockOutputStream.h
dbms/src/DataStreams/CheckConstraintsBlockOutputStream.h
+3
-2
dbms/src/DataStreams/InputStreamFromASTInsertQuery.cpp
dbms/src/DataStreams/InputStreamFromASTInsertQuery.cpp
+2
-2
dbms/src/DataStreams/PushingToViewsBlockOutputStream.cpp
dbms/src/DataStreams/PushingToViewsBlockOutputStream.cpp
+1
-2
dbms/src/Interpreters/Context.h
dbms/src/Interpreters/Context.h
+4
-3
dbms/src/Interpreters/InterpreterCreateQuery.cpp
dbms/src/Interpreters/InterpreterCreateQuery.cpp
+1
-5
dbms/src/Interpreters/InterpreterInsertQuery.cpp
dbms/src/Interpreters/InterpreterInsertQuery.cpp
+8
-11
dbms/src/Interpreters/InterpreterInsertQuery.h
dbms/src/Interpreters/InterpreterInsertQuery.h
+1
-1
dbms/src/Interpreters/SystemLog.h
dbms/src/Interpreters/SystemLog.h
+1
-2
dbms/src/Interpreters/executeQuery.cpp
dbms/src/Interpreters/executeQuery.cpp
+3
-3
dbms/src/Parsers/ASTInsertQuery.cpp
dbms/src/Parsers/ASTInsertQuery.cpp
+3
-1
dbms/src/Parsers/ASTInsertQuery.h
dbms/src/Parsers/ASTInsertQuery.h
+3
-4
dbms/src/Parsers/ParserInsertQuery.cpp
dbms/src/Parsers/ParserInsertQuery.cpp
+2
-2
dbms/src/Storages/Kafka/StorageKafka.cpp
dbms/src/Storages/Kafka/StorageKafka.cpp
+1
-2
dbms/src/Storages/StorageBuffer.cpp
dbms/src/Storages/StorageBuffer.cpp
+1
-3
dbms/src/Storages/StorageDistributed.cpp
dbms/src/Storages/StorageDistributed.cpp
+1
-2
未找到文件。
dbms/programs/server/MySQLHandler.cpp
浏览文件 @
70dc82f9
...
...
@@ -252,7 +252,7 @@ void MySQLHandler::comFieldList(ReadBuffer & payload)
ComFieldList
packet
;
packet
.
readPayload
(
payload
);
String
database
=
connection_context
.
getCurrentDatabase
();
StoragePtr
tablePtr
=
connection_context
.
getTable
(
database
,
packet
.
table
);
StoragePtr
tablePtr
=
DatabaseCatalog
::
instance
().
getTable
({
database
,
packet
.
table
}
);
for
(
const
NameAndTypePair
&
column
:
tablePtr
->
getColumns
().
getAll
())
{
ColumnDefinition
column_definition
(
...
...
dbms/programs/server/TCPHandler.cpp
浏览文件 @
70dc82f9
...
...
@@ -463,11 +463,11 @@ void TCPHandler::processInsertQuery(const Settings & connection_settings)
/// Send ColumnsDescription for insertion table
if
(
client_revision
>=
DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA
)
{
const
auto
&
db_and_table
=
query_context
->
getInsertionTable
();
const
auto
&
table_id
=
query_context
->
getInsertionTable
();
if
(
query_context
->
getSettingsRef
().
input_format_defaults_for_omitted_fields
)
{
if
(
!
db_and_table
.
secon
d
.
empty
())
sendTableColumns
(
query_context
->
getTable
(
db_and_table
.
first
,
db_and_table
.
secon
d
)
->
getColumns
());
if
(
!
table_i
d
.
empty
())
sendTableColumns
(
DatabaseCatalog
::
instance
().
getTable
(
table_i
d
)
->
getColumns
());
}
}
...
...
dbms/src/DataStreams/CheckConstraintsBlockOutputStream.cpp
浏览文件 @
70dc82f9
...
...
@@ -19,12 +19,12 @@ namespace ErrorCodes
CheckConstraintsBlockOutputStream
::
CheckConstraintsBlockOutputStream
(
const
St
ring
&
table
_
,
const
St
orageID
&
table_id
_
,
const
BlockOutputStreamPtr
&
output_
,
const
Block
&
header_
,
const
ConstraintsDescription
&
constraints_
,
const
Context
&
context_
)
:
table
(
table
_
),
:
table
_id
(
table_id
_
),
output
(
output_
),
header
(
header_
),
constraints
(
constraints_
),
...
...
@@ -62,7 +62,7 @@ void CheckConstraintsBlockOutputStream::write(const Block & block)
std
::
stringstream
exception_message
;
exception_message
<<
"Constraint "
<<
backQuote
(
constraints
.
constraints
[
i
]
->
name
)
<<
" for table "
<<
backQuote
(
table
)
<<
" for table "
<<
table_id
.
getNameForLogs
(
)
<<
" is violated at row "
<<
(
rows_written
+
row_idx
+
1
)
<<
". Expression: ("
<<
serializeAST
(
*
(
constraints
.
constraints
[
i
]
->
expr
),
true
)
<<
")"
<<
". Column values"
;
...
...
dbms/src/DataStreams/CheckConstraintsBlockOutputStream.h
浏览文件 @
70dc82f9
...
...
@@ -2,6 +2,7 @@
#include <DataStreams/IBlockOutputStream.h>
#include <Storages/ConstraintsDescription.h>
#include <Storages/StorageID.h>
namespace
DB
...
...
@@ -15,7 +16,7 @@ class CheckConstraintsBlockOutputStream : public IBlockOutputStream
{
public:
CheckConstraintsBlockOutputStream
(
const
St
ring
&
table_
,
const
St
orageID
&
table_
,
const
BlockOutputStreamPtr
&
output_
,
const
Block
&
header_
,
const
ConstraintsDescription
&
constraints_
,
...
...
@@ -30,7 +31,7 @@ public:
void
writeSuffix
()
override
;
private:
St
ring
table
;
St
orageID
table_id
;
BlockOutputStreamPtr
output
;
Block
header
;
const
ConstraintsDescription
constraints
;
...
...
dbms/src/DataStreams/InputStreamFromASTInsertQuery.cpp
浏览文件 @
70dc82f9
...
...
@@ -56,9 +56,9 @@ InputStreamFromASTInsertQuery::InputStreamFromASTInsertQuery(
res_stream
=
context
.
getInputFormat
(
format
,
*
input_buffer_contacenated
,
header
,
context
.
getSettings
().
max_insert_block_size
);
if
(
context
.
getSettingsRef
().
input_format_defaults_for_omitted_fields
&&
!
ast_insert_query
->
table
.
empty
()
&&
!
input_function
)
if
(
context
.
getSettingsRef
().
input_format_defaults_for_omitted_fields
&&
!
ast_insert_query
->
table
_id
.
empty
()
&&
!
input_function
)
{
StoragePtr
storage
=
context
.
getTable
(
ast_insert_query
->
database
,
ast_insert_query
->
table
);
StoragePtr
storage
=
DatabaseCatalog
::
instance
().
getTable
(
ast_insert_query
->
table_id
);
auto
column_defaults
=
storage
->
getColumns
().
getDefaults
();
if
(
!
column_defaults
.
empty
())
res_stream
=
std
::
make_shared
<
AddingDefaultsBlockInputStream
>
(
res_stream
,
column_defaults
,
context
);
...
...
dbms/src/DataStreams/PushingToViewsBlockOutputStream.cpp
浏览文件 @
70dc82f9
...
...
@@ -61,8 +61,7 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
query
=
materialized_view
->
getInnerQuery
();
std
::
unique_ptr
<
ASTInsertQuery
>
insert
=
std
::
make_unique
<
ASTInsertQuery
>
();
insert
->
database
=
inner_table_id
.
database_name
;
insert
->
table
=
inner_table_id
.
table_name
;
insert
->
table_id
=
inner_table_id
;
/// Get list of columns we get from select query.
auto
header
=
InterpreterSelectQuery
(
query
,
*
views_context
,
SelectQueryOptions
().
analyze
())
...
...
dbms/src/Interpreters/Context.h
浏览文件 @
70dc82f9
...
...
@@ -160,7 +160,7 @@ private:
using
ProgressCallback
=
std
::
function
<
void
(
const
Progress
&
progress
)
>
;
ProgressCallback
progress_callback
;
/// Callback for tracking progress of query execution.
QueryStatus
*
process_list_elem
=
nullptr
;
/// For tracking total resource usage for query.
std
::
pair
<
String
,
String
>
insertion_table
;
/// Saved insertion table in query context
StorageID
insertion_table
=
StorageID
::
createEmpty
()
;
/// Saved insertion table in query context
String
default_format
;
/// Format, used when server formats data by itself and if query does not have FORMAT specification.
/// Thus, used in HTTP interface. If not specified - then some globally default format is used.
...
...
@@ -297,6 +297,7 @@ public:
ResolveCurrentDatabase
=
2u
,
/// Use current database
ResolveOrdinary
=
ResolveGlobal
|
ResolveCurrentDatabase
,
/// If database name is not specified, use current database
ResolveExternal
=
4u
,
/// Try get external table
ResolveExternalOrGlobal
=
ResolveGlobal
|
ResolveExternal
,
/// If external table doesn't exist, database name must be specifies
ResolveAll
=
ResolveExternal
|
ResolveOrdinary
/// If database name is not specified, try get external table,
/// if external table not found use current database.
};
...
...
@@ -332,8 +333,8 @@ public:
void
killCurrentQuery
();
void
setInsertionTable
(
std
::
pair
<
String
,
String
>
&&
db_and_table
)
{
insertion_table
=
db_and_table
;
}
const
std
::
pair
<
String
,
String
>
&
getInsertionTable
()
const
{
return
insertion_table
;
}
void
setInsertionTable
(
StorageID
db_and_table
)
{
insertion_table
=
std
::
move
(
db_and_table
)
;
}
const
StorageID
&
getInsertionTable
()
const
{
return
insertion_table
;
}
String
getDefaultFormat
()
const
;
/// If default_format is not specified, some global default format is returned.
void
setDefaultFormat
(
const
String
&
name
);
...
...
dbms/src/Interpreters/InterpreterCreateQuery.cpp
浏览文件 @
70dc82f9
...
...
@@ -662,11 +662,7 @@ BlockIO InterpreterCreateQuery::fillTableIfNeeded(const ASTCreateQuery & create)
&&
!
create
.
is_view
&&
!
create
.
is_live_view
&&
(
!
create
.
is_materialized_view
||
create
.
is_populate
))
{
auto
insert
=
std
::
make_shared
<
ASTInsertQuery
>
();
if
(
!
create
.
temporary
)
insert
->
database
=
create
.
database
;
insert
->
table
=
create
.
table
;
insert
->
table_id
=
context
.
getSessionContext
().
resolveStorageID
({
create
.
database
,
create
.
table
,
create
.
uuid
},
Context
::
ResolveExternalOrGlobal
);
insert
->
select
=
create
.
select
->
clone
();
if
(
create
.
temporary
&&
!
context
.
getSessionContext
().
hasQueryContext
())
...
...
dbms/src/Interpreters/InterpreterInsertQuery.cpp
浏览文件 @
70dc82f9
...
...
@@ -56,10 +56,8 @@ StoragePtr InterpreterInsertQuery::getTable(ASTInsertQuery & query)
return
table_function_ptr
->
execute
(
query
.
table_function
,
context
,
table_function_ptr
->
getName
());
}
/// Into what table to write.
if
(
query
.
database
.
empty
()
&&
!
context
.
isExternalTableExist
(
query
.
table
))
query
.
database
=
context
.
getCurrentDatabase
();
return
context
.
getTable
(
query
.
database
,
query
.
table
);
query
.
table_id
=
context
.
resolveStorageID
(
query
.
table_id
);
return
DatabaseCatalog
::
instance
().
getTable
(
query
.
table_id
);
}
Block
InterpreterInsertQuery
::
getSampleBlock
(
const
ASTInsertQuery
&
query
,
const
StoragePtr
&
table
)
...
...
@@ -83,7 +81,7 @@ Block InterpreterInsertQuery::getSampleBlock(const ASTInsertQuery & query, const
/// The table does not have a column with that name
if
(
!
table_sample
.
has
(
current_name
))
throw
Exception
(
"No such column "
+
current_name
+
" in table "
+
query
.
table
,
ErrorCodes
::
NO_SUCH_COLUMN_IN_TABLE
);
throw
Exception
(
"No such column "
+
current_name
+
" in table "
+
query
.
table
_id
.
getNameForLogs
()
,
ErrorCodes
::
NO_SUCH_COLUMN_IN_TABLE
);
if
(
!
allow_materialized
&&
!
table_sample_non_materialized
.
has
(
current_name
))
throw
Exception
(
"Cannot insert column "
+
current_name
+
", because it is MATERIALIZED column."
,
ErrorCodes
::
ILLEGAL_COLUMN
);
...
...
@@ -107,8 +105,8 @@ BlockIO InterpreterInsertQuery::execute()
auto
table_lock
=
table
->
lockStructureForShare
(
true
,
context
.
getInitialQueryId
());
auto
query_sample_block
=
getSampleBlock
(
query
,
table
);
if
(
!
query
.
table
.
empty
()
&&
!
query
.
database
.
empty
()
/* always allow access to temporary tables */
)
context
.
checkAccess
(
AccessType
::
INSERT
,
query
.
database
,
query
.
tabl
e
,
query_sample_block
.
getNames
());
if
(
!
query
.
table
_function
)
context
.
checkAccess
(
AccessType
::
INSERT
,
query
.
table_id
.
database_name
,
query
.
table_id
.
table_nam
e
,
query_sample_block
.
getNames
());
BlockInputStreams
in_streams
;
size_t
out_streams_size
=
1
;
...
...
@@ -159,7 +157,7 @@ BlockIO InterpreterInsertQuery::execute()
out
,
query_sample_block
,
out
->
getHeader
(),
table
->
getColumns
().
getDefaults
(),
context
);
if
(
const
auto
&
constraints
=
table
->
getConstraints
();
!
constraints
.
empty
())
out
=
std
::
make_shared
<
CheckConstraintsBlockOutputStream
>
(
query
.
table
,
out
=
std
::
make_shared
<
CheckConstraintsBlockOutputStream
>
(
query
.
table
_id
,
out
,
query_sample_block
,
table
->
getConstraints
(),
context
);
auto
out_wrapper
=
std
::
make_shared
<
CountingBlockOutputStream
>
(
out
);
...
...
@@ -207,10 +205,9 @@ BlockIO InterpreterInsertQuery::execute()
}
std
::
pair
<
String
,
String
>
InterpreterInsertQuery
::
getDatabaseTable
()
const
StorageID
InterpreterInsertQuery
::
getDatabaseTable
()
const
{
const
auto
&
query
=
query_ptr
->
as
<
ASTInsertQuery
&>
();
return
{
query
.
database
,
query
.
table
};
return
query_ptr
->
as
<
ASTInsertQuery
&>
().
table_id
;
}
}
dbms/src/Interpreters/InterpreterInsertQuery.h
浏览文件 @
70dc82f9
...
...
@@ -29,7 +29,7 @@ public:
*/
BlockIO
execute
()
override
;
std
::
pair
<
String
,
String
>
getDatabaseTable
()
const
;
StorageID
getDatabaseTable
()
const
;
private:
StoragePtr
getTable
(
ASTInsertQuery
&
query
);
...
...
dbms/src/Interpreters/SystemLog.h
浏览文件 @
70dc82f9
...
...
@@ -339,8 +339,7 @@ void SystemLog<LogElement>::flushImpl(const std::vector<LogElement> & to_flush,
/// This is needed to support DEFAULT-columns in table.
std
::
unique_ptr
<
ASTInsertQuery
>
insert
=
std
::
make_unique
<
ASTInsertQuery
>
();
insert
->
database
=
table_id
.
database_name
;
insert
->
table
=
table_id
.
table_name
;
insert
->
table_id
=
table_id
;
ASTPtr
query_ptr
(
insert
.
release
());
InterpreterInsertQuery
interpreter
(
query_ptr
,
context
);
...
...
dbms/src/Interpreters/executeQuery.cpp
浏览文件 @
70dc82f9
...
...
@@ -330,9 +330,9 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
if
(
auto
*
insert_interpreter
=
typeid_cast
<
const
InterpreterInsertQuery
*>
(
&*
interpreter
))
{
/// Save insertion table (not table function). TODO: support remote() table function.
auto
db_table
=
insert_interpreter
->
getDatabaseTable
();
if
(
!
db_table
.
secon
d
.
empty
())
context
.
setInsertionTable
(
std
::
move
(
db_table
));
auto
table_id
=
insert_interpreter
->
getDatabaseTable
();
if
(
!
table_i
d
.
empty
())
context
.
setInsertionTable
(
std
::
move
(
table_id
));
}
if
(
process_list_entry
)
...
...
dbms/src/Parsers/ASTInsertQuery.cpp
浏览文件 @
70dc82f9
...
...
@@ -2,6 +2,7 @@
#include <Parsers/ASTInsertQuery.h>
#include <Parsers/ASTFunction.h>
#include <Common/quoteString.h>
#include <IO/WriteHelpers.h>
namespace
DB
...
...
@@ -25,7 +26,8 @@ void ASTInsertQuery::formatImpl(const FormatSettings & settings, FormatState & s
}
else
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_none
:
""
)
<<
(
!
database
.
empty
()
?
backQuoteIfNeed
(
database
)
+
"."
:
""
)
<<
backQuoteIfNeed
(
table
);
<<
(
!
table_id
.
database_name
.
empty
()
?
backQuoteIfNeed
(
table_id
.
database_name
)
+
"."
:
""
)
<<
backQuoteIfNeed
(
table_id
.
table_name
)
<<
(
table_id
.
hasUUID
()
?
" UUID "
:
""
)
<<
(
table_id
.
hasUUID
()
?
quoteString
(
toString
(
table_id
.
uuid
))
:
""
);
if
(
columns
)
{
...
...
dbms/src/Parsers/ASTInsertQuery.h
浏览文件 @
70dc82f9
#pragma once
#include <Parsers/IAST.h>
#include <Storages/StorageID.h>
namespace
DB
{
...
...
@@ -12,8 +12,7 @@ namespace DB
class
ASTInsertQuery
:
public
IAST
{
public:
String
database
;
String
table
;
StorageID
table_id
=
StorageID
::
createEmpty
();
ASTPtr
columns
;
String
format
;
ASTPtr
select
;
...
...
@@ -31,7 +30,7 @@ public:
void
tryFindInputFunction
(
ASTPtr
&
input_function
)
const
;
/** Get the text that identifies this element. */
String
getID
(
char
delim
)
const
override
{
return
"InsertQuery"
+
(
delim
+
database
)
+
delim
+
tabl
e
;
}
String
getID
(
char
delim
)
const
override
{
return
"InsertQuery"
+
(
delim
+
table_id
.
database_name
)
+
delim
+
table_id
.
table_nam
e
;
}
ASTPtr
clone
()
const
override
{
...
...
dbms/src/Parsers/ParserInsertQuery.cpp
浏览文件 @
70dc82f9
...
...
@@ -151,8 +151,8 @@ bool ParserInsertQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
}
else
{
tryGetIdentifierNameInto
(
database
,
query
->
databas
e
);
tryGetIdentifierNameInto
(
table
,
query
->
table
);
tryGetIdentifierNameInto
(
database
,
query
->
table_id
.
database_nam
e
);
tryGetIdentifierNameInto
(
table
,
query
->
table
_id
.
table_name
);
}
tryGetIdentifierNameInto
(
format
,
query
->
format
);
...
...
dbms/src/Storages/Kafka/StorageKafka.cpp
浏览文件 @
70dc82f9
...
...
@@ -353,8 +353,7 @@ bool StorageKafka::streamToViews()
// Create an INSERT query for streaming data
auto
insert
=
std
::
make_shared
<
ASTInsertQuery
>
();
insert
->
database
=
table_id
.
database_name
;
insert
->
table
=
table_id
.
table_name
;
insert
->
table_id
=
table_id
;
const
Settings
&
settings
=
global_context
.
getSettingsRef
();
size_t
block_size
=
max_block_size
;
...
...
dbms/src/Storages/StorageBuffer.cpp
浏览文件 @
70dc82f9
...
...
@@ -643,9 +643,7 @@ void StorageBuffer::writeBlockToDestination(const Block & block, StoragePtr tabl
auto
temporarily_disable_memory_tracker
=
getCurrentMemoryTrackerActionLock
();
auto
insert
=
std
::
make_shared
<
ASTInsertQuery
>
();
insert
->
database
=
destination_id
.
database_name
;
insert
->
table
=
destination_id
.
table_name
;
insert
->
table_id
=
destination_id
;
/** We will insert columns that are the intersection set of columns of the buffer table and the subordinate table.
* This will support some of the cases (but not all) when the table structure does not match.
...
...
dbms/src/Storages/StorageDistributed.cpp
浏览文件 @
70dc82f9
...
...
@@ -110,8 +110,7 @@ ASTPtr rewriteSelectQuery(const ASTPtr & query, const std::string & database, co
ASTPtr
createInsertToRemoteTableQuery
(
const
std
::
string
&
database
,
const
std
::
string
&
table
,
const
Block
&
sample_block_non_materialized
)
{
auto
query
=
std
::
make_shared
<
ASTInsertQuery
>
();
query
->
database
=
database
;
query
->
table
=
table
;
query
->
table_id
=
StorageID
(
database
,
table
);
auto
columns
=
std
::
make_shared
<
ASTExpressionList
>
();
query
->
columns
=
columns
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录