ClickHouse/src/Analyzer/ConstantNode.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.8 KiB
C++
Raw Normal View History

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();
}
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;
}
String getName() const override
{
return value_string_dump;
}
DataTypePtr getResultType() const override
{
2022-08-31 15:21:17 +00:00
return constant_value->getType();
2022-07-14 11:20:16 +00:00
}
protected:
void dumpTreeImpl(WriteBuffer & buffer, FormatState & format_state, size_t indent) const override;
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;
ASTPtr toASTImpl() const override;
QueryTreeNodePtr cloneImpl() const override;
private:
2022-08-31 15:21:17 +00:00
ConstantValuePtr constant_value;
2022-07-14 11:20:16 +00:00
String value_string_dump;
};
}