提交 0a5cc96b 编写于 作者: A Alexander Kuzmenkov

Fuzzing-related changes.

* More LOGICAL_ERROR
* Proper cloning of some Asts
* Field::safeGet for user-supplied values
上级 58c1d965
......@@ -13,7 +13,7 @@ namespace DB
{
namespace ErrorCodes
{
extern const int BAD_CAST;
extern const int LOGICAL_ERROR;
}
}
......@@ -41,11 +41,11 @@ To assert_cast(From && from)
}
catch (const std::exception & e)
{
throw DB::Exception(e.what(), DB::ErrorCodes::BAD_CAST);
throw DB::Exception(e.what(), DB::ErrorCodes::LOGICAL_ERROR);
}
throw DB::Exception("Bad cast from type " + demangle(typeid(from).name()) + " to " + demangle(typeid(To).name()),
DB::ErrorCodes::BAD_CAST);
DB::ErrorCodes::LOGICAL_ERROR);
#else
return static_cast<To>(from);
#endif
......
......@@ -12,7 +12,9 @@ ASTPtr ASTColumnDeclaration::clone() const
if (type)
{
res->type = type;
// Type may be an ASTFunction (e.g. `create table t (a Decimal(9,0))`),
// so we have to clone it properly as well.
res->type = type->clone();
res->children.push_back(res->type);
}
......
......@@ -23,7 +23,13 @@ public:
String getID(char delim) const override { return "Explain" + (delim + toString(kind)); }
ExplainKind getKind() const { return kind; }
ASTPtr clone() const override { return std::make_shared<ASTExplainQuery>(*this); }
ASTPtr clone() const override
{
auto res = std::make_shared<ASTExplainQuery>(*this);
res->children.clear();
res->children.push_back(children[0]->clone());
return res;
}
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
......
......@@ -843,7 +843,7 @@ bool KeyCondition::tryParseAtomFromAST(const ASTPtr & node, const Context & cont
|| const_value.getType() == Field::Types::Float64)
{
/// Zero in all types is represented in memory the same way as in UInt64.
out.function = const_value.get<UInt64>()
out.function = const_value.safeGet<UInt64>()
? RPNElement::ALWAYS_TRUE
: RPNElement::ALWAYS_FALSE;
......
......@@ -785,13 +785,13 @@ std::unique_ptr<IMergeTreeIndex> bloomFilterIndexCreator(
throw Exception("`ngrambf` index must have exactly 4 arguments.", ErrorCodes::INCORRECT_QUERY);
size_t n = typeid_cast<const ASTLiteral &>(
*node->type->arguments->children[0]).value.get<size_t>();
*node->type->arguments->children[0]).value.safeGet<size_t>();
size_t bloom_filter_size = typeid_cast<const ASTLiteral &>(
*node->type->arguments->children[1]).value.get<size_t>();
*node->type->arguments->children[1]).value.safeGet<size_t>();
size_t bloom_filter_hashes = typeid_cast<const ASTLiteral &>(
*node->type->arguments->children[2]).value.get<size_t>();
*node->type->arguments->children[2]).value.safeGet<size_t>();
size_t seed = typeid_cast<const ASTLiteral &>(
*node->type->arguments->children[3]).value.get<size_t>();
*node->type->arguments->children[3]).value.safeGet<size_t>();
auto tokenizer = std::make_unique<NgramTokenExtractor>(n);
......@@ -805,11 +805,11 @@ std::unique_ptr<IMergeTreeIndex> bloomFilterIndexCreator(
throw Exception("`tokenbf` index must have exactly 3 arguments.", ErrorCodes::INCORRECT_QUERY);
size_t bloom_filter_size = typeid_cast<const ASTLiteral &>(
*node->type->arguments->children[0]).value.get<size_t>();
*node->type->arguments->children[0]).value.safeGet<size_t>();
size_t bloom_filter_hashes = typeid_cast<const ASTLiteral &>(
*node->type->arguments->children[1]).value.get<size_t>();
*node->type->arguments->children[1]).value.safeGet<size_t>();
size_t seed = typeid_cast<const ASTLiteral &>(
*node->type->arguments->children[2]).value.get<size_t>();
*node->type->arguments->children[2]).value.safeGet<size_t>();
auto tokenizer = std::make_unique<SplitTokenExtractor>();
......
......@@ -468,7 +468,7 @@ std::unique_ptr<IMergeTreeIndex> setIndexCreator(
if (!node->type->arguments || node->type->arguments->children.size() != 1)
throw Exception("Set index must have exactly one argument.", ErrorCodes::INCORRECT_QUERY);
else if (node->type->arguments->children.size() == 1)
max_rows = node->type->arguments->children[0]->as<ASTLiteral &>().value.get<size_t>();
max_rows = node->type->arguments->children[0]->as<ASTLiteral &>().value.safeGet<size_t>();
ASTPtr expr_list = MergeTreeData::extractKeyExpressionList(node->expr->clone());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册