2019-07-21 17:03:58 +00:00
|
|
|
#include "ASTColumnsMatcher.h"
|
2019-07-12 11:17:38 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
2019-10-08 18:42:22 +00:00
|
|
|
#include <Common/quoteString.h>
|
2019-07-16 20:05:00 +00:00
|
|
|
#include <re2/re2.h>
|
2020-08-20 02:01:40 +00:00
|
|
|
#include <Common/SipHash.h>
|
2019-07-16 20:05:00 +00:00
|
|
|
|
|
|
|
|
2019-07-12 11:17:38 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-25 18:10:48 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int CANNOT_COMPILE_REGEXP;
|
|
|
|
}
|
2019-07-12 11:17:38 +00:00
|
|
|
|
2019-07-21 17:03:58 +00:00
|
|
|
ASTPtr ASTColumnsMatcher::clone() const
|
2019-07-12 11:17:38 +00:00
|
|
|
{
|
2019-07-21 17:03:58 +00:00
|
|
|
auto clone = std::make_shared<ASTColumnsMatcher>(*this);
|
2019-07-12 11:17:38 +00:00
|
|
|
clone->cloneChildren();
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2019-07-21 17:03:58 +00:00
|
|
|
void ASTColumnsMatcher::appendColumnName(WriteBuffer & ostr) const { writeString(original_pattern, ostr); }
|
2019-07-12 11:17:38 +00:00
|
|
|
|
2020-08-20 02:01:40 +00:00
|
|
|
void ASTColumnsMatcher::updateTreeHashImpl(SipHash & hash_state) const
|
|
|
|
{
|
|
|
|
hash_state.update(original_pattern.size());
|
|
|
|
hash_state.update(original_pattern);
|
|
|
|
IAST::updateTreeHashImpl(hash_state);
|
|
|
|
}
|
|
|
|
|
2020-08-29 05:33:46 +00:00
|
|
|
void ASTColumnsMatcher::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
2019-07-12 11:17:38 +00:00
|
|
|
{
|
2020-09-16 12:44:05 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "COLUMNS" << (settings.hilite ? hilite_none : "") << "(";
|
|
|
|
if (column_list)
|
|
|
|
column_list->formatImpl(settings, state, frame);
|
|
|
|
else
|
|
|
|
settings.ostr << quoteString(original_pattern);
|
|
|
|
settings.ostr << ")";
|
2020-08-29 05:33:46 +00:00
|
|
|
for (ASTs::const_iterator it = children.begin() + 1; it != children.end(); ++it)
|
|
|
|
{
|
|
|
|
settings.ostr << ' ';
|
|
|
|
(*it)->formatImpl(settings, state, frame);
|
|
|
|
}
|
2019-07-16 20:05:00 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 17:03:58 +00:00
|
|
|
void ASTColumnsMatcher::setPattern(String pattern)
|
2019-07-16 20:05:00 +00:00
|
|
|
{
|
|
|
|
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-21 17:03:58 +00:00
|
|
|
bool ASTColumnsMatcher::isColumnMatching(const String & column_name) const
|
2019-07-16 20:05:00 +00:00
|
|
|
{
|
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
|
|
|
}
|