mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Fix logical error in evaluate constant expression
This commit is contained in:
parent
d3a514d221
commit
2958c5f0f1
@ -44,6 +44,9 @@ static std::pair<Field, std::shared_ptr<const IDataType>> getFieldAndDataTypeFro
|
|||||||
|
|
||||||
std::pair<Field, std::shared_ptr<const IDataType>> evaluateConstantExpression(const ASTPtr & node, const ContextPtr & context)
|
std::pair<Field, std::shared_ptr<const IDataType>> evaluateConstantExpression(const ASTPtr & node, const ContextPtr & context)
|
||||||
{
|
{
|
||||||
|
if (!node->hasColumnName())
|
||||||
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Expression '{}' is not a constant expression", node->formatForErrorMessage());
|
||||||
|
|
||||||
if (ASTLiteral * literal = node->as<ASTLiteral>())
|
if (ASTLiteral * literal = node->as<ASTLiteral>())
|
||||||
return getFieldAndDataTypeFromLiteral(literal);
|
return getFieldAndDataTypeFromLiteral(literal);
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ public:
|
|||||||
String getID(char) const override { return "Asterisk"; }
|
String getID(char) const override { return "Asterisk"; }
|
||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
ASTPtr expression;
|
ASTPtr expression;
|
||||||
ASTPtr transformers;
|
ASTPtr transformers;
|
||||||
|
@ -23,6 +23,8 @@ public:
|
|||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
|
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
void setPattern(String pattern);
|
void setPattern(String pattern);
|
||||||
const String & getPattern() const;
|
const String & getPattern() const;
|
||||||
const std::shared_ptr<re2::RE2> & getMatcher() const;
|
const std::shared_ptr<re2::RE2> & getMatcher() const;
|
||||||
@ -46,6 +48,7 @@ public:
|
|||||||
String getID(char) const override { return "ColumnsListMatcher"; }
|
String getID(char) const override { return "ColumnsListMatcher"; }
|
||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
ASTPtr expression;
|
ASTPtr expression;
|
||||||
ASTPtr column_list;
|
ASTPtr column_list;
|
||||||
@ -62,6 +65,8 @@ public:
|
|||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
|
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
const std::shared_ptr<re2::RE2> & getMatcher() const;
|
const std::shared_ptr<re2::RE2> & getMatcher() const;
|
||||||
void setPattern(String pattern, bool set_matcher = true);
|
void setPattern(String pattern, bool set_matcher = true);
|
||||||
void setMatcher(std::shared_ptr<re2::RE2> matcher);
|
void setMatcher(std::shared_ptr<re2::RE2> matcher);
|
||||||
@ -84,6 +89,7 @@ public:
|
|||||||
String getID(char) const override { return "QualifiedColumnsListMatcher"; }
|
String getID(char) const override { return "QualifiedColumnsListMatcher"; }
|
||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
ASTPtr qualifier;
|
ASTPtr qualifier;
|
||||||
ASTPtr column_list;
|
ASTPtr column_list;
|
||||||
|
@ -48,6 +48,8 @@ public:
|
|||||||
}
|
}
|
||||||
void transform(ASTs & nodes) const override;
|
void transform(ASTs & nodes) const override;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
void updateTreeHashImpl(SipHash & hash_state) const override;
|
void updateTreeHashImpl(SipHash & hash_state) const override;
|
||||||
|
|
||||||
// Case 1 APPLY (quantile(0.9))
|
// Case 1 APPLY (quantile(0.9))
|
||||||
@ -80,6 +82,7 @@ public:
|
|||||||
const std::shared_ptr<re2::RE2> & getMatcher() const;
|
const std::shared_ptr<re2::RE2> & getMatcher() const;
|
||||||
bool isColumnMatching(const String & column_name) const;
|
bool isColumnMatching(const String & column_name) const;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
void updateTreeHashImpl(SipHash & hash_state) const override;
|
void updateTreeHashImpl(SipHash & hash_state) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -103,6 +106,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
void updateTreeHashImpl(SipHash & hash_state) const override;
|
void updateTreeHashImpl(SipHash & hash_state) const override;
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
@ -121,6 +126,8 @@ public:
|
|||||||
}
|
}
|
||||||
void transform(ASTs & nodes) const override;
|
void transform(ASTs & nodes) const override;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
void updateTreeHashImpl(SipHash & hash_state) const override;
|
void updateTreeHashImpl(SipHash & hash_state) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -468,6 +468,27 @@ namespace
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ASTFunction::hasColumnName() const
|
||||||
|
{
|
||||||
|
if (parameters)
|
||||||
|
{
|
||||||
|
for (const auto & child : parameters->children)
|
||||||
|
{
|
||||||
|
if (!child->hasColumnName())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments)
|
||||||
|
{
|
||||||
|
for (const auto & child : arguments->children)
|
||||||
|
{
|
||||||
|
if (!child->hasColumnName())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ASTFunction::appendColumnNameImpl(WriteBuffer & ostr) const
|
void ASTFunction::appendColumnNameImpl(WriteBuffer & ostr) const
|
||||||
{
|
{
|
||||||
|
@ -79,6 +79,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
||||||
void appendColumnNameImpl(WriteBuffer & ostr) const override;
|
void appendColumnNameImpl(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void finishFormatWithWindow(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const;
|
void finishFormatWithWindow(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const;
|
||||||
};
|
};
|
||||||
|
@ -58,6 +58,7 @@ protected:
|
|||||||
|
|
||||||
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
||||||
void appendColumnNameImpl(WriteBuffer & ostr) const override;
|
void appendColumnNameImpl(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ASTWithAlias::children; /// ASTIdentifier is child free
|
using ASTWithAlias::children; /// ASTIdentifier is child free
|
||||||
|
@ -47,6 +47,7 @@ protected:
|
|||||||
void formatImplWithoutAlias(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
|
void formatImplWithoutAlias(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
|
||||||
|
|
||||||
void appendColumnNameImpl(WriteBuffer & ostr) const override;
|
void appendColumnNameImpl(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Legacy version of 'appendColumnNameImpl'. It differs only with tuple literals.
|
/// Legacy version of 'appendColumnNameImpl'. It differs only with tuple literals.
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
ASTPtr qualifier;
|
ASTPtr qualifier;
|
||||||
ASTPtr transformers;
|
ASTPtr transformers;
|
||||||
|
@ -21,6 +21,8 @@ public:
|
|||||||
using IAST::IAST;
|
using IAST::IAST;
|
||||||
|
|
||||||
void appendColumnName(WriteBuffer & ostr) const final;
|
void appendColumnName(WriteBuffer & ostr) const final;
|
||||||
|
bool hasColumnName() const override { return true; }
|
||||||
|
|
||||||
void appendColumnNameWithoutAlias(WriteBuffer & ostr) const final;
|
void appendColumnNameWithoutAlias(WriteBuffer & ostr) const final;
|
||||||
String getAliasOrColumnName() const override { return alias.empty() ? getColumnName() : alias; }
|
String getAliasOrColumnName() const override { return alias.empty() ? getColumnName() : alias; }
|
||||||
String tryGetAlias() const override { return alias; }
|
String tryGetAlias() const override { return alias; }
|
||||||
|
@ -56,6 +56,9 @@ public:
|
|||||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to get name of not a column: {}", getID());
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to get name of not a column: {}", getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This method should be overridden with appendColumnName */
|
||||||
|
virtual bool hasColumnName() const { return false; }
|
||||||
|
|
||||||
/** Get the alias, if any, or the canonical name of the column, if it is not. */
|
/** Get the alias, if any, or the canonical name of the column, if it is not. */
|
||||||
virtual String getAliasOrColumnName() const { return getColumnName(); }
|
virtual String getAliasOrColumnName() const { return getColumnName(); }
|
||||||
|
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
SELECT count() FROM mysql(mysql('127.0.0.1:9004', currentDatabase(), 'foo', 'default', '', SETTINGS connection_pool_size = 1), '127.0.0.1:9004', currentDatabase(), 'foo', '', ''); -- { serverError BAD_ARGUMENTS }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user