Fix SET query formatting

This commit is contained in:
Nikolay Degterinsky 2023-11-16 05:18:50 +00:00
parent 648e0bd4cb
commit ef17d972ab
3 changed files with 71 additions and 1 deletions

View File

@ -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)

View 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%\''}

View 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;