mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Merge pull request #54337 from wat-ze-hex/show-functions-2023-09-04
Add SHOW FUNCTIONS support to client
This commit is contained in:
commit
21a2cf7707
@ -638,3 +638,16 @@ Outputs the content of the [system.table_engines](../../operations/system-tables
|
||||
**See Also**
|
||||
|
||||
- [system.table_engines](../../operations/system-tables/table_engines.md) table
|
||||
|
||||
## SHOW FUNCTIONS
|
||||
|
||||
``` sql
|
||||
SHOW FUNCTIONS [LIKE | ILIKE '<pattern>']
|
||||
```
|
||||
|
||||
Outputs the content of the [system.functions](../../operations/system-tables/functions.md) table.
|
||||
|
||||
If either `LIKE` or `ILIKE` clause is specified, the query returns a list of system functions whose names match the provided `<pattern>`.
|
||||
|
||||
**See Also**
|
||||
- [system.functions](../../operations/system-tables/functions.md) table
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <Parsers/ASTSelectWithUnionQuery.h>
|
||||
#include <Parsers/ASTSetQuery.h>
|
||||
#include <Parsers/ASTShowEngineQuery.h>
|
||||
#include <Parsers/ASTShowFunctionsQuery.h>
|
||||
#include <Parsers/ASTShowProcesslistQuery.h>
|
||||
#include <Parsers/ASTShowTablesQuery.h>
|
||||
#include <Parsers/ASTShowColumnsQuery.h>
|
||||
@ -80,6 +81,7 @@
|
||||
#include <Interpreters/InterpreterSetQuery.h>
|
||||
#include <Interpreters/InterpreterShowCreateQuery.h>
|
||||
#include <Interpreters/InterpreterShowEngineQuery.h>
|
||||
#include <Interpreters/InterpreterShowFunctionsQuery.h>
|
||||
#include <Interpreters/InterpreterShowProcesslistQuery.h>
|
||||
#include <Interpreters/InterpreterShowTablesQuery.h>
|
||||
#include <Interpreters/InterpreterShowColumnsQuery.h>
|
||||
@ -203,6 +205,10 @@ std::unique_ptr<IInterpreter> InterpreterFactory::get(ASTPtr & query, ContextMut
|
||||
{
|
||||
return std::make_unique<InterpreterShowEnginesQuery>(query, context);
|
||||
}
|
||||
else if (query->as<ASTShowFunctionsQuery>())
|
||||
{
|
||||
return std::make_unique<InterpreterShowFunctionsQuery>(query, context);
|
||||
}
|
||||
else if (query->as<ASTUseQuery>())
|
||||
{
|
||||
return std::make_unique<InterpreterUseQuery>(query, context);
|
||||
|
46
src/Interpreters/InterpreterShowFunctionsQuery.cpp
Normal file
46
src/Interpreters/InterpreterShowFunctionsQuery.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <Interpreters/InterpreterShowFunctionsQuery.h>
|
||||
|
||||
#include <Interpreters/Context.h>
|
||||
#include <Interpreters/DatabaseCatalog.h>
|
||||
#include <Interpreters/executeQuery.h>
|
||||
#include <Parsers/ASTShowFunctionsQuery.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
InterpreterShowFunctionsQuery::InterpreterShowFunctionsQuery(const ASTPtr & query_ptr_, ContextMutablePtr context_)
|
||||
: WithMutableContext(context_), query_ptr(query_ptr_)
|
||||
{
|
||||
}
|
||||
|
||||
BlockIO InterpreterShowFunctionsQuery::execute()
|
||||
{
|
||||
return executeQuery(getRewrittenQuery(), getContext(), true);
|
||||
}
|
||||
|
||||
String InterpreterShowFunctionsQuery::getRewrittenQuery()
|
||||
{
|
||||
constexpr const char * functions_table = "functions";
|
||||
|
||||
const auto & query = query_ptr->as<ASTShowFunctionsQuery &>();
|
||||
|
||||
DatabasePtr systemDb = DatabaseCatalog::instance().getSystemDatabase();
|
||||
|
||||
String rewritten_query = fmt::format(
|
||||
R"(
|
||||
SELECT *
|
||||
FROM {}.{})",
|
||||
systemDb->getDatabaseName(),
|
||||
functions_table);
|
||||
|
||||
if (!query.like.empty())
|
||||
{
|
||||
rewritten_query += " WHERE name ";
|
||||
rewritten_query += query.case_insensitive_like ? "ILIKE " : "LIKE ";
|
||||
rewritten_query += fmt::format("'{}'", query.like);
|
||||
}
|
||||
|
||||
return rewritten_query;
|
||||
}
|
||||
|
||||
}
|
27
src/Interpreters/InterpreterShowFunctionsQuery.h
Normal file
27
src/Interpreters/InterpreterShowFunctionsQuery.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <Interpreters/IInterpreter.h>
|
||||
#include <Parsers/IAST_fwd.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class Context;
|
||||
|
||||
class InterpreterShowFunctionsQuery : public IInterpreter, WithMutableContext
|
||||
{
|
||||
public:
|
||||
InterpreterShowFunctionsQuery(const ASTPtr & query_ptr_, ContextMutablePtr context_);
|
||||
|
||||
BlockIO execute() override;
|
||||
|
||||
bool ignoreQuota() const override { return true; }
|
||||
bool ignoreLimits() const override { return true; }
|
||||
|
||||
private:
|
||||
ASTPtr query_ptr;
|
||||
|
||||
String getRewrittenQuery();
|
||||
};
|
||||
|
||||
}
|
25
src/Parsers/ASTShowFunctionsQuery.cpp
Normal file
25
src/Parsers/ASTShowFunctionsQuery.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include <Parsers/ASTShowFunctionsQuery.h>
|
||||
|
||||
#include <Common/quoteString.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
ASTPtr ASTShowFunctionsQuery::clone() const
|
||||
{
|
||||
auto res = std::make_shared<ASTShowFunctionsQuery>(*this);
|
||||
res->children.clear();
|
||||
cloneOutputOptions(*res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ASTShowFunctionsQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW FUNCTIONS" << (settings.hilite ? hilite_none : "");
|
||||
|
||||
if (!like.empty())
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << (case_insensitive_like ? " ILIKE " : " LIKE ")
|
||||
<< (settings.hilite ? hilite_none : "") << DB::quote << like;
|
||||
}
|
||||
|
||||
}
|
23
src/Parsers/ASTShowFunctionsQuery.h
Normal file
23
src/Parsers/ASTShowFunctionsQuery.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <Parsers/ASTQueryWithOutput.h>
|
||||
#include <Parsers/IAST_fwd.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class ASTShowFunctionsQuery : public ASTQueryWithOutput
|
||||
{
|
||||
public:
|
||||
bool case_insensitive_like = false;
|
||||
String like;
|
||||
|
||||
String getID(char) const override { return "ShowFunctions"; }
|
||||
ASTPtr clone() const override;
|
||||
QueryKind getQueryKind() const override { return QueryKind::Show; }
|
||||
|
||||
protected:
|
||||
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
|
||||
};
|
||||
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
#include <Parsers/ParserShowTablesQuery.h>
|
||||
#include <Parsers/ParserShowColumnsQuery.h>
|
||||
#include <Parsers/ParserShowEngineQuery.h>
|
||||
#include <Parsers/ParserShowFunctionsQuery.h>
|
||||
#include <Parsers/ParserShowIndexesQuery.h>
|
||||
#include <Parsers/ParserTablePropertiesQuery.h>
|
||||
#include <Parsers/ParserWatchQuery.h>
|
||||
@ -40,6 +41,7 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
ParserShowTablesQuery show_tables_p;
|
||||
ParserShowColumnsQuery show_columns_p;
|
||||
ParserShowEnginesQuery show_engine_p;
|
||||
ParserShowFunctionsQuery show_functions_p;
|
||||
ParserShowIndexesQuery show_indexes_p;
|
||||
ParserSelectWithUnionQuery select_p;
|
||||
ParserTablePropertiesQuery table_p;
|
||||
@ -71,6 +73,7 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
|| show_tables_p.parse(pos, query, expected)
|
||||
|| show_columns_p.parse(pos, query, expected)
|
||||
|| show_engine_p.parse(pos, query, expected)
|
||||
|| show_functions_p.parse(pos, query, expected)
|
||||
|| show_indexes_p.parse(pos, query, expected)
|
||||
|| table_p.parse(pos, query, expected)
|
||||
|| describe_cache_p.parse(pos, query, expected)
|
||||
|
35
src/Parsers/ParserShowFunctionsQuery.cpp
Normal file
35
src/Parsers/ParserShowFunctionsQuery.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <Parsers/ParserShowFunctionsQuery.h>
|
||||
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/ASTShowFunctionsQuery.h>
|
||||
#include <Parsers/CommonParsers.h>
|
||||
#include <Parsers/ExpressionElementParsers.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
bool ParserShowFunctionsQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
{
|
||||
ASTPtr like;
|
||||
|
||||
auto query = std::make_shared<ASTShowFunctionsQuery>();
|
||||
if (!ParserKeyword("SHOW FUNCTIONS").ignore(pos, expected))
|
||||
return false;
|
||||
|
||||
if (bool insensitive = ParserKeyword("ILIKE").ignore(pos, expected); insensitive || ParserKeyword("LIKE").ignore(pos, expected))
|
||||
{
|
||||
if (insensitive)
|
||||
query->case_insensitive_like = true;
|
||||
|
||||
if (!ParserStringLiteral().parse(pos, like, expected))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (like)
|
||||
query->like = like->as<ASTLiteral &>().value.safeGet<const String &>();
|
||||
node = query;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
19
src/Parsers/ParserShowFunctionsQuery.h
Normal file
19
src/Parsers/ParserShowFunctionsQuery.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <Parsers/IParserBase.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/** Parses queries of the form
|
||||
* SHOW FUNCTIONS [LIKE | ILIKE '<pattern>']
|
||||
*/
|
||||
class ParserShowFunctionsQuery : public IParserBase
|
||||
{
|
||||
protected:
|
||||
const char * getName() const override { return "SHOW FUNCTIONS query"; }
|
||||
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
||||
};
|
||||
|
||||
}
|
@ -8,3 +8,4 @@ $CLICKHOUSE_CLIENT -q "SHOW PROCESSLIST" &>/dev/null
|
||||
$CLICKHOUSE_CLIENT -q "SHOW DATABASES" &>/dev/null
|
||||
$CLICKHOUSE_CLIENT -q "SHOW TABLES" &>/dev/null
|
||||
$CLICKHOUSE_CLIENT -q "SHOW ENGINES" &>/dev/null
|
||||
$CLICKHOUSE_CLIENT -q "SHOW FUNCTIONS" &>/dev/null
|
||||
|
14
tests/queries/0_stateless/02875_show_functions.sh
Executable file
14
tests/queries/0_stateless/02875_show_functions.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
diff -q <($CLICKHOUSE_CLIENT -q "SELECT * from system.functions") \
|
||||
<($CLICKHOUSE_CLIENT -q "SHOW FUNCTIONS")
|
||||
|
||||
diff -q <($CLICKHOUSE_CLIENT -q "SELECT * FROM system.functions WHERE name ILIKE 'quantile%'") \
|
||||
<($CLICKHOUSE_CLIENT -q "SHOW FUNCTIONS ILIKE 'quantile%'")
|
||||
|
||||
diff -q <($CLICKHOUSE_CLIENT -q "SELECT * FROM system.functions WHERE name LIKE 'median%'") \
|
||||
<($CLICKHOUSE_CLIENT -q "SHOW FUNCTIONS LIKE 'median%'")
|
Loading…
Reference in New Issue
Block a user