mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Merge pull request #36834 from azat/client-complete-func
Add functions from CREATE FUNCTION to completion
This commit is contained in:
commit
9621d44345
@ -44,6 +44,7 @@
|
||||
#include <Parsers/formatAST.h>
|
||||
#include <Parsers/ASTInsertQuery.h>
|
||||
#include <Parsers/ASTCreateQuery.h>
|
||||
#include <Parsers/ASTCreateFunctionQuery.h>
|
||||
#include <Parsers/ASTDropQuery.h>
|
||||
#include <Parsers/ASTSetQuery.h>
|
||||
#include <Parsers/ASTUseQuery.h>
|
||||
@ -592,24 +593,33 @@ void ClientBase::initLogsOutputStream()
|
||||
}
|
||||
}
|
||||
|
||||
void ClientBase::updateSuggest(const ASTCreateQuery & ast_create)
|
||||
void ClientBase::updateSuggest(const ASTPtr & ast)
|
||||
{
|
||||
std::vector<std::string> new_words;
|
||||
|
||||
if (ast_create.database)
|
||||
new_words.push_back(ast_create.getDatabase());
|
||||
new_words.push_back(ast_create.getTable());
|
||||
|
||||
if (ast_create.columns_list && ast_create.columns_list->columns)
|
||||
if (auto * create = ast->as<ASTCreateQuery>())
|
||||
{
|
||||
for (const auto & elem : ast_create.columns_list->columns->children)
|
||||
if (create->database)
|
||||
new_words.push_back(create->getDatabase());
|
||||
new_words.push_back(create->getTable());
|
||||
|
||||
if (create->columns_list && create->columns_list->columns)
|
||||
{
|
||||
if (const auto * column = elem->as<ASTColumnDeclaration>())
|
||||
new_words.push_back(column->name);
|
||||
for (const auto & elem : create->columns_list->columns->children)
|
||||
{
|
||||
if (const auto * column = elem->as<ASTColumnDeclaration>())
|
||||
new_words.push_back(column->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suggest->addWords(std::move(new_words));
|
||||
if (const auto * create_function = ast->as<ASTCreateFunctionQuery>())
|
||||
{
|
||||
new_words.push_back(create_function->getFunctionName());
|
||||
}
|
||||
|
||||
if (!new_words.empty())
|
||||
suggest->addWords(std::move(new_words));
|
||||
}
|
||||
|
||||
bool ClientBase::isSyncInsertWithData(const ASTInsertQuery & insert_query, const ContextPtr & context)
|
||||
@ -640,13 +650,11 @@ void ClientBase::processTextAsSingleQuery(const String & full_query)
|
||||
/// always means a problem, i.e. if table already exists, and it is no a
|
||||
/// huge problem if suggestion will be added even on error, since this is
|
||||
/// just suggestion.
|
||||
if (auto * create = parsed_query->as<ASTCreateQuery>())
|
||||
{
|
||||
/// Do not update suggest, until suggestion will be ready
|
||||
/// (this will avoid extra complexity)
|
||||
if (suggest)
|
||||
updateSuggest(*create);
|
||||
}
|
||||
///
|
||||
/// Do not update suggest, until suggestion will be ready
|
||||
/// (this will avoid extra complexity)
|
||||
if (suggest)
|
||||
updateSuggest(parsed_query);
|
||||
|
||||
/// An INSERT query may have the data that follows query text.
|
||||
/// Send part of the query without data, because data will be sent separately.
|
||||
|
@ -146,7 +146,7 @@ private:
|
||||
std::vector<Arguments> & hosts_and_ports_arguments);
|
||||
void parseAndCheckOptions(OptionsDescription & options_description, po::variables_map & options, Arguments & arguments);
|
||||
|
||||
void updateSuggest(const ASTCreateQuery & ast_create);
|
||||
void updateSuggest(const ASTPtr & ast);
|
||||
|
||||
void initQueryIdFormats();
|
||||
|
||||
|
@ -44,13 +44,9 @@ expect -re TSV.*TSV.*begin-(.*)-end.*
|
||||
set uuid $expect_out(1,string)
|
||||
expect ":) "
|
||||
|
||||
# Create
|
||||
# CREATE DATABASE
|
||||
send -- "create database new_${uuid}_database\r"
|
||||
expect ":) "
|
||||
send -- "create table new_${uuid}_table (new_${uuid}_column Int) engine=Null()\r"
|
||||
expect ":) "
|
||||
|
||||
# Check completion
|
||||
send -- "new_${uuid}_data"
|
||||
expect "new_${uuid}_data"
|
||||
send -- "\t"
|
||||
@ -59,6 +55,9 @@ expect "base"
|
||||
send -- "\3"
|
||||
expect ":) "
|
||||
|
||||
# CREATE TABLE
|
||||
send -- "create table new_${uuid}_table (new_${uuid}_column Int) engine=Null()\r"
|
||||
expect ":) "
|
||||
send -- "new_${uuid}_ta"
|
||||
expect "new_${uuid}_ta"
|
||||
send -- "\t"
|
||||
@ -67,6 +66,7 @@ expect "ble"
|
||||
send -- "\3"
|
||||
expect ":) "
|
||||
|
||||
# Column from table
|
||||
send -- "new_${uuid}_col"
|
||||
expect "new_${uuid}_col"
|
||||
send -- "\t"
|
||||
@ -75,11 +75,24 @@ expect "umn"
|
||||
send -- "\3"
|
||||
expect ":) "
|
||||
|
||||
# CREATE FUNCTION
|
||||
send -- "create function new_${uuid}_function as x -> x\r"
|
||||
expect ":) "
|
||||
send -- "new_${uuid}_func"
|
||||
expect "new_${uuid}_func"
|
||||
send -- "\t"
|
||||
expect "tion"
|
||||
# Ctrl-C
|
||||
send -- "\3"
|
||||
expect ":) "
|
||||
|
||||
# Cleanup
|
||||
send -- "drop database new_${uuid}_database\r"
|
||||
expect ":) "
|
||||
send -- "drop table new_${uuid}_table\r"
|
||||
expect ":) "
|
||||
send -- "drop function new_${uuid}_function\r"
|
||||
expect ":) "
|
||||
|
||||
# Ctrl-D
|
||||
send -- "\4"
|
||||
|
Loading…
Reference in New Issue
Block a user