Merge branch 'remove_tenantid_showcreate_dev1' into 'cnch-dev'

fix(clickhousech@m-5285122147): remove tenant id for show create query result

See merge request dp/ClickHouse!25693
This commit is contained in:
Yuan Zhu 2024-10-15 08:37:03 +00:00 committed by Fred Wang
parent 2d86bfd3e9
commit 96f6db8858
7 changed files with 18 additions and 10 deletions

View File

@ -143,7 +143,7 @@ BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl()
create.to_inner_uuid = UUIDHelpers::Nil;
}
String res = create_query->formatWithHiddenSecrets(/* max_length= */ 0, /* one_line= */ false, /*no_alias*/ false, getContext()->getSettingsRef().dialect_type);
String res = create_query->formatWithHiddenSecrets(/* max_length= */ 0, /* one_line= */ false, /*no_alias*/ false, getContext()->getSettingsRef().dialect_type, /*remove_tenant_id*/true);
MutableColumnPtr column = ColumnString::create();
column->insert(res);

View File

@ -139,9 +139,12 @@ const std::vector<String> & ASTIdentifier::nameParts() const
void ASTIdentifier::formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
auto format_element = [&](const String & elem_name) {
auto format_element = [&](const String & elem_name, bool remove_tenant = false) {
settings.ostr << (settings.hilite ? hilite_identifier : "");
settings.writeIdentifier(elem_name);
if (remove_tenant)
settings.writeIdentifier(getOriginalEntityName(elem_name));
else
settings.writeIdentifier(elem_name);
settings.ostr << (settings.hilite ? hilite_none : "");
};
@ -161,7 +164,7 @@ void ASTIdentifier::formatImplWithoutAlias(const FormatSettings & settings, Form
++j;
}
else
format_element(name_parts[i]);
format_element(name_parts[i], i == 0 && settings.remove_tenant_id);
}
}
else if (is_implicit_map_key)

View File

@ -91,12 +91,13 @@ size_t IAST::checkDepthImpl(size_t max_depth, size_t level) const
return res;
}
String IAST::formatWithHiddenSecrets(size_t max_length, bool one_line, bool no_alias, DialectType dialect) const
String IAST::formatWithHiddenSecrets(size_t max_length, bool one_line, bool no_alias, DialectType dialect, bool remove_tenant_id) const
{
WriteBufferFromOwnString buf;
FormatSettings settings{buf, one_line, no_alias};
settings.show_secrets = false;
settings.dialect_type = dialect;
settings.remove_tenant_id = remove_tenant_id;
format(settings);
return wipeSensitiveDataAndCutToLength(buf.str(), max_length);

View File

@ -400,6 +400,7 @@ public:
struct FormatSettings
{
WriteBuffer & ostr;
bool remove_tenant_id = false;
bool hilite = false;
bool one_line;
bool always_quote_identifiers = false;
@ -466,7 +467,8 @@ public:
String formatWithHiddenSecrets(size_t max_length = 0,
bool one_line = true,
bool no_alias = false,
DialectType dialect = DialectType::CLICKHOUSE) const;
DialectType dialect = DialectType::CLICKHOUSE,
bool remove_tenant_id = false) const;
String formatForLogging(size_t max_length = 0) const { return formatWithHiddenSecrets(max_length, true); }
String formatForErrorMessage() const { return formatWithHiddenSecrets(0, true); }
String formatForErrorMessageWithoutAlias() const { return formatWithHiddenSecrets(0, true, true); }

View File

@ -26,12 +26,13 @@
namespace DB
{
void formatAST(const IAST & ast, WriteBuffer & buf, bool hilite, bool one_line, bool always_quote_identifiers, DialectType dialect)
void formatAST(const IAST & ast, WriteBuffer & buf, bool hilite, bool one_line, bool always_quote_identifiers, DialectType dialect, bool remove_tenant_id)
{
IAST::FormatSettings settings(buf, one_line);
settings.hilite = hilite;
settings.always_quote_identifiers = always_quote_identifiers;
settings.dialect_type = dialect;
settings.remove_tenant_id = remove_tenant_id;
ast.format(settings);
}

View File

@ -36,8 +36,9 @@ void formatAST(const IAST &ast,
WriteBuffer &buf,
bool hilite = true,
bool one_line = false,
bool always_quote_identifiers = false,
DialectType dialect = DialectType::CLICKHOUSE);
bool always_quote_identifiers = false,
DialectType dialect = DialectType::CLICKHOUSE,
bool remove_tenant_id = false);
String serializeAST(const IAST & ast, bool one_line = true, bool always_quote_identifiers = false);

View File

@ -1 +1 @@
CREATE VIEW default.test_view_00599\n(\n `id` UInt64\n) AS\nSELECT *\nFROM `${TENANT_DB_PREFIX}default`.test_00599\nWHERE id = (\n SELECT 1\n)
CREATE VIEW default.test_view_00599\n(\n `id` UInt64\n) AS\nSELECT *\nFROM default.test_00599\nWHERE id = (\n SELECT 1\n)