2022-07-14 11:20:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Field.h>
|
|
|
|
|
|
|
|
#include <Analyzer/IQueryTreeNode.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Constant node represents constant value in query tree.
|
|
|
|
* Constant value must be representable by Field.
|
|
|
|
* Examples: 1, 'constant_string', [1,2,3].
|
|
|
|
*/
|
|
|
|
class ConstantNode;
|
|
|
|
using ConstantNodePtr = std::shared_ptr<ConstantNode>;
|
|
|
|
|
|
|
|
class ConstantNode final : public IQueryTreeNode
|
|
|
|
{
|
|
|
|
public:
|
2022-08-31 15:21:17 +00:00
|
|
|
/// Construct constant query tree node from constant value
|
|
|
|
explicit ConstantNode(ConstantValuePtr constant_value_);
|
|
|
|
|
2022-09-06 15:25:52 +00:00
|
|
|
/** Construct constant query tree node from field and data type.
|
|
|
|
*
|
|
|
|
* Throws exception if value cannot be converted to value data type.
|
|
|
|
*/
|
2022-07-14 11:20:16 +00:00
|
|
|
explicit ConstantNode(Field value_, DataTypePtr value_data_type_);
|
|
|
|
|
|
|
|
/// Construct constant query tree node from field, data type will be derived from field value
|
|
|
|
explicit ConstantNode(Field value_);
|
|
|
|
|
|
|
|
/// Get constant value
|
2022-08-31 15:21:17 +00:00
|
|
|
const Field & getValue() const
|
|
|
|
{
|
|
|
|
return constant_value->getValue();
|
|
|
|
}
|
|
|
|
|
2022-10-06 19:36:06 +00:00
|
|
|
/// Get constant value string representation
|
|
|
|
const String & getValueStringRepresentation() const
|
|
|
|
{
|
|
|
|
return value_string;
|
|
|
|
}
|
|
|
|
|
2022-08-31 15:21:17 +00:00
|
|
|
ConstantValuePtr getConstantValueOrNull() const override
|
2022-07-14 11:20:16 +00:00
|
|
|
{
|
2022-08-31 15:21:17 +00:00
|
|
|
return constant_value;
|
2022-07-14 11:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QueryTreeNodeType getNodeType() const override
|
|
|
|
{
|
|
|
|
return QueryTreeNodeType::CONSTANT;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTypePtr getResultType() const override
|
|
|
|
{
|
2022-08-31 15:21:17 +00:00
|
|
|
return constant_value->getType();
|
2022-07-14 11:20:16 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 10:54:45 +00:00
|
|
|
void dumpTreeImpl(WriteBuffer & buffer, FormatState & format_state, size_t indent) const override;
|
|
|
|
|
2022-10-10 10:25:58 +00:00
|
|
|
protected:
|
2022-07-15 13:32:53 +00:00
|
|
|
bool isEqualImpl(const IQueryTreeNode & rhs) const override;
|
|
|
|
|
2022-07-14 11:20:16 +00:00
|
|
|
void updateTreeHashImpl(HashState & hash_state) const override;
|
|
|
|
|
|
|
|
QueryTreeNodePtr cloneImpl() const override;
|
|
|
|
|
2022-10-10 10:25:58 +00:00
|
|
|
ASTPtr toASTImpl() const override;
|
|
|
|
|
2022-07-14 11:20:16 +00:00
|
|
|
private:
|
2022-08-31 15:21:17 +00:00
|
|
|
ConstantValuePtr constant_value;
|
2022-10-06 19:36:06 +00:00
|
|
|
String value_string;
|
2022-10-07 10:44:28 +00:00
|
|
|
|
|
|
|
static constexpr size_t children_size = 0;
|
2022-07-14 11:20:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|