ClickHouse/dbms/src/Parsers/ASTColumnsClause.cpp

46 lines
1.3 KiB
C++
Raw Normal View History

2019-07-16 20:05:00 +00:00
#include "ASTColumnsClause.h"
2019-07-12 11:17:38 +00:00
#include <IO/WriteBuffer.h>
#include <IO/WriteHelpers.h>
2019-07-16 20:05:00 +00:00
#include <IO/WriteBufferFromString.h>
#include <re2/re2.h>
2019-07-12 11:17:38 +00:00
namespace DB
{
ASTPtr ASTColumnsClause::clone() const
{
auto clone = std::make_shared<ASTColumnsClause>(*this);
clone->cloneChildren();
return clone;
}
2019-07-16 20:05:00 +00:00
void ASTColumnsClause::appendColumnName(WriteBuffer & ostr) const { writeString(original_pattern, ostr); }
2019-07-12 11:17:38 +00:00
void ASTColumnsClause::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
{
2019-07-16 20:05:00 +00:00
WriteBufferFromOwnString pattern_quoted;
writeQuotedString(original_pattern, pattern_quoted);
settings.ostr << (settings.hilite ? hilite_keyword : "") << "COLUMNS" << (settings.hilite ? hilite_none : "") << "(" << pattern_quoted.str() << ")";
}
void ASTColumnsClause::setPattern(String pattern)
{
original_pattern = std::move(pattern);
2019-07-21 02:13:42 +00:00
column_matcher = std::make_shared<RE2>(original_pattern, RE2::Quiet);
2019-07-16 20:05:00 +00:00
if (!column_matcher->ok())
throw DB::Exception("COLUMNS pattern " + original_pattern + " cannot be compiled: " + column_matcher->error(), DB::ErrorCodes::CANNOT_COMPILE_REGEXP);
2019-07-12 11:17:38 +00:00
}
2019-07-16 20:05:00 +00:00
bool ASTColumnsClause::isColumnMatching(const String & column_name) const
{
2019-07-21 02:13:42 +00:00
return RE2::PartialMatch(column_name, *column_matcher);
2019-07-16 20:05:00 +00:00
}
2019-07-12 11:17:38 +00:00
}