ClickHouse/src/Analyzer/ConstantNode.h

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

98 lines
2.6 KiB
C++
Raw Normal View History

2022-07-14 11:20:16 +00:00
#pragma once
#include <Core/Field.h>
#include <Analyzer/IQueryTreeNode.h>
2023-03-24 02:44:52 +00:00
#include <Analyzer/ConstantValue.h>
2022-07-14 11:20:16 +00:00
namespace DB
{
/** Constant node represents constant value in query tree.
* Constant value must be representable by Field.
* Examples: 1, 'constant_string', [1,2,3].
2022-11-29 11:35:05 +00:00
*
* Constant node can optionally keep pointer to its source expression.
2022-07-14 11:20:16 +00:00
*/
class ConstantNode;
using ConstantNodePtr = std::shared_ptr<ConstantNode>;
class ConstantNode final : public IQueryTreeNode
{
public:
2022-11-29 11:35:05 +00:00
/// Construct constant query tree node from constant value and source expression
explicit ConstantNode(ConstantValuePtr constant_value_, QueryTreeNodePtr source_expression);
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();
}
/// Get constant value string representation
const String & getValueStringRepresentation() const
{
return value_string;
}
2022-11-29 11:35:05 +00:00
/// Returns true if constant node has source expression, false otherwise
bool hasSourceExpression() const
{
2023-02-18 16:06:00 +00:00
return source_expression != nullptr;
2022-11-29 11:35:05 +00:00
}
/// Get source expression
const QueryTreeNodePtr & getSourceExpression() const
{
2023-02-18 16:06:00 +00:00
return source_expression;
2022-11-29 11:35:05 +00:00
}
/// Get source expression
QueryTreeNodePtr & getSourceExpression()
2022-07-14 11:20:16 +00:00
{
2023-02-18 16:06:00 +00:00
return source_expression;
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
}
void dumpTreeImpl(WriteBuffer & buffer, FormatState & format_state, size_t indent) const override;
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;
2023-03-14 09:14:58 +00:00
ASTPtr toASTImpl(const ConvertToASTOptions & options) const override;
2022-07-14 11:20:16 +00:00
private:
2022-08-31 15:21:17 +00:00
ConstantValuePtr constant_value;
String value_string;
2023-02-18 16:06:00 +00:00
QueryTreeNodePtr source_expression;
2022-10-07 10:44:28 +00:00
2023-02-18 16:06:00 +00:00
static constexpr size_t children_size = 0;
2022-07-14 11:20:16 +00:00
};
}