Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-milovidov committed Mar 21, 2024
1 parent 99ed82d commit 4d67095
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/Analyzer/MatcherNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ MatcherNode::MatcherNode(Identifier qualified_identifier_, Identifiers columns_i
MatcherNode::MatcherNode(MatcherNodeType matcher_type_,
Identifier qualified_identifier_,
Identifiers columns_identifiers_,
String pattern_,
std::optional<String> pattern_,
ColumnTransformersNodes column_transformers_)
: IQueryTreeNode(children_size)
, matcher_type(matcher_type_)
, qualified_identifier(qualified_identifier_)
, columns_identifiers(columns_identifiers_)
{
if (!pattern_.empty())
if (pattern_)
{
columns_matcher = std::make_shared<re2::RE2>(pattern_, re2::RE2::Quiet);
columns_matcher = std::make_shared<re2::RE2>(*pattern_, re2::RE2::Quiet);
if (!columns_matcher->ok())
throw DB::Exception(ErrorCodes::CANNOT_COMPILE_REGEXP,
"COLUMNS pattern {} cannot be compiled: {}", pattern_, columns_matcher->error());
"COLUMNS pattern {} cannot be compiled: {}", *pattern_, columns_matcher->error());
}

auto column_transformers_list_node = std::make_shared<ListNode>();
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/MatcherNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class MatcherNode final : public IQueryTreeNode
explicit MatcherNode(MatcherNodeType matcher_type_,
Identifier qualified_identifier_,
Identifiers columns_identifiers_,
String pattern_,
std::optional<String> pattern_,
ColumnTransformersNodes column_transformers_);

MatcherNodeType matcher_type;
Expand Down
23 changes: 13 additions & 10 deletions src/Parsers/ASTColumnsTransformers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ void ASTColumnsExceptTransformer::formatImpl(const FormatSettings & settings, Fo
(*it)->formatImpl(settings, state, frame);
}

if (!pattern.empty())
settings.ostr << quoteString(pattern);
if (pattern)
settings.ostr << quoteString(*pattern);

if (children.size() > 1)
settings.ostr << ")";
Expand All @@ -203,8 +203,8 @@ void ASTColumnsExceptTransformer::appendColumnName(WriteBuffer & ostr) const
(*it)->appendColumnName(ostr);
}

if (!pattern.empty())
writeQuotedString(pattern, ostr);
if (pattern)
writeQuotedString(*pattern, ostr);

if (children.size() > 1)
writeChar(')', ostr);
Expand All @@ -213,16 +213,19 @@ void ASTColumnsExceptTransformer::appendColumnName(WriteBuffer & ostr) const
void ASTColumnsExceptTransformer::updateTreeHashImpl(SipHash & hash_state, bool ignore_aliases) const
{
hash_state.update(is_strict);
hash_state.update(pattern.size());
hash_state.update(pattern);
if (pattern)
{
hash_state.update(pattern->size());
hash_state.update(*pattern);
}

IAST::updateTreeHashImpl(hash_state, ignore_aliases);
}

void ASTColumnsExceptTransformer::transform(ASTs & nodes) const
{
std::set<String> expected_columns;
if (pattern.empty())
if (!pattern)
{
for (const auto & child : children)
expected_columns.insert(child->as<const ASTIdentifier &>().name());
Expand Down Expand Up @@ -278,13 +281,13 @@ void ASTColumnsExceptTransformer::setPattern(String pattern_)

std::shared_ptr<re2::RE2> ASTColumnsExceptTransformer::getMatcher() const
{
if (pattern.empty())
if (!pattern)
return {};

auto regexp = std::make_shared<re2::RE2>(pattern, re2::RE2::Quiet);
auto regexp = std::make_shared<re2::RE2>(*pattern, re2::RE2::Quiet);
if (!regexp->ok())
throw Exception(ErrorCodes::CANNOT_COMPILE_REGEXP,
"COLUMNS pattern {} cannot be compiled: {}", pattern, regexp->error());
"COLUMNS pattern {} cannot be compiled: {}", *pattern, regexp->error());
return regexp;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/ASTColumnsTransformers.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ASTColumnsExceptTransformer : public IASTColumnsTransformer

protected:
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
String pattern;
std::optional<String> pattern;
};

class ASTColumnsReplaceTransformer : public IASTColumnsTransformer
Expand Down

0 comments on commit 4d67095

Please sign in to comment.