Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
7254478f
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,发现更多精彩内容 >>
提交
7254478f
编写于
7月 20, 2017
作者:
V
Vladimir Chebotarev
提交者:
alexey-milovidov
7月 20, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
functions: Remote mode for hasColumnInTable. [#CHEBOTAREV-9]
上级
dd0905e9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
71 addition
and
20 deletion
+71
-20
dbms/src/Functions/FunctionsMiscellaneous.cpp
dbms/src/Functions/FunctionsMiscellaneous.cpp
+51
-14
dbms/tests/queries/0_stateless/00386_has_column_in_table.reference
...s/queries/0_stateless/00386_has_column_in_table.reference
+7
-0
dbms/tests/queries/0_stateless/00386_has_column_in_table.sql
dbms/tests/queries/0_stateless/00386_has_column_in_table.sql
+7
-0
docs/en/functions/other_functions.rst
docs/en/functions/other_functions.rst
+3
-3
docs/ru/functions/other_functions.rst
docs/ru/functions/other_functions.rst
+3
-3
未找到文件。
dbms/src/Functions/FunctionsMiscellaneous.cpp
浏览文件 @
7254478f
...
...
@@ -16,10 +16,12 @@
#include <DataTypes/DataTypeTuple.h>
#include <DataTypes/DataTypesNumber.h>
#include <Functions/FunctionFactory.h>
#include <Interpreters/Cluster.h>
#include <Interpreters/Context.h>
#include <Interpreters/Set.h>
#include <Storages/IStorage.h>
#include <Common/typeid_cast.h>
#include <TableFunctions/getStructureOfRemoteTable.h>
namespace
DB
...
...
@@ -1666,18 +1668,12 @@ public:
/** Usage:
* hasColumnInTable('database', 'table', 'column')
* hasColumnInTable(
['hostname'[, 'username'[, 'password']],]
'database', 'table', 'column')
*/
class
FunctionHasColumnInTable
:
public
IFunction
{
public:
static
constexpr
auto
name
=
"hasColumnInTable"
;
size_t
getNumberOfArguments
()
const
override
{
return
3
;
}
static
FunctionPtr
create
(
const
Context
&
context
)
{
return
std
::
make_shared
<
FunctionHasColumnInTable
>
(
context
.
getGlobalContext
());
...
...
@@ -1687,6 +1683,15 @@ public:
{
}
bool
isVariadic
()
const
override
{
return
true
;
}
size_t
getNumberOfArguments
()
const
override
{
return
0
;
}
String
getName
()
const
override
{
return
name
;
...
...
@@ -1743,8 +1748,12 @@ void FunctionVisibleWidth::executeImpl(Block & block, const ColumnNumbers & argu
void
FunctionHasColumnInTable
::
getReturnTypeAndPrerequisitesImpl
(
const
ColumnsWithTypeAndName
&
arguments
,
DataTypePtr
&
out_return_type
,
ExpressionActions
::
Actions
&
out_prerequisites
)
{
static
const
std
::
string
arg_pos_description
[]
=
{
"First"
,
"Second"
,
"Third"
};
for
(
size_t
i
=
0
;
i
<
getNumberOfArguments
();
++
i
)
if
(
arguments
.
size
()
<
3
||
arguments
.
size
()
>
6
)
throw
Exception
{
"Invalid number of arguments for function "
+
getName
(),
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
};
static
const
std
::
string
arg_pos_description
[]
=
{
"First"
,
"Second"
,
"Third"
,
"Fourth"
,
"Fifth"
,
"Sixth"
};
for
(
size_t
i
=
0
;
i
<
arguments
.
size
();
++
i
)
{
const
ColumnWithTypeAndName
&
argument
=
arguments
[
i
];
...
...
@@ -1768,12 +1777,40 @@ void FunctionHasColumnInTable::executeImpl(Block & block, const ColumnNumbers &
return
const_column
->
getData
();
};
const
String
&
database_name
=
get_string_from_block
(
arguments
[
0
]);
const
String
&
table_name
=
get_string_from_block
(
arguments
[
1
]);
const
String
&
column_name
=
get_string_from_block
(
arguments
[
2
]);
size_t
arg
=
0
;
const
String
*
host_name
=
nullptr
;
const
String
*
user_name
=
nullptr
;
const
String
*
password
=
nullptr
;
if
(
arguments
.
size
()
>
3
)
{
host_name
=
&
get_string_from_block
(
arguments
[
arg
++
]);
}
if
(
arguments
.
size
()
>
4
)
{
user_name
=
&
get_string_from_block
(
arguments
[
arg
++
]);
}
if
(
arguments
.
size
()
>
5
)
{
password
=
&
get_string_from_block
(
arguments
[
arg
++
]);
}
const
String
&
database_name
=
get_string_from_block
(
arguments
[
arg
++
]);
const
String
&
table_name
=
get_string_from_block
(
arguments
[
arg
++
]);
const
String
&
column_name
=
get_string_from_block
(
arguments
[
arg
++
]);
const
StoragePtr
&
table
=
global_context
.
getTable
(
database_name
,
table_name
);
const
bool
has_column
=
table
->
hasColumn
(
column_name
);
bool
has_column
;
if
(
host_name
==
nullptr
)
{
const
StoragePtr
&
table
=
global_context
.
getTable
(
database_name
,
table_name
);
has_column
=
table
->
hasColumn
(
column_name
);
}
else
{
std
::
vector
<
std
::
vector
<
String
>>
host_names
=
{{
*
host_name
}};
auto
cluster
=
std
::
make_shared
<
Cluster
>
(
global_context
.
getSettings
(),
host_names
,
user_name
!=
nullptr
?
*
user_name
:
"default"
,
password
!=
nullptr
?
*
password
:
""
);
auto
names_and_types_list
=
std
::
make_shared
<
NamesAndTypesList
>
(
getStructureOfRemoteTable
(
*
cluster
,
database_name
,
table_name
,
global_context
));
const
auto
&
names
=
names_and_types_list
->
getNames
();
has_column
=
std
::
find
(
names
.
begin
(),
names
.
end
(),
column_name
)
!=
names
.
end
();
}
block
.
safeGetByPosition
(
result
).
column
=
std
::
make_shared
<
ColumnConstUInt8
>
(
block
.
rows
(),
has_column
);
}
...
...
dbms/tests/queries/0_stateless/00386_has_column_in_table.reference
浏览文件 @
7254478f
...
...
@@ -2,6 +2,13 @@
1
1
1
1
1
1
1
0
0
0
0
0
0
dbms/tests/queries/0_stateless/00386_has_column_in_table.sql
浏览文件 @
7254478f
...
...
@@ -4,13 +4,20 @@ CREATE TABLE test.has_column_in_table (i Int64, s String, nest Nested(x UInt8, y
/* existing column */
SELECT
hasColumnInTable
(
'test'
,
'has_column_in_table'
,
'i'
);
SELECT
hasColumnInTable
(
'localhost'
,
'test'
,
'has_column_in_table'
,
'i'
);
SELECT
hasColumnInTable
(
'test'
,
'has_column_in_table'
,
's'
);
SELECT
hasColumnInTable
(
'localhost'
,
'test'
,
'has_column_in_table'
,
's'
);
SELECT
hasColumnInTable
(
'test'
,
'has_column_in_table'
,
'nest.x'
);
SELECT
hasColumnInTable
(
'localhost'
,
'test'
,
'has_column_in_table'
,
'nest.x'
);
SELECT
hasColumnInTable
(
'test'
,
'has_column_in_table'
,
'nest.y'
);
SELECT
hasColumnInTable
(
'localhost'
,
'test'
,
'has_column_in_table'
,
'nest.y'
);
/* not existing column */
SELECT
hasColumnInTable
(
'test'
,
'has_column_in_table'
,
'nest'
);
SELECT
hasColumnInTable
(
'localhost'
,
'test'
,
'has_column_in_table'
,
'nest'
);
SELECT
hasColumnInTable
(
'test'
,
'has_column_in_table'
,
'nest.not_existing'
);
SELECT
hasColumnInTable
(
'localhost'
,
'test'
,
'has_column_in_table'
,
'nest.not_existing'
);
SELECT
hasColumnInTable
(
'test'
,
'has_column_in_table'
,
'not_existing'
);
SELECT
hasColumnInTable
(
'localhost'
,
'test'
,
'has_column_in_table'
,
'not_existing'
);
DROP
TABLE
test
.
has_column_in_table
;
docs/en/functions/other_functions.rst
浏览文件 @
7254478f
...
...
@@ -50,10 +50,10 @@ isNaN(x)
~~~~~~~~
Accepts Float32 and Float64 and returns UInt8 equal to 1 if the argument is a NaN, otherwise 0.
hasColumnInTable('database', 'table', 'column')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hasColumnInTable(
['hostname'[, 'username'[, 'password']],]
'database', 'table', 'column')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Accepts constant String columns - database name, table name and column name. Returns constant UInt8 value, equal to 1 if column exists,
otherwise 0.
otherwise 0.
If hostname is specified, the check will proceed on remote host.
If table doesn't exist than exception is thrown.
For elements of nested data structure function checks existence of column. For nested data structure 0 is returned.
...
...
docs/ru/functions/other_functions.rst
浏览文件 @
7254478f
...
...
@@ -50,10 +50,10 @@ isNaN(x)
~~~~~~~~
Принимает Float32 или Float64 и возвращает UInt8, равный 1, если аргумент является NaN, иначе 0.
hasColumnInTable('database', 'table', 'column')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hasColumnInTable(
['hostname'[, 'username'[, 'password']],]
'database', 'table', 'column')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Принимает константные строки - имя базы данных, имя таблицы и название столбца. Возвращает константное выражение типа UInt8, равное 1,
если есть столбец, иначе 0.
если есть столбец, иначе 0.
Если задан параметр hostname, проверка будет выполнена на удалённом сервере.
Функция кидает исключение, если таблица не существует.
Для элементов вложенной структуры данных функция проверяет существование столбца. Для самой же вложенной структуры данных функция возвращает 0.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录