mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Fix SET query formatting
This commit is contained in:
parent
648e0bd4cb
commit
ef17d972ab
@ -4,11 +4,57 @@
|
||||
#include <Common/FieldVisitorHash.h>
|
||||
#include <Common/FieldVisitorToString.h>
|
||||
#include <IO/Operators.h>
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class FieldVisitorToSetting : public StaticVisitor<String>
|
||||
{
|
||||
public:
|
||||
template <class T>
|
||||
String operator() (const T & x) const
|
||||
{
|
||||
FieldVisitorToString visitor;
|
||||
return visitor(x);
|
||||
}
|
||||
|
||||
String operator() (const Map & x) const
|
||||
{
|
||||
WriteBufferFromOwnString wb;
|
||||
|
||||
wb << '{';
|
||||
|
||||
auto it = x.begin();
|
||||
while (it != x.end())
|
||||
{
|
||||
if (it != x.begin())
|
||||
wb << ", ";
|
||||
wb << applyVisitor(*this, *it);
|
||||
++it;
|
||||
}
|
||||
wb << '}';
|
||||
|
||||
return wb.str();
|
||||
}
|
||||
|
||||
String operator() (const Tuple & x) const
|
||||
{
|
||||
WriteBufferFromOwnString wb;
|
||||
|
||||
for (auto it = x.begin(); it != x.end(); ++it)
|
||||
{
|
||||
if (it != x.begin())
|
||||
wb << ":";
|
||||
wb << applyVisitor(*this, *it);
|
||||
}
|
||||
|
||||
return wb.str();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void ASTSetQuery::updateTreeHashImpl(SipHash & hash_state, bool /*ignore_aliases*/) const
|
||||
{
|
||||
for (const auto & change : changes)
|
||||
@ -38,7 +84,7 @@ void ASTSetQuery::formatImpl(const FormatSettings & format, FormatState &, Forma
|
||||
if (!format.show_secrets && change.value.tryGet<CustomType>(custom) && custom.isSecret())
|
||||
format.ostr << " = " << custom.toString(false);
|
||||
else
|
||||
format.ostr << " = " << applyVisitor(FieldVisitorToString(), change.value);
|
||||
format.ostr << " = " << applyVisitor(FieldVisitorToSetting(), change.value);
|
||||
}
|
||||
|
||||
for (const auto & setting_name : default_settings)
|
||||
|
11
tests/queries/0_stateless/02916_set_formatting.reference
Normal file
11
tests/queries/0_stateless/02916_set_formatting.reference
Normal file
@ -0,0 +1,11 @@
|
||||
SET additional_table_filters = {\'kjsnckjn\':\'ksanmn\', \'dkm\':\'dd\'}
|
||||
SELECT v FROM t1 SETTINGS additional_table_filters = {\'default.t1\':\'s\'}
|
||||
Row 1:
|
||||
──────
|
||||
statement: CREATE VIEW default.v1
|
||||
(
|
||||
`v` UInt64
|
||||
) AS
|
||||
SELECT v
|
||||
FROM default.t1
|
||||
SETTINGS additional_table_filters = {'default.t1':'s != \'s1%\''}
|
13
tests/queries/0_stateless/02916_set_formatting.sql
Normal file
13
tests/queries/0_stateless/02916_set_formatting.sql
Normal file
@ -0,0 +1,13 @@
|
||||
SELECT formatQuerySingleLine('set additional_table_filters = {\'kjsnckjn\': \'ksanmn\', \'dkm\': \'dd\'}');
|
||||
SELECT formatQuerySingleLine('SELECT v FROM t1 SETTINGS additional_table_filters = {\'default.t1\': \'s\'}');
|
||||
|
||||
DROP TABLE IF EXISTS t1;
|
||||
DROP VIEW IF EXISTS v1;
|
||||
|
||||
CREATE TABLE t1 (v UInt64, s String) ENGINE=MergeTree() ORDER BY v;
|
||||
CREATE VIEW v1 (v UInt64) AS SELECT v FROM t1 SETTINGS additional_table_filters = {'default.t1': 's != \'s1%\''};
|
||||
|
||||
SHOW CREATE TABLE v1 FORMAT Vertical;
|
||||
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
Loading…
Reference in New Issue
Block a user