diff --git a/cli/PrintToScreen.cpp b/cli/PrintToScreen.cpp index bb64c938..59f34546 100644 --- a/cli/PrintToScreen.cpp +++ b/cli/PrintToScreen.cpp @@ -158,7 +158,7 @@ void PrintToScreen::printTuple(const TupleStorageSubBlock &tuple_store, *width_it, "NULL"); } else { - attr_it->getType().printValueToFile(value, out, *width_it); + attr_it->getType().printTypedValueToFile(value, out, *width_it); } fputc('|', out); diff --git a/compression/CompressionDictionaryBuilder.cpp b/compression/CompressionDictionaryBuilder.cpp index 905af915..41235412 100644 --- a/compression/CompressionDictionaryBuilder.cpp +++ b/compression/CompressionDictionaryBuilder.cpp @@ -121,7 +121,8 @@ void CompressionDictionaryBuilder::buildDictionary(void *location) { bool CompressionDictionaryBuilder::insertEntryInternal(const TypedValue &value, bool by_reference) { DCHECK(!built_); - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. if (type_is_nullable_ && value.isNull()) { last_insert_was_null_ = !null_value_present_; diff --git a/compression/CompressionDictionaryBuilder.hpp b/compression/CompressionDictionaryBuilder.hpp index cad6852c..9c92ecce 100644 --- a/compression/CompressionDictionaryBuilder.hpp +++ b/compression/CompressionDictionaryBuilder.hpp @@ -114,7 +114,8 @@ class CompressionDictionaryBuilder { * value. **/ bool containsValue(const TypedValue &value) const { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. if (value.isNull()) { return null_value_present_; } @@ -133,7 +134,8 @@ class CompressionDictionaryBuilder { * @return The code that maps to value. **/ inline std::uint32_t getCodeForValue(const TypedValue &value) const { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. DCHECK(containsValue(value)); DCHECK(built_); if (value.isNull()) { diff --git a/expressions/CMakeLists.txt b/expressions/CMakeLists.txt index 33606cd4..3d2e156e 100644 --- a/expressions/CMakeLists.txt +++ b/expressions/CMakeLists.txt @@ -56,9 +56,9 @@ target_link_libraries(quickstep_expressions_ExpressionFactories quickstep_expressions_scalar_ScalarUnaryExpression quickstep_types_TypeFactory quickstep_types_TypedValue - quickstep_types_operations_binaryoperations_BinaryOperationFactory + quickstep_types_operations_OperationFactory + quickstep_types_operations_OperationSignature quickstep_types_operations_comparisons_ComparisonFactory - quickstep_types_operations_unaryoperations_UnaryOperationFactory quickstep_utility_Macros) target_link_libraries(quickstep_expressions_Expressions_proto quickstep_types_Type_proto diff --git a/expressions/ExpressionFactories.cpp b/expressions/ExpressionFactories.cpp index 871db50b..2dd5124c 100644 --- a/expressions/ExpressionFactories.cpp +++ b/expressions/ExpressionFactories.cpp @@ -43,9 +43,9 @@ #include "expressions/scalar/ScalarUnaryExpression.hpp" #include "types/TypeFactory.hpp" #include "types/TypedValue.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" +#include "types/operations/OperationFactory.hpp" +#include "types/operations/OperationSignature.hpp" #include "types/operations/comparisons/ComparisonFactory.hpp" -#include "types/operations/unary_operations/UnaryOperationFactory.hpp" #include "utility/Macros.hpp" #include "glog/logging.h" @@ -168,17 +168,43 @@ Scalar* ScalarFactory::ReconstructFromProto(const serialization::Scalar &proto, proto.GetExtension(serialization::ScalarAttribute::attribute_id))); } case serialization::Scalar::UNARY_EXPRESSION: { + std::vector static_arguments; + const int num_static_args = + proto.ExtensionSize(serialization::ScalarUnaryExpression::static_arguments); + for (int i = 0; i < num_static_args; ++i) { + static_arguments.emplace_back( + TypedValue::ReconstructFromProto( + proto.GetExtension(serialization::ScalarUnaryExpression::static_arguments, i))); + } + const OperationSignaturePtr op_signature = + OperationSignature::ReconstructFromProto( + proto.GetExtension(serialization::ScalarUnaryExpression::op_signature)); return new ScalarUnaryExpression( - UnaryOperationFactory::ReconstructFromProto( - proto.GetExtension(serialization::ScalarUnaryExpression::operation)), - ReconstructFromProto(proto.GetExtension(serialization::ScalarUnaryExpression::operand), database)); + op_signature, + OperationFactory::GetUnaryOperation(op_signature), + ReconstructFromProto(proto.GetExtension(serialization::ScalarUnaryExpression::operand), database), + std::make_shared>(std::move(static_arguments))); } case serialization::Scalar::BINARY_EXPRESSION: { + std::vector static_arguments; + const int num_static_args = + proto.ExtensionSize(serialization::ScalarBinaryExpression::static_arguments); + for (int i = 0; i < num_static_args; ++i) { + static_arguments.emplace_back( + TypedValue::ReconstructFromProto( + proto.GetExtension(serialization::ScalarBinaryExpression::static_arguments, i))); + } + const OperationSignaturePtr op_signature = + OperationSignature::ReconstructFromProto( + proto.GetExtension(serialization::ScalarBinaryExpression::op_signature)); return new ScalarBinaryExpression( - BinaryOperationFactory::ReconstructFromProto( - proto.GetExtension(serialization::ScalarBinaryExpression::operation)), - ReconstructFromProto(proto.GetExtension(serialization::ScalarBinaryExpression::left_operand), database), - ReconstructFromProto(proto.GetExtension(serialization::ScalarBinaryExpression::right_operand), database)); + op_signature, + OperationFactory::GetBinaryOperation(op_signature), + ReconstructFromProto( + proto.GetExtension(serialization::ScalarBinaryExpression::left_operand), database), + ReconstructFromProto( + proto.GetExtension(serialization::ScalarBinaryExpression::right_operand), database), + std::make_shared>(std::move(static_arguments))); } case serialization::Scalar::CASE_EXPRESSION: { const Type &result_type = TypeFactory::ReconstructFromProto( @@ -248,22 +274,13 @@ bool ScalarFactory::ProtoIsValid(const serialization::Scalar &proto, break; } case serialization::Scalar::UNARY_EXPRESSION: { - if (proto.HasExtension(serialization::ScalarUnaryExpression::operation) - && proto.HasExtension(serialization::ScalarUnaryExpression::operand)) { - return UnaryOperationFactory::ProtoIsValid(proto.GetExtension(serialization::ScalarUnaryExpression::operation)) - && ProtoIsValid(proto.GetExtension(serialization::ScalarUnaryExpression::operand), database); - } + // TODO + return true; break; } case serialization::Scalar::BINARY_EXPRESSION: { - if (proto.HasExtension(serialization::ScalarBinaryExpression::operation) - && proto.HasExtension(serialization::ScalarBinaryExpression::left_operand) - && proto.HasExtension(serialization::ScalarBinaryExpression::right_operand)) { - return BinaryOperationFactory::ProtoIsValid( - proto.GetExtension(serialization::ScalarBinaryExpression::operation)) - && ProtoIsValid(proto.GetExtension(serialization::ScalarBinaryExpression::left_operand), database) - && ProtoIsValid(proto.GetExtension(serialization::ScalarBinaryExpression::right_operand), database); - } + // TODO + return true; break; } case serialization::Scalar::CASE_EXPRESSION: { diff --git a/expressions/Expressions.proto b/expressions/Expressions.proto index 8b4611e3..3a9e6731 100644 --- a/expressions/Expressions.proto +++ b/expressions/Expressions.proto @@ -103,16 +103,18 @@ message ScalarAttribute { message ScalarUnaryExpression { extend Scalar { - optional UnaryOperation operation = 96; - optional Scalar operand = 97; + optional OperationSignature op_signature = 97; + optional Scalar operand = 98; + repeated TypedValue static_arguments = 99; } } message ScalarBinaryExpression { extend Scalar { - optional BinaryOperation operation = 128; - optional Scalar left_operand = 129; - optional Scalar right_operand = 130; + optional OperationSignature op_signature = 129; + optional Scalar left_operand = 130; + optional Scalar right_operand = 131; + repeated TypedValue static_arguments = 132; } } diff --git a/expressions/aggregation/AggregateFunctionAvg.cpp b/expressions/aggregation/AggregateFunctionAvg.cpp index 040d7d9b..3acdb5ba 100644 --- a/expressions/aggregation/AggregateFunctionAvg.cpp +++ b/expressions/aggregation/AggregateFunctionAvg.cpp @@ -25,9 +25,8 @@ #include "types/Type.hpp" #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" +#include "types/operations/OperationFactory.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "glog/logging.h" @@ -41,10 +40,12 @@ bool AggregateFunctionAvg::canApplyToTypes( } // Argument must be addable and divisible. - return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .canApplyToTypes(*argument_types.front(), *argument_types.front()) - && BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .canApplyToTypes(*argument_types.front(), TypeFactory::GetType(kDouble)); + const Type &type = *argument_types.front(); + if (!OperationFactory::CanApplyAddOperation(type, type)) { + return false; + } + return OperationFactory::CanApplyDivideOperation( + type, TypeFactory::GetType(kDouble)); } const Type* AggregateFunctionAvg::resultTypeForArgumentTypes( @@ -67,8 +68,9 @@ const Type* AggregateFunctionAvg::resultTypeForArgumentTypes( break; } - return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .resultTypeForArgumentTypes(*sum_type, TypeFactory::GetType(kDouble)); + return OperationFactory::GetDivideOperation( + sum_type->getTypeID(), kDouble) + ->getResultType(*sum_type, TypeFactory::GetType(kDouble)); } AggregationHandle* AggregateFunctionAvg::createHandle( diff --git a/expressions/aggregation/AggregateFunctionSum.cpp b/expressions/aggregation/AggregateFunctionSum.cpp index b62660f3..b8c94b3b 100644 --- a/expressions/aggregation/AggregateFunctionSum.cpp +++ b/expressions/aggregation/AggregateFunctionSum.cpp @@ -25,9 +25,8 @@ #include "types/Type.hpp" #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" +#include "types/operations/OperationFactory.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "glog/logging.h" @@ -41,8 +40,8 @@ bool AggregateFunctionSum::canApplyToTypes( } // Argument must be addable. - return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .canApplyToTypes(*argument_types.front(), *argument_types.front()); + const Type &type = *argument_types.front(); + return OperationFactory::CanApplyAddOperation(type, type); } const Type* AggregateFunctionSum::resultTypeForArgumentTypes( diff --git a/expressions/aggregation/AggregationHandleAvg.cpp b/expressions/aggregation/AggregationHandleAvg.cpp index 46bec1e2..6ec59c73 100644 --- a/expressions/aggregation/AggregationHandleAvg.cpp +++ b/expressions/aggregation/AggregationHandleAvg.cpp @@ -32,9 +32,8 @@ #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" +#include "types/operations/OperationFactory.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "glog/logging.h" @@ -69,24 +68,23 @@ AggregationHandleAvg::AggregationHandleAvg(const Type &type) // Make operators to do arithmetic: // Add operator for summing argument values. fast_add_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .makeUncheckedBinaryOperatorForTypes(sum_type, argument_type_)); + OperationFactory::GetAddOperation(type_precision_id, argument_type_.getTypeID()) + ->makeUncheckedBinaryOperator(sum_type, argument_type_)); // Add operator for merging states. merge_add_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .makeUncheckedBinaryOperatorForTypes(sum_type, sum_type)); + OperationFactory::GetAddOperation(type_precision_id, type_precision_id) + ->makeUncheckedBinaryOperator(sum_type, sum_type)); // Divide operator for dividing sum by count to get final average. divide_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .makeUncheckedBinaryOperatorForTypes(sum_type, - TypeFactory::GetType(kDouble))); + OperationFactory::GetDivideOperation(type_precision_id, kDouble) + ->makeUncheckedBinaryOperator(sum_type, TypeFactory::GetType(kDouble))); // Result is nullable, because AVG() over 0 values (or all NULL values) is // NULL. result_type_ = - &(BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .resultTypeForArgumentTypes(sum_type, TypeFactory::GetType(kDouble)) - ->getNullableVersion()); + &OperationFactory::GetDivideOperation(type_precision_id, kDouble) + ->getResultType(sum_type, TypeFactory::GetType(kDouble)) + ->getNullableVersion(); } AggregationState* AggregationHandleAvg::accumulateValueAccessor( diff --git a/expressions/aggregation/AggregationHandleAvg.hpp b/expressions/aggregation/AggregationHandleAvg.hpp index 970561c8..5dd42052 100644 --- a/expressions/aggregation/AggregationHandleAvg.hpp +++ b/expressions/aggregation/AggregationHandleAvg.hpp @@ -117,7 +117,8 @@ class AggregationHandleAvg : public AggregationConcreteHandle { inline void iterateUnaryInl(AggregationStateAvg *state, const TypedValue &value) const { - DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); + // TODO(refactor-type): fix signature. if (value.isNull()) return; SpinMutexLock lock(state->mutex_); @@ -127,8 +128,9 @@ class AggregationHandleAvg : public AggregationConcreteHandle { inline void iterateUnaryInl(const TypedValue &value, std::uint8_t *byte_ptr) const { - DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); - if (value.isNull()) return; +// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); + // TODO(refactor-type): fix signature. + if (value.isNull()) return; TypedValue *sum_ptr = reinterpret_cast(byte_ptr + blank_state_.sum_offset_); std::int64_t *count_ptr = diff --git a/expressions/aggregation/AggregationHandleMax.hpp b/expressions/aggregation/AggregationHandleMax.hpp index 8f8c0d8d..7f55cc70 100644 --- a/expressions/aggregation/AggregationHandleMax.hpp +++ b/expressions/aggregation/AggregationHandleMax.hpp @@ -98,13 +98,15 @@ class AggregationHandleMax : public AggregationConcreteHandle { inline void iterateUnaryInl(AggregationStateMax *state, const TypedValue &value) const { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. compareAndUpdate(static_cast(state), value); } inline void iterateUnaryInl(const TypedValue &value, std::uint8_t *byte_ptr) const { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. TypedValue *max_ptr = reinterpret_cast(byte_ptr); compareAndUpdate(max_ptr, value); } diff --git a/expressions/aggregation/AggregationHandleMin.hpp b/expressions/aggregation/AggregationHandleMin.hpp index 0e62be58..c9977885 100644 --- a/expressions/aggregation/AggregationHandleMin.hpp +++ b/expressions/aggregation/AggregationHandleMin.hpp @@ -100,13 +100,15 @@ class AggregationHandleMin : public AggregationConcreteHandle { inline void iterateUnaryInl(AggregationStateMin *state, const TypedValue &value) const { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. compareAndUpdate(state, value); } inline void iterateUnaryInl(const TypedValue &value, std::uint8_t *byte_ptr) const { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. TypedValue *min_ptr = reinterpret_cast(byte_ptr); compareAndUpdate(min_ptr, value); } diff --git a/expressions/aggregation/AggregationHandleSum.cpp b/expressions/aggregation/AggregationHandleSum.cpp index 9f5f2203..9fdbab79 100644 --- a/expressions/aggregation/AggregationHandleSum.cpp +++ b/expressions/aggregation/AggregationHandleSum.cpp @@ -32,9 +32,8 @@ #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" +#include "types/operations/OperationFactory.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "glog/logging.h" @@ -68,12 +67,12 @@ AggregationHandleSum::AggregationHandleSum(const Type &type) // Make operators to do arithmetic: // Add operator for summing argument values. fast_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .makeUncheckedBinaryOperatorForTypes(sum_type, argument_type_)); + OperationFactory::GetAddOperation(type_precision_id, argument_type_.getTypeID()) + ->makeUncheckedBinaryOperator(sum_type, argument_type_)); // Add operator for merging states. merge_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .makeUncheckedBinaryOperatorForTypes(sum_type, sum_type)); + OperationFactory::GetAddOperation(type_precision_id, type_precision_id) + ->makeUncheckedBinaryOperator(sum_type, sum_type)); // Result is nullable, because SUM() over 0 values (or all NULL values) is // NULL. diff --git a/expressions/aggregation/AggregationHandleSum.hpp b/expressions/aggregation/AggregationHandleSum.hpp index ba4fa9b4..72a46737 100644 --- a/expressions/aggregation/AggregationHandleSum.hpp +++ b/expressions/aggregation/AggregationHandleSum.hpp @@ -113,7 +113,8 @@ class AggregationHandleSum : public AggregationConcreteHandle { inline void iterateUnaryInl(AggregationStateSum *state, const TypedValue &value) const { - DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); + // TODO(refactor-type): fix signature. if (value.isNull()) return; SpinMutexLock lock(state->mutex_); @@ -123,8 +124,10 @@ class AggregationHandleSum : public AggregationConcreteHandle { inline void iterateUnaryInl(const TypedValue &value, std::uint8_t *byte_ptr) const { - DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); + // TODO(refactor-type): fix signature. if (value.isNull()) return; + TypedValue *sum_ptr = reinterpret_cast(byte_ptr + blank_state_.sum_offset_); bool *null_ptr = diff --git a/expressions/aggregation/CMakeLists.txt b/expressions/aggregation/CMakeLists.txt index 4220a8d8..29a58c65 100644 --- a/expressions/aggregation/CMakeLists.txt +++ b/expressions/aggregation/CMakeLists.txt @@ -84,9 +84,8 @@ target_link_libraries(quickstep_expressions_aggregation_AggregateFunctionAvg quickstep_types_Type quickstep_types_TypeFactory quickstep_types_TypeID + quickstep_types_operations_OperationFactory quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Macros) target_link_libraries(quickstep_expressions_aggregation_AggregateFunctionCount glog @@ -135,9 +134,8 @@ target_link_libraries(quickstep_expressions_aggregation_AggregateFunctionSum quickstep_types_Type quickstep_types_TypeFactory quickstep_types_TypeID + quickstep_types_operations_OperationFactory quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Macros) target_link_libraries(quickstep_expressions_aggregation_AggregationConcreteHandle glog @@ -170,9 +168,8 @@ target_link_libraries(quickstep_expressions_aggregation_AggregationHandleAvg quickstep_types_TypeFactory quickstep_types_TypeID quickstep_types_TypedValue + quickstep_types_operations_OperationFactory quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Macros) target_link_libraries(quickstep_expressions_aggregation_AggregationHandleCount glog @@ -228,9 +225,8 @@ target_link_libraries(quickstep_expressions_aggregation_AggregationHandleSum quickstep_types_TypeFactory quickstep_types_TypeID quickstep_types_TypedValue + quickstep_types_operations_OperationFactory quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Macros) # Submodule all-in-one library: diff --git a/expressions/predicate/CMakeLists.txt b/expressions/predicate/CMakeLists.txt index 04abfc74..def0bc5e 100644 --- a/expressions/predicate/CMakeLists.txt +++ b/expressions/predicate/CMakeLists.txt @@ -150,7 +150,6 @@ target_link_libraries(Predicate_unittest quickstep_types_TypeID quickstep_types_TypedValue quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID diff --git a/expressions/scalar/CMakeLists.txt b/expressions/scalar/CMakeLists.txt index 6b52231a..a59635b8 100644 --- a/expressions/scalar/CMakeLists.txt +++ b/expressions/scalar/CMakeLists.txt @@ -68,9 +68,9 @@ target_link_libraries(quickstep_expressions_scalar_ScalarBinaryExpression quickstep_types_TypeErrors quickstep_types_TypedValue quickstep_types_containers_ColumnVector + quickstep_types_operations_OperationSignature quickstep_types_operations_Operation_proto quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Macros) target_link_libraries(quickstep_expressions_scalar_ScalarCaseExpression quickstep_catalog_CatalogTypedefs @@ -118,9 +118,9 @@ target_link_libraries(quickstep_expressions_scalar_ScalarUnaryExpression quickstep_types_TypeErrors quickstep_types_TypedValue quickstep_types_containers_ColumnVector + quickstep_types_operations_OperationSignature quickstep_types_operations_Operation_proto quickstep_types_operations_unaryoperations_UnaryOperation - quickstep_types_operations_unaryoperations_UnaryOperationID quickstep_utility_Macros) # Submodule all-in-one library: @@ -161,12 +161,8 @@ target_link_libraries(ScalarCaseExpression_unittest quickstep_types_TypedValue quickstep_types_containers_ColumnVector quickstep_types_containers_ColumnVectorsValueAccessor - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_ComparisonFactory - quickstep_types_operations_comparisons_ComparisonID - quickstep_types_operations_unaryoperations_UnaryOperationFactory - quickstep_types_operations_unaryoperations_UnaryOperationID) + quickstep_types_operations_comparisons_ComparisonID) add_test(ScalarCaseExpression_unittest ScalarCaseExpression_unittest) add_executable(Scalar_unittest "${CMAKE_CURRENT_SOURCE_DIR}/tests/Scalar_unittest.cpp") @@ -189,11 +185,7 @@ target_link_libraries(Scalar_unittest quickstep_types_TypeID quickstep_types_TypedValue quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID - quickstep_types_operations_unaryoperations_NumericCastOperation + quickstep_types_operations_unaryoperations_CastOperation quickstep_types_operations_unaryoperations_UnaryOperation - quickstep_types_operations_unaryoperations_UnaryOperationFactory - quickstep_types_operations_unaryoperations_UnaryOperationID quickstep_utility_Macros) add_test(Scalar_unittest Scalar_unittest) diff --git a/expressions/scalar/ScalarBinaryExpression.cpp b/expressions/scalar/ScalarBinaryExpression.cpp index b3568f80..78d16a38 100644 --- a/expressions/scalar/ScalarBinaryExpression.cpp +++ b/expressions/scalar/ScalarBinaryExpression.cpp @@ -34,43 +34,71 @@ #include "types/containers/ColumnVector.hpp" #include "types/operations/Operation.pb.h" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "glog/logging.h" namespace quickstep { -ScalarBinaryExpression::ScalarBinaryExpression(const BinaryOperation &operation, - Scalar *left_operand, - Scalar *right_operand) - : Scalar(*operation.resultTypeForArgumentTypes(left_operand->getType(), - right_operand->getType())), +ScalarBinaryExpression::ScalarBinaryExpression( + const OperationSignaturePtr &op_signature, + const BinaryOperationPtr &operation, + Scalar *left_operand, + Scalar *right_operand, + const std::shared_ptr> &static_arguments) + : Scalar(*operation->getResultType(left_operand->getType(), + right_operand->getType(), + *static_arguments)), + op_signature_(op_signature), operation_(operation), left_operand_(left_operand), - right_operand_(right_operand) { - initHelper(false); + right_operand_(right_operand), + static_arguments_(static_arguments) { + DCHECK(operation_->canApplyTo(left_operand_->getType(), + right_operand_->getType(), + *static_arguments)); + fast_operator_.reset( + operation_->makeUncheckedBinaryOperator(left_operand_->getType(), + right_operand_->getType(), + *static_arguments)); + if (left_operand_->hasStaticValue() && right_operand_->hasStaticValue()) { + static_value_.reset(new TypedValue( + fast_operator_->applyToTypedValues(left_operand_->getStaticValue(), + right_operand_->getStaticValue()))); + } } serialization::Scalar ScalarBinaryExpression::getProto() const { serialization::Scalar proto; proto.set_data_source(serialization::Scalar::BINARY_EXPRESSION); - proto.MutableExtension(serialization::ScalarBinaryExpression::operation)->CopyFrom(operation_.getProto()); - proto.MutableExtension(serialization::ScalarBinaryExpression::left_operand)->CopyFrom(left_operand_->getProto()); - proto.MutableExtension(serialization::ScalarBinaryExpression::right_operand)->CopyFrom(right_operand_->getProto()); - + proto.MutableExtension( + serialization::ScalarBinaryExpression::op_signature)->CopyFrom( + op_signature_->getProto()); + proto.MutableExtension( + serialization::ScalarBinaryExpression::left_operand)->CopyFrom( + left_operand_->getProto()); + proto.MutableExtension( + serialization::ScalarBinaryExpression::right_operand)->CopyFrom( + right_operand_->getProto()); + for (const TypedValue &value : *static_arguments_) { + proto.AddExtension( + serialization::ScalarUnaryExpression::static_arguments)->CopyFrom( + value.getProto()); + } return proto; } Scalar* ScalarBinaryExpression::clone() const { - return new ScalarBinaryExpression(operation_, + return new ScalarBinaryExpression(op_signature_, + operation_, left_operand_->clone(), - right_operand_->clone()); + right_operand_->clone(), + static_arguments_); } TypedValue ScalarBinaryExpression::getValueForSingleTuple(const ValueAccessor &accessor, const tuple_id tuple) const { if (fast_operator_.get() == nullptr) { - return static_value_.makeReferenceToThis(); + return static_value_->makeReferenceToThis(); } else { return fast_operator_->applyToTypedValues(left_operand_->getValueForSingleTuple(accessor, tuple), right_operand_->getValueForSingleTuple(accessor, tuple)); @@ -85,7 +113,7 @@ TypedValue ScalarBinaryExpression::getValueForJoinedTuples( const relation_id right_relation_id, const tuple_id right_tuple_id) const { if (fast_operator_.get() == nullptr) { - return static_value_.makeReferenceToThis(); + return static_value_->makeReferenceToThis(); } else { return fast_operator_->applyToTypedValues( left_operand_->getValueForJoinedTuples(left_accessor, @@ -110,7 +138,7 @@ ColumnVectorPtr ScalarBinaryExpression::getAllValues( if (fast_operator_.get() == nullptr) { return ColumnVectorPtr( ColumnVector::MakeVectorOfValue(getType(), - static_value_, + *static_value_, accessor->getNumTuplesVirtual())); } else { // NOTE(chasseur): We don't check if BOTH operands have a static value, @@ -208,7 +236,7 @@ ColumnVectorPtr ScalarBinaryExpression::getAllValuesForJoin( if (fast_operator_.get() == nullptr) { return ColumnVectorPtr( ColumnVector::MakeVectorOfValue(getType(), - static_value_, + *static_value_, joined_tuple_ids.size())); } else { if (left_operand_->hasStaticValue()) { @@ -380,31 +408,6 @@ ColumnVectorPtr ScalarBinaryExpression::getAllValuesForJoin( } } -void ScalarBinaryExpression::initHelper(bool own_children) { - if (operation_.canApplyToTypes(left_operand_->getType(), right_operand_->getType())) { - if (left_operand_->hasStaticValue() && right_operand_->hasStaticValue()) { - static_value_ = operation_.applyToChecked(left_operand_->getStaticValue(), - left_operand_->getType(), - right_operand_->getStaticValue(), - right_operand_->getType()); - } else { - fast_operator_.reset(operation_.makeUncheckedBinaryOperatorForTypes(left_operand_->getType(), - right_operand_->getType())); - } - } else { - const Type &left_operand_type = left_operand_->getType(); - const Type &right_operand_type = right_operand_->getType(); - if (!own_children) { - left_operand_.release(); - right_operand_.release(); - } - throw OperationInapplicableToType(operation_.getName(), - 2, - left_operand_type.getName().c_str(), - right_operand_type.getName().c_str()); - } -} - void ScalarBinaryExpression::getFieldStringItems( std::vector *inline_field_names, std::vector *inline_field_values, @@ -419,19 +422,17 @@ void ScalarBinaryExpression::getFieldStringItems( container_child_field_names, container_child_fields); - if (fast_operator_ == nullptr) { + if (static_value_ != nullptr) { inline_field_names->emplace_back("static_value"); - if (static_value_.isNull()) { + if (static_value_->isNull()) { inline_field_values->emplace_back("NULL"); } else { - inline_field_values->emplace_back(type_.printValueToString(static_value_)); + inline_field_values->emplace_back(type_.printTypedValueToString(*static_value_)); } } - inline_field_names->emplace_back("operation"); - inline_field_values->emplace_back( - kBinaryOperationNames[static_cast::type>( - operation_.getBinaryOperationID())]); + inline_field_names->emplace_back("op_signature"); + inline_field_values->emplace_back(op_signature_->toString()); non_container_child_field_names->emplace_back("left_operand"); non_container_child_fields->emplace_back(left_operand_.get()); diff --git a/expressions/scalar/ScalarBinaryExpression.hpp b/expressions/scalar/ScalarBinaryExpression.hpp index 4ac1f62e..a27c820e 100644 --- a/expressions/scalar/ScalarBinaryExpression.hpp +++ b/expressions/scalar/ScalarBinaryExpression.hpp @@ -31,6 +31,7 @@ #include "storage/StorageBlockInfo.hpp" #include "types/TypedValue.hpp" #include "types/containers/ColumnVector.hpp" +#include "types/operations/OperationSignature.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" #include "utility/Macros.hpp" @@ -52,18 +53,11 @@ struct SubBlocksReference; **/ class ScalarBinaryExpression : public Scalar { public: - /** - * @brief Constructor. - * - * @param operation The binary operation to be performed. - * @param left_operand The left argument of the operation, which this - * ScalarBinaryExpression takes ownership of. - * @param right_operand The right argument of the operation, which this - * ScalarBinaryExpression takes ownership of. - **/ - ScalarBinaryExpression(const BinaryOperation &operation, + ScalarBinaryExpression(const OperationSignaturePtr &op_signature, + const BinaryOperationPtr &operation, Scalar *left_operand, - Scalar *right_operand); + Scalar *right_operand, + const std::shared_ptr> &static_arguments); /** * @brief Destructor @@ -91,12 +85,12 @@ class ScalarBinaryExpression : public Scalar { const tuple_id right_tuple_id) const override; bool hasStaticValue() const override { - return fast_operator_.get() == nullptr; + return static_value_ != nullptr; } const TypedValue& getStaticValue() const override { DCHECK(hasStaticValue()); - return static_value_; + return *static_value_; } ColumnVectorPtr getAllValues(ValueAccessor *accessor, @@ -121,13 +115,14 @@ class ScalarBinaryExpression : public Scalar { std::vector> *container_child_fields) const override; private: - void initHelper(bool own_children); + const OperationSignaturePtr op_signature_; + const BinaryOperationPtr operation_; - const BinaryOperation &operation_; + const std::unique_ptr left_operand_; + const std::unique_ptr right_operand_; + const std::shared_ptr> static_arguments_; - std::unique_ptr left_operand_; - std::unique_ptr right_operand_; - TypedValue static_value_; + std::unique_ptr static_value_; std::unique_ptr fast_operator_; friend class PredicateTest; diff --git a/expressions/scalar/ScalarCaseExpression.cpp b/expressions/scalar/ScalarCaseExpression.cpp index 68474256..4a0cc72f 100644 --- a/expressions/scalar/ScalarCaseExpression.cpp +++ b/expressions/scalar/ScalarCaseExpression.cpp @@ -470,7 +470,7 @@ ColumnVectorPtr ScalarCaseExpression::multiplexColumnVectors( for (std::vector>::size_type case_idx = 0; case_idx < case_matches.size(); ++case_idx) { - DCHECK(case_results[case_idx]->isNative()); + DCHECK(case_results[case_idx]->getImplementation() == ColumnVector::kNative); if (!case_matches[case_idx]->empty()) { MultiplexNativeColumnVector( source_sequence, @@ -481,7 +481,7 @@ ColumnVectorPtr ScalarCaseExpression::multiplexColumnVectors( } if (else_result != nullptr) { - DCHECK(else_result->isNative()); + DCHECK(else_result->getImplementation() == ColumnVector::kNative); DCHECK(!else_matches.empty()); MultiplexNativeColumnVector(source_sequence, else_matches, @@ -498,7 +498,7 @@ ColumnVectorPtr ScalarCaseExpression::multiplexColumnVectors( for (std::vector>::size_type case_idx = 0; case_idx < case_matches.size(); ++case_idx) { - DCHECK(!case_results[case_idx]->isNative()); + DCHECK(case_results[case_idx]->getImplementation() == ColumnVector::kIndirect); if (!case_matches[case_idx]->empty()) { MultiplexIndirectColumnVector( source_sequence, @@ -509,7 +509,7 @@ ColumnVectorPtr ScalarCaseExpression::multiplexColumnVectors( } if (else_result != nullptr) { - DCHECK(!else_result->isNative()); + DCHECK(else_result->getImplementation() == ColumnVector::kIndirect); DCHECK(!else_matches.empty()); MultiplexIndirectColumnVector(source_sequence, else_matches, @@ -540,7 +540,7 @@ void ScalarCaseExpression::getFieldStringItems( if (static_value_.isNull()) { inline_field_values->emplace_back("NULL"); } else { - inline_field_values->emplace_back(type_.printValueToString(static_value_)); + inline_field_values->emplace_back(type_.printTypedValueToString(static_value_)); } } diff --git a/expressions/scalar/ScalarLiteral.cpp b/expressions/scalar/ScalarLiteral.cpp index 808953df..53ba8273 100644 --- a/expressions/scalar/ScalarLiteral.cpp +++ b/expressions/scalar/ScalarLiteral.cpp @@ -89,7 +89,7 @@ void ScalarLiteral::getFieldStringItems( if (internal_literal_.isNull()) { inline_field_values->emplace_back("NULL"); } else { - inline_field_values->emplace_back(type_.printValueToString(internal_literal_)); + inline_field_values->emplace_back(type_.printTypedValueToString(internal_literal_)); } } diff --git a/expressions/scalar/ScalarUnaryExpression.cpp b/expressions/scalar/ScalarUnaryExpression.cpp index c51e38f4..3e83a6a2 100644 --- a/expressions/scalar/ScalarUnaryExpression.cpp +++ b/expressions/scalar/ScalarUnaryExpression.cpp @@ -34,41 +34,62 @@ #include "types/containers/ColumnVector.hpp" #include "types/operations/Operation.pb.h" #include "types/operations/unary_operations/UnaryOperation.hpp" -#include "types/operations/unary_operations/UnaryOperationID.hpp" -#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_JOIN #include "glog/logging.h" -#endif // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_JOIN namespace quickstep { struct SubBlocksReference; -ScalarUnaryExpression::ScalarUnaryExpression(const UnaryOperation &operation, - Scalar *operand) - : Scalar(*operation.resultTypeForArgumentType(operand->getType())), +ScalarUnaryExpression::ScalarUnaryExpression( + const OperationSignaturePtr &op_signature, + const UnaryOperationPtr &operation, + Scalar *operand, + const std::shared_ptr> &static_arguments) + : Scalar(*operation->getResultType(operand->getType(), *static_arguments)), + op_signature_(op_signature), operation_(operation), - operand_(operand) { - initHelper(false); + operand_(operand), + static_arguments_(static_arguments) { + DCHECK(operation_->canApplyTo(operand_->getType(), *static_arguments_)); + + fast_operator_.reset( + operation_->makeUncheckedUnaryOperator(operand_->getType(), + *static_arguments_)); + if (operand_->hasStaticValue()) { + static_value_.reset(new TypedValue( + fast_operator_->applyToTypedValue(operand_->getStaticValue()))); + } } serialization::Scalar ScalarUnaryExpression::getProto() const { serialization::Scalar proto; proto.set_data_source(serialization::Scalar::UNARY_EXPRESSION); - proto.MutableExtension(serialization::ScalarUnaryExpression::operation)->CopyFrom(operation_.getProto()); - proto.MutableExtension(serialization::ScalarUnaryExpression::operand)->CopyFrom(operand_->getProto()); - + proto.MutableExtension( + serialization::ScalarUnaryExpression::op_signature)->CopyFrom( + op_signature_->getProto()); + proto.MutableExtension( + serialization::ScalarUnaryExpression::operand)->CopyFrom( + operand_->getProto()); + for (const TypedValue &value : *static_arguments_) { + proto.AddExtension( + serialization::ScalarUnaryExpression::static_arguments)->CopyFrom( + value.getProto()); + } return proto; } Scalar* ScalarUnaryExpression::clone() const { - return new ScalarUnaryExpression(operation_, operand_->clone()); + return new ScalarUnaryExpression(op_signature_, + operation_, + operand_->clone(), + static_arguments_); } TypedValue ScalarUnaryExpression::getValueForSingleTuple(const ValueAccessor &accessor, const tuple_id tuple) const { if (fast_operator_.get() == nullptr) { - return static_value_.makeReferenceToThis(); + return static_value_->makeReferenceToThis(); } else { return fast_operator_->applyToTypedValue(operand_->getValueForSingleTuple(accessor, tuple)); } @@ -82,7 +103,7 @@ TypedValue ScalarUnaryExpression::getValueForJoinedTuples( const relation_id right_relation_id, const tuple_id right_tuple_id) const { if (fast_operator_.get() == nullptr) { - return static_value_.makeReferenceToThis(); + return static_value_->makeReferenceToThis(); } else { return fast_operator_->applyToTypedValue(operand_->getValueForJoinedTuples(left_accessor, left_relation_id, @@ -100,7 +121,7 @@ ColumnVectorPtr ScalarUnaryExpression::getAllValues( if (fast_operator_.get() == nullptr) { return ColumnVectorPtr( ColumnVector::MakeVectorOfValue(getType(), - static_value_, + *static_value_, accessor->getNumTuplesVirtual())); } else { #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION @@ -128,27 +149,9 @@ ColumnVectorPtr ScalarUnaryExpression::getAllValuesForJoin( if (fast_operator_.get() == nullptr) { return ColumnVectorPtr( ColumnVector::MakeVectorOfValue(getType(), - static_value_, + *static_value_, joined_tuple_ids.size())); } else { -#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_JOIN - const attribute_id operand_attr_id = operand_->getAttributeIdForValueAccessor(); - if (operand_attr_id != -1) { - const relation_id operand_relation_id = operand_->getRelationIdForValueAccessor(); - DCHECK_NE(operand_relation_id, -1); - DCHECK((operand_relation_id == left_relation_id) - || (operand_relation_id == right_relation_id)); - const bool using_left_relation = (operand_relation_id == left_relation_id); - ValueAccessor *operand_accessor = using_left_relation ? left_accessor - : right_accessor; - return ColumnVectorPtr( - fast_operator_->applyToValueAccessorForJoin(operand_accessor, - using_left_relation, - operand_attr_id, - joined_tuple_ids)); - } -#endif // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_JOIN - ColumnVectorPtr operand_result( operand_->getAllValuesForJoin(left_relation_id, left_accessor, @@ -161,23 +164,6 @@ ColumnVectorPtr ScalarUnaryExpression::getAllValuesForJoin( } } -void ScalarUnaryExpression::initHelper(bool own_children) { - if (operation_.canApplyToType(operand_->getType())) { - if (operand_->hasStaticValue()) { - static_value_ = operation_.applyToChecked(operand_->getStaticValue(), - operand_->getType()); - } else { - fast_operator_.reset(operation_.makeUncheckedUnaryOperatorForType(operand_->getType())); - } - } else { - const Type &operand_type = operand_->getType(); - if (!own_children) { - operand_.release(); - } - throw OperationInapplicableToType(operation_.getName(), 1, operand_type.getName().c_str()); - } -} - void ScalarUnaryExpression::getFieldStringItems( std::vector *inline_field_names, std::vector *inline_field_values, @@ -192,19 +178,17 @@ void ScalarUnaryExpression::getFieldStringItems( container_child_field_names, container_child_fields); - if (fast_operator_ == nullptr) { + if (static_value_ != nullptr) { inline_field_names->emplace_back("static_value"); - if (static_value_.isNull()) { + if (static_value_->isNull()) { inline_field_values->emplace_back("NULL"); } else { - inline_field_values->emplace_back(type_.printValueToString(static_value_)); + inline_field_values->emplace_back(type_.printTypedValueToString(*static_value_)); } } - inline_field_names->emplace_back("operation"); - inline_field_values->emplace_back( - kUnaryOperationNames[static_cast::type>( - operation_.getUnaryOperationID())]); + inline_field_names->emplace_back("op_signature"); + inline_field_values->emplace_back(op_signature_->toString()); non_container_child_field_names->emplace_back("operand"); non_container_child_fields->emplace_back(operand_.get()); diff --git a/expressions/scalar/ScalarUnaryExpression.hpp b/expressions/scalar/ScalarUnaryExpression.hpp index 52edea71..8dc4c301 100644 --- a/expressions/scalar/ScalarUnaryExpression.hpp +++ b/expressions/scalar/ScalarUnaryExpression.hpp @@ -30,6 +30,8 @@ #include "expressions/scalar/Scalar.hpp" #include "storage/StorageBlockInfo.hpp" #include "types/TypedValue.hpp" +#include "types/containers/ColumnVector.hpp" +#include "types/operations/OperationSignature.hpp" #include "types/operations/unary_operations/UnaryOperation.hpp" #include "utility/Macros.hpp" @@ -51,14 +53,10 @@ struct SubBlocksReference; **/ class ScalarUnaryExpression : public Scalar { public: - /** - * @brief Constructor. - * - * @param operation The unary operation to be performed. - * @param operand The argument of the operation, which this - * ScalarUnaryExpression takes ownership of. - **/ - ScalarUnaryExpression(const UnaryOperation &operation, Scalar *operand); + ScalarUnaryExpression(const OperationSignaturePtr &op_signature, + const UnaryOperationPtr &operation, + Scalar *operand, + const std::shared_ptr> &static_arguments); /** * @brief Destructor. @@ -86,12 +84,12 @@ class ScalarUnaryExpression : public Scalar { const tuple_id right_tuple_id) const override; bool hasStaticValue() const override { - return fast_operator_.get() == nullptr; + return static_value_ != nullptr; } const TypedValue& getStaticValue() const override { DCHECK(hasStaticValue()); - return static_value_; + return *static_value_; } ColumnVectorPtr getAllValues(ValueAccessor *accessor, @@ -116,12 +114,13 @@ class ScalarUnaryExpression : public Scalar { std::vector> *container_child_fields) const override; private: - void initHelper(bool own_children); + const OperationSignaturePtr op_signature_; + const UnaryOperationPtr operation_; - const UnaryOperation &operation_; + const std::unique_ptr operand_; + const std::shared_ptr> static_arguments_; - std::unique_ptr operand_; - TypedValue static_value_; + std::unique_ptr static_value_; std::unique_ptr fast_operator_; friend class PredicateTest; diff --git a/expressions/table_generator/GenerateSeries.hpp b/expressions/table_generator/GenerateSeries.hpp index d7498108..19523f5e 100644 --- a/expressions/table_generator/GenerateSeries.hpp +++ b/expressions/table_generator/GenerateSeries.hpp @@ -118,11 +118,11 @@ class GenerateSeries : public GeneratorFunction { DCHECK(args.size() == 2 || args.size() == 3); // Coerce all arguments to the unified type. - TypedValue start = type.coerceValue(args[0], *arg_types[0]); - TypedValue end = type.coerceValue(args[1], *arg_types[1]); - TypedValue step = - args.size() > 2 ? type.coerceValue(args[2], *arg_types[2]) - : type.coerceValue(TypedValue(1), TypeFactory::GetType(TypeID::kInt)); + TypedValue start = type.coerceTypedValue(args[0], *arg_types[0]); + TypedValue end = type.coerceTypedValue(args[1], *arg_types[1]); + TypedValue step = args.size() > 2 + ? type.coerceTypedValue(args[2], *arg_types[2]) + : type.coerceTypedValue(TypedValue(1), TypeFactory::GetType(TypeID::kInt)); // Check that step is not 0, and (end - start) / step is positive const GreaterComparison >_comparator = GreaterComparison::Instance(); diff --git a/expressions/window_aggregation/CMakeLists.txt b/expressions/window_aggregation/CMakeLists.txt index b33a4014..1b5b743c 100644 --- a/expressions/window_aggregation/CMakeLists.txt +++ b/expressions/window_aggregation/CMakeLists.txt @@ -72,8 +72,6 @@ target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFun quickstep_types_TypeFactory quickstep_types_TypeID quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Macros) target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFunctionCount glog @@ -123,8 +121,6 @@ target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFun quickstep_types_TypeFactory quickstep_types_TypeID quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Macros) target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregationHandle glog @@ -138,9 +134,8 @@ target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregationH quickstep_types_TypedValue quickstep_types_containers_ColumnVector quickstep_types_containers_ColumnVectorsValueAccessor + quickstep_types_operations_OperationFactory quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID @@ -156,8 +151,6 @@ target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregationH quickstep_types_TypedValue quickstep_types_containers_ColumnVectorsValueAccessor quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_utility_Macros) diff --git a/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp b/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp index 20c296bb..fcd737e7 100644 --- a/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp +++ b/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp @@ -26,8 +26,6 @@ #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "glog/logging.h" @@ -41,10 +39,12 @@ bool WindowAggregateFunctionAvg::canApplyToTypes( } // Argument must be addable and divisible. - return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .canApplyToTypes(*argument_types.front(), *argument_types.front()) && - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .canApplyToTypes(*argument_types.front(), TypeFactory::GetType(kDouble)); + // TODO(refactor-type): Fix this. +// return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) +// .canApplyTo(*argument_types.front(), *argument_types.front()) && +// BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) +// .canApplyTo(*argument_types.front(), TypeFactory::GetType(kDouble)); + return false; } const Type* WindowAggregateFunctionAvg::resultTypeForArgumentTypes( @@ -67,8 +67,10 @@ const Type* WindowAggregateFunctionAvg::resultTypeForArgumentTypes( break; } - return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .resultTypeForArgumentTypes(*sum_type, TypeFactory::GetType(kDouble)); + // TODO(refactor-type): Fix this. +// return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) +// .getResultType(*sum_type, TypeFactory::GetType(kDouble)); + return nullptr; } WindowAggregationHandle* WindowAggregateFunctionAvg::createHandle( diff --git a/expressions/window_aggregation/WindowAggregateFunctionSum.cpp b/expressions/window_aggregation/WindowAggregateFunctionSum.cpp index 14c51d88..09bc4e95 100644 --- a/expressions/window_aggregation/WindowAggregateFunctionSum.cpp +++ b/expressions/window_aggregation/WindowAggregateFunctionSum.cpp @@ -26,8 +26,6 @@ #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "glog/logging.h" @@ -41,8 +39,10 @@ bool WindowAggregateFunctionSum::canApplyToTypes( } // Argument must be addable. - return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .canApplyToTypes(*argument_types.front(), *argument_types.front()); + // TODO(refactor-type): Fix this. +// return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) +// .canApplyTo(*argument_types.front(), *argument_types.front()); + return false; } const Type* WindowAggregateFunctionSum::resultTypeForArgumentTypes( diff --git a/expressions/window_aggregation/WindowAggregationHandle.cpp b/expressions/window_aggregation/WindowAggregationHandle.cpp index f26656df..e327a4f6 100644 --- a/expressions/window_aggregation/WindowAggregationHandle.cpp +++ b/expressions/window_aggregation/WindowAggregationHandle.cpp @@ -30,9 +30,8 @@ #include "types/TypeID.hpp" #include "types/TypedValue.hpp" #include "types/containers/ColumnVectorsValueAccessor.hpp" +#include "types/operations/OperationFactory.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "types/operations/comparisons/Comparison.hpp" #include "glog/logging.h" @@ -83,8 +82,9 @@ WindowAggregationHandle::WindowAggregationHandle( TypeFactory::GetUnifyingType(*first_order_key_type, long_type); range_add_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .makeUncheckedBinaryOperatorForTypes(*first_order_key_type, long_type)); + OperationFactory::GetAddOperation( + first_order_key_type->getTypeID(), kLong) + ->makeUncheckedBinaryOperator(*first_order_key_type, long_type)); range_comparator_.reset( ComparisonFactory::GetComparison(ComparisonID::kLessOrEqual) .makeUncheckedComparatorForTypes(*range_compare_type_, *range_compare_type_)); diff --git a/expressions/window_aggregation/WindowAggregationHandle.hpp b/expressions/window_aggregation/WindowAggregationHandle.hpp index 3569123f..0d5f5ca5 100644 --- a/expressions/window_aggregation/WindowAggregationHandle.hpp +++ b/expressions/window_aggregation/WindowAggregationHandle.hpp @@ -37,8 +37,6 @@ #include "types/operations/comparisons/ComparisonFactory.hpp" #include "types/operations/comparisons/ComparisonID.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "utility/Macros.hpp" namespace quickstep { diff --git a/expressions/window_aggregation/WindowAggregationHandleAvg.cpp b/expressions/window_aggregation/WindowAggregationHandleAvg.cpp index b1c6e3b9..10272a9a 100644 --- a/expressions/window_aggregation/WindowAggregationHandleAvg.cpp +++ b/expressions/window_aggregation/WindowAggregationHandleAvg.cpp @@ -32,8 +32,6 @@ #include "types/TypedValue.hpp" #include "types/containers/ColumnVectorsValueAccessor.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "types/operations/comparisons/Comparison.hpp" #include "glog/logging.h" @@ -71,35 +69,36 @@ WindowAggregationHandleAvg::WindowAggregationHandleAvg( sum_type_ = &(TypeFactory::GetType(type_id)); - // Result is nullable, because AVG() over 0 values (or all NULL values) is - // NULL. - result_type_ - = &(BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .resultTypeForArgumentTypes(*sum_type_, TypeFactory::GetType(kDouble)) - ->getNullableVersion()); - - // Make operators to do arithmetic: - // Add operator for summing argument values. - fast_add_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .makeUncheckedBinaryOperatorForTypes(*sum_type_, *argument_type)); - - // Subtract operator for dropping argument values off the window. - fast_subtract_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kSubtract) - .makeUncheckedBinaryOperatorForTypes(*sum_type_, *argument_type)); - - // Divide operator for dividing sum by count to get final average. - divide_operator_.reset( - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .makeUncheckedBinaryOperatorForTypes(*sum_type_, TypeFactory::GetType(kDouble))); + LOG(FATAL) << "TODO(refactor-type)"; +// // Result is nullable, because AVG() over 0 values (or all NULL values) is +// // NULL. +// result_type_ +// = &(BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) +// .getResultType(*sum_type_, TypeFactory::GetType(kDouble)) +// ->getNullableVersion()); +// +// // Make operators to do arithmetic: +// // Add operator for summing argument values. +// fast_add_operator_.reset( +// BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) +// .makeUncheckedBinaryOperator(*sum_type_, *argument_type)); +// +// // Subtract operator for dropping argument values off the window. +// fast_subtract_operator_.reset( +// BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kSubtract) +// .makeUncheckedBinaryOperator(*sum_type_, *argument_type)); +// +// // Divide operator for dividing sum by count to get final average. +// divide_operator_.reset( +// BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) +// .makeUncheckedBinaryOperator(*sum_type_, TypeFactory::GetType(kDouble))); } ColumnVector* WindowAggregationHandleAvg::calculate( ColumnVectorsValueAccessor *tuple_accessor, const std::vector &arguments) const { DCHECK_EQ(1u, arguments.size()); - DCHECK(arguments[0]->isNative()); + DCHECK(arguments[0]->getImplementation() == ColumnVector::kNative); DCHECK_EQ(static_cast(tuple_accessor->getNumTuples()), static_cast(arguments[0])->size()); diff --git a/parser/CMakeLists.txt b/parser/CMakeLists.txt index d4aaab40..64af205c 100644 --- a/parser/CMakeLists.txt +++ b/parser/CMakeLists.txt @@ -89,6 +89,7 @@ add_library(quickstep_parser_ParseAttributeDefinition ParseAttributeDefinition.c add_library(quickstep_parser_ParseBasicExpressions ParseBasicExpressions.cpp ParseBasicExpressions.hpp) add_library(quickstep_parser_ParseBlockProperties ParseBlockProperties.cpp ParseBlockProperties.hpp) add_library(quickstep_parser_ParseCaseExpressions ParseCaseExpressions.cpp ParseCaseExpressions.hpp) +add_library(quickstep_parser_ParseDataType ParseDataType.cpp ParseDataType.hpp) add_library(quickstep_parser_ParseExpression ../empty_src.cpp ParseExpression.hpp) add_library(quickstep_parser_ParseGeneratorTableReference ParseGeneratorTableReference.cpp ParseGeneratorTableReference.hpp) add_library(quickstep_parser_ParseGroupBy ParseGroupBy.cpp ParseGroupBy.hpp) @@ -128,12 +129,14 @@ target_link_libraries(quickstep_parser_ParseAssignment quickstep_parser_ParseTreeNode quickstep_utility_Macros) target_link_libraries(quickstep_parser_ParseAttributeDefinition + quickstep_parser_ParseDataType quickstep_parser_ParseString quickstep_parser_ParseTreeNode quickstep_types_Type quickstep_utility_Macros quickstep_utility_PtrList) target_link_libraries(quickstep_parser_ParseBasicExpressions + quickstep_parser_ParseDataType quickstep_parser_ParseExpression quickstep_parser_ParseLiteralValue quickstep_parser_ParseString @@ -158,6 +161,11 @@ target_link_libraries(quickstep_parser_ParseCaseExpressions quickstep_parser_ParseTreeNode quickstep_utility_Macros quickstep_utility_PtrVector) +target_link_libraries(quickstep_parser_ParseDataType + quickstep_parser_ParseLiteralValue + quickstep_parser_ParseString + quickstep_parser_ParseTreeNode + quickstep_utility_Macros) target_link_libraries(quickstep_parser_ParseExpression quickstep_parser_ParseTreeNode quickstep_utility_Macros) @@ -337,6 +345,7 @@ target_link_libraries(quickstep_parser_SqlParser quickstep_parser_ParseBasicExpressions quickstep_parser_ParseBlockProperties quickstep_parser_ParseCaseExpressions + quickstep_parser_ParseDataType quickstep_parser_ParseExpression quickstep_parser_ParseGeneratorTableReference quickstep_parser_ParseGroupBy @@ -367,15 +376,9 @@ target_link_libraries(quickstep_parser_SqlParser quickstep_types_Type quickstep_types_TypeFactory quickstep_types_TypeID - quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID - quickstep_types_operations_unaryoperations_UnaryOperation - quickstep_types_operations_unaryoperations_UnaryOperationFactory - quickstep_types_operations_unaryoperations_UnaryOperationID quickstep_utility_PtrList quickstep_utility_PtrVector) target_link_libraries(quickstep_parser_SqlParserWrapper @@ -416,6 +419,7 @@ target_link_libraries(quickstep_parser quickstep_parser_ParseBasicExpressions quickstep_parser_ParseBlockProperties quickstep_parser_ParseCaseExpressions + quickstep_parser_ParseDataType quickstep_parser_ParseExpression quickstep_parser_ParseGeneratorTableReference quickstep_parser_ParseGroupBy diff --git a/parser/ParseAttributeDefinition.cpp b/parser/ParseAttributeDefinition.cpp index ec6508b9..0612d9e8 100644 --- a/parser/ParseAttributeDefinition.cpp +++ b/parser/ParseAttributeDefinition.cpp @@ -54,12 +54,12 @@ void ParseAttributeDefinition::getFieldStringItems( std::vector> *container_child_fields) const { inline_field_names->push_back("name"); inline_field_values->push_back(name_->value()); - inline_field_names->push_back("type"); - inline_field_values->push_back(data_type_->getType().getName()); + non_container_child_field_names->push_back("type"); + non_container_child_fields->push_back(data_type_.get()); } void ParseColumnConstraintNull::applyTo(ParseAttributeDefinition *target) const { - target->data_type_->type_ = &(target->data_type_->type_->getNullableVersion()); + target->setNullable(true); } void ParseColumnConstraintNull::getFieldStringItems( @@ -74,7 +74,7 @@ void ParseColumnConstraintNull::getFieldStringItems( } void ParseColumnConstraintNotNull::applyTo(ParseAttributeDefinition *target) const { - target->data_type_->type_ = &(target->data_type_->type_->getNonNullableVersion()); + target->setNullable(false); } void ParseColumnConstraintNotNull::getFieldStringItems( diff --git a/parser/ParseAttributeDefinition.hpp b/parser/ParseAttributeDefinition.hpp index 5c20d13e..0e79ac44 100644 --- a/parser/ParseAttributeDefinition.hpp +++ b/parser/ParseAttributeDefinition.hpp @@ -24,6 +24,7 @@ #include #include +#include "parser/ParseDataType.hpp" #include "parser/ParseString.hpp" #include "parser/ParseTreeNode.hpp" #include "utility/Macros.hpp" @@ -31,7 +32,6 @@ namespace quickstep { class ParseColumnConstraint; -class Type; template class PtrList; @@ -39,40 +39,6 @@ template class PtrList; * @{ */ -/** - * @brief Parsed representation of a data type. - **/ -class ParseDataType { - public: - /** - * @brief Constructor. - * - * @param type The Type of the data. - **/ - explicit ParseDataType(const Type &type) - : type_(&type) { - } - - /** - * @brief Get the type. - * - * @return The Type. - **/ - const Type& getType() const { - return *type_; - } - - private: - // Use a pointer instead of a reference so that it may be modified by column - // constraints. - const Type *type_; - - friend class ParseColumnConstraintNull; - friend class ParseColumnConstraintNotNull; - - DISALLOW_COPY_AND_ASSIGN(ParseDataType); -}; - /** * @brief Parsed representation of an attribute definition **/ @@ -122,6 +88,14 @@ class ParseAttributeDefinition : public ParseTreeNode { return *data_type_; } + const bool nullable() const { + return nullable_; + } + + void setNullable(const bool nullable) { + nullable_ = nullable; + } + protected: void getFieldStringItems( std::vector *inline_field_names, @@ -134,9 +108,7 @@ class ParseAttributeDefinition : public ParseTreeNode { private: std::unique_ptr name_; std::unique_ptr data_type_; - - friend class ParseColumnConstraintNull; - friend class ParseColumnConstraintNotNull; + bool nullable_; DISALLOW_COPY_AND_ASSIGN(ParseAttributeDefinition); }; diff --git a/parser/ParseBasicExpressions.cpp b/parser/ParseBasicExpressions.cpp index b0b12471..64250028 100644 --- a/parser/ParseBasicExpressions.cpp +++ b/parser/ParseBasicExpressions.cpp @@ -68,54 +68,6 @@ void ParseAttribute::getFieldStringItems( } } -std::string ParseUnaryExpression::getName() const { - return op_.getName(); -} - -string ParseUnaryExpression::generateName() const { - string name(op_.getShortName()); - name.append(operand_->generateName()); - return name; -} - -void ParseUnaryExpression::getFieldStringItems( - std::vector *inline_field_names, - std::vector *inline_field_values, - std::vector *non_container_child_field_names, - std::vector *non_container_child_fields, - std::vector *container_child_field_names, - std::vector> *container_child_fields) const { - non_container_child_field_names->push_back(""); - non_container_child_fields->push_back(operand_.get()); -} - -std::string ParseBinaryExpression::getName() const { - return op_.getName(); -} - -string ParseBinaryExpression::generateName() const { - string name("("); - name.append(left_operand_->generateName()); - name.append(op_.getShortName()); - name.append(right_operand_->generateName()); - name.push_back(')'); - return name; -} - -void ParseBinaryExpression::getFieldStringItems( - std::vector *inline_field_names, - std::vector *inline_field_values, - std::vector *non_container_child_field_names, - std::vector *non_container_child_fields, - std::vector *container_child_field_names, - std::vector> *container_child_fields) const { - non_container_child_field_names->push_back("left_operand"); - non_container_child_fields->push_back(left_operand_.get()); - - non_container_child_field_names->push_back("right_operand"); - non_container_child_fields->push_back(right_operand_.get()); -} - std::string ParseFunctionCall::generateName() const { string name(name_->value()); name.push_back('('); @@ -175,59 +127,48 @@ void ParseFunctionCall::getFieldStringItems( } } -std::string ParseExtractFunction::generateName() const { - std::string name; - name.append("EXTRACT("); - name.append(extract_field_->value()); - name.append(" FROM "); - name.append(date_expression_->generateName()); - name.push_back(')'); - return name; +std::string ParseTypeCast::generateName() const { + return operand_->generateName(); } -void ParseExtractFunction::getFieldStringItems( +void ParseTypeCast::getFieldStringItems( std::vector *inline_field_names, std::vector *inline_field_values, std::vector *non_container_child_field_names, std::vector *non_container_child_fields, std::vector *container_child_field_names, std::vector> *container_child_fields) const { - inline_field_names->push_back("unit"); - inline_field_values->push_back(extract_field_->value()); - - non_container_child_field_names->push_back("date_expression"); - non_container_child_fields->push_back(date_expression_.get()); + non_container_child_field_names->emplace_back("operand"); + non_container_child_fields->emplace_back(operand_.get()); + non_container_child_field_names->emplace_back("target_type"); + non_container_child_fields->emplace_back(target_type_.get()); } -std::string ParseSubstringFunction::generateName() const { - std::string name; - name.append("SUBSTRING("); - name.append(operand_->generateName()); - name.append(" FROM "); - name.append(std::to_string(start_position_)); - if (length_ != kDefaultLength) { - name.append(" FOR "); - name.append(std::to_string(length_)); +std::string ParseArray::generateName() const { + string name("{"); + if (!elements_.empty()) { + name.append(elements_.front()->generateName()); + for (std::size_t i = 1; i < elements_.size(); ++i) { + name.append(","); + name.append(elements_.at(i)->generateName()); + } } - name.push_back(')'); + name.append("}"); return name; } -void ParseSubstringFunction::getFieldStringItems( +void ParseArray::getFieldStringItems( std::vector *inline_field_names, std::vector *inline_field_values, std::vector *non_container_child_field_names, std::vector *non_container_child_fields, std::vector *container_child_field_names, std::vector> *container_child_fields) const { - inline_field_names->push_back("start_position"); - inline_field_values->push_back(std::to_string(start_position_)); - - inline_field_names->push_back("length"); - inline_field_values->push_back(std::to_string(length_)); - - non_container_child_field_names->push_back("operand"); - non_container_child_fields->push_back(operand_.get()); + container_child_field_names->emplace_back("elements"); + container_child_fields->emplace_back(); + for (const auto &element : elements_) { + container_child_fields->back().emplace_back(element.get()); + } } } // namespace quickstep diff --git a/parser/ParseBasicExpressions.hpp b/parser/ParseBasicExpressions.hpp index d8de6695..56295e73 100644 --- a/parser/ParseBasicExpressions.hpp +++ b/parser/ParseBasicExpressions.hpp @@ -26,6 +26,7 @@ #include #include +#include "parser/ParseDataType.hpp" #include "parser/ParseExpression.hpp" #include "parser/ParseLiteralValue.hpp" #include "parser/ParseString.hpp" @@ -36,9 +37,6 @@ namespace quickstep { -class BinaryOperation; -class UnaryOperation; - /** \addtogroup Parser * @{ */ @@ -172,155 +170,6 @@ class ParseAttribute : public ParseExpression { }; -/** - * @brief The parsed representation of an unary operation applied to an expression. - **/ -class ParseUnaryExpression : public ParseExpression { - public: - /** - * @brief Constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - * @param op The UnaryOperation from the quickstep type system to apply. - * @param operand The parsed scalar representation of the unary operation's - * argument, which becomes owned by this ParseScalarUnaryExpression. - **/ - ParseUnaryExpression(const int line_number, - const int column_number, - const UnaryOperation &op, - ParseExpression *operand) - : ParseExpression(line_number, column_number), - op_(op), - operand_(operand) { - } - - /** - * @brief Destructor. - */ - ~ParseUnaryExpression() override { - } - - ExpressionType getExpressionType() const override { - return kUnaryExpression; - } - - std::string getName() const override; - - /** - * @return The unary operation. - */ - const UnaryOperation& op() const { - return op_; - } - - /** - * @return The operand expression. - */ - const ParseExpression* operand() const { - return operand_.get(); - } - - std::string generateName() const override; - - protected: - void getFieldStringItems( - std::vector *inline_field_names, - std::vector *inline_field_values, - std::vector *non_container_child_field_names, - std::vector *non_container_child_fields, - std::vector *container_child_field_names, - std::vector> *container_child_fields) const override; - - private: - const UnaryOperation &op_; - std::unique_ptr operand_; - - DISALLOW_COPY_AND_ASSIGN(ParseUnaryExpression); -}; - -/** - * @brief The parsed representation of a binary operation applied to two - * expressions. - **/ -class ParseBinaryExpression : public ParseExpression { - public: - /** - * @brief Constructor. - * - * @param line_number Line number of the binary operator token in the SQL statement. - * @param column_number Column number of the binary operator token in the SQL statement. - * @param op The BinaryOperation from the quickstep type system to apply. - * @param left_operand The parsed scalar representation of the binary - * operation's left argument, which becomes owned by this - * ParseScalarBinaryExpression. - * @param right_operand The parsed scalar representation of the binary - * operation's right argument, which becomes owned by this - * ParseScalarBinaryExpression. - **/ - ParseBinaryExpression(const int line_number, - const int column_number, - const BinaryOperation &op, - ParseExpression *left_operand, - ParseExpression *right_operand) - : ParseExpression(line_number, column_number), - op_(op), - left_operand_(left_operand), - right_operand_(right_operand) { - } - - /** - * @brief Destructor. - */ - ~ParseBinaryExpression() override { - } - - ExpressionType getExpressionType() const override { - return kBinaryExpression; - } - - std::string getName() const override; - - /** - * @return The binary operation. - */ - const BinaryOperation& op() const { - return op_; - } - - /** - * @return The left operand expression. - */ - const ParseExpression* left_operand() const { - return left_operand_.get(); - } - - /** - * @return The right operand expression. - */ - const ParseExpression* right_operand() const { - return right_operand_.get(); - } - - std::string generateName() const override; - - protected: - void getFieldStringItems( - std::vector *inline_field_names, - std::vector *inline_field_values, - std::vector *non_container_child_field_names, - std::vector *non_container_child_fields, - std::vector *container_child_field_names, - std::vector> *container_child_fields) const override; - - private: - const BinaryOperation &op_; - std::unique_ptr left_operand_; - std::unique_ptr right_operand_; - - DISALLOW_COPY_AND_ASSIGN(ParseBinaryExpression); -}; - /** * @brief The parsed representation of '*' as a function argument. */ @@ -346,6 +195,7 @@ class ParseStar : public ParseTreeNode { DISALLOW_COPY_AND_ASSIGN(ParseStar); }; + /** * @brief Parsed function call in the form of a name with a list of arguments in parentheses. */ @@ -496,51 +346,35 @@ class ParseFunctionCall : public ParseExpression { }; -/** - * @brief Parsed representation of EXTRACT(unit FROM date). - */ -class ParseExtractFunction : public ParseExpression { +class ParseTypeCast : public ParseExpression { public: - /** - * @brief Constructor. - * - * @param line_number The line number of the token "extract" in the statement. - * @param column_number The column number of the token "extract in the statement. - * @param extract_field The field to extract. - * @param source_expression The expression to extract a field from. - */ - ParseExtractFunction(const int line_number, - const int column_number, - ParseString *extract_field, - ParseExpression *date_expression) + ParseTypeCast(const int line_number, + const int column_number, + ParseExpression *operand, + ParseDataType *target_type) : ParseExpression(line_number, column_number), - extract_field_(extract_field), - date_expression_(date_expression) { - } + operand_(operand), + target_type_(target_type) {} + + ~ParseTypeCast() override {} ExpressionType getExpressionType() const override { - return kExtract; + return kTypeCast; } std::string getName() const override { - return "Extract"; + return "TypeCast"; } - /** - * @return The field to extract. - */ - const ParseString* extract_field() const { - return extract_field_.get(); - } + std::string generateName() const override; - /** - * @return The expression to extract a field from. - */ - const ParseExpression* date_expression() const { - return date_expression_.get(); + const ParseExpression& operand() const { + return *operand_; } - std::string generateName() const override; + const ParseDataType& target_type() const { + return *target_type_; + } protected: void getFieldStringItems( @@ -552,70 +386,39 @@ class ParseExtractFunction : public ParseExpression { std::vector> *container_child_fields) const override; private: - std::unique_ptr extract_field_; - std::unique_ptr date_expression_; + std::unique_ptr operand_; + std::unique_ptr target_type_; - DISALLOW_COPY_AND_ASSIGN(ParseExtractFunction); + DISALLOW_COPY_AND_ASSIGN(ParseTypeCast); }; -/** - * @brief Parsed representation of the substring function. - */ -class ParseSubstringFunction : public ParseExpression { +class ParseArray : public ParseExpression { public: - static constexpr std::size_t kDefaultLength = std::numeric_limits::max(); + ParseArray(const int line_number, const int column_number) + : ParseExpression(line_number, column_number) {} - /** - * @brief Constructor. - * - * @param line_number The line number of the first token of the function call. - * @param column_number The column number of the first token of the function call. - * @param operand The operand of the substring. - * @param start_position The 1-based starting position of the substring. - * @param length Optional substring length. - */ - ParseSubstringFunction(const int line_number, - const int column_number, - ParseExpression *operand, - const std::size_t start_position, - const std::size_t length = kDefaultLength) - : ParseExpression(line_number, column_number), - operand_(operand), - start_position_(start_position), - length_(length) {} + ~ParseArray() override { + } ExpressionType getExpressionType() const override { - return kSubstring; + return kArray; } std::string getName() const override { - return "Substring"; + return "Array"; } - /** - * @return The operand of the substring. - */ - const ParseExpression* operand() const { - return operand_.get(); - } + std::string generateName() const override; - /** - * @return The 1-based starting position of the substring. - */ - std::size_t start_position() const { - return start_position_; + const std::vector>& elements() const { + return elements_; } - /** - * @return Then substring length. - */ - std::size_t length() const { - return length_; + void add(ParseExpression *element) { + elements_.emplace_back(std::unique_ptr(element)); } - std::string generateName() const override; - protected: void getFieldStringItems( std::vector *inline_field_names, @@ -626,11 +429,9 @@ class ParseSubstringFunction : public ParseExpression { std::vector> *container_child_fields) const override; private: - std::unique_ptr operand_; - const std::size_t start_position_; - const std::size_t length_; + std::vector> elements_; - DISALLOW_COPY_AND_ASSIGN(ParseSubstringFunction); + DISALLOW_COPY_AND_ASSIGN(ParseArray); }; /** @} */ diff --git a/types/operations/binary_operations/BinaryOperationID.cpp b/parser/ParseDataType-decl.hpp similarity index 72% rename from types/operations/binary_operations/BinaryOperationID.cpp rename to parser/ParseDataType-decl.hpp index 7ba2e699..f85ab55f 100644 --- a/types/operations/binary_operations/BinaryOperationID.cpp +++ b/parser/ParseDataType-decl.hpp @@ -17,24 +17,8 @@ * under the License. **/ -#include "types/operations/binary_operations/BinaryOperationID.hpp" +#ifndef QUICKSTEP_PARSER_PARSE_DATA_TYPE_DECL_HPP_ +#define QUICKSTEP_PARSER_PARSE_DATA_TYPE_DECL_HPP_ -namespace quickstep { -const char *kBinaryOperationNames[] = { - "Add", - "Subtract", - "Multiply", - "Divide", - "Modulo" -}; - -const char *kBinaryOperationShortNames[] = { - "+", - "-", - "*", - "/", - "%" -}; - -} // namespace quickstep +#endif // QUICKSTEP_PARSER_PARSE_DATA_TYPE_DECL_HPP_ diff --git a/parser/ParseDataType.cpp b/parser/ParseDataType.cpp new file mode 100644 index 00000000..7892122a --- /dev/null +++ b/parser/ParseDataType.cpp @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#include "parser/ParseDataType.hpp" + +#include +#include + +#include "parser/ParseTreeNode.hpp" + +namespace quickstep { + +void ParseDataType::getFieldStringItems( + std::vector *inline_field_names, + std::vector *inline_field_values, + std::vector *non_container_child_field_names, + std::vector *non_container_child_fields, + std::vector *container_child_field_names, + std::vector> *container_child_fields) const { + inline_field_names->emplace_back("type_name"); + inline_field_values->emplace_back(type_name_->value()); + + inline_field_names->emplace_back("nullable"); + inline_field_values->emplace_back(nullable_ ? "true" : "false"); + + container_child_field_names->emplace_back("parameters"); + container_child_fields->emplace_back(); + for (const auto ¶meter : parameters_) { + container_child_fields->back().emplace_back(parameter.get()); + } +} + +void ParseDataTypeParameterLiteralValue::getFieldStringItems( + std::vector *inline_field_names, + std::vector *inline_field_values, + std::vector *non_container_child_field_names, + std::vector *non_container_child_fields, + std::vector *container_child_field_names, + std::vector> *container_child_fields) const { + non_container_child_field_names->emplace_back("literal_value"); + non_container_child_fields->emplace_back(literal_value_.get()); +} + +void ParseDataTypeParameterDataType::getFieldStringItems( + std::vector *inline_field_names, + std::vector *inline_field_values, + std::vector *non_container_child_field_names, + std::vector *non_container_child_fields, + std::vector *container_child_field_names, + std::vector> *container_child_fields) const { + non_container_child_field_names->emplace_back("data_type"); + non_container_child_fields->emplace_back(data_type_.get()); +} + +} // namespace quickstep diff --git a/parser/ParseDataType.hpp b/parser/ParseDataType.hpp new file mode 100644 index 00000000..b554011c --- /dev/null +++ b/parser/ParseDataType.hpp @@ -0,0 +1,187 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_PARSER_PARSE_DATA_TYPE_HPP_ +#define QUICKSTEP_PARSER_PARSE_DATA_TYPE_HPP_ + +#include +#include +#include + +#include "parser/ParseLiteralValue.hpp" +#include "parser/ParseString.hpp" +#include "parser/ParseTreeNode.hpp" +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +class Type; + +/** \addtogroup Parser + * @{ + */ + +class ParseDataTypeParameter : public ParseTreeNode { + public: + enum ParameterType { + kDataType, + kLiteralValue + }; + + virtual ParameterType getParameterType() const = 0; + + protected: + ParseDataTypeParameter(const int line_number, + const int column_number) + : ParseTreeNode(line_number, column_number) {} + + private: + DISALLOW_COPY_AND_ASSIGN(ParseDataTypeParameter); +}; + +/** + * @brief Parsed representation of a data type. + **/ +class ParseDataType : public ParseTreeNode { + public: + ParseDataType(const int line_number, + const int column_number, + ParseString *type_name) + : ParseTreeNode(line_number, column_number), + type_name_(type_name), + nullable_(false) {} + + std::string getName() const override { + return "DataType"; + } + + const ParseString& type_name() const { + return *type_name_; + } + + const std::vector>& parameters() const { + return parameters_; + } + + bool nullable() const { + return nullable_; + } + + void addParameter(ParseDataTypeParameter *parameter) { + parameters_.emplace_back(std::unique_ptr(parameter)); + } + + void setNullable(const bool nullable) { + nullable_ = nullable; + } + + protected: + void getFieldStringItems( + std::vector *inline_field_names, + std::vector *inline_field_values, + std::vector *non_container_child_field_names, + std::vector *non_container_child_fields, + std::vector *container_child_field_names, + std::vector> *container_child_fields) const override; + + private: + const std::unique_ptr type_name_; + std::vector> parameters_; + bool nullable_; + + DISALLOW_COPY_AND_ASSIGN(ParseDataType); +}; + +class ParseDataTypeParameterLiteralValue : public ParseDataTypeParameter { + public: + ParseDataTypeParameterLiteralValue(const int line_number, + const int column_number, + ParseLiteralValue *literal_value) + : ParseDataTypeParameter(line_number, column_number), + literal_value_(literal_value) {} + + std::string getName() const override { + return "DataTypeParameterLiteralValue"; + } + + ParameterType getParameterType() const override { + return ParameterType::kLiteralValue; + } + + const ParseLiteralValue& literal_value() const { + return *literal_value_; + } + + protected: + void getFieldStringItems( + std::vector *inline_field_names, + std::vector *inline_field_values, + std::vector *non_container_child_field_names, + std::vector *non_container_child_fields, + std::vector *container_child_field_names, + std::vector> *container_child_fields) const override; + + private: + std::unique_ptr literal_value_; + + DISALLOW_COPY_AND_ASSIGN(ParseDataTypeParameterLiteralValue); +}; + +class ParseDataTypeParameterDataType : public ParseDataTypeParameter { + public: + ParseDataTypeParameterDataType(const int line_number, + const int column_number, + ParseDataType *data_type) + : ParseDataTypeParameter(line_number, column_number), + data_type_(data_type) {} + + std::string getName() const override { + return "DataTypeParameterDataType"; + } + + ParameterType getParameterType() const override { + return ParameterType::kDataType; + } + + const ParseDataType& data_type() const { + return *data_type_; + } + + protected: + void getFieldStringItems( + std::vector *inline_field_names, + std::vector *inline_field_values, + std::vector *non_container_child_field_names, + std::vector *non_container_child_fields, + std::vector *container_child_field_names, + std::vector> *container_child_fields) const override; + + private: + std::unique_ptr data_type_; + + DISALLOW_COPY_AND_ASSIGN(ParseDataTypeParameterDataType); +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_PARSER_PARSE_DATA_TYPE_HPP_ diff --git a/parser/ParseExpression.hpp b/parser/ParseExpression.hpp index 1b9ade4d..01da16ab 100644 --- a/parser/ParseExpression.hpp +++ b/parser/ParseExpression.hpp @@ -37,16 +37,15 @@ namespace quickstep { class ParseExpression : public ParseTreeNode { public: enum ExpressionType { + kArray, kAttribute, kBinaryExpression, - kExtract, kFunctionCall, kScalarLiteral, kSearchedCaseExpression, kSimpleCaseExpression, kSubqueryExpression, - kSubstring, - kUnaryExpression, + kTypeCast, }; /** diff --git a/parser/ParseLiteralValue.cpp b/parser/ParseLiteralValue.cpp index d4753ab7..caa21e39 100644 --- a/parser/ParseLiteralValue.cpp +++ b/parser/ParseLiteralValue.cpp @@ -87,15 +87,15 @@ TypedValue NumericParseLiteralValue::concretize( const Type **concretized_type) const { TypedValue parsed_value; if ((type_hint != nullptr) - && (type_hint->getSuperTypeID() == Type::kNumeric) - && (type_hint->parseValueFromString(numeric_string_, &parsed_value))) { + && (type_hint->getSuperTypeID() == SuperTypeID::kNumeric) + && (type_hint->parseTypedValueFromString(numeric_string_, &parsed_value))) { *concretized_type = &(type_hint->getNonNullableVersion()); return parsed_value; } if (float_like_) { *concretized_type = &DoubleType::InstanceNonNullable(); - CHECK((*concretized_type)->parseValueFromString(numeric_string_, &parsed_value)) + CHECK((*concretized_type)->parseTypedValueFromString(numeric_string_, &parsed_value)) << "Failed to parse double from numeric string \"" << numeric_string_ << "\""; return parsed_value; @@ -153,7 +153,7 @@ TypedValue StringParseLiteralValue::concretize(const Type *type_hint, if (explicit_type_ != nullptr) { if ((type_hint != nullptr) && (type_hint->isSafelyCoercibleFrom(*explicit_type_))) { *concretized_type = type_hint; - return type_hint->coerceValue(explicit_parsed_value_, *explicit_type_); + return type_hint->coerceTypedValue(explicit_parsed_value_, *explicit_type_); } else { *concretized_type = explicit_type_; return explicit_parsed_value_; @@ -161,12 +161,12 @@ TypedValue StringParseLiteralValue::concretize(const Type *type_hint, } else { TypedValue parsed_value; if ((type_hint != nullptr) - && (type_hint->parseValueFromString(value_->value(), &parsed_value))) { + && (type_hint->parseTypedValueFromString(value_->value(), &parsed_value))) { *concretized_type = &(type_hint->getNonNullableVersion()); return parsed_value; } else { *concretized_type = &VarCharType::InstanceNonNullable(value_->value().length()); - CHECK((*concretized_type)->parseValueFromString(value_->value(), &parsed_value)); + CHECK((*concretized_type)->parseTypedValueFromString(value_->value(), &parsed_value)); return parsed_value; } } @@ -189,7 +189,7 @@ std::string StringParseLiteralValue::generateName() const { bool StringParseLiteralValue::tryExplicitTypeParse() { DCHECK(explicit_type_ != nullptr); - return explicit_type_->parseValueFromString(value_->value(), &explicit_parsed_value_); + return explicit_type_->parseTypedValueFromString(value_->value(), &explicit_parsed_value_); } void StringParseLiteralValue::getFieldStringItems( diff --git a/parser/SqlLexer.lpp b/parser/SqlLexer.lpp index d818d0b0..4d4d1712 100644 --- a/parser/SqlLexer.lpp +++ b/parser/SqlLexer.lpp @@ -39,6 +39,7 @@ namespace quickstep { class BinaryOperation; class Comparison; +class ParseArray; class ParseAssignment; class ParseAttribute; class ParseAttributeDefinition; @@ -89,6 +90,7 @@ class ParseSubqueryExpression; class ParseSubqueryTableReference; class ParseTableReference; class ParseTableReferenceSignature; +class ParseTypeCast; class ParseWindow; class Type; class UnaryOperation; @@ -177,33 +179,26 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} "asc" return TOKEN_ASC; "ascending" return TOKEN_ASC; "between" return TOKEN_BETWEEN; - "bigint" return TOKEN_BIGINT; - "bit" return TOKEN_BIT; "bitweaving" return TOKEN_BITWEAVING; "blockproperties" return TOKEN_BLOCKPROPERTIES; "blocksample" return TOKEN_BLOCKSAMPLE; "bloomfilter" return TOKEN_BLOOM_FILTER; "case" return TOKEN_CASE; + "cast" return TOKEN_CAST; "csbtree" return TOKEN_CSB_TREE; "by" return TOKEN_BY; - "char" return TOKEN_CHARACTER; - "character" return TOKEN_CHARACTER; "check" return TOKEN_CHECK; "column" return TOKEN_COLUMN; "constraint" return TOKEN_CONSTRAINT; "copy" return TOKEN_COPY; "create" return TOKEN_CREATE; "current" return TOKEN_CURRENT; - "date" return TOKEN_DATE; - "datetime" return TOKEN_DATETIME; "day" return TOKEN_DAY; - "decimal" return TOKEN_DECIMAL; "default" return TOKEN_DEFAULT; "delete" return TOKEN_DELETE; "desc" return TOKEN_DESC; "descending" return TOKEN_DESC; "distinct" return TOKEN_DISTINCT; - "double" return TOKEN_DOUBLE; "drop" return TOKEN_DROP; "else" return TOKEN_ELSE; "end" return TOKEN_END; @@ -211,7 +206,6 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} "extract" return TOKEN_EXTRACT; "false" return TOKEN_FALSE; "first" return TOKEN_FIRST; - "float" return TOKEN_FLOAT; "following" return TOKEN_FOLLOWING; "for" return TOKEN_FOR; "foreign" return TOKEN_FOREIGN; @@ -225,8 +219,6 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} "index" return TOKEN_INDEX; "inner" return TOKEN_INNER; "insert" return TOKEN_INSERT; - "int" return TOKEN_INTEGER; - "integer" return TOKEN_INTEGER; "intersect" return TOKEN_INTERSECT; "interval" return TOKEN_INTERVAL; "into" return TOKEN_INTO; @@ -237,7 +229,6 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} "left" return TOKEN_LEFT; "like" return TOKEN_LIKE; "limit" return TOKEN_LIMIT; - "long" return TOKEN_LONG; "minute" return TOKEN_MINUTE; "month" return TOKEN_MONTH; "not" return TOKEN_NOT; @@ -268,14 +259,11 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} "select" return TOKEN_SELECT; "set" return TOKEN_SET; "sma" return TOKEN_SMA; - "smallint" return TOKEN_SMALLINT; "stderr" return TOKEN_STDERR; "stdout" return TOKEN_STDOUT; "substring" return TOKEN_SUBSTRING; "table" return TOKEN_TABLE; "then" return TOKEN_THEN; - "time" return TOKEN_TIME; - "timestamp" return TOKEN_TIMESTAMP; "to" return TOKEN_TO; "true" return TOKEN_TRUE; "tuplesample" return TOKEN_TUPLESAMPLE; @@ -285,13 +273,11 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} "update" return TOKEN_UPDATE; "using" return TOKEN_USING; "values" return TOKEN_VALUES; - "varchar" return TOKEN_VARCHAR; "when" return TOKEN_WHEN; "where" return TOKEN_WHERE; "window" return TOKEN_WINDOW; "with" return TOKEN_WITH; "year" return TOKEN_YEAR; - "yearmonth" return TOKEN_YEARMONTH; "=" return TOKEN_EQ; "!=" return TOKEN_NEQ; @@ -300,6 +286,9 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} ">" return TOKEN_GT; "<=" return TOKEN_LEQ; ">=" return TOKEN_GEQ; + "::" return TOKEN_DOUBLECOLON; + "{" return TOKEN_LBRACE; + "}" return TOKEN_RBRACE; [-+*/%(),.;] return yytext[0]; [\[\]] return yytext[0]; diff --git a/parser/SqlParser.ypp b/parser/SqlParser.ypp index 8fbcdd79..16e30bcd 100644 --- a/parser/SqlParser.ypp +++ b/parser/SqlParser.ypp @@ -30,7 +30,7 @@ * occurs, Bison resolves it by preferring to shift rather than reduce, which * is the correct, expected behavior for both cases in this parser. **/ -%expect 2 +%expect 1 %{ @@ -72,6 +72,7 @@ typedef struct YYLTYPE { #include "parser/ParseBasicExpressions.hpp" #include "parser/ParseBlockProperties.hpp" #include "parser/ParseCaseExpressions.hpp" +#include "parser/ParseDataType.hpp" #include "parser/ParseExpression.hpp" #include "parser/ParseGeneratorTableReference.hpp" #include "parser/ParseGroupBy.hpp" @@ -102,15 +103,9 @@ typedef struct YYLTYPE { #include "types/Type.hpp" #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" -#include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "types/operations/comparisons/Comparison.hpp" #include "types/operations/comparisons/ComparisonFactory.hpp" #include "types/operations/comparisons/ComparisonID.hpp" -#include "types/operations/unary_operations/UnaryOperation.hpp" -#include "types/operations/unary_operations/UnaryOperationFactory.hpp" -#include "types/operations/unary_operations/UnaryOperationID.hpp" #include "utility/PtrList.hpp" #include "utility/PtrVector.hpp" @@ -189,9 +184,10 @@ typedef void* yyscan_t; quickstep::ParseStatementQuit *quit_statement_; const quickstep::Comparison *comparison_; - const quickstep::UnaryOperation *unary_operation_; - const quickstep::BinaryOperation *binary_operation_; + quickstep::ParseString *unary_operation_; + quickstep::ParseString *binary_operation_; + quickstep::ParseArray *array_expression_; quickstep::ParseFunctionCall *function_call_; quickstep::PtrList *expression_list_; @@ -252,7 +248,6 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_AND; %token TOKEN_AS; %token TOKEN_ASC; -%token TOKEN_BIGINT; %token TOKEN_BIT; %token TOKEN_BITWEAVING; %token TOKEN_BLOCKPROPERTIES; @@ -261,22 +256,19 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_CSB_TREE; %token TOKEN_BY; %token TOKEN_CASE; -%token TOKEN_CHARACTER; +%token TOKEN_CAST; %token TOKEN_CHECK; %token TOKEN_COLUMN; %token TOKEN_CONSTRAINT; %token TOKEN_COPY; %token TOKEN_CREATE; %token TOKEN_CURRENT; -%token TOKEN_DATE; -%token TOKEN_DATETIME; %token TOKEN_DAY; -%token TOKEN_DECIMAL; %token TOKEN_DEFAULT; %token TOKEN_DELETE; %token TOKEN_DESC; %token TOKEN_DISTINCT; -%token TOKEN_DOUBLE; +%token TOKEN_DOUBLECOLON; %token TOKEN_DROP; %token TOKEN_ELSE; %token TOKEN_END; @@ -284,7 +276,6 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_EXTRACT; %token TOKEN_FALSE; %token TOKEN_FIRST; -%token TOKEN_FLOAT; %token TOKEN_FOLLOWING; %token TOKEN_FOR; %token TOKEN_FOREIGN; @@ -298,16 +289,15 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_INDEX; %token TOKEN_INNER; %token TOKEN_INSERT; -%token TOKEN_INTEGER; %token TOKEN_INTERSECT; %token TOKEN_INTERVAL; %token TOKEN_INTO; %token TOKEN_JOIN; %token TOKEN_KEY; %token TOKEN_LAST; +%token TOKEN_LBRACE; %token TOKEN_LEFT; %token TOKEN_LIMIT; -%token TOKEN_LONG; %token TOKEN_MINUTE; %token TOKEN_MONTH; %token TOKEN_NOT; @@ -327,6 +317,7 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_PRIORITY; %token TOKEN_QUIT; %token TOKEN_RANGE; +%token TOKEN_RBRACE; %token TOKEN_REAL; %token TOKEN_REFERENCES; %token TOKEN_REGEXP; @@ -338,14 +329,11 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_SELECT; %token TOKEN_SET; %token TOKEN_SMA; -%token TOKEN_SMALLINT; %token TOKEN_STDERR; %token TOKEN_STDOUT; %token TOKEN_SUBSTRING; %token TOKEN_TABLE; %token TOKEN_THEN; -%token TOKEN_TIME; -%token TOKEN_TIMESTAMP; %token TOKEN_TO; %token TOKEN_TRUE; %token TOKEN_TUPLESAMPLE; @@ -355,13 +343,11 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_UPDATE; %token TOKEN_USING; %token TOKEN_VALUES; -%token TOKEN_VARCHAR; %token TOKEN_WHEN; %token TOKEN_WHERE; %token TOKEN_WINDOW; %token TOKEN_WITH; %token TOKEN_YEAR; -%token TOKEN_YEARMONTH; %token TOKEN_EOF; %token TOKEN_LEX_ERROR; @@ -376,6 +362,7 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string boolean_value frame_mode opt_all_distinct + opt_nullable %type literal_value @@ -394,9 +381,15 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string add_expression case_expression opt_else_clause + cast_function extract_function substr_function + +%type + array_expression + array_element_commalist + %type attribute_ref @@ -453,6 +446,7 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %type data_type + data_type_parameter_commalist %type column_def @@ -624,8 +618,6 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %destructor { } %destructor { } -%destructor { } -%destructor { } %destructor { } %destructor { @@ -765,102 +757,46 @@ column_def_commalist: }; data_type: - TOKEN_BIT { - $$ = nullptr; - NotSupported(&@1, yyscanner, "BIT data type"); - YYERROR; - } - | TOKEN_DATE { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDate)); - } - | TOKEN_DATETIME { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDatetime)); - } - | TOKEN_TIME { - $$ = nullptr; - NotSupported(&@1, yyscanner, "TIME data type"); - YYERROR; - } - | TOKEN_TIMESTAMP { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDatetime)); - } - | TOKEN_DECIMAL { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble)); - } - | TOKEN_REAL { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble)); - } - | TOKEN_DOUBLE { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble)); - } - | TOKEN_FLOAT { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kFloat)); - } - | TOKEN_SMALLINT { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kInt)); - } - | TOKEN_INTEGER { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kInt)); - } - | TOKEN_BIGINT { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kLong)); + any_name { + $$ = new quickstep::ParseDataType(@1.first_line, @1.first_column, $1); } - | TOKEN_LONG { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kLong)); + | data_type_parameter_commalist ')' { + $$ = $1; + }; + +data_type_parameter_commalist: + any_name '(' data_type opt_nullable { + $$ = new quickstep::ParseDataType(@1.first_line, @1.first_column, $1); + $3->setNullable($4); + $$->addParameter( + new quickstep::ParseDataTypeParameterDataType($3->line_number(), $3->column_number(), $3)); } - | TOKEN_INTERVAL { - /** - * NOTE(chasseur): This pattern exhibits a shift/reduce conflict with the - * TOKEN_INTERVAL case in 'literal_value'. Bison prefers to shift rather - * than reduce, so the case in 'literal_value' has precedence over this. - **/ - $$ = nullptr; - quickstep_yyerror(&@1, yyscanner, nullptr, - "INTERVAL is ambiguous as a column type. Specify either DATETIME INTERVAL " - "or YEARMONTH INTERVAL"); - YYERROR; + | data_type_parameter_commalist ',' data_type opt_nullable { + $$ = $1; + $3->setNullable($4); + $$->addParameter( + new quickstep::ParseDataTypeParameterDataType($3->line_number(), $3->column_number(), $3)); } - | TOKEN_DATETIME TOKEN_INTERVAL { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDatetimeInterval)); + | any_name '(' literal_value { + $$ = new quickstep::ParseDataType(@1.first_line, @1.first_column, $1); + $$->addParameter( + new quickstep::ParseDataTypeParameterLiteralValue($3->line_number(), $3->column_number(), $3)); } - | TOKEN_YEARMONTH TOKEN_INTERVAL { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kYearMonthInterval)); + | data_type_parameter_commalist ',' literal_value { + $$ = $1; + $$->addParameter( + new quickstep::ParseDataTypeParameterLiteralValue($3->line_number(), $3->column_number(), $3)); + }; + +opt_nullable: + { + $$ = false; // NOT NULL } - | TOKEN_CHARACTER '(' TOKEN_UNSIGNED_NUMVAL ')' { - if ($3->float_like()) { - delete $3; - $$ = NULL; - quickstep_yyerror(&@3, yyscanner, nullptr, "Non-integer length supplied for CHAR type"); - YYERROR; - } else { - if ($3->long_value() <= 0) { - delete $3; - $$ = NULL; - quickstep_yyerror(&@3, yyscanner, nullptr, "Length for CHAR type must be at least 1"); - YYERROR; - } else { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kChar, $3->long_value(), false)); - delete $3; - } - } + | TOKEN_NULL { + $$ = true; // NULL } - | TOKEN_VARCHAR '(' TOKEN_UNSIGNED_NUMVAL ')' { - if ($3->float_like()) { - delete $3; - $$ = NULL; - quickstep_yyerror(&@3, yyscanner, nullptr, "Non-integer length supplied for VARCHAR type"); - YYERROR; - } else { - if ($3->long_value() < 0) { - delete $3; - $$ = NULL; - quickstep_yyerror(&@3, yyscanner, nullptr, "Negative length supplied for VARCHAR type"); - YYERROR; - } else { - $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kVarChar, $3->long_value(), false)); - delete $3; - } - } + | TOKEN_NOT TOKEN_NULL { + $$ = true; // NOT NULL }; column_constraint_def: @@ -1676,7 +1612,10 @@ predicate_expression_base: /* Scalars */ add_expression: add_expression add_operation multiply_expression { - $$ = new quickstep::ParseBinaryExpression(@2.first_line, @2.first_column, *$2, $1, $3); + auto *arguments = new quickstep::PtrList(); + arguments->push_back($1); + arguments->push_back($3); + $$ = new quickstep::ParseFunctionCall(@1.first_line, @1.first_column, false, $2, arguments); } | multiply_expression { $$ = $1; @@ -1684,7 +1623,10 @@ add_expression: multiply_expression: multiply_expression multiply_operation unary_expression { - $$ = new quickstep::ParseBinaryExpression(@2.first_line, @2.first_column, *$2, $1, $3); + auto *arguments = new quickstep::PtrList(); + arguments->push_back($1); + arguments->push_back($3); + $$ = new quickstep::ParseFunctionCall(@1.first_line, @1.first_column, false, $2, arguments); } | unary_expression { $$ = $1; @@ -1692,7 +1634,9 @@ multiply_expression: unary_expression: unary_operation expression_base { - $$ = new quickstep::ParseUnaryExpression(@1.first_line, @1.first_column, *$1, $2); + auto *arguments = new quickstep::PtrList(); + arguments->push_back($2); + $$ = new quickstep::ParseFunctionCall(@1.first_line, @1.first_column, false, $1, arguments); } | expression_base { $$ = $1; @@ -1705,6 +1649,9 @@ expression_base: | literal_value { $$ = new quickstep::ParseScalarLiteral($1); } + | array_expression { + $$ = $1; + } | function_call { $$ = $1; } @@ -1716,6 +1663,9 @@ expression_base: $1->setWindow($4); $$ = $1; } + | cast_function { + $$ = $1; + } | extract_function { $$ = $1; } @@ -1732,6 +1682,26 @@ expression_base: $$ = $1; }; +array_expression: + array_element_commalist TOKEN_RBRACE { + $$ = $1; + } + | TOKEN_LBRACE TOKEN_RBRACE { + $$ = new quickstep::ParseArray(@1.first_line, @1.first_column); + } + ; + +array_element_commalist: + array_element_commalist ',' add_expression { + $$ = $1; + $$->add($3); + } + | TOKEN_LBRACE add_expression { + $$ = new quickstep::ParseArray(@1.first_line, @1.first_column); + $$->add($2); + } + ; + function_call: any_name '(' ')' { $$ = new quickstep::ParseFunctionCall( @@ -1748,19 +1718,42 @@ function_call: $$ = new quickstep::ParseFunctionCall(@1.first_line, @1.first_column, true, $1, $4); }; +cast_function: + TOKEN_CAST '(' add_expression TOKEN_AS data_type ')' { + $$ = new quickstep::ParseTypeCast(@1.first_line, @1.first_column, $3, $5); + } + | expression_base TOKEN_DOUBLECOLON data_type { + $$ = new quickstep::ParseTypeCast(@2.first_line, @2.first_column, $1, $3); + }; + extract_function: TOKEN_EXTRACT '(' datetime_unit TOKEN_FROM add_expression ')' { - $$ = new quickstep::ParseExtractFunction(@1.first_line, @1.first_column, $3, $5); + auto *arguments = new quickstep::PtrList(); + arguments->push_back($5); + arguments->push_back(new quickstep::ParseScalarLiteral( + new quickstep::StringParseLiteralValue($3, nullptr))); + auto *name = new quickstep::ParseString(@1.first_line, @1.first_column, "extract"); + $$ = new quickstep::ParseFunctionCall( + @1.first_line, @1.first_column, false, name, arguments); }; substr_function: TOKEN_SUBSTRING '(' add_expression TOKEN_FROM TOKEN_UNSIGNED_NUMVAL ')' { - $$ = new quickstep::ParseSubstringFunction( - @1.first_line, @1.first_column, $3, $5->long_value()); + auto *arguments = new quickstep::PtrList(); + arguments->push_back($3); + arguments->push_back(new quickstep::ParseScalarLiteral($5)); + auto *name = new quickstep::ParseString(@1.first_line, @1.first_column, "substring"); + $$ = new quickstep::ParseFunctionCall( + @1.first_line, @1.first_column, false, name, arguments); } | TOKEN_SUBSTRING '(' add_expression TOKEN_FROM TOKEN_UNSIGNED_NUMVAL TOKEN_FOR TOKEN_UNSIGNED_NUMVAL ')' { - $$ = new quickstep::ParseSubstringFunction( - @1.first_line, @1.first_column, $3, $5->long_value(), $7->long_value()); + auto *arguments = new quickstep::PtrList(); + arguments->push_back($3); + arguments->push_back(new quickstep::ParseScalarLiteral($5)); + arguments->push_back(new quickstep::ParseScalarLiteral($7)); + auto *name = new quickstep::ParseString(@1.first_line, @1.first_column, "substring"); + $$ = new quickstep::ParseFunctionCall( + @1.first_line, @1.first_column, false, name, arguments); }; case_expression: @@ -1876,20 +1869,7 @@ literal_value: quickstep_yyerror(&@3, yyscanner, nullptr, "Failed to parse literal as specified type"); YYERROR; } - } - | data_type TOKEN_STRING_SINGLE_QUOTED { - quickstep::StringParseLiteralValue *parse_value - = new quickstep::StringParseLiteralValue($2, &($1->getType())); - delete $1; - if (!parse_value->tryExplicitTypeParse()) { - delete parse_value; - $$ = nullptr; - quickstep_yyerror(&@2, yyscanner, nullptr, "Failed to parse literal as specified type"); - YYERROR; - } else { - $$ = parse_value; - } - } + }; datetime_unit: TOKEN_YEAR { @@ -1980,26 +1960,26 @@ unary_operation: * to shift rather than reduce, the case in 'literal_value' has precedence * over this one. **/ - $$ = &quickstep::UnaryOperationFactory::GetUnaryOperation(quickstep::UnaryOperationID::kNegate); + $$ = new quickstep::ParseString(@1.first_line, @1.first_column, std::string("-")); }; add_operation: '+' { - $$ = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kAdd); + $$ = new quickstep::ParseString(@1.first_line, @1.first_column, std::string("+")); } | '-' { - $$ = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kSubtract); + $$ = new quickstep::ParseString(@1.first_line, @1.first_column, std::string("-")); }; multiply_operation: '%' { - $$ = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kModulo); + $$ = new quickstep::ParseString(@1.first_line, @1.first_column, std::string("%")); } | '*' { - $$ = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kMultiply); + $$ = new quickstep::ParseString(@1.first_line, @1.first_column, std::string("*")); } | '/' { - $$ = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kDivide); + $$ = new quickstep::ParseString(@1.first_line, @1.first_column, std::string("/")); }; /* General Utility Stuff */ diff --git a/parser/preprocessed/SqlLexer_gen.cpp b/parser/preprocessed/SqlLexer_gen.cpp index 4800cde1..eef10d44 100644 --- a/parser/preprocessed/SqlLexer_gen.cpp +++ b/parser/preprocessed/SqlLexer_gen.cpp @@ -592,8 +592,8 @@ static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner ); yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 164 -#define YY_END_OF_BUFFER 165 +#define YY_NUM_RULES 151 +#define YY_END_OF_BUFFER 152 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -601,72 +601,67 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static const flex_int16_t yy_accept[589] = +static const flex_int16_t yy_accept[534] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 165, 2, 2, 163, 163, 162, 161, 163, - 140, 136, 139, 136, 136, 159, 132, 129, 133, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 137, 4, 5, 5, 3, 155, - 155, 152, 156, 156, 150, 157, 157, 154, 1, 162, - 130, 160, 159, 159, 159, 0, 134, 131, 135, 158, - 158, 158, 158, 10, 158, 158, 158, 22, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 138, - - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 58, 67, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 81, 82, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 113, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 4, 5, 3, 155, 151, 156, - 149, 149, 141, 143, 144, 145, 146, 147, 148, 149, - 157, 153, 160, 159, 0, 159, 6, 7, 158, 9, - 11, 158, 158, 15, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 33, 158, 158, 158, 158, - - 158, 158, 158, 158, 43, 158, 158, 158, 158, 158, - 158, 50, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 62, 158, 69, 158, 158, 158, 158, 158, 158, - 158, 77, 158, 80, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 98, 158, 158, - 103, 104, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 141, - 143, 142, 158, 158, 158, 158, 158, 158, 158, 20, - 23, 158, 158, 158, 28, 158, 158, 158, 31, 158, - 158, 158, 37, 158, 158, 41, 42, 158, 158, 158, - - 158, 158, 158, 158, 52, 53, 158, 55, 158, 57, - 158, 158, 158, 158, 66, 68, 70, 71, 72, 158, - 74, 158, 158, 78, 158, 158, 85, 158, 158, 158, - 158, 158, 92, 158, 94, 158, 158, 158, 100, 158, - 158, 158, 158, 158, 158, 158, 158, 110, 111, 114, - 158, 158, 158, 158, 158, 158, 158, 158, 123, 158, - 158, 126, 127, 141, 142, 8, 158, 158, 158, 158, - 158, 158, 158, 25, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 46, 47, - 48, 158, 158, 54, 158, 59, 60, 158, 158, 158, - - 73, 158, 76, 79, 83, 84, 158, 158, 158, 158, - 158, 93, 158, 158, 97, 158, 158, 158, 158, 158, - 158, 158, 109, 158, 158, 158, 117, 158, 158, 120, - 158, 158, 124, 158, 158, 158, 158, 14, 158, 158, - 158, 158, 158, 26, 158, 29, 158, 158, 158, 158, - 158, 36, 158, 158, 40, 44, 158, 158, 158, 56, - 61, 158, 158, 158, 75, 158, 158, 158, 158, 158, - 158, 96, 158, 101, 102, 158, 106, 107, 158, 158, - 158, 158, 118, 119, 121, 158, 125, 158, 158, 13, - 158, 158, 158, 158, 158, 158, 21, 30, 158, 34, - - 35, 158, 158, 45, 158, 51, 63, 158, 158, 158, - 88, 158, 90, 158, 158, 158, 158, 158, 158, 158, - 158, 122, 158, 158, 158, 158, 158, 158, 158, 158, - 32, 158, 39, 158, 158, 65, 158, 158, 91, 158, - 158, 105, 158, 158, 158, 158, 158, 12, 158, 158, - 158, 158, 24, 158, 158, 49, 64, 86, 89, 158, - 158, 108, 112, 158, 116, 128, 16, 158, 158, 158, - 27, 38, 87, 95, 158, 158, 158, 18, 19, 158, - 115, 158, 158, 158, 99, 158, 17, 0 + 0, 0, 152, 2, 2, 150, 150, 149, 148, 150, + 127, 123, 126, 123, 123, 146, 150, 116, 113, 117, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 124, 121, 122, 4, 5, + 5, 3, 142, 142, 139, 143, 143, 137, 144, 144, + 141, 1, 149, 114, 147, 146, 146, 146, 0, 120, + 118, 115, 119, 145, 145, 145, 145, 10, 145, 145, + 145, 21, 145, 145, 145, 145, 145, 145, 145, 145, + + 145, 145, 125, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 50, 57, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 70, 71, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 99, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 4, 5, 3, 142, 138, 143, + 136, 136, 128, 130, 131, 132, 133, 134, 135, 136, + 144, 140, 147, 146, 0, 146, 6, 7, 145, 9, + 11, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 28, 145, 145, 145, 145, 145, 145, 36, + + 145, 145, 145, 145, 145, 42, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 59, 145, 145, + 145, 145, 145, 145, 66, 145, 69, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 87, 145, 145, 92, 93, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 128, 130, 129, 145, 145, 145, 145, 145, 145, 18, + 19, 145, 145, 145, 25, 145, 145, 145, 145, 145, + 31, 145, 34, 35, 145, 145, 145, 145, 145, 145, + 44, 45, 145, 47, 145, 49, 145, 145, 145, 145, + + 56, 58, 60, 61, 62, 145, 145, 145, 67, 145, + 145, 74, 145, 145, 145, 145, 145, 81, 145, 83, + 145, 145, 145, 89, 145, 145, 145, 145, 145, 145, + 145, 98, 100, 145, 145, 145, 145, 145, 145, 145, + 108, 145, 145, 111, 112, 128, 129, 8, 145, 145, + 145, 145, 145, 22, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 39, 40, 145, 145, 46, + 145, 51, 52, 145, 145, 63, 145, 65, 68, 72, + 73, 145, 145, 145, 145, 145, 82, 145, 145, 86, + 145, 145, 145, 145, 145, 145, 97, 145, 145, 103, + + 145, 145, 106, 145, 109, 145, 145, 145, 145, 145, + 145, 145, 23, 145, 26, 145, 145, 145, 30, 145, + 145, 37, 145, 145, 145, 48, 53, 145, 145, 64, + 145, 145, 145, 145, 145, 145, 85, 145, 90, 91, + 94, 95, 145, 145, 145, 104, 105, 107, 110, 145, + 13, 145, 145, 145, 145, 145, 20, 27, 29, 145, + 145, 38, 145, 43, 145, 145, 145, 77, 145, 79, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 33, 145, 145, 55, 145, 145, 80, + 145, 145, 145, 145, 145, 12, 145, 145, 145, 145, + + 145, 145, 41, 54, 75, 78, 145, 145, 96, 145, + 102, 14, 145, 145, 145, 24, 32, 76, 84, 145, + 145, 145, 16, 17, 145, 101, 145, 145, 145, 88, + 145, 15, 0 } ; static const YY_CHAR yy_ec[256] = @@ -684,7 +679,7 @@ static const YY_CHAR yy_ec[256] = 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 43, 1, 1, 1, 1, 1, 1, 1, 1, + 71, 43, 72, 1, 73, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -701,7 +696,7 @@ static const YY_CHAR yy_ec[256] = 1, 1, 1, 1, 1 } ; -static const YY_CHAR yy_meta[72] = +static const YY_CHAR yy_meta[74] = { 0, 1, 1, 2, 1, 1, 3, 1, 4, 1, 5, 5, 6, 6, 5, 1, 1, 1, 7, 7, 7, @@ -710,314 +705,286 @@ static const YY_CHAR yy_meta[72] = 8, 8, 8, 1, 9, 10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8 + 8, 1, 1 } ; -static const flex_int16_t yy_base[604] = +static const flex_int16_t yy_base[549] = { 0, - 0, 1, 46, 0, 117, 162, 2, 3, 127, 128, - 6, 10, 147, 1316, 1316, 0, 1316, 13, 1316, 130, - 1316, 1316, 1316, 129, 6, 129, 4, 1316, 28, 124, - 159, 213, 165, 167, 263, 92, 158, 163, 96, 107, - 214, 160, 186, 219, 221, 155, 281, 274, 325, 257, - 186, 209, 0, 219, 1316, 27, 4, 19, 0, 0, - 0, 17, 0, 0, 389, 0, 0, 8, 0, 22, - 1316, 0, 293, 325, 343, 18, 1316, 1316, 1316, 0, - 223, 265, 234, 242, 260, 292, 288, 0, 299, 330, - 337, 324, 334, 324, 325, 380, 325, 331, 346, 1316, - - 348, 364, 378, 376, 371, 378, 382, 386, 390, 389, - 386, 385, 435, 0, 402, 389, 400, 435, 433, 431, - 433, 436, 431, 440, 447, 0, 452, 437, 453, 441, - 442, 456, 453, 449, 465, 457, 444, 494, 468, 495, - 500, 501, 499, 492, 0, 486, 492, 507, 506, 502, - 500, 508, 501, 516, 0, 29, 0, 0, 1316, 0, - 1316, 1316, 22, 24, 1316, 1316, 1316, 1316, 1316, 0, - 0, 1316, 0, 524, 26, 28, 0, 0, 517, 0, - 518, 501, 516, 504, 545, 525, 531, 552, 536, 542, - 537, 562, 544, 547, 561, 0, 558, 567, 564, 567, - - 551, 570, 557, 569, 0, 556, 558, 560, 561, 580, - 570, 578, 572, 575, 567, 598, 598, 595, 610, 613, - 614, 615, 607, 0, 602, 603, 619, 616, 619, 606, - 608, 0, 617, 0, 626, 627, 615, 614, 634, 635, - 626, 620, 636, 633, 641, 659, 657, 652, 658, 671, - 0, 665, 673, 660, 668, 668, 678, 679, 673, 671, - 672, 689, 677, 671, 692, 683, 692, 690, 681, 30, - 125, 0, 685, 690, 705, 708, 718, 718, 718, 0, - 733, 724, 723, 717, 0, 718, 722, 736, 722, 730, - 723, 725, 741, 738, 736, 0, 0, 729, 749, 748, - - 734, 735, 741, 748, 0, 0, 743, 0, 747, 0, - 738, 750, 762, 774, 0, 0, 0, 0, 0, 767, - 0, 769, 785, 775, 777, 778, 0, 789, 794, 795, - 800, 784, 0, 798, 0, 786, 781, 786, 0, 803, - 794, 808, 800, 795, 793, 795, 812, 0, 800, 0, - 815, 805, 824, 818, 825, 840, 845, 843, 0, 847, - 838, 0, 841, 131, 1316, 0, 852, 852, 838, 858, - 844, 855, 859, 0, 850, 847, 861, 864, 856, 862, - 871, 861, 870, 863, 864, 879, 877, 894, 0, 0, - 0, 880, 898, 0, 901, 0, 0, 889, 905, 892, - - 0, 907, 0, 0, 0, 0, 895, 902, 913, 900, - 910, 0, 915, 905, 0, 917, 919, 904, 918, 910, - 909, 912, 0, 911, 914, 921, 0, 931, 937, 0, - 935, 954, 0, 938, 948, 957, 953, 0, 946, 951, - 969, 963, 953, 0, 973, 0, 970, 956, 964, 966, - 959, 0, 976, 978, 0, 0, 962, 976, 972, 0, - 0, 969, 983, 988, 0, 982, 973, 985, 975, 992, - 999, 0, 1007, 0, 0, 1007, 0, 0, 1015, 1024, - 1025, 1023, 0, 0, 0, 1010, 0, 1016, 1017, 0, - 1023, 1018, 1021, 1023, 1031, 1028, 0, 0, 1033, 0, - - 0, 1030, 1020, 0, 1029, 0, 0, 1041, 1033, 1031, - 0, 1033, 0, 1024, 1048, 1043, 1038, 1056, 1058, 1064, - 1074, 0, 1062, 1076, 1070, 1069, 1070, 1068, 1071, 1076, - 0, 1077, 0, 1085, 1073, 0, 1080, 1088, 0, 1091, - 1084, 0, 1091, 1085, 1086, 1099, 1096, 0, 1098, 1102, - 1097, 1105, 0, 1096, 1121, 0, 0, 1110, 0, 1116, - 1128, 0, 0, 1128, 0, 0, 0, 1123, 1137, 1125, - 0, 0, 0, 0, 1124, 1141, 1127, 0, 0, 1143, - 0, 1140, 1132, 1146, 0, 1133, 0, 1316, 1198, 1208, - 1218, 1228, 1238, 1242, 1245, 1251, 1261, 1271, 1281, 1291, - - 1301, 1306, 1308 + 0, 1, 46, 0, 119, 192, 2, 3, 129, 130, + 6, 10, 231, 1182, 1182, 0, 1182, 13, 1182, 151, + 1182, 1182, 1182, 152, 6, 118, 132, 4, 1182, 28, + 118, 131, 248, 188, 197, 186, 106, 124, 112, 118, + 129, 193, 126, 123, 237, 195, 121, 256, 255, 298, + 189, 185, 236, 0, 194, 1182, 1182, 1182, 27, 4, + 19, 0, 0, 0, 17, 0, 0, 362, 0, 0, + 8, 0, 22, 1182, 0, 257, 306, 313, 18, 1182, + 1182, 1182, 1182, 0, 206, 302, 208, 214, 234, 244, + 266, 0, 284, 307, 309, 310, 315, 306, 301, 350, + + 311, 316, 1182, 315, 332, 352, 325, 320, 359, 355, + 361, 359, 356, 358, 406, 0, 374, 359, 368, 382, + 381, 375, 381, 394, 407, 416, 0, 423, 408, 424, + 412, 413, 427, 424, 420, 434, 430, 415, 465, 441, + 440, 443, 444, 442, 0, 429, 436, 478, 449, 463, + 466, 478, 470, 485, 0, 29, 0, 0, 1182, 0, + 1182, 1182, 22, 24, 1182, 1182, 1182, 1182, 1182, 0, + 0, 1182, 0, 493, 26, 28, 0, 0, 486, 0, + 487, 470, 471, 493, 490, 496, 479, 483, 478, 503, + 485, 493, 0, 516, 513, 523, 510, 519, 531, 0, + + 519, 523, 523, 524, 532, 540, 535, 537, 529, 543, + 543, 535, 549, 551, 552, 553, 546, 0, 541, 542, + 558, 557, 548, 555, 0, 564, 0, 579, 583, 575, + 574, 593, 596, 587, 581, 596, 594, 602, 603, 601, + 591, 596, 607, 0, 0, 609, 596, 604, 604, 614, + 609, 611, 634, 626, 619, 613, 628, 648, 646, 639, + 30, 132, 0, 640, 645, 655, 656, 653, 652, 0, + 0, 655, 654, 648, 0, 649, 652, 667, 652, 654, + 671, 668, 0, 0, 659, 681, 679, 665, 676, 683, + 0, 0, 684, 0, 690, 0, 683, 691, 692, 694, + + 0, 0, 0, 0, 0, 695, 696, 709, 699, 701, + 704, 0, 714, 719, 720, 725, 709, 0, 723, 0, + 712, 707, 712, 0, 730, 721, 734, 722, 721, 723, + 744, 0, 0, 745, 737, 748, 744, 747, 761, 765, + 0, 768, 759, 0, 0, 153, 1182, 0, 771, 771, + 776, 764, 775, 0, 768, 766, 780, 781, 774, 777, + 785, 778, 779, 776, 795, 0, 0, 777, 794, 0, + 800, 0, 0, 788, 801, 0, 811, 0, 0, 0, + 0, 805, 812, 824, 813, 823, 0, 828, 818, 0, + 830, 834, 819, 822, 821, 824, 0, 824, 830, 0, + + 841, 842, 0, 829, 0, 827, 842, 839, 834, 840, + 858, 856, 0, 865, 0, 869, 858, 861, 0, 879, + 881, 0, 866, 880, 876, 0, 0, 886, 891, 0, + 884, 876, 888, 873, 879, 886, 0, 889, 0, 0, + 0, 0, 893, 903, 901, 0, 0, 0, 0, 892, + 0, 899, 894, 898, 902, 907, 0, 0, 0, 908, + 903, 0, 910, 0, 929, 924, 924, 0, 927, 0, + 917, 941, 938, 934, 936, 945, 944, 940, 939, 940, + 937, 944, 945, 0, 953, 942, 0, 949, 957, 0, + 961, 954, 962, 956, 970, 0, 968, 976, 970, 985, + + 974, 990, 0, 0, 980, 0, 981, 993, 0, 993, + 0, 0, 988, 1002, 990, 0, 0, 0, 0, 989, + 1007, 993, 0, 0, 1009, 0, 1006, 998, 1012, 0, + 999, 0, 1182, 1064, 1074, 1084, 1094, 1104, 1108, 1111, + 1117, 1127, 1137, 1147, 1157, 1167, 1172, 1174 } ; -static const flex_int16_t yy_def[604] = +static const flex_int16_t yy_def[549] = { 0, - 589, 589, 588, 3, 590, 590, 591, 591, 592, 592, - 593, 593, 588, 588, 588, 594, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 588, 588, 588, 588, 596, 597, - 597, 588, 598, 598, 599, 600, 600, 588, 594, 588, - 588, 601, 588, 588, 588, 588, 588, 588, 588, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 588, - - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 588, 588, 596, 597, 588, 598, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 602, - 600, 588, 601, 588, 588, 588, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 588, - 588, 603, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 588, 588, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, - 595, 595, 595, 595, 595, 595, 595, 0, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - - 588, 588, 588 + 534, 534, 533, 3, 535, 535, 536, 536, 537, 537, + 538, 538, 533, 533, 533, 539, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 533, 533, 533, 533, 533, + 533, 541, 542, 542, 533, 543, 543, 544, 545, 545, + 533, 539, 533, 533, 546, 533, 533, 533, 533, 533, + 533, 533, 533, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + + 540, 540, 533, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 533, 533, 541, 542, 533, 543, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 547, + 545, 533, 546, 533, 533, 533, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 533, 533, 548, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 533, 533, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, + 540, 540, 0, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533 } ; -static const flex_int16_t yy_nxt[1388] = +static const flex_int16_t yy_nxt[1256] = { 0, - 588, 155, 15, 15, 61, 61, 156, 156, 67, 62, - 62, 68, 67, 172, 70, 68, 70, 73, 73, 77, - 78, 156, 156, 70, 159, 70, 175, 175, 155, 176, - 176, 156, 156, 270, 271, 271, 271, 176, 176, 176, - 176, 364, 271, 79, 16, 16, 17, 18, 19, 18, - 20, 21, 22, 23, 22, 24, 25, 26, 26, 17, - 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 53, 55, - 17, 17, 30, 31, 32, 33, 34, 35, 36, 37, - + 533, 155, 15, 15, 64, 64, 156, 156, 70, 65, + 65, 71, 70, 172, 73, 71, 73, 76, 76, 81, + 82, 156, 156, 73, 159, 73, 175, 175, 155, 176, + 176, 156, 156, 261, 262, 262, 262, 176, 176, 176, + 176, 346, 262, 83, 16, 16, 17, 18, 19, 18, + 20, 21, 22, 23, 22, 24, 25, 26, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 17, 56, 57, - 58, 17, 17, 17, 17, 17, 110, 115, 116, 64, - 64, 17, 17, 17, 62, 62, 271, 271, 72, 74, - 75, 75, 271, 271, 81, 71, 588, 588, 588, 588, - 76, 588, 82, 588, 83, 110, 115, 116, 588, 84, - 17, 17, 17, 56, 57, 58, 17, 17, 17, 17, - 17, 65, 65, 81, 100, 111, 17, 17, 17, 76, - 85, 82, 95, 83, 86, 121, 96, 87, 84, 112, - 97, 122, 133, 113, 588, 101, 98, 102, 114, 99, - - 88, 588, 588, 151, 111, 17, 17, 103, 588, 85, - 588, 95, 588, 86, 121, 96, 87, 123, 112, 97, - 122, 133, 113, 124, 101, 98, 102, 114, 99, 88, - 89, 117, 151, 152, 153, 118, 103, 90, 130, 119, - 154, 125, 131, 177, 91, 120, 123, 92, 93, 126, - 94, 588, 124, 127, 180, 132, 128, 129, 588, 89, - 117, 181, 152, 153, 118, 588, 90, 130, 119, 154, - 125, 131, 177, 91, 120, 588, 92, 93, 126, 94, - 104, 588, 127, 180, 132, 128, 129, 148, 105, 149, - 181, 106, 150, 178, 107, 138, 182, 108, 134, 588, - - 109, 179, 135, 139, 73, 73, 136, 588, 588, 104, - 140, 141, 137, 588, 76, 183, 148, 105, 149, 185, - 106, 150, 178, 107, 138, 182, 108, 134, 184, 109, - 179, 135, 139, 588, 186, 136, 174, 174, 588, 140, - 141, 137, 142, 76, 183, 192, 76, 187, 185, 143, - 144, 188, 193, 74, 75, 75, 145, 184, 194, 146, - 201, 195, 147, 186, 76, 189, 196, 190, 202, 191, - 588, 142, 588, 588, 192, 76, 187, 203, 143, 144, - 188, 193, 588, 204, 205, 145, 588, 194, 146, 201, - 195, 147, 162, 76, 189, 196, 190, 202, 191, 197, - - 163, 164, 198, 206, 208, 209, 203, 165, 199, 210, - 211, 166, 204, 205, 207, 200, 212, 213, 214, 167, - 215, 216, 218, 168, 217, 169, 588, 223, 197, 170, - 224, 198, 206, 208, 209, 225, 165, 199, 210, 211, - 166, 588, 588, 207, 200, 212, 213, 214, 167, 215, - 216, 218, 168, 217, 169, 219, 223, 226, 170, 224, - 227, 229, 228, 230, 225, 220, 231, 232, 233, 234, - 221, 222, 235, 236, 237, 238, 239, 240, 242, 243, - 247, 241, 244, 248, 219, 252, 226, 245, 246, 227, - 229, 228, 230, 588, 220, 231, 232, 233, 234, 221, - - 222, 235, 236, 237, 238, 239, 240, 242, 243, 247, - 241, 244, 248, 249, 252, 253, 245, 246, 254, 255, - 256, 257, 250, 258, 259, 260, 262, 263, 264, 266, - 251, 267, 261, 269, 265, 174, 174, 268, 273, 274, - 275, 276, 249, 277, 253, 76, 280, 254, 255, 256, - 257, 250, 258, 259, 260, 262, 263, 264, 266, 251, - 267, 261, 269, 265, 278, 281, 268, 273, 274, 275, - 276, 282, 277, 283, 76, 280, 279, 284, 285, 286, - 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, - 297, 298, 299, 278, 281, 300, 301, 302, 303, 304, - - 282, 305, 283, 306, 307, 279, 284, 285, 286, 287, - 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, - 298, 299, 308, 309, 300, 301, 302, 303, 304, 310, - 305, 311, 306, 307, 312, 313, 314, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 315, 325, 326, 327, - 328, 308, 309, 329, 330, 331, 333, 332, 310, 334, - 311, 335, 336, 312, 313, 314, 316, 317, 318, 319, - 320, 321, 322, 323, 324, 315, 325, 326, 327, 328, - 337, 338, 329, 330, 331, 333, 332, 339, 334, 341, - 335, 336, 342, 343, 344, 346, 347, 340, 348, 349, - - 350, 351, 352, 353, 345, 354, 355, 356, 357, 337, - 338, 358, 361, 359, 362, 363, 339, 360, 341, 366, - 367, 342, 343, 344, 346, 347, 368, 348, 349, 350, - 351, 352, 353, 345, 354, 355, 356, 357, 369, 370, - 358, 361, 359, 362, 363, 371, 360, 372, 366, 367, - 373, 374, 375, 376, 377, 368, 378, 379, 380, 381, - 382, 383, 384, 385, 386, 387, 388, 369, 370, 389, - 390, 391, 392, 393, 371, 394, 372, 395, 396, 373, - 374, 375, 376, 377, 397, 378, 379, 380, 381, 382, - 383, 384, 385, 386, 387, 388, 398, 399, 389, 390, - - 391, 392, 393, 401, 394, 402, 395, 396, 400, 403, - 404, 405, 406, 397, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, 417, 398, 399, 418, 419, 420, - 421, 422, 401, 423, 402, 424, 425, 400, 403, 404, - 405, 406, 426, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 427, 428, 418, 419, 420, 421, - 422, 429, 423, 430, 424, 425, 431, 432, 433, 434, - 435, 426, 436, 437, 438, 439, 440, 442, 443, 441, - 444, 445, 446, 427, 428, 447, 448, 449, 450, 451, - 429, 452, 430, 453, 454, 431, 432, 433, 434, 435, - - 455, 436, 437, 438, 439, 440, 442, 443, 441, 444, - 445, 446, 456, 457, 447, 448, 449, 450, 451, 458, - 452, 459, 453, 454, 460, 461, 462, 463, 465, 455, - 464, 466, 467, 468, 469, 470, 471, 472, 473, 474, - 475, 456, 457, 476, 477, 478, 479, 480, 458, 481, - 459, 482, 483, 460, 461, 462, 463, 465, 484, 464, - 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, - 485, 486, 476, 477, 478, 479, 480, 487, 481, 488, - 482, 483, 489, 490, 491, 492, 493, 484, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 503, 504, 485, - - 486, 505, 506, 507, 508, 509, 487, 510, 488, 511, - 512, 489, 490, 491, 492, 493, 513, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 514, 515, - 505, 506, 507, 508, 509, 516, 510, 517, 511, 512, - 518, 519, 520, 521, 522, 513, 523, 524, 525, 526, - 527, 528, 529, 530, 531, 532, 533, 514, 515, 534, - 535, 536, 537, 538, 516, 539, 517, 540, 541, 518, - 519, 520, 521, 522, 542, 523, 524, 525, 526, 527, - 528, 529, 530, 531, 532, 533, 543, 544, 534, 535, - 536, 537, 538, 545, 539, 546, 540, 541, 547, 548, - - 549, 550, 551, 542, 552, 553, 554, 555, 556, 557, - 558, 559, 560, 561, 562, 543, 544, 563, 564, 565, - 566, 567, 545, 568, 546, 569, 570, 547, 548, 549, - 550, 551, 571, 552, 553, 554, 555, 556, 557, 558, - 559, 560, 561, 562, 572, 573, 563, 564, 565, 566, - 567, 574, 568, 575, 569, 570, 576, 577, 578, 579, - 580, 571, 581, 582, 583, 584, 585, 586, 587, 588, - 588, 588, 588, 572, 573, 588, 588, 588, 588, 588, - 574, 588, 575, 588, 588, 576, 577, 578, 579, 580, - 588, 581, 582, 583, 584, 585, 586, 587, 14, 14, - - 14, 14, 14, 14, 14, 14, 14, 14, 59, 59, - 59, 59, 59, 59, 59, 59, 59, 59, 60, 60, - 60, 60, 60, 60, 60, 60, 60, 60, 63, 63, - 63, 63, 63, 63, 63, 63, 63, 63, 66, 66, - 66, 66, 66, 66, 66, 66, 66, 66, 69, 69, - 80, 80, 80, 588, 80, 157, 157, 157, 157, 588, - 157, 158, 158, 158, 588, 158, 158, 158, 158, 158, - 158, 160, 160, 160, 588, 160, 160, 160, 160, 588, - 160, 161, 161, 161, 161, 161, 161, 161, 161, 161, - 161, 171, 171, 588, 171, 171, 171, 171, 171, 171, - - 171, 173, 588, 173, 173, 173, 173, 173, 173, 173, - 173, 272, 272, 365, 365, 13, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588 + 48, 49, 50, 51, 52, 53, 54, 55, 54, 56, + 17, 17, 31, 32, 33, 34, 35, 36, 37, 38, + + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 57, 58, 17, + 59, 60, 61, 17, 17, 17, 17, 17, 77, 78, + 78, 67, 67, 17, 17, 17, 65, 65, 85, 79, + 112, 113, 115, 262, 262, 80, 86, 116, 87, 117, + 118, 122, 89, 88, 124, 114, 90, 123, 134, 91, + 125, 75, 17, 17, 262, 262, 74, 85, 79, 112, + 113, 115, 92, 68, 68, 86, 116, 87, 117, 118, + 122, 89, 88, 124, 114, 90, 123, 134, 91, 125, + 17, 17, 17, 59, 60, 61, 17, 17, 17, 17, + + 17, 92, 151, 107, 103, 99, 17, 17, 17, 100, + 119, 108, 131, 101, 120, 154, 132, 109, 121, 148, + 110, 149, 102, 111, 150, 104, 177, 105, 180, 133, + 533, 151, 107, 181, 99, 17, 17, 106, 100, 119, + 108, 131, 101, 120, 154, 132, 109, 121, 148, 110, + 149, 102, 111, 150, 104, 177, 105, 180, 133, 126, + 152, 153, 181, 17, 17, 93, 106, 127, 76, 76, + 182, 128, 94, 135, 129, 130, 139, 136, 79, 95, + 183, 137, 96, 97, 140, 98, 533, 138, 126, 152, + 153, 141, 142, 533, 93, 533, 127, 184, 533, 182, + + 128, 94, 135, 129, 130, 139, 136, 79, 95, 183, + 137, 96, 97, 140, 98, 143, 138, 174, 174, 185, + 141, 142, 144, 77, 78, 78, 184, 79, 186, 145, + 178, 190, 146, 191, 79, 147, 533, 187, 179, 188, + 192, 189, 193, 533, 143, 533, 197, 198, 185, 533, + 199, 144, 200, 203, 204, 533, 79, 186, 145, 178, + 190, 146, 191, 79, 147, 162, 187, 179, 188, 192, + 189, 193, 194, 163, 164, 197, 198, 201, 195, 199, + 165, 200, 203, 204, 166, 196, 207, 205, 202, 208, + 209, 210, 167, 206, 211, 212, 168, 533, 169, 217, + + 218, 194, 170, 219, 220, 223, 201, 195, 221, 165, + 222, 224, 533, 166, 196, 207, 205, 202, 208, 209, + 210, 167, 206, 211, 212, 168, 213, 169, 217, 218, + 225, 170, 219, 220, 223, 226, 214, 221, 227, 222, + 224, 215, 216, 228, 229, 230, 231, 232, 233, 235, + 236, 237, 234, 240, 241, 213, 238, 239, 245, 225, + 246, 247, 248, 249, 226, 214, 250, 227, 251, 254, + 215, 216, 228, 229, 230, 231, 232, 233, 235, 236, + 237, 234, 240, 241, 242, 238, 239, 245, 255, 246, + 247, 248, 249, 243, 256, 250, 252, 251, 254, 257, + + 258, 244, 260, 253, 174, 174, 259, 264, 265, 266, + 267, 270, 268, 242, 79, 272, 273, 255, 274, 275, + 276, 277, 243, 256, 269, 252, 271, 278, 257, 258, + 244, 260, 253, 279, 280, 259, 264, 265, 266, 267, + 270, 268, 281, 79, 272, 273, 282, 274, 275, 276, + 277, 283, 284, 269, 285, 271, 278, 286, 287, 288, + 289, 290, 279, 280, 291, 292, 293, 294, 295, 296, + 297, 281, 298, 299, 300, 282, 302, 303, 304, 305, + 283, 284, 306, 285, 301, 307, 286, 287, 288, 289, + 290, 308, 309, 291, 292, 293, 294, 295, 296, 297, + + 310, 298, 299, 300, 311, 302, 303, 304, 305, 312, + 313, 306, 314, 301, 307, 315, 316, 318, 317, 319, + 308, 309, 320, 321, 322, 323, 324, 326, 327, 310, + 328, 330, 331, 311, 332, 333, 325, 334, 312, 313, + 329, 314, 335, 338, 315, 316, 318, 317, 319, 339, + 340, 320, 321, 322, 323, 324, 326, 327, 341, 328, + 330, 331, 342, 332, 333, 336, 334, 337, 343, 329, + 344, 335, 338, 345, 348, 349, 350, 351, 339, 340, + 352, 353, 354, 355, 356, 357, 358, 341, 359, 360, + 361, 342, 362, 363, 336, 364, 337, 343, 365, 344, + + 366, 367, 345, 348, 349, 350, 351, 368, 369, 352, + 353, 354, 355, 356, 357, 358, 370, 359, 360, 361, + 371, 362, 363, 372, 364, 373, 374, 365, 375, 366, + 367, 376, 377, 378, 379, 380, 368, 369, 381, 382, + 383, 384, 385, 386, 387, 370, 388, 389, 390, 371, + 391, 392, 372, 393, 373, 374, 394, 375, 395, 396, + 376, 377, 378, 379, 380, 397, 398, 381, 382, 383, + 384, 385, 386, 387, 399, 388, 389, 390, 400, 391, + 392, 401, 393, 402, 403, 394, 404, 395, 396, 405, + 406, 407, 408, 409, 397, 398, 410, 412, 413, 411, + + 414, 415, 416, 399, 417, 418, 419, 400, 420, 421, + 401, 422, 402, 403, 423, 404, 424, 425, 405, 406, + 407, 408, 409, 426, 427, 410, 412, 413, 411, 414, + 415, 416, 430, 417, 418, 419, 428, 420, 421, 429, + 422, 431, 432, 423, 433, 424, 425, 434, 435, 436, + 437, 438, 426, 427, 439, 440, 441, 442, 443, 444, + 445, 430, 446, 447, 448, 428, 449, 450, 429, 451, + 431, 432, 452, 433, 453, 454, 434, 435, 436, 437, + 438, 455, 456, 439, 440, 441, 442, 443, 444, 445, + 457, 446, 447, 448, 458, 449, 450, 459, 451, 460, + + 461, 452, 462, 453, 454, 463, 464, 465, 466, 467, + 455, 456, 468, 469, 470, 471, 472, 473, 474, 457, + 475, 476, 477, 458, 478, 479, 459, 480, 460, 461, + 481, 462, 482, 483, 463, 464, 465, 466, 467, 484, + 485, 468, 469, 470, 471, 472, 473, 474, 486, 475, + 476, 477, 487, 478, 479, 488, 480, 489, 490, 481, + 491, 482, 483, 492, 493, 494, 495, 496, 484, 485, + 497, 498, 499, 500, 501, 502, 503, 486, 504, 505, + 506, 487, 507, 508, 488, 509, 489, 490, 510, 491, + 511, 512, 492, 493, 494, 495, 496, 513, 514, 497, + + 498, 499, 500, 501, 502, 503, 515, 504, 505, 506, + 516, 507, 508, 517, 509, 518, 519, 510, 520, 511, + 512, 521, 522, 523, 524, 525, 513, 514, 526, 527, + 528, 529, 530, 531, 532, 515, 533, 533, 533, 516, + 533, 533, 517, 533, 518, 519, 533, 520, 533, 533, + 521, 522, 523, 524, 525, 533, 533, 526, 527, 528, + 529, 530, 531, 532, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 62, 62, 62, 62, 62, 62, + 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 66, 66, 66, 66, 66, 66, + + 66, 66, 66, 66, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 72, 72, 84, 84, 84, 533, + 84, 157, 157, 157, 157, 533, 157, 158, 158, 158, + 533, 158, 158, 158, 158, 158, 158, 160, 160, 160, + 533, 160, 160, 160, 160, 533, 160, 161, 161, 161, + 161, 161, 161, 161, 161, 161, 161, 171, 171, 533, + 171, 171, 171, 171, 171, 171, 171, 173, 533, 173, + 173, 173, 173, 173, 173, 173, 173, 263, 263, 347, + 347, 13, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533 } ; -static const flex_int16_t yy_chk[1388] = +static const flex_int16_t yy_chk[1256] = { 0, - 0, 155, 1, 2, 7, 8, 57, 57, 11, 7, - 8, 11, 12, 68, 18, 12, 18, 25, 25, 27, - 27, 58, 58, 70, 62, 70, 76, 76, 56, 76, - 76, 156, 156, 163, 163, 164, 164, 175, 175, 176, - 176, 270, 270, 29, 1, 2, 3, 3, 3, 3, + 0, 155, 1, 2, 7, 8, 60, 60, 11, 7, + 8, 11, 12, 71, 18, 12, 18, 25, 25, 28, + 28, 61, 61, 73, 65, 73, 79, 79, 59, 79, + 79, 156, 156, 163, 163, 164, 164, 175, 175, 176, + 176, 261, 261, 30, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, @@ -1025,150 +992,136 @@ static const flex_int16_t yy_chk[1388] = 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 36, 39, 40, 9, - 10, 5, 5, 5, 9, 10, 271, 271, 24, 26, - 26, 26, 364, 364, 30, 20, 13, 0, 0, 0, - 26, 0, 30, 0, 30, 36, 39, 40, 0, 30, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 26, 26, + 26, 9, 10, 5, 5, 5, 9, 10, 31, 26, + 37, 38, 39, 262, 262, 27, 31, 39, 31, 40, + 41, 43, 32, 31, 44, 38, 32, 43, 47, 32, + 44, 24, 5, 5, 346, 346, 20, 31, 26, 37, + 38, 39, 32, 9, 10, 31, 39, 31, 40, 41, + 43, 32, 31, 44, 38, 32, 43, 47, 32, 44, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 9, 10, 30, 34, 37, 6, 6, 6, 26, - 31, 30, 33, 30, 31, 42, 33, 31, 30, 37, - 33, 42, 46, 38, 0, 34, 33, 34, 38, 33, - - 31, 0, 0, 51, 37, 6, 6, 34, 0, 31, - 0, 33, 0, 31, 42, 33, 31, 43, 37, 33, - 42, 46, 38, 43, 34, 33, 34, 38, 33, 31, - 32, 41, 51, 52, 52, 41, 34, 32, 45, 41, - 54, 44, 45, 81, 32, 41, 43, 32, 32, 44, - 32, 0, 43, 44, 83, 45, 44, 44, 0, 32, - 41, 84, 52, 52, 41, 0, 32, 45, 41, 54, - 44, 45, 81, 32, 41, 0, 32, 32, 44, 32, - 35, 0, 44, 83, 45, 44, 44, 50, 35, 50, - 84, 35, 50, 82, 35, 48, 85, 35, 47, 0, - - 35, 82, 47, 48, 73, 73, 47, 0, 0, 35, - 48, 48, 47, 0, 73, 86, 50, 35, 50, 87, - 35, 50, 82, 35, 48, 85, 35, 47, 86, 35, - 82, 47, 48, 0, 89, 47, 74, 74, 0, 48, - 48, 47, 49, 73, 86, 92, 74, 90, 87, 49, - 49, 90, 93, 75, 75, 75, 49, 86, 94, 49, - 97, 95, 49, 89, 75, 91, 95, 91, 98, 91, - 0, 49, 0, 0, 92, 74, 90, 99, 49, 49, - 90, 93, 0, 101, 102, 49, 0, 94, 49, 97, - 95, 49, 65, 75, 91, 95, 91, 98, 91, 96, - - 65, 65, 96, 103, 104, 105, 99, 65, 96, 106, - 107, 65, 101, 102, 103, 96, 107, 108, 109, 65, - 110, 111, 112, 65, 111, 65, 0, 115, 96, 65, - 116, 96, 103, 104, 105, 117, 65, 96, 106, 107, - 65, 0, 0, 103, 96, 107, 108, 109, 65, 110, - 111, 112, 65, 111, 65, 113, 115, 118, 65, 116, - 119, 120, 119, 121, 117, 113, 122, 123, 124, 125, - 113, 113, 127, 128, 129, 130, 131, 132, 133, 134, - 136, 132, 135, 137, 113, 139, 118, 135, 135, 119, - 120, 119, 121, 0, 113, 122, 123, 124, 125, 113, - - 113, 127, 128, 129, 130, 131, 132, 133, 134, 136, - 132, 135, 137, 138, 139, 140, 135, 135, 141, 142, - 143, 144, 138, 146, 147, 148, 149, 150, 151, 152, - 138, 153, 148, 154, 151, 174, 174, 153, 179, 181, - 182, 183, 138, 184, 140, 174, 186, 141, 142, 143, - 144, 138, 146, 147, 148, 149, 150, 151, 152, 138, - 153, 148, 154, 151, 185, 187, 153, 179, 181, 182, - 183, 188, 184, 189, 174, 186, 185, 190, 191, 192, - 193, 194, 195, 197, 198, 199, 200, 201, 202, 203, - 204, 206, 207, 185, 187, 208, 209, 210, 211, 212, - - 188, 213, 189, 214, 215, 185, 190, 191, 192, 193, - 194, 195, 197, 198, 199, 200, 201, 202, 203, 204, - 206, 207, 216, 217, 208, 209, 210, 211, 212, 218, - 213, 219, 214, 215, 220, 221, 222, 223, 225, 226, - 227, 228, 229, 230, 231, 233, 222, 235, 236, 237, - 238, 216, 217, 239, 240, 241, 242, 241, 218, 243, - 219, 244, 245, 220, 221, 222, 223, 225, 226, 227, - 228, 229, 230, 231, 233, 222, 235, 236, 237, 238, - 246, 247, 239, 240, 241, 242, 241, 248, 243, 249, - 244, 245, 250, 252, 253, 254, 255, 248, 256, 257, - - 258, 259, 260, 261, 253, 261, 262, 263, 264, 246, - 247, 265, 267, 266, 268, 269, 248, 266, 249, 273, - 274, 250, 252, 253, 254, 255, 275, 256, 257, 258, - 259, 260, 261, 253, 261, 262, 263, 264, 276, 277, - 265, 267, 266, 268, 269, 278, 266, 279, 273, 274, - 281, 282, 283, 284, 286, 275, 287, 288, 289, 290, - 291, 292, 293, 294, 295, 298, 299, 276, 277, 300, - 301, 302, 303, 304, 278, 307, 279, 309, 311, 281, - 282, 283, 284, 286, 312, 287, 288, 289, 290, 291, - 292, 293, 294, 295, 298, 299, 313, 314, 300, 301, - - 302, 303, 304, 320, 307, 322, 309, 311, 314, 323, - 324, 325, 326, 312, 328, 329, 330, 331, 332, 334, - 336, 337, 338, 340, 341, 313, 314, 342, 343, 344, - 345, 346, 320, 347, 322, 349, 351, 314, 323, 324, - 325, 326, 352, 328, 329, 330, 331, 332, 334, 336, - 337, 338, 340, 341, 353, 354, 342, 343, 344, 345, - 346, 355, 347, 356, 349, 351, 357, 358, 360, 361, - 363, 352, 367, 368, 369, 370, 371, 372, 373, 371, - 375, 376, 377, 353, 354, 378, 379, 380, 381, 382, - 355, 383, 356, 384, 385, 357, 358, 360, 361, 363, - - 386, 367, 368, 369, 370, 371, 372, 373, 371, 375, - 376, 377, 387, 388, 378, 379, 380, 381, 382, 392, - 383, 393, 384, 385, 395, 398, 399, 400, 402, 386, - 400, 407, 408, 409, 410, 411, 413, 414, 416, 417, - 418, 387, 388, 419, 420, 421, 422, 424, 392, 425, - 393, 426, 428, 395, 398, 399, 400, 402, 429, 400, - 407, 408, 409, 410, 411, 413, 414, 416, 417, 418, - 431, 432, 419, 420, 421, 422, 424, 434, 425, 435, - 426, 428, 436, 437, 439, 440, 441, 429, 442, 443, - 445, 447, 448, 449, 450, 451, 453, 454, 457, 431, - - 432, 458, 459, 462, 463, 464, 434, 466, 435, 467, - 468, 436, 437, 439, 440, 441, 469, 442, 443, 445, - 447, 448, 449, 450, 451, 453, 454, 457, 470, 471, - 458, 459, 462, 463, 464, 473, 466, 476, 467, 468, - 479, 480, 481, 482, 486, 469, 488, 489, 491, 492, - 493, 494, 495, 496, 499, 502, 503, 470, 471, 505, - 508, 509, 510, 512, 473, 514, 476, 515, 516, 479, - 480, 481, 482, 486, 517, 488, 489, 491, 492, 493, - 494, 495, 496, 499, 502, 503, 518, 519, 505, 508, - 509, 510, 512, 520, 514, 521, 515, 516, 523, 524, - - 525, 526, 527, 517, 528, 529, 530, 532, 534, 535, - 537, 538, 540, 541, 543, 518, 519, 544, 545, 546, - 547, 549, 520, 550, 521, 551, 552, 523, 524, 525, - 526, 527, 554, 528, 529, 530, 532, 534, 535, 537, - 538, 540, 541, 543, 555, 558, 544, 545, 546, 547, - 549, 560, 550, 561, 551, 552, 564, 568, 569, 570, - 575, 554, 576, 577, 580, 582, 583, 584, 586, 0, - 0, 0, 0, 555, 558, 0, 0, 0, 0, 0, - 560, 0, 561, 0, 0, 564, 568, 569, 570, 575, - 0, 576, 577, 580, 582, 583, 584, 586, 589, 589, - - 589, 589, 589, 589, 589, 589, 589, 589, 590, 590, - 590, 590, 590, 590, 590, 590, 590, 590, 591, 591, - 591, 591, 591, 591, 591, 591, 591, 591, 592, 592, - 592, 592, 592, 592, 592, 592, 592, 592, 593, 593, - 593, 593, 593, 593, 593, 593, 593, 593, 594, 594, - 595, 595, 595, 0, 595, 596, 596, 596, 596, 0, - 596, 597, 597, 597, 0, 597, 597, 597, 597, 597, - 597, 598, 598, 598, 0, 598, 598, 598, 598, 0, - 598, 599, 599, 599, 599, 599, 599, 599, 599, 599, - 599, 600, 600, 0, 600, 600, 600, 600, 600, 600, - - 600, 601, 0, 601, 601, 601, 601, 601, 601, 601, - 601, 602, 602, 603, 603, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, - 588, 588, 588, 588, 588, 588, 588 + + 6, 32, 52, 36, 35, 34, 6, 6, 6, 34, + 42, 36, 46, 34, 42, 55, 46, 36, 42, 51, + 36, 51, 34, 36, 51, 35, 85, 35, 87, 46, + 13, 52, 36, 88, 34, 6, 6, 35, 34, 42, + 36, 46, 34, 42, 55, 46, 36, 42, 51, 36, + 51, 34, 36, 51, 35, 85, 35, 87, 46, 45, + 53, 53, 88, 6, 6, 33, 35, 45, 76, 76, + 89, 45, 33, 48, 45, 45, 49, 48, 76, 33, + 90, 48, 33, 33, 49, 33, 0, 48, 45, 53, + 53, 49, 49, 0, 33, 0, 45, 91, 0, 89, + + 45, 33, 48, 45, 45, 49, 48, 76, 33, 90, + 48, 33, 33, 49, 33, 50, 48, 77, 77, 93, + 49, 49, 50, 78, 78, 78, 91, 77, 94, 50, + 86, 96, 50, 97, 78, 50, 0, 95, 86, 95, + 98, 95, 99, 0, 50, 0, 101, 102, 93, 0, + 104, 50, 105, 107, 108, 0, 77, 94, 50, 86, + 96, 50, 97, 78, 50, 68, 95, 86, 95, 98, + 95, 99, 100, 68, 68, 101, 102, 106, 100, 104, + 68, 105, 107, 108, 68, 100, 110, 109, 106, 111, + 112, 113, 68, 109, 113, 114, 68, 0, 68, 117, + + 118, 100, 68, 119, 120, 122, 106, 100, 121, 68, + 121, 123, 0, 68, 100, 110, 109, 106, 111, 112, + 113, 68, 109, 113, 114, 68, 115, 68, 117, 118, + 124, 68, 119, 120, 122, 125, 115, 121, 126, 121, + 123, 115, 115, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 133, 137, 138, 115, 136, 136, 140, 124, + 141, 142, 143, 144, 125, 115, 146, 126, 147, 149, + 115, 115, 128, 129, 130, 131, 132, 133, 134, 135, + 136, 133, 137, 138, 139, 136, 136, 140, 150, 141, + 142, 143, 144, 139, 151, 146, 148, 147, 149, 152, + + 153, 139, 154, 148, 174, 174, 153, 179, 181, 182, + 183, 185, 184, 139, 174, 186, 187, 150, 188, 189, + 190, 191, 139, 151, 184, 148, 185, 192, 152, 153, + 139, 154, 148, 194, 195, 153, 179, 181, 182, 183, + 185, 184, 196, 174, 186, 187, 197, 188, 189, 190, + 191, 198, 199, 184, 201, 185, 192, 202, 203, 204, + 205, 206, 194, 195, 207, 208, 209, 210, 211, 212, + 213, 196, 214, 215, 216, 197, 217, 219, 220, 221, + 198, 199, 222, 201, 216, 223, 202, 203, 204, 205, + 206, 224, 226, 207, 208, 209, 210, 211, 212, 213, + + 228, 214, 215, 216, 229, 217, 219, 220, 221, 230, + 231, 222, 232, 216, 223, 233, 234, 235, 234, 236, + 224, 226, 237, 238, 239, 240, 241, 242, 243, 228, + 246, 247, 248, 229, 249, 250, 241, 251, 230, 231, + 246, 232, 252, 254, 233, 234, 235, 234, 236, 255, + 256, 237, 238, 239, 240, 241, 242, 243, 257, 246, + 247, 248, 257, 249, 250, 253, 251, 253, 258, 246, + 259, 252, 254, 260, 264, 265, 266, 267, 255, 256, + 268, 269, 272, 273, 274, 276, 277, 257, 278, 279, + 280, 257, 281, 282, 253, 285, 253, 258, 286, 259, + + 287, 288, 260, 264, 265, 266, 267, 289, 290, 268, + 269, 272, 273, 274, 276, 277, 293, 278, 279, 280, + 295, 281, 282, 297, 285, 298, 299, 286, 300, 287, + 288, 306, 307, 308, 309, 310, 289, 290, 311, 313, + 314, 315, 316, 317, 319, 293, 321, 322, 323, 295, + 325, 326, 297, 327, 298, 299, 328, 300, 329, 330, + 306, 307, 308, 309, 310, 331, 334, 311, 313, 314, + 315, 316, 317, 319, 335, 321, 322, 323, 336, 325, + 326, 337, 327, 338, 339, 328, 340, 329, 330, 342, + 343, 349, 350, 351, 331, 334, 352, 353, 355, 352, + + 356, 357, 358, 335, 359, 360, 361, 336, 362, 363, + 337, 364, 338, 339, 365, 340, 368, 369, 342, 343, + 349, 350, 351, 371, 374, 352, 353, 355, 352, 356, + 357, 358, 377, 359, 360, 361, 375, 362, 363, 375, + 364, 382, 383, 365, 384, 368, 369, 385, 386, 388, + 389, 391, 371, 374, 392, 393, 394, 395, 396, 398, + 399, 377, 401, 402, 404, 375, 406, 407, 375, 408, + 382, 383, 409, 384, 410, 411, 385, 386, 388, 389, + 391, 412, 414, 392, 393, 394, 395, 396, 398, 399, + 416, 401, 402, 404, 417, 406, 407, 418, 408, 420, + + 421, 409, 423, 410, 411, 424, 425, 428, 429, 431, + 412, 414, 432, 433, 434, 435, 436, 438, 443, 416, + 444, 445, 450, 417, 452, 453, 418, 454, 420, 421, + 455, 423, 456, 460, 424, 425, 428, 429, 431, 461, + 463, 432, 433, 434, 435, 436, 438, 443, 465, 444, + 445, 450, 466, 452, 453, 467, 454, 469, 471, 455, + 472, 456, 460, 473, 474, 475, 476, 477, 461, 463, + 478, 479, 480, 481, 482, 483, 485, 465, 486, 488, + 489, 466, 491, 492, 467, 493, 469, 471, 494, 472, + 495, 497, 473, 474, 475, 476, 477, 498, 499, 478, + + 479, 480, 481, 482, 483, 485, 500, 486, 488, 489, + 501, 491, 492, 502, 493, 505, 507, 494, 508, 495, + 497, 510, 513, 514, 515, 520, 498, 499, 521, 522, + 525, 527, 528, 529, 531, 500, 0, 0, 0, 501, + 0, 0, 502, 0, 505, 507, 0, 508, 0, 0, + 510, 513, 514, 515, 520, 0, 0, 521, 522, 525, + 527, 528, 529, 531, 534, 534, 534, 534, 534, 534, + 534, 534, 534, 534, 535, 535, 535, 535, 535, 535, + 535, 535, 535, 535, 536, 536, 536, 536, 536, 536, + 536, 536, 536, 536, 537, 537, 537, 537, 537, 537, + + 537, 537, 537, 537, 538, 538, 538, 538, 538, 538, + 538, 538, 538, 538, 539, 539, 540, 540, 540, 0, + 540, 541, 541, 541, 541, 0, 541, 542, 542, 542, + 0, 542, 542, 542, 542, 542, 542, 543, 543, 543, + 0, 543, 543, 543, 543, 0, 543, 544, 544, 544, + 544, 544, 544, 544, 544, 544, 544, 545, 545, 0, + 545, 545, 545, 545, 545, 545, 545, 546, 0, 546, + 546, 546, 546, 546, 546, 546, 546, 547, 547, 548, + 548, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533, 533, 533, 533, 533, 533, + 533, 533, 533, 533, 533 } ; /* Table of booleans, true if rule could match eol. */ -static const flex_int32_t yy_rule_can_match_eol[165] = +static const flex_int32_t yy_rule_can_match_eol[152] = { 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1176,9 +1129,8 @@ static const flex_int32_t yy_rule_can_match_eol[165] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, - 0, 1, 0, 0, 0, }; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, }; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -1222,6 +1174,7 @@ namespace quickstep { class BinaryOperation; class Comparison; +class ParseArray; class ParseAssignment; class ParseAttribute; class ParseAttributeDefinition; @@ -1272,6 +1225,7 @@ class ParseSubqueryExpression; class ParseSubqueryTableReference; class ParseTableReference; class ParseTableReferenceSignature; +class ParseTypeCast; class ParseWindow; class Type; class UnaryOperation; @@ -1289,14 +1243,14 @@ class UnaryOperation; yycolumn += yyleng; \ } -#line 1292 "SqlLexer_gen.cpp" +#line 1246 "SqlLexer_gen.cpp" /* FIXME(chasseur, qzeng): Add support for hexadecimal literals. */ /** * These patterns are based on the SQL-2011 standard for syntax of numeric * literals (Part 2, Section 5.3 of the standard). **/ -#line 1299 "SqlLexer_gen.cpp" +#line 1253 "SqlLexer_gen.cpp" #define INITIAL 0 #define CONDITION_SQL 1 @@ -1583,10 +1537,10 @@ YY_DECL } { -#line 132 "../SqlLexer.lpp" +#line 134 "../SqlLexer.lpp" -#line 1589 "SqlLexer_gen.cpp" +#line 1543 "SqlLexer_gen.cpp" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -1613,13 +1567,13 @@ YY_DECL while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 589 ) + if ( yy_current_state >= 534 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } - while ( yy_current_state != 588 ); + while ( yy_current_state != 533 ); yy_cp = yyg->yy_last_accepting_cpos; yy_current_state = yyg->yy_last_accepting_state; @@ -1653,7 +1607,7 @@ YY_DECL case 1: YY_RULE_SETUP -#line 135 "../SqlLexer.lpp" +#line 137 "../SqlLexer.lpp" { /* A forward slash character represents a system command. */ BEGIN(CONDITION_COMMAND); @@ -1665,7 +1619,7 @@ YY_RULE_SETUP case 2: /* rule 2 can match eol */ YY_RULE_SETUP -#line 143 "../SqlLexer.lpp" +#line 145 "../SqlLexer.lpp" { /* This is a SQL command. Place the char back and process normally. */ yyless(0); @@ -1677,7 +1631,7 @@ YY_RULE_SETUP case 3: YY_RULE_SETUP -#line 152 "../SqlLexer.lpp" +#line 154 "../SqlLexer.lpp" { /* This is a command argument. */ yylval->string_value_ = new quickstep::ParseString( @@ -1687,7 +1641,7 @@ YY_RULE_SETUP YY_BREAK case 4: YY_RULE_SETUP -#line 159 "../SqlLexer.lpp" +#line 161 "../SqlLexer.lpp" { /* Ignore whitespace. */ } @@ -1695,7 +1649,7 @@ YY_RULE_SETUP case 5: /* rule 5 can match eol */ YY_RULE_SETUP -#line 163 "../SqlLexer.lpp" +#line 165 "../SqlLexer.lpp" { /* Newline reverts the lexer to the initial state. */ yycolumn = 0; @@ -1707,687 +1661,622 @@ YY_RULE_SETUP case 6: YY_RULE_SETUP -#line 172 "../SqlLexer.lpp" +#line 174 "../SqlLexer.lpp" return TOKEN_ADD; YY_BREAK case 7: YY_RULE_SETUP -#line 173 "../SqlLexer.lpp" +#line 175 "../SqlLexer.lpp" return TOKEN_ALL; YY_BREAK case 8: YY_RULE_SETUP -#line 174 "../SqlLexer.lpp" +#line 176 "../SqlLexer.lpp" return TOKEN_ALTER; YY_BREAK case 9: YY_RULE_SETUP -#line 175 "../SqlLexer.lpp" +#line 177 "../SqlLexer.lpp" return TOKEN_AND; YY_BREAK case 10: YY_RULE_SETUP -#line 176 "../SqlLexer.lpp" +#line 178 "../SqlLexer.lpp" return TOKEN_AS; YY_BREAK case 11: YY_RULE_SETUP -#line 177 "../SqlLexer.lpp" +#line 179 "../SqlLexer.lpp" return TOKEN_ASC; YY_BREAK case 12: YY_RULE_SETUP -#line 178 "../SqlLexer.lpp" +#line 180 "../SqlLexer.lpp" return TOKEN_ASC; YY_BREAK case 13: YY_RULE_SETUP -#line 179 "../SqlLexer.lpp" +#line 181 "../SqlLexer.lpp" return TOKEN_BETWEEN; YY_BREAK case 14: YY_RULE_SETUP -#line 180 "../SqlLexer.lpp" -return TOKEN_BIGINT; - YY_BREAK -case 15: -YY_RULE_SETUP -#line 181 "../SqlLexer.lpp" -return TOKEN_BIT; - YY_BREAK -case 16: -YY_RULE_SETUP #line 182 "../SqlLexer.lpp" return TOKEN_BITWEAVING; YY_BREAK -case 17: +case 15: YY_RULE_SETUP #line 183 "../SqlLexer.lpp" return TOKEN_BLOCKPROPERTIES; YY_BREAK -case 18: +case 16: YY_RULE_SETUP #line 184 "../SqlLexer.lpp" return TOKEN_BLOCKSAMPLE; YY_BREAK -case 19: +case 17: YY_RULE_SETUP #line 185 "../SqlLexer.lpp" return TOKEN_BLOOM_FILTER; YY_BREAK -case 20: +case 18: YY_RULE_SETUP #line 186 "../SqlLexer.lpp" return TOKEN_CASE; YY_BREAK -case 21: +case 19: YY_RULE_SETUP #line 187 "../SqlLexer.lpp" -return TOKEN_CSB_TREE; +return TOKEN_CAST; YY_BREAK -case 22: +case 20: YY_RULE_SETUP #line 188 "../SqlLexer.lpp" -return TOKEN_BY; +return TOKEN_CSB_TREE; YY_BREAK -case 23: +case 21: YY_RULE_SETUP #line 189 "../SqlLexer.lpp" -return TOKEN_CHARACTER; +return TOKEN_BY; YY_BREAK -case 24: +case 22: YY_RULE_SETUP #line 190 "../SqlLexer.lpp" -return TOKEN_CHARACTER; +return TOKEN_CHECK; YY_BREAK -case 25: +case 23: YY_RULE_SETUP #line 191 "../SqlLexer.lpp" -return TOKEN_CHECK; +return TOKEN_COLUMN; YY_BREAK -case 26: +case 24: YY_RULE_SETUP #line 192 "../SqlLexer.lpp" -return TOKEN_COLUMN; +return TOKEN_CONSTRAINT; YY_BREAK -case 27: +case 25: YY_RULE_SETUP #line 193 "../SqlLexer.lpp" -return TOKEN_CONSTRAINT; +return TOKEN_COPY; YY_BREAK -case 28: +case 26: YY_RULE_SETUP #line 194 "../SqlLexer.lpp" -return TOKEN_COPY; +return TOKEN_CREATE; YY_BREAK -case 29: +case 27: YY_RULE_SETUP #line 195 "../SqlLexer.lpp" -return TOKEN_CREATE; +return TOKEN_CURRENT; YY_BREAK -case 30: +case 28: YY_RULE_SETUP #line 196 "../SqlLexer.lpp" -return TOKEN_CURRENT; +return TOKEN_DAY; YY_BREAK -case 31: +case 29: YY_RULE_SETUP #line 197 "../SqlLexer.lpp" -return TOKEN_DATE; +return TOKEN_DEFAULT; YY_BREAK -case 32: +case 30: YY_RULE_SETUP #line 198 "../SqlLexer.lpp" -return TOKEN_DATETIME; +return TOKEN_DELETE; YY_BREAK -case 33: +case 31: YY_RULE_SETUP #line 199 "../SqlLexer.lpp" -return TOKEN_DAY; +return TOKEN_DESC; YY_BREAK -case 34: +case 32: YY_RULE_SETUP #line 200 "../SqlLexer.lpp" -return TOKEN_DECIMAL; +return TOKEN_DESC; YY_BREAK -case 35: +case 33: YY_RULE_SETUP #line 201 "../SqlLexer.lpp" -return TOKEN_DEFAULT; +return TOKEN_DISTINCT; YY_BREAK -case 36: +case 34: YY_RULE_SETUP #line 202 "../SqlLexer.lpp" -return TOKEN_DELETE; +return TOKEN_DROP; YY_BREAK -case 37: +case 35: YY_RULE_SETUP #line 203 "../SqlLexer.lpp" -return TOKEN_DESC; +return TOKEN_ELSE; YY_BREAK -case 38: +case 36: YY_RULE_SETUP #line 204 "../SqlLexer.lpp" -return TOKEN_DESC; +return TOKEN_END; YY_BREAK -case 39: +case 37: YY_RULE_SETUP #line 205 "../SqlLexer.lpp" -return TOKEN_DISTINCT; +return TOKEN_EXISTS; YY_BREAK -case 40: +case 38: YY_RULE_SETUP #line 206 "../SqlLexer.lpp" -return TOKEN_DOUBLE; +return TOKEN_EXTRACT; YY_BREAK -case 41: +case 39: YY_RULE_SETUP #line 207 "../SqlLexer.lpp" -return TOKEN_DROP; +return TOKEN_FALSE; YY_BREAK -case 42: +case 40: YY_RULE_SETUP #line 208 "../SqlLexer.lpp" -return TOKEN_ELSE; +return TOKEN_FIRST; YY_BREAK -case 43: +case 41: YY_RULE_SETUP #line 209 "../SqlLexer.lpp" -return TOKEN_END; +return TOKEN_FOLLOWING; YY_BREAK -case 44: +case 42: YY_RULE_SETUP #line 210 "../SqlLexer.lpp" -return TOKEN_EXISTS; +return TOKEN_FOR; YY_BREAK -case 45: +case 43: YY_RULE_SETUP #line 211 "../SqlLexer.lpp" -return TOKEN_EXTRACT; +return TOKEN_FOREIGN; YY_BREAK -case 46: +case 44: YY_RULE_SETUP #line 212 "../SqlLexer.lpp" -return TOKEN_FALSE; +return TOKEN_FROM; YY_BREAK -case 47: +case 45: YY_RULE_SETUP #line 213 "../SqlLexer.lpp" -return TOKEN_FIRST; +return TOKEN_FULL; YY_BREAK -case 48: +case 46: YY_RULE_SETUP #line 214 "../SqlLexer.lpp" -return TOKEN_FLOAT; +return TOKEN_GROUP; YY_BREAK -case 49: +case 47: YY_RULE_SETUP #line 215 "../SqlLexer.lpp" -return TOKEN_FOLLOWING; +return TOKEN_HASH; YY_BREAK -case 50: +case 48: YY_RULE_SETUP #line 216 "../SqlLexer.lpp" -return TOKEN_FOR; +return TOKEN_HAVING; YY_BREAK -case 51: +case 49: YY_RULE_SETUP #line 217 "../SqlLexer.lpp" -return TOKEN_FOREIGN; +return TOKEN_HOUR; YY_BREAK -case 52: +case 50: YY_RULE_SETUP #line 218 "../SqlLexer.lpp" -return TOKEN_FROM; +return TOKEN_IN; YY_BREAK -case 53: +case 51: YY_RULE_SETUP #line 219 "../SqlLexer.lpp" -return TOKEN_FULL; +return TOKEN_INDEX; YY_BREAK -case 54: +case 52: YY_RULE_SETUP #line 220 "../SqlLexer.lpp" -return TOKEN_GROUP; +return TOKEN_INNER; YY_BREAK -case 55: +case 53: YY_RULE_SETUP #line 221 "../SqlLexer.lpp" -return TOKEN_HASH; +return TOKEN_INSERT; YY_BREAK -case 56: +case 54: YY_RULE_SETUP #line 222 "../SqlLexer.lpp" -return TOKEN_HAVING; +return TOKEN_INTERSECT; YY_BREAK -case 57: +case 55: YY_RULE_SETUP #line 223 "../SqlLexer.lpp" -return TOKEN_HOUR; +return TOKEN_INTERVAL; YY_BREAK -case 58: +case 56: YY_RULE_SETUP #line 224 "../SqlLexer.lpp" -return TOKEN_IN; +return TOKEN_INTO; YY_BREAK -case 59: +case 57: YY_RULE_SETUP #line 225 "../SqlLexer.lpp" -return TOKEN_INDEX; +return TOKEN_IS; YY_BREAK -case 60: +case 58: YY_RULE_SETUP #line 226 "../SqlLexer.lpp" -return TOKEN_INNER; +return TOKEN_JOIN; YY_BREAK -case 61: +case 59: YY_RULE_SETUP #line 227 "../SqlLexer.lpp" -return TOKEN_INSERT; +return TOKEN_KEY; YY_BREAK -case 62: +case 60: YY_RULE_SETUP #line 228 "../SqlLexer.lpp" -return TOKEN_INTEGER; +return TOKEN_LAST; YY_BREAK -case 63: +case 61: YY_RULE_SETUP #line 229 "../SqlLexer.lpp" -return TOKEN_INTEGER; +return TOKEN_LEFT; YY_BREAK -case 64: +case 62: YY_RULE_SETUP #line 230 "../SqlLexer.lpp" -return TOKEN_INTERSECT; +return TOKEN_LIKE; YY_BREAK -case 65: +case 63: YY_RULE_SETUP #line 231 "../SqlLexer.lpp" -return TOKEN_INTERVAL; +return TOKEN_LIMIT; YY_BREAK -case 66: +case 64: YY_RULE_SETUP #line 232 "../SqlLexer.lpp" -return TOKEN_INTO; +return TOKEN_MINUTE; YY_BREAK -case 67: +case 65: YY_RULE_SETUP #line 233 "../SqlLexer.lpp" -return TOKEN_IS; +return TOKEN_MONTH; YY_BREAK -case 68: +case 66: YY_RULE_SETUP #line 234 "../SqlLexer.lpp" -return TOKEN_JOIN; +return TOKEN_NOT; YY_BREAK -case 69: +case 67: YY_RULE_SETUP #line 235 "../SqlLexer.lpp" -return TOKEN_KEY; +return TOKEN_NULL; YY_BREAK -case 70: +case 68: YY_RULE_SETUP #line 236 "../SqlLexer.lpp" -return TOKEN_LAST; +return TOKEN_NULLS; YY_BREAK -case 71: +case 69: YY_RULE_SETUP #line 237 "../SqlLexer.lpp" -return TOKEN_LEFT; +return TOKEN_OFF; YY_BREAK -case 72: +case 70: YY_RULE_SETUP #line 238 "../SqlLexer.lpp" -return TOKEN_LIKE; +return TOKEN_ON; YY_BREAK -case 73: +case 71: YY_RULE_SETUP #line 239 "../SqlLexer.lpp" -return TOKEN_LIMIT; +return TOKEN_OR; YY_BREAK -case 74: +case 72: YY_RULE_SETUP #line 240 "../SqlLexer.lpp" -return TOKEN_LONG; +return TOKEN_ORDER; YY_BREAK -case 75: +case 73: YY_RULE_SETUP #line 241 "../SqlLexer.lpp" -return TOKEN_MINUTE; +return TOKEN_OUTER; YY_BREAK -case 76: +case 74: YY_RULE_SETUP #line 242 "../SqlLexer.lpp" -return TOKEN_MONTH; +return TOKEN_OVER; YY_BREAK -case 77: +case 75: YY_RULE_SETUP #line 243 "../SqlLexer.lpp" -return TOKEN_NOT; +return TOKEN_PARTITION; YY_BREAK -case 78: +case 76: YY_RULE_SETUP #line 244 "../SqlLexer.lpp" -return TOKEN_NULL; +return TOKEN_PARTITIONS; YY_BREAK -case 79: +case 77: YY_RULE_SETUP #line 245 "../SqlLexer.lpp" -return TOKEN_NULLS; +return TOKEN_PERCENT; YY_BREAK -case 80: +case 78: YY_RULE_SETUP #line 246 "../SqlLexer.lpp" -return TOKEN_OFF; +return TOKEN_PRECEDING; YY_BREAK -case 81: +case 79: YY_RULE_SETUP #line 247 "../SqlLexer.lpp" -return TOKEN_ON; +return TOKEN_PRIMARY; YY_BREAK -case 82: +case 80: YY_RULE_SETUP #line 248 "../SqlLexer.lpp" -return TOKEN_OR; +return TOKEN_PRIORITY; YY_BREAK -case 83: +case 81: YY_RULE_SETUP #line 249 "../SqlLexer.lpp" -return TOKEN_ORDER; +return TOKEN_QUIT; YY_BREAK -case 84: +case 82: YY_RULE_SETUP #line 250 "../SqlLexer.lpp" -return TOKEN_OUTER; +return TOKEN_RANGE; YY_BREAK -case 85: +case 83: YY_RULE_SETUP #line 251 "../SqlLexer.lpp" -return TOKEN_OVER; +return TOKEN_REAL; YY_BREAK -case 86: +case 84: YY_RULE_SETUP #line 252 "../SqlLexer.lpp" -return TOKEN_PARTITION; +return TOKEN_REFERENCES; YY_BREAK -case 87: +case 85: YY_RULE_SETUP #line 253 "../SqlLexer.lpp" -return TOKEN_PARTITIONS; +return TOKEN_REGEXP; YY_BREAK -case 88: +case 86: YY_RULE_SETUP #line 254 "../SqlLexer.lpp" -return TOKEN_PERCENT; +return TOKEN_RIGHT; YY_BREAK -case 89: +case 87: YY_RULE_SETUP #line 255 "../SqlLexer.lpp" -return TOKEN_PRECEDING; +return TOKEN_ROW; YY_BREAK -case 90: +case 88: YY_RULE_SETUP #line 256 "../SqlLexer.lpp" -return TOKEN_PRIMARY; +return TOKEN_ROW_DELIMITER; YY_BREAK -case 91: +case 89: YY_RULE_SETUP #line 257 "../SqlLexer.lpp" -return TOKEN_PRIORITY; +return TOKEN_ROWS; YY_BREAK -case 92: +case 90: YY_RULE_SETUP #line 258 "../SqlLexer.lpp" -return TOKEN_QUIT; +return TOKEN_SECOND; YY_BREAK -case 93: +case 91: YY_RULE_SETUP #line 259 "../SqlLexer.lpp" -return TOKEN_RANGE; +return TOKEN_SELECT; YY_BREAK -case 94: +case 92: YY_RULE_SETUP #line 260 "../SqlLexer.lpp" -return TOKEN_REAL; +return TOKEN_SET; YY_BREAK -case 95: +case 93: YY_RULE_SETUP #line 261 "../SqlLexer.lpp" -return TOKEN_REFERENCES; +return TOKEN_SMA; YY_BREAK -case 96: +case 94: YY_RULE_SETUP #line 262 "../SqlLexer.lpp" -return TOKEN_REGEXP; +return TOKEN_STDERR; YY_BREAK -case 97: +case 95: YY_RULE_SETUP #line 263 "../SqlLexer.lpp" -return TOKEN_RIGHT; +return TOKEN_STDOUT; YY_BREAK -case 98: +case 96: YY_RULE_SETUP #line 264 "../SqlLexer.lpp" -return TOKEN_ROW; +return TOKEN_SUBSTRING; YY_BREAK -case 99: +case 97: YY_RULE_SETUP #line 265 "../SqlLexer.lpp" -return TOKEN_ROW_DELIMITER; +return TOKEN_TABLE; YY_BREAK -case 100: +case 98: YY_RULE_SETUP #line 266 "../SqlLexer.lpp" -return TOKEN_ROWS; +return TOKEN_THEN; YY_BREAK -case 101: +case 99: YY_RULE_SETUP #line 267 "../SqlLexer.lpp" -return TOKEN_SECOND; +return TOKEN_TO; YY_BREAK -case 102: +case 100: YY_RULE_SETUP #line 268 "../SqlLexer.lpp" -return TOKEN_SELECT; +return TOKEN_TRUE; YY_BREAK -case 103: +case 101: YY_RULE_SETUP #line 269 "../SqlLexer.lpp" -return TOKEN_SET; +return TOKEN_TUPLESAMPLE; YY_BREAK -case 104: +case 102: YY_RULE_SETUP #line 270 "../SqlLexer.lpp" -return TOKEN_SMA; +return TOKEN_UNBOUNDED; YY_BREAK -case 105: +case 103: YY_RULE_SETUP #line 271 "../SqlLexer.lpp" -return TOKEN_SMALLINT; +return TOKEN_UNION; YY_BREAK -case 106: +case 104: YY_RULE_SETUP #line 272 "../SqlLexer.lpp" -return TOKEN_STDERR; +return TOKEN_UNIQUE; YY_BREAK -case 107: +case 105: YY_RULE_SETUP #line 273 "../SqlLexer.lpp" -return TOKEN_STDOUT; +return TOKEN_UPDATE; YY_BREAK -case 108: +case 106: YY_RULE_SETUP #line 274 "../SqlLexer.lpp" -return TOKEN_SUBSTRING; +return TOKEN_USING; YY_BREAK -case 109: +case 107: YY_RULE_SETUP #line 275 "../SqlLexer.lpp" -return TOKEN_TABLE; +return TOKEN_VALUES; YY_BREAK -case 110: +case 108: YY_RULE_SETUP #line 276 "../SqlLexer.lpp" -return TOKEN_THEN; +return TOKEN_WHEN; YY_BREAK -case 111: +case 109: YY_RULE_SETUP #line 277 "../SqlLexer.lpp" -return TOKEN_TIME; +return TOKEN_WHERE; YY_BREAK -case 112: +case 110: YY_RULE_SETUP #line 278 "../SqlLexer.lpp" -return TOKEN_TIMESTAMP; +return TOKEN_WINDOW; YY_BREAK -case 113: +case 111: YY_RULE_SETUP #line 279 "../SqlLexer.lpp" -return TOKEN_TO; +return TOKEN_WITH; YY_BREAK -case 114: +case 112: YY_RULE_SETUP #line 280 "../SqlLexer.lpp" -return TOKEN_TRUE; - YY_BREAK -case 115: -YY_RULE_SETUP -#line 281 "../SqlLexer.lpp" -return TOKEN_TUPLESAMPLE; +return TOKEN_YEAR; YY_BREAK -case 116: +case 113: YY_RULE_SETUP #line 282 "../SqlLexer.lpp" -return TOKEN_UNBOUNDED; +return TOKEN_EQ; YY_BREAK -case 117: +case 114: YY_RULE_SETUP #line 283 "../SqlLexer.lpp" -return TOKEN_UNION; +return TOKEN_NEQ; YY_BREAK -case 118: +case 115: YY_RULE_SETUP #line 284 "../SqlLexer.lpp" -return TOKEN_UNIQUE; +return TOKEN_NEQ; YY_BREAK -case 119: +case 116: YY_RULE_SETUP #line 285 "../SqlLexer.lpp" -return TOKEN_UPDATE; +return TOKEN_LT; YY_BREAK -case 120: +case 117: YY_RULE_SETUP #line 286 "../SqlLexer.lpp" -return TOKEN_USING; +return TOKEN_GT; YY_BREAK -case 121: +case 118: YY_RULE_SETUP #line 287 "../SqlLexer.lpp" -return TOKEN_VALUES; +return TOKEN_LEQ; YY_BREAK -case 122: +case 119: YY_RULE_SETUP #line 288 "../SqlLexer.lpp" -return TOKEN_VARCHAR; +return TOKEN_GEQ; YY_BREAK -case 123: +case 120: YY_RULE_SETUP #line 289 "../SqlLexer.lpp" -return TOKEN_WHEN; +return TOKEN_DOUBLECOLON; YY_BREAK -case 124: +case 121: YY_RULE_SETUP #line 290 "../SqlLexer.lpp" -return TOKEN_WHERE; +return TOKEN_LBRACE; YY_BREAK -case 125: +case 122: YY_RULE_SETUP #line 291 "../SqlLexer.lpp" -return TOKEN_WINDOW; +return TOKEN_RBRACE; YY_BREAK -case 126: -YY_RULE_SETUP -#line 292 "../SqlLexer.lpp" -return TOKEN_WITH; - YY_BREAK -case 127: +case 123: YY_RULE_SETUP #line 293 "../SqlLexer.lpp" -return TOKEN_YEAR; - YY_BREAK -case 128: -YY_RULE_SETUP -#line 294 "../SqlLexer.lpp" -return TOKEN_YEARMONTH; - YY_BREAK -case 129: -YY_RULE_SETUP -#line 296 "../SqlLexer.lpp" -return TOKEN_EQ; - YY_BREAK -case 130: -YY_RULE_SETUP -#line 297 "../SqlLexer.lpp" -return TOKEN_NEQ; - YY_BREAK -case 131: -YY_RULE_SETUP -#line 298 "../SqlLexer.lpp" -return TOKEN_NEQ; - YY_BREAK -case 132: -YY_RULE_SETUP -#line 299 "../SqlLexer.lpp" -return TOKEN_LT; - YY_BREAK -case 133: -YY_RULE_SETUP -#line 300 "../SqlLexer.lpp" -return TOKEN_GT; - YY_BREAK -case 134: -YY_RULE_SETUP -#line 301 "../SqlLexer.lpp" -return TOKEN_LEQ; - YY_BREAK -case 135: -YY_RULE_SETUP -#line 302 "../SqlLexer.lpp" -return TOKEN_GEQ; - YY_BREAK -case 136: -YY_RULE_SETUP -#line 304 "../SqlLexer.lpp" return yytext[0]; YY_BREAK -case 137: +case 124: YY_RULE_SETUP -#line 305 "../SqlLexer.lpp" +#line 294 "../SqlLexer.lpp" return yytext[0]; YY_BREAK /** * Quoted strings. Prefacing a string with an 'e' or 'E' causes escape * sequences to be processed (as in PostgreSQL). **/ -case 138: +case 125: YY_RULE_SETUP -#line 311 "../SqlLexer.lpp" +#line 300 "../SqlLexer.lpp" { yylval->string_value_ = new quickstep::ParseString(yylloc->first_line, yylloc->first_column); BEGIN(CONDITION_STRING_SINGLE_QUOTED_ESCAPED); } YY_BREAK -case 139: +case 126: YY_RULE_SETUP -#line 316 "../SqlLexer.lpp" +#line 305 "../SqlLexer.lpp" { yylval->string_value_ = new quickstep::ParseString(yylloc->first_line, yylloc->first_column); BEGIN(CONDITION_STRING_SINGLE_QUOTED); } YY_BREAK -case 140: +case 127: YY_RULE_SETUP -#line 321 "../SqlLexer.lpp" +#line 310 "../SqlLexer.lpp" { yylval->string_value_ = new quickstep::ParseString(yylloc->first_line, yylloc->first_column); BEGIN(CONDITION_STRING_DOUBLE_QUOTED); @@ -2399,7 +2288,7 @@ YY_RULE_SETUP case YY_STATE_EOF(CONDITION_STRING_SINGLE_QUOTED): case YY_STATE_EOF(CONDITION_STRING_SINGLE_QUOTED_ESCAPED): case YY_STATE_EOF(CONDITION_STRING_DOUBLE_QUOTED): -#line 330 "../SqlLexer.lpp" +#line 319 "../SqlLexer.lpp" { delete yylval->string_value_; BEGIN(INITIAL); @@ -2410,9 +2299,9 @@ case YY_STATE_EOF(CONDITION_STRING_DOUBLE_QUOTED): /* Process escape sequences. */ -case 141: +case 128: YY_RULE_SETUP -#line 340 "../SqlLexer.lpp" +#line 329 "../SqlLexer.lpp" { /* Octal code */ unsigned int code; @@ -2426,9 +2315,9 @@ YY_RULE_SETUP yylval->string_value_->push_back(code); } YY_BREAK -case 142: +case 129: YY_RULE_SETUP -#line 352 "../SqlLexer.lpp" +#line 341 "../SqlLexer.lpp" { /* Hexadecimal code */ unsigned int code; @@ -2436,9 +2325,9 @@ YY_RULE_SETUP yylval->string_value_->push_back(code); } YY_BREAK -case 143: +case 130: YY_RULE_SETUP -#line 358 "../SqlLexer.lpp" +#line 347 "../SqlLexer.lpp" { /* A numeric escape sequence that isn't correctly specified. */ delete yylval->string_value_; @@ -2447,58 +2336,58 @@ YY_RULE_SETUP return TOKEN_LEX_ERROR; } YY_BREAK -case 144: +case 131: YY_RULE_SETUP -#line 365 "../SqlLexer.lpp" +#line 354 "../SqlLexer.lpp" { /* Backspace */ yylval->string_value_->push_back('\b'); } YY_BREAK -case 145: +case 132: YY_RULE_SETUP -#line 369 "../SqlLexer.lpp" +#line 358 "../SqlLexer.lpp" { /* Form-feed */ yylval->string_value_->push_back('\f'); } YY_BREAK -case 146: +case 133: YY_RULE_SETUP -#line 373 "../SqlLexer.lpp" +#line 362 "../SqlLexer.lpp" { /* Newline */ yylval->string_value_->push_back('\n'); } YY_BREAK -case 147: +case 134: YY_RULE_SETUP -#line 377 "../SqlLexer.lpp" +#line 366 "../SqlLexer.lpp" { /* Carriage-return */ yylval->string_value_->push_back('\r'); } YY_BREAK -case 148: +case 135: YY_RULE_SETUP -#line 381 "../SqlLexer.lpp" +#line 370 "../SqlLexer.lpp" { /* Horizontal Tab */ yylval->string_value_->push_back('\t'); } YY_BREAK -case 149: -/* rule 149 can match eol */ +case 136: +/* rule 136 can match eol */ YY_RULE_SETUP -#line 385 "../SqlLexer.lpp" +#line 374 "../SqlLexer.lpp" { /* Any other character (including actual newline or carriage return) */ yylval->string_value_->push_back(yytext[1]); } YY_BREAK -case 150: +case 137: YY_RULE_SETUP -#line 389 "../SqlLexer.lpp" +#line 378 "../SqlLexer.lpp" { /* This should only be encountered right before an EOF. */ delete yylval->string_value_; @@ -2509,17 +2398,17 @@ YY_RULE_SETUP YY_BREAK -case 151: +case 138: YY_RULE_SETUP -#line 399 "../SqlLexer.lpp" +#line 388 "../SqlLexer.lpp" { /* Two quotes in a row become a single quote (this is specified by the SQL standard). */ yylval->string_value_->push_back('\''); } YY_BREAK -case 152: +case 139: YY_RULE_SETUP -#line 403 "../SqlLexer.lpp" +#line 392 "../SqlLexer.lpp" { /* End string */ BEGIN(CONDITION_SQL); @@ -2528,17 +2417,17 @@ YY_RULE_SETUP YY_BREAK -case 153: +case 140: YY_RULE_SETUP -#line 411 "../SqlLexer.lpp" +#line 400 "../SqlLexer.lpp" { /* Two quotes in a row become a single quote (this is specified by the SQL standard). */ yylval->string_value_->push_back('"'); } YY_BREAK -case 154: +case 141: YY_RULE_SETUP -#line 415 "../SqlLexer.lpp" +#line 404 "../SqlLexer.lpp" { /* End string */ BEGIN(CONDITION_SQL); @@ -2546,94 +2435,94 @@ YY_RULE_SETUP } YY_BREAK -case 155: -/* rule 155 can match eol */ +case 142: +/* rule 142 can match eol */ YY_RULE_SETUP -#line 422 "../SqlLexer.lpp" +#line 411 "../SqlLexer.lpp" { /* Scan up to a quote. */ yylval->string_value_->append(yytext, yyleng); } YY_BREAK -case 156: -/* rule 156 can match eol */ +case 143: +/* rule 143 can match eol */ YY_RULE_SETUP -#line 427 "../SqlLexer.lpp" +#line 416 "../SqlLexer.lpp" { /* Scan up to a quote or escape sequence. */ yylval->string_value_->append(yytext, yyleng); } YY_BREAK -case 157: -/* rule 157 can match eol */ +case 144: +/* rule 144 can match eol */ YY_RULE_SETUP -#line 432 "../SqlLexer.lpp" +#line 421 "../SqlLexer.lpp" { /* Scan up to a quote. */ yylval->string_value_->append(yytext, yyleng); } YY_BREAK -case 158: +case 145: YY_RULE_SETUP -#line 438 "../SqlLexer.lpp" +#line 427 "../SqlLexer.lpp" { yylval->string_value_ = new quickstep::ParseString( yylloc->first_line, yylloc->first_column, std::string(yytext, yyleng)); return TOKEN_NAME; } YY_BREAK -case 159: +case 146: YY_RULE_SETUP -#line 444 "../SqlLexer.lpp" +#line 433 "../SqlLexer.lpp" { yylval->numeric_literal_value_ = new quickstep::NumericParseLiteralValue( yylloc->first_line, yylloc->first_column, yytext); return TOKEN_UNSIGNED_NUMVAL; } YY_BREAK -case 160: +case 147: YY_RULE_SETUP -#line 450 "../SqlLexer.lpp" +#line 439 "../SqlLexer.lpp" /* comment */ YY_BREAK -case 161: -/* rule 161 can match eol */ +case 148: +/* rule 148 can match eol */ YY_RULE_SETUP -#line 452 "../SqlLexer.lpp" +#line 441 "../SqlLexer.lpp" { yycolumn = 0; } YY_BREAK -case 162: +case 149: YY_RULE_SETUP -#line 454 "../SqlLexer.lpp" +#line 443 "../SqlLexer.lpp" ; /* ignore white space */ YY_BREAK /* CONDITION_SQL */ case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(CONDITION_COMMAND): case YY_STATE_EOF(CONDITION_SQL): -#line 458 "../SqlLexer.lpp" +#line 447 "../SqlLexer.lpp" { /* All conditions except for mutli-state string extracting conditions. */ BEGIN(INITIAL); return TOKEN_EOF; } YY_BREAK -case 163: +case 150: YY_RULE_SETUP -#line 464 "../SqlLexer.lpp" +#line 453 "../SqlLexer.lpp" { BEGIN(INITIAL); quickstep_yyerror(NULL, yyscanner, NULL, "illegal character"); return TOKEN_LEX_ERROR; } YY_BREAK -case 164: +case 151: YY_RULE_SETUP -#line 470 "../SqlLexer.lpp" +#line 459 "../SqlLexer.lpp" YY_FATAL_ERROR( "flex scanner jammed" ); YY_BREAK -#line 2636 "SqlLexer_gen.cpp" +#line 2525 "SqlLexer_gen.cpp" case YY_END_OF_BUFFER: { @@ -2931,7 +2820,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 589 ) + if ( yy_current_state >= 534 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; @@ -2960,11 +2849,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 589 ) + if ( yy_current_state >= 534 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 588); + yy_is_jam = (yy_current_state == 533); (void)yyg; return yy_is_jam ? 0 : yy_current_state; @@ -3794,6 +3683,6 @@ void yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 470 "../SqlLexer.lpp" +#line 459 "../SqlLexer.lpp" diff --git a/parser/preprocessed/SqlLexer_gen.hpp b/parser/preprocessed/SqlLexer_gen.hpp index 5fafae5a..ba92557d 100644 --- a/parser/preprocessed/SqlLexer_gen.hpp +++ b/parser/preprocessed/SqlLexer_gen.hpp @@ -733,7 +733,7 @@ extern int yylex \ #undef yyTABLES_NAME #endif -#line 470 "../SqlLexer.lpp" +#line 459 "../SqlLexer.lpp" #line 739 "SqlLexer_gen.hpp" diff --git a/parser/preprocessed/SqlParser_gen.cpp b/parser/preprocessed/SqlParser_gen.cpp index 72c61dd4..fcd070f0 100644 --- a/parser/preprocessed/SqlParser_gen.cpp +++ b/parser/preprocessed/SqlParser_gen.cpp @@ -108,6 +108,7 @@ typedef struct YYLTYPE { #include "parser/ParseBasicExpressions.hpp" #include "parser/ParseBlockProperties.hpp" #include "parser/ParseCaseExpressions.hpp" +#include "parser/ParseDataType.hpp" #include "parser/ParseExpression.hpp" #include "parser/ParseGeneratorTableReference.hpp" #include "parser/ParseGroupBy.hpp" @@ -138,22 +139,16 @@ typedef struct YYLTYPE { #include "types/Type.hpp" #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" -#include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "types/operations/comparisons/Comparison.hpp" #include "types/operations/comparisons/ComparisonFactory.hpp" #include "types/operations/comparisons/ComparisonID.hpp" -#include "types/operations/unary_operations/UnaryOperation.hpp" -#include "types/operations/unary_operations/UnaryOperationFactory.hpp" -#include "types/operations/unary_operations/UnaryOperationID.hpp" #include "utility/PtrList.hpp" #include "utility/PtrVector.hpp" // Needed for Bison 2.6 and higher, which do not automatically provide this typedef. typedef void* yyscan_t; -#line 157 "SqlParser_gen.cpp" /* yacc.c:339 */ +#line 152 "SqlParser_gen.cpp" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -215,113 +210,103 @@ extern int quickstep_yydebug; TOKEN_ALTER = 282, TOKEN_AS = 283, TOKEN_ASC = 284, - TOKEN_BIGINT = 285, - TOKEN_BIT = 286, - TOKEN_BITWEAVING = 287, - TOKEN_BLOCKPROPERTIES = 288, - TOKEN_BLOCKSAMPLE = 289, - TOKEN_BLOOM_FILTER = 290, - TOKEN_CSB_TREE = 291, - TOKEN_BY = 292, - TOKEN_CASE = 293, - TOKEN_CHARACTER = 294, - TOKEN_CHECK = 295, - TOKEN_COLUMN = 296, - TOKEN_CONSTRAINT = 297, - TOKEN_COPY = 298, - TOKEN_CREATE = 299, - TOKEN_CURRENT = 300, - TOKEN_DATE = 301, - TOKEN_DATETIME = 302, - TOKEN_DAY = 303, - TOKEN_DECIMAL = 304, - TOKEN_DEFAULT = 305, - TOKEN_DELETE = 306, - TOKEN_DESC = 307, - TOKEN_DISTINCT = 308, - TOKEN_DOUBLE = 309, - TOKEN_DROP = 310, - TOKEN_ELSE = 311, - TOKEN_END = 312, - TOKEN_EXISTS = 313, - TOKEN_EXTRACT = 314, - TOKEN_FALSE = 315, - TOKEN_FIRST = 316, - TOKEN_FLOAT = 317, - TOKEN_FOLLOWING = 318, - TOKEN_FOR = 319, - TOKEN_FOREIGN = 320, - TOKEN_FROM = 321, - TOKEN_FULL = 322, - TOKEN_GROUP = 323, - TOKEN_HASH = 324, - TOKEN_HAVING = 325, - TOKEN_HOUR = 326, - TOKEN_IN = 327, - TOKEN_INDEX = 328, - TOKEN_INNER = 329, - TOKEN_INSERT = 330, - TOKEN_INTEGER = 331, - TOKEN_INTERVAL = 332, - TOKEN_INTO = 333, - TOKEN_JOIN = 334, - TOKEN_KEY = 335, - TOKEN_LAST = 336, - TOKEN_LEFT = 337, - TOKEN_LIMIT = 338, - TOKEN_LONG = 339, - TOKEN_MINUTE = 340, - TOKEN_MONTH = 341, - TOKEN_NULL = 342, - TOKEN_NULLS = 343, - TOKEN_OFF = 344, - TOKEN_ON = 345, - TOKEN_ORDER = 346, - TOKEN_OUTER = 347, - TOKEN_OVER = 348, - TOKEN_PARTITION = 349, - TOKEN_PARTITIONS = 350, - TOKEN_PERCENT = 351, - TOKEN_PRECEDING = 352, - TOKEN_PRIMARY = 353, - TOKEN_PRIORITY = 354, - TOKEN_QUIT = 355, - TOKEN_RANGE = 356, - TOKEN_REAL = 357, - TOKEN_REFERENCES = 358, - TOKEN_RIGHT = 359, - TOKEN_ROW = 360, - TOKEN_ROW_DELIMITER = 361, - TOKEN_ROWS = 362, - TOKEN_SECOND = 363, - TOKEN_SELECT = 364, - TOKEN_SET = 365, - TOKEN_SMA = 366, - TOKEN_SMALLINT = 367, - TOKEN_STDERR = 368, - TOKEN_STDOUT = 369, - TOKEN_SUBSTRING = 370, - TOKEN_TABLE = 371, - TOKEN_THEN = 372, - TOKEN_TIME = 373, - TOKEN_TIMESTAMP = 374, - TOKEN_TO = 375, - TOKEN_TRUE = 376, - TOKEN_TUPLESAMPLE = 377, - TOKEN_UNBOUNDED = 378, - TOKEN_UNIQUE = 379, - TOKEN_UPDATE = 380, - TOKEN_USING = 381, - TOKEN_VALUES = 382, - TOKEN_VARCHAR = 383, - TOKEN_WHEN = 384, - TOKEN_WHERE = 385, - TOKEN_WINDOW = 386, - TOKEN_WITH = 387, - TOKEN_YEAR = 388, - TOKEN_YEARMONTH = 389, - TOKEN_EOF = 390, - TOKEN_LEX_ERROR = 391 + TOKEN_BIT = 285, + TOKEN_BITWEAVING = 286, + TOKEN_BLOCKPROPERTIES = 287, + TOKEN_BLOCKSAMPLE = 288, + TOKEN_BLOOM_FILTER = 289, + TOKEN_CSB_TREE = 290, + TOKEN_BY = 291, + TOKEN_CASE = 292, + TOKEN_CAST = 293, + TOKEN_CHECK = 294, + TOKEN_COLUMN = 295, + TOKEN_CONSTRAINT = 296, + TOKEN_COPY = 297, + TOKEN_CREATE = 298, + TOKEN_CURRENT = 299, + TOKEN_DAY = 300, + TOKEN_DEFAULT = 301, + TOKEN_DELETE = 302, + TOKEN_DESC = 303, + TOKEN_DISTINCT = 304, + TOKEN_DOUBLECOLON = 305, + TOKEN_DROP = 306, + TOKEN_ELSE = 307, + TOKEN_END = 308, + TOKEN_EXISTS = 309, + TOKEN_EXTRACT = 310, + TOKEN_FALSE = 311, + TOKEN_FIRST = 312, + TOKEN_FOLLOWING = 313, + TOKEN_FOR = 314, + TOKEN_FOREIGN = 315, + TOKEN_FROM = 316, + TOKEN_FULL = 317, + TOKEN_GROUP = 318, + TOKEN_HASH = 319, + TOKEN_HAVING = 320, + TOKEN_HOUR = 321, + TOKEN_IN = 322, + TOKEN_INDEX = 323, + TOKEN_INNER = 324, + TOKEN_INSERT = 325, + TOKEN_INTERVAL = 326, + TOKEN_INTO = 327, + TOKEN_JOIN = 328, + TOKEN_KEY = 329, + TOKEN_LAST = 330, + TOKEN_LBRACE = 331, + TOKEN_LEFT = 332, + TOKEN_LIMIT = 333, + TOKEN_MINUTE = 334, + TOKEN_MONTH = 335, + TOKEN_NULL = 336, + TOKEN_NULLS = 337, + TOKEN_OFF = 338, + TOKEN_ON = 339, + TOKEN_ORDER = 340, + TOKEN_OUTER = 341, + TOKEN_OVER = 342, + TOKEN_PARTITION = 343, + TOKEN_PARTITIONS = 344, + TOKEN_PERCENT = 345, + TOKEN_PRECEDING = 346, + TOKEN_PRIMARY = 347, + TOKEN_PRIORITY = 348, + TOKEN_QUIT = 349, + TOKEN_RANGE = 350, + TOKEN_RBRACE = 351, + TOKEN_REAL = 352, + TOKEN_REFERENCES = 353, + TOKEN_RIGHT = 354, + TOKEN_ROW = 355, + TOKEN_ROW_DELIMITER = 356, + TOKEN_ROWS = 357, + TOKEN_SECOND = 358, + TOKEN_SELECT = 359, + TOKEN_SET = 360, + TOKEN_SMA = 361, + TOKEN_STDERR = 362, + TOKEN_STDOUT = 363, + TOKEN_SUBSTRING = 364, + TOKEN_TABLE = 365, + TOKEN_THEN = 366, + TOKEN_TO = 367, + TOKEN_TRUE = 368, + TOKEN_TUPLESAMPLE = 369, + TOKEN_UNBOUNDED = 370, + TOKEN_UNIQUE = 371, + TOKEN_UPDATE = 372, + TOKEN_USING = 373, + TOKEN_VALUES = 374, + TOKEN_WHEN = 375, + TOKEN_WHERE = 376, + TOKEN_WINDOW = 377, + TOKEN_WITH = 378, + TOKEN_YEAR = 379, + TOKEN_EOF = 380, + TOKEN_LEX_ERROR = 381 }; #endif @@ -330,7 +315,7 @@ extern int quickstep_yydebug; union YYSTYPE { -#line 121 "../SqlParser.ypp" /* yacc.c:355 */ +#line 116 "../SqlParser.ypp" /* yacc.c:355 */ quickstep::ParseString *string_value_; @@ -402,9 +387,10 @@ union YYSTYPE quickstep::ParseStatementQuit *quit_statement_; const quickstep::Comparison *comparison_; - const quickstep::UnaryOperation *unary_operation_; - const quickstep::BinaryOperation *binary_operation_; + quickstep::ParseString *unary_operation_; + quickstep::ParseString *binary_operation_; + quickstep::ParseArray *array_expression_; quickstep::ParseFunctionCall *function_call_; quickstep::PtrList *expression_list_; @@ -431,7 +417,7 @@ union YYSTYPE quickstep::ParsePriority *opt_priority_clause_; -#line 435 "SqlParser_gen.cpp" /* yacc.c:355 */ +#line 421 "SqlParser_gen.cpp" /* yacc.c:355 */ }; typedef union YYSTYPE YYSTYPE; @@ -460,13 +446,13 @@ int quickstep_yyparse (yyscan_t yyscanner, quickstep::ParseStatement **parsedSta #endif /* !YY_QUICKSTEP_YY_SQLPARSER_GEN_HPP_INCLUDED */ /* Copy the second part of user declarations. */ -#line 222 "../SqlParser.ypp" /* yacc.c:358 */ +#line 218 "../SqlParser.ypp" /* yacc.c:358 */ /* This header needs YYSTYPE, which is defined by the %union directive above */ #include "SqlLexer_gen.hpp" void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string &feature); -#line 470 "SqlParser_gen.cpp" /* yacc.c:358 */ +#line 456 "SqlParser_gen.cpp" /* yacc.c:358 */ #ifdef short # undef short @@ -710,21 +696,21 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 50 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 1391 +#define YYLAST 792 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 148 +#define YYNTOKENS 138 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 110 +#define YYNNTS 115 /* YYNRULES -- Number of rules. */ -#define YYNRULES 298 +#define YYNRULES 296 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 550 +#define YYNSTATES 554 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 391 +#define YYMAXUTOK 381 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -734,11 +720,11 @@ union yyalloc static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 143, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 133, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 147, 2, 2, - 144, 145, 23, 21, 146, 22, 27, 24, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 142, + 2, 2, 2, 2, 2, 2, 2, 137, 2, 2, + 134, 135, 23, 21, 136, 22, 27, 24, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 132, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -771,44 +757,43 @@ static const yytype_uint8 yytranslate[] = 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, - 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, - 140, 141 + 130, 131 }; #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 640, 640, 644, 648, 652, 656, 659, 666, 669, - 672, 675, 678, 681, 684, 687, 690, 693, 699, 705, - 712, 718, 725, 734, 739, 748, 753, 758, 762, 768, - 773, 776, 779, 784, 787, 790, 793, 796, 799, 802, - 805, 808, 811, 823, 826, 829, 847, 867, 870, 873, - 878, 883, 889, 895, 904, 908, 914, 917, 922, 927, - 932, 939, 946, 950, 956, 959, 964, 967, 972, 975, - 980, 983, 1002, 1005, 1010, 1014, 1020, 1023, 1026, 1029, - 1034, 1037, 1040, 1047, 1052, 1063, 1068, 1073, 1077, 1081, - 1087, 1090, 1096, 1104, 1107, 1110, 1116, 1121, 1126, 1130, - 1136, 1140, 1143, 1148, 1151, 1156, 1161, 1166, 1170, 1176, - 1185, 1188, 1193, 1196, 1215, 1220, 1224, 1230, 1236, 1245, - 1250, 1258, 1264, 1270, 1273, 1276, 1281, 1284, 1289, 1293, - 1299, 1302, 1305, 1310, 1315, 1320, 1323, 1326, 1331, 1334, - 1337, 1340, 1343, 1346, 1349, 1352, 1357, 1360, 1365, 1369, - 1373, 1376, 1380, 1383, 1388, 1391, 1396, 1399, 1404, 1408, - 1414, 1417, 1422, 1425, 1430, 1433, 1438, 1441, 1460, 1463, - 1468, 1472, 1478, 1484, 1489, 1492, 1497, 1500, 1505, 1508, - 1513, 1516, 1521, 1522, 1525, 1530, 1531, 1534, 1539, 1543, - 1549, 1556, 1559, 1562, 1567, 1570, 1573, 1579, 1582, 1587, - 1592, 1601, 1606, 1615, 1620, 1623, 1628, 1631, 1636, 1642, - 1648, 1651, 1654, 1657, 1660, 1663, 1669, 1678, 1681, 1686, - 1689, 1694, 1697, 1702, 1705, 1708, 1711, 1715, 1719, 1722, - 1725, 1728, 1731, 1736, 1740, 1744, 1747, 1752, 1757, 1761, - 1767, 1770, 1775, 1779, 1785, 1790, 1794, 1800, 1805, 1808, - 1813, 1817, 1823, 1826, 1829, 1832, 1844, 1848, 1867, 1880, - 1895, 1898, 1901, 1904, 1907, 1910, 1915, 1919, 1925, 1928, - 1933, 1937, 1944, 1947, 1950, 1953, 1956, 1959, 1962, 1965, - 1968, 1971, 1976, 1987, 1990, 1995, 1998, 2001, 2007, 2011, - 2017, 2020, 2028, 2031, 2034, 2037, 2043, 2048, 2053 + 0, 632, 632, 636, 640, 644, 648, 651, 658, 661, + 664, 667, 670, 673, 676, 679, 682, 685, 691, 697, + 704, 710, 717, 726, 731, 740, 745, 750, 754, 760, + 763, 768, 774, 780, 785, 792, 795, 798, 803, 806, + 809, 814, 819, 825, 831, 840, 844, 850, 853, 858, + 863, 868, 875, 882, 886, 892, 895, 900, 903, 908, + 911, 916, 919, 938, 941, 946, 950, 956, 959, 962, + 965, 970, 973, 976, 983, 988, 999, 1004, 1009, 1013, + 1017, 1023, 1026, 1032, 1040, 1043, 1046, 1052, 1057, 1062, + 1066, 1072, 1076, 1079, 1084, 1087, 1092, 1097, 1102, 1106, + 1112, 1121, 1124, 1129, 1132, 1151, 1156, 1160, 1166, 1172, + 1181, 1186, 1194, 1200, 1206, 1209, 1212, 1217, 1220, 1225, + 1229, 1235, 1238, 1241, 1246, 1251, 1256, 1259, 1262, 1267, + 1270, 1273, 1276, 1279, 1282, 1285, 1288, 1293, 1296, 1301, + 1305, 1309, 1312, 1316, 1319, 1324, 1327, 1332, 1335, 1340, + 1344, 1350, 1353, 1358, 1361, 1366, 1369, 1374, 1377, 1396, + 1399, 1404, 1408, 1414, 1420, 1425, 1428, 1433, 1436, 1441, + 1444, 1449, 1452, 1457, 1458, 1461, 1466, 1467, 1470, 1475, + 1479, 1485, 1492, 1495, 1498, 1503, 1506, 1509, 1515, 1518, + 1523, 1528, 1537, 1542, 1551, 1556, 1559, 1564, 1567, 1572, + 1578, 1584, 1587, 1590, 1593, 1596, 1599, 1605, 1614, 1620, + 1625, 1631, 1636, 1641, 1646, 1649, 1652, 1655, 1658, 1662, + 1666, 1669, 1672, 1675, 1678, 1681, 1686, 1689, 1695, 1699, + 1706, 1710, 1714, 1717, 1722, 1725, 1730, 1741, 1749, 1760, + 1763, 1768, 1772, 1778, 1783, 1787, 1793, 1798, 1801, 1806, + 1810, 1816, 1819, 1822, 1825, 1837, 1841, 1860, 1875, 1878, + 1881, 1884, 1887, 1890, 1895, 1899, 1905, 1908, 1913, 1917, + 1924, 1927, 1930, 1933, 1936, 1939, 1942, 1945, 1948, 1951, + 1956, 1967, 1970, 1975, 1978, 1981, 1987, 1991, 1997, 2000, + 2008, 2011, 2014, 2017, 2023, 2028, 2033 }; #endif @@ -824,42 +809,40 @@ static const char *const yytname[] = "TOKEN_NEQ", "TOKEN_LIKE", "TOKEN_REGEXP", "TOKEN_BETWEEN", "TOKEN_IS", "'+'", "'-'", "'*'", "'/'", "UNARY_PLUS", "UNARY_MINUS", "'.'", "TOKEN_ALL", "TOKEN_UNION", "TOKEN_INTERSECT", "TOKEN_ADD", - "TOKEN_ALTER", "TOKEN_AS", "TOKEN_ASC", "TOKEN_BIGINT", "TOKEN_BIT", - "TOKEN_BITWEAVING", "TOKEN_BLOCKPROPERTIES", "TOKEN_BLOCKSAMPLE", - "TOKEN_BLOOM_FILTER", "TOKEN_CSB_TREE", "TOKEN_BY", "TOKEN_CASE", - "TOKEN_CHARACTER", "TOKEN_CHECK", "TOKEN_COLUMN", "TOKEN_CONSTRAINT", - "TOKEN_COPY", "TOKEN_CREATE", "TOKEN_CURRENT", "TOKEN_DATE", - "TOKEN_DATETIME", "TOKEN_DAY", "TOKEN_DECIMAL", "TOKEN_DEFAULT", - "TOKEN_DELETE", "TOKEN_DESC", "TOKEN_DISTINCT", "TOKEN_DOUBLE", - "TOKEN_DROP", "TOKEN_ELSE", "TOKEN_END", "TOKEN_EXISTS", "TOKEN_EXTRACT", - "TOKEN_FALSE", "TOKEN_FIRST", "TOKEN_FLOAT", "TOKEN_FOLLOWING", - "TOKEN_FOR", "TOKEN_FOREIGN", "TOKEN_FROM", "TOKEN_FULL", "TOKEN_GROUP", - "TOKEN_HASH", "TOKEN_HAVING", "TOKEN_HOUR", "TOKEN_IN", "TOKEN_INDEX", - "TOKEN_INNER", "TOKEN_INSERT", "TOKEN_INTEGER", "TOKEN_INTERVAL", - "TOKEN_INTO", "TOKEN_JOIN", "TOKEN_KEY", "TOKEN_LAST", "TOKEN_LEFT", - "TOKEN_LIMIT", "TOKEN_LONG", "TOKEN_MINUTE", "TOKEN_MONTH", "TOKEN_NULL", - "TOKEN_NULLS", "TOKEN_OFF", "TOKEN_ON", "TOKEN_ORDER", "TOKEN_OUTER", - "TOKEN_OVER", "TOKEN_PARTITION", "TOKEN_PARTITIONS", "TOKEN_PERCENT", + "TOKEN_ALTER", "TOKEN_AS", "TOKEN_ASC", "TOKEN_BIT", "TOKEN_BITWEAVING", + "TOKEN_BLOCKPROPERTIES", "TOKEN_BLOCKSAMPLE", "TOKEN_BLOOM_FILTER", + "TOKEN_CSB_TREE", "TOKEN_BY", "TOKEN_CASE", "TOKEN_CAST", "TOKEN_CHECK", + "TOKEN_COLUMN", "TOKEN_CONSTRAINT", "TOKEN_COPY", "TOKEN_CREATE", + "TOKEN_CURRENT", "TOKEN_DAY", "TOKEN_DEFAULT", "TOKEN_DELETE", + "TOKEN_DESC", "TOKEN_DISTINCT", "TOKEN_DOUBLECOLON", "TOKEN_DROP", + "TOKEN_ELSE", "TOKEN_END", "TOKEN_EXISTS", "TOKEN_EXTRACT", + "TOKEN_FALSE", "TOKEN_FIRST", "TOKEN_FOLLOWING", "TOKEN_FOR", + "TOKEN_FOREIGN", "TOKEN_FROM", "TOKEN_FULL", "TOKEN_GROUP", "TOKEN_HASH", + "TOKEN_HAVING", "TOKEN_HOUR", "TOKEN_IN", "TOKEN_INDEX", "TOKEN_INNER", + "TOKEN_INSERT", "TOKEN_INTERVAL", "TOKEN_INTO", "TOKEN_JOIN", + "TOKEN_KEY", "TOKEN_LAST", "TOKEN_LBRACE", "TOKEN_LEFT", "TOKEN_LIMIT", + "TOKEN_MINUTE", "TOKEN_MONTH", "TOKEN_NULL", "TOKEN_NULLS", "TOKEN_OFF", + "TOKEN_ON", "TOKEN_ORDER", "TOKEN_OUTER", "TOKEN_OVER", + "TOKEN_PARTITION", "TOKEN_PARTITIONS", "TOKEN_PERCENT", "TOKEN_PRECEDING", "TOKEN_PRIMARY", "TOKEN_PRIORITY", "TOKEN_QUIT", - "TOKEN_RANGE", "TOKEN_REAL", "TOKEN_REFERENCES", "TOKEN_RIGHT", - "TOKEN_ROW", "TOKEN_ROW_DELIMITER", "TOKEN_ROWS", "TOKEN_SECOND", - "TOKEN_SELECT", "TOKEN_SET", "TOKEN_SMA", "TOKEN_SMALLINT", - "TOKEN_STDERR", "TOKEN_STDOUT", "TOKEN_SUBSTRING", "TOKEN_TABLE", - "TOKEN_THEN", "TOKEN_TIME", "TOKEN_TIMESTAMP", "TOKEN_TO", "TOKEN_TRUE", - "TOKEN_TUPLESAMPLE", "TOKEN_UNBOUNDED", "TOKEN_UNIQUE", "TOKEN_UPDATE", - "TOKEN_USING", "TOKEN_VALUES", "TOKEN_VARCHAR", "TOKEN_WHEN", - "TOKEN_WHERE", "TOKEN_WINDOW", "TOKEN_WITH", "TOKEN_YEAR", - "TOKEN_YEARMONTH", "TOKEN_EOF", "TOKEN_LEX_ERROR", "';'", "'\\n'", "'('", - "')'", "','", "'%'", "$accept", "start", "sql_statement", - "quit_statement", "alter_table_statement", "create_table_statement", + "TOKEN_RANGE", "TOKEN_RBRACE", "TOKEN_REAL", "TOKEN_REFERENCES", + "TOKEN_RIGHT", "TOKEN_ROW", "TOKEN_ROW_DELIMITER", "TOKEN_ROWS", + "TOKEN_SECOND", "TOKEN_SELECT", "TOKEN_SET", "TOKEN_SMA", "TOKEN_STDERR", + "TOKEN_STDOUT", "TOKEN_SUBSTRING", "TOKEN_TABLE", "TOKEN_THEN", + "TOKEN_TO", "TOKEN_TRUE", "TOKEN_TUPLESAMPLE", "TOKEN_UNBOUNDED", + "TOKEN_UNIQUE", "TOKEN_UPDATE", "TOKEN_USING", "TOKEN_VALUES", + "TOKEN_WHEN", "TOKEN_WHERE", "TOKEN_WINDOW", "TOKEN_WITH", "TOKEN_YEAR", + "TOKEN_EOF", "TOKEN_LEX_ERROR", "';'", "'\\n'", "'('", "')'", "','", + "'%'", "$accept", "start", "sql_statement", "quit_statement", + "alter_table_statement", "create_table_statement", "create_index_statement", "drop_table_statement", "column_def", - "column_def_commalist", "data_type", "column_constraint_def", - "column_constraint_def_list", "opt_column_constraint_def_list", - "table_constraint_def", "table_constraint_def_commalist", - "opt_table_constraint_def_commalist", "opt_column_list", - "opt_block_properties", "opt_partition_clause", "partition_type", - "key_value_list", "key_value", "key_string_value", "key_string_list", - "key_integer_value", "key_bool_value", "index_type", + "column_def_commalist", "data_type", "data_type_parameter_commalist", + "opt_nullable", "column_constraint_def", "column_constraint_def_list", + "opt_column_constraint_def_list", "table_constraint_def", + "table_constraint_def_commalist", "opt_table_constraint_def_commalist", + "opt_column_list", "opt_block_properties", "opt_partition_clause", + "partition_type", "key_value_list", "key_value", "key_string_value", + "key_string_list", "key_integer_value", "key_bool_value", "index_type", "opt_index_properties", "insert_statement", "copy_statement", "copy_to_target", "opt_copy_params", "update_statement", "delete_statement", "assignment_list", "assignment_item", @@ -878,7 +861,8 @@ static const char *const yytname[] = "opt_order_direction", "opt_nulls_first", "opt_where_clause", "where_clause", "or_expression", "and_expression", "not_expression", "predicate_expression_base", "add_expression", "multiply_expression", - "unary_expression", "expression_base", "function_call", + "unary_expression", "expression_base", "array_expression", + "array_element_commalist", "function_call", "cast_function", "extract_function", "substr_function", "case_expression", "simple_when_clause_list", "simple_when_clause", "searched_when_clause_list", "searched_when_clause", "opt_else_clause", @@ -908,17 +892,16 @@ static const yytype_uint16 yytoknum[] = 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 391, 59, 10, 40, 41, 44, 37 + 380, 381, 59, 10, 40, 41, 44, 37 }; # endif -#define YYPACT_NINF -395 +#define YYPACT_NINF -257 #define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-395))) + (!!((Yystate) == (-257))) -#define YYTABLE_NINF -139 +#define YYTABLE_NINF -130 #define yytable_value_is_error(Yytable_value) \ 0 @@ -927,61 +910,62 @@ static const yytype_uint16 yytoknum[] = STATE-NUM. */ static const yytype_int16 yypact[] = { - 174, -395, -395, -64, 85, -26, 14, -31, -16, -395, - 40, 196, 196, -395, 109, 102, -395, -395, -395, -395, - -395, -395, -395, -395, -395, -395, 148, -3, 87, -395, - -40, 121, 196, -395, -395, 1, -5, 196, 196, 196, - 196, 196, -395, -395, 716, 82, 2, -395, 153, 63, - -395, -395, -395, 98, 152, -3, 40, 141, -395, 98, - -395, -395, -395, 12, 97, 116, 261, 116, 169, 126, - 138, -395, 176, -395, -395, 270, 274, -395, -395, -395, - 807, 139, -395, 210, -395, -395, 154, -395, -395, 297, - -395, -395, -395, -395, 172, -395, -395, 177, 231, 901, - 313, 265, 192, -395, -395, 338, 23, -395, -395, 243, - -395, -395, -395, -395, -395, 1083, -7, 196, 196, 214, - 196, 1, 196, -395, 98, 363, -395, 205, 263, -395, - -395, -395, 255, -395, 116, -395, 196, 196, 625, -395, - -395, 262, 196, -395, -395, -395, 625, 33, -29, -395, - 409, -395, 165, 165, 1174, 411, -395, -14, 28, -395, - 13, 138, 1174, -395, -395, 196, 1174, -395, -395, -395, - -395, 1174, 18, 274, -395, 196, 398, 59, -395, 417, - -395, 98, -395, 202, -395, 116, 98, 87, -395, 196, - 80, 196, 196, 196, -395, 285, -395, 211, 1241, 992, - 214, 534, 422, 423, -395, -395, 312, 415, 1252, 219, - 43, 1174, 61, -395, 1174, -395, 369, 292, -395, -395, - -395, -395, -395, -395, 367, -395, 216, 294, -395, -395, - 7, 186, 267, -395, 298, 186, 3, 372, -395, -395, - 23, -395, 347, -395, -395, 295, 1174, -395, 351, 229, - 196, -395, 1174, -395, 196, -395, -395, -395, 303, 366, - 368, 304, -395, -395, -395, 232, -395, -395, -395, -395, - -395, 34, 196, 323, 80, 196, -395, 188, -395, -395, - 4, 65, 625, 625, 276, -395, -395, -395, -395, -395, - -395, -395, -395, 1174, 311, 1174, 51, -395, 234, 326, - 1174, 71, -395, 399, 351, -395, -395, 1174, 453, -395, - 160, 196, -395, -395, 370, -395, 373, 374, 379, 13, - -395, 457, 462, 186, 430, 400, 431, 329, 380, -395, - 236, -395, 1174, -395, 351, -395, 625, 333, 334, 196, - -395, 196, -395, -395, -395, -395, -395, -395, -395, 196, - -395, -395, -395, 238, 454, 184, -395, 336, 348, -395, - 391, 342, 1252, -395, 403, 196, -395, -395, 188, -395, - -395, 423, -395, -395, -395, 1174, 345, 341, 901, -395, - 351, 401, -395, -395, 1252, 350, 351, 1174, -395, 37, - 35, -395, -395, -395, -395, -395, 13, 267, 390, 395, - -395, 1174, 625, 396, 1174, -395, 455, 108, -395, 351, - 8, 196, 196, 240, -395, 242, -395, 196, -395, -395, - -395, -395, 354, 80, 461, 402, -395, 625, -395, -395, - 356, -395, 346, 901, -395, 1174, 245, -395, -395, 1252, - 351, -395, 495, -395, 408, -395, -395, 358, 422, 464, - 420, 358, 1174, -395, -395, -395, 490, -395, 249, 251, - -395, -395, -395, 196, -395, -395, 375, 468, -395, 19, - 196, 1174, 264, 351, -395, 266, 371, 625, 1174, 504, - 376, 377, -395, 227, 46, 405, -395, 269, 196, -9, - -395, 381, 351, -395, -395, -395, 422, 377, -395, 196, - -395, 376, -395, 1174, -395, -395, 421, 418, 407, 425, - 515, 196, -395, 277, -395, -395, 384, -395, 496, -395, - -395, 49, -395, -395, -395, -395, 56, 386, -395, 196, - 388, -395, -395, 466, 426, 467, -395, 196, 279, 347, - -395, -395, -395, 281, 445, 404, -395, 539, -395, -395 + 653, -257, -257, 37, 86, 4, 58, 84, 157, -257, + 55, 286, 286, -257, 245, 185, -257, -257, -257, -257, + -257, -257, -257, -257, -257, -257, 169, -17, 226, -257, + 144, 276, 286, -257, -257, 10, -22, 286, 286, 286, + 286, 286, -257, -257, 479, 189, 125, -257, 271, 178, + -257, -257, -257, 217, 252, -17, 55, 254, -257, 217, + -257, -257, -257, 174, 79, 207, 354, 207, 281, 251, + 277, -257, -35, -257, -257, 393, 403, -257, 491, 280, + 294, 416, 503, -257, 316, 569, 379, 319, -257, -257, + 386, 7, -257, 396, -257, -39, 360, -257, -257, -257, + -257, -257, -257, 626, 48, 286, 286, 320, 286, 10, + 286, -257, 217, 449, -257, 26, 278, -257, -257, -257, + 323, -257, 207, -257, 286, 286, 472, -257, -257, 324, + 286, -257, -257, -257, 472, 72, 101, -257, 637, 156, + 156, -257, 310, 637, 35, 21, 14, 277, 637, -257, + -257, 286, 637, -257, -257, -257, -257, 637, 286, -257, + 637, 17, 403, 396, 286, 339, 162, -257, 450, -257, + 217, -257, 198, -257, 207, 217, 226, -257, 286, 152, + 286, 286, 286, -257, 326, -257, 206, 286, 576, 320, + 315, 455, 456, -257, -257, 720, 444, 232, 212, 16, + 637, 147, -257, 637, -257, 409, 274, -257, -257, -257, + -257, -257, -257, 402, -257, 39, -257, -257, 9, 74, + 335, -257, 334, 74, 53, 404, -257, -257, 7, -257, + -257, 215, 337, 310, 382, -257, -257, 345, 637, -257, + 310, 228, 286, -257, 637, -257, 286, -257, -257, -257, + 347, 408, 410, 356, -257, -257, -257, 237, -257, -257, + -257, -257, -257, 133, 286, 368, 152, 286, 149, -257, + -257, 6, 36, 472, 472, 283, -257, -257, -257, -257, + -257, -257, -257, -257, 637, 369, 637, 30, -257, 241, + 380, 637, 91, -257, 447, 310, -257, 286, 637, 499, + 151, 286, -257, -257, 425, -257, 426, 427, 441, 14, + -257, 513, 516, 74, 485, 457, -257, 362, 362, 487, + 395, 445, -257, 243, -257, 637, -257, 310, -257, 472, + 406, 407, 286, -257, 286, -257, -257, -257, -257, -257, + -257, -257, 286, -257, -257, -257, 253, 509, 192, -257, + 411, 414, -257, 452, 415, 232, -257, 464, 286, -257, + -257, 149, -257, -257, 456, -257, -257, -257, 637, 418, + 180, 569, -257, 310, 458, -257, -257, 232, 420, 310, + 637, -257, 421, 44, 122, -257, -257, -257, -257, -257, + 14, 335, 462, 466, -257, 637, 472, 460, 77, -257, + 77, -257, 637, -257, 518, 175, -257, 310, 11, 286, + 286, 259, -257, 262, -257, 286, -257, -257, -257, -257, + 428, 152, 527, 473, -257, 472, -257, -257, 434, -257, + 318, 569, -257, 637, 287, -257, -257, 232, 310, -257, + -257, 562, -257, 481, -257, -257, 435, 455, 537, 502, + 501, -257, -257, -257, 435, 637, -257, -257, -257, 573, + -257, 291, 295, -257, -257, -257, 286, -257, -257, 454, + 553, -257, 18, 286, 637, 297, 310, -257, 299, 461, + 472, 637, 588, 474, -257, 463, -257, 190, 49, 497, + -257, 301, 286, 0, -257, 467, 310, -257, -257, -257, + 455, 463, -257, 286, -257, 474, -257, 637, -257, -257, + 520, 507, 504, 512, 601, 286, -257, 306, -257, -257, + 480, -257, 582, -257, -257, 23, -257, -257, -257, -257, + 61, 486, -257, 286, 488, -257, -257, 558, 519, 560, + -257, 286, 308, 382, -257, -257, -257, 311, 532, 492, + -257, 621, -257, -257 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -989,93 +973,96 @@ static const yytype_int16 yypact[] = means the default is an error. */ static const yytype_uint16 yydefact[] = { - 0, 6, 298, 0, 0, 0, 0, 0, 0, 18, - 123, 0, 0, 7, 0, 0, 15, 8, 10, 11, - 13, 14, 9, 17, 12, 16, 0, 112, 119, 121, - 0, 296, 0, 290, 291, 0, 0, 0, 0, 0, - 0, 0, 124, 125, 0, 0, 114, 115, 0, 156, - 1, 3, 2, 0, 0, 112, 123, 0, 110, 0, - 5, 4, 297, 0, 0, 103, 0, 103, 0, 0, - 197, 25, 0, 256, 253, 0, 282, 126, 40, 29, - 0, 0, 30, 31, 34, 36, 0, 37, 39, 0, - 41, 252, 35, 38, 0, 32, 33, 0, 0, 0, - 0, 0, 127, 128, 232, 132, 218, 220, 222, 225, - 228, 229, 230, 224, 223, 0, 268, 0, 0, 0, - 0, 0, 0, 111, 0, 0, 120, 0, 0, 100, - 102, 101, 0, 98, 103, 97, 0, 0, 0, 106, - 198, 0, 0, 94, 254, 255, 0, 0, 248, 245, - 0, 43, 0, 257, 0, 0, 44, 0, 0, 259, - 0, 197, 0, 283, 284, 0, 0, 131, 286, 287, - 285, 0, 0, 0, 221, 0, 0, 197, 108, 0, - 116, 0, 117, 0, 288, 103, 0, 118, 113, 0, - 0, 0, 0, 0, 96, 66, 27, 0, 0, 0, - 0, 0, 199, 201, 203, 205, 0, 223, 0, 0, - 0, 0, 248, 242, 0, 246, 0, 0, 262, 263, - 264, 261, 265, 260, 0, 258, 0, 0, 134, 231, - 0, 0, 158, 147, 133, 152, 135, 160, 129, 130, - 217, 219, 174, 226, 269, 0, 0, 233, 250, 0, - 0, 105, 0, 157, 0, 99, 95, 19, 0, 0, - 0, 0, 20, 21, 22, 0, 74, 76, 77, 78, - 79, 0, 0, 0, 64, 0, 42, 56, 204, 212, - 0, 0, 0, 0, 0, 272, 274, 275, 276, 277, - 273, 278, 280, 0, 0, 0, 0, 266, 0, 0, - 0, 0, 243, 0, 249, 241, 45, 0, 0, 46, - 138, 0, 148, 154, 144, 139, 140, 142, 0, 0, - 151, 0, 0, 150, 0, 162, 0, 0, 176, 234, - 0, 235, 0, 107, 109, 289, 0, 0, 0, 0, - 104, 0, 81, 84, 82, 294, 295, 293, 292, 0, - 80, 85, 270, 0, 268, 0, 63, 65, 68, 28, - 0, 0, 0, 47, 0, 0, 49, 55, 57, 26, - 211, 200, 202, 279, 281, 0, 0, 0, 0, 213, - 210, 0, 209, 93, 0, 0, 247, 0, 240, 0, - 0, 153, 155, 145, 141, 143, 0, 159, 0, 0, - 149, 0, 0, 164, 0, 227, 0, 178, 236, 251, - 0, 0, 0, 0, 75, 0, 67, 0, 86, 87, - 88, 89, 90, 0, 0, 70, 48, 0, 51, 50, - 0, 54, 0, 0, 215, 0, 0, 208, 267, 0, - 244, 237, 0, 238, 0, 136, 137, 161, 163, 0, - 166, 175, 0, 181, 180, 173, 0, 61, 0, 0, - 58, 83, 271, 0, 24, 62, 0, 0, 23, 0, - 0, 0, 0, 206, 214, 0, 0, 0, 0, 0, - 168, 177, 188, 191, 0, 0, 59, 0, 0, 0, - 52, 0, 207, 216, 92, 239, 146, 165, 167, 0, - 122, 169, 170, 0, 192, 193, 194, 0, 0, 0, - 0, 0, 91, 0, 72, 73, 0, 53, 0, 171, - 189, 0, 190, 182, 184, 183, 0, 0, 69, 0, - 0, 195, 196, 0, 0, 0, 179, 0, 0, 174, - 185, 187, 186, 0, 0, 0, 60, 0, 172, 71 + 0, 6, 296, 0, 0, 0, 0, 0, 0, 18, + 114, 0, 0, 7, 0, 0, 15, 8, 10, 11, + 13, 14, 9, 17, 12, 16, 0, 103, 110, 112, + 0, 294, 0, 288, 289, 0, 0, 0, 0, 0, + 0, 0, 115, 116, 0, 0, 105, 106, 0, 147, + 1, 3, 2, 0, 0, 103, 114, 0, 101, 0, + 5, 4, 295, 0, 0, 94, 0, 94, 0, 0, + 188, 25, 0, 255, 252, 0, 280, 117, 0, 0, + 0, 0, 0, 251, 0, 0, 0, 118, 119, 225, + 123, 209, 211, 213, 216, 0, 217, 220, 221, 222, + 223, 215, 214, 0, 266, 0, 0, 0, 0, 0, + 0, 102, 0, 0, 111, 0, 0, 91, 93, 92, + 0, 89, 94, 88, 0, 0, 0, 97, 189, 0, + 0, 85, 253, 254, 0, 0, 247, 244, 0, 0, + 256, 227, 229, 0, 0, 0, 0, 188, 0, 281, + 282, 0, 0, 122, 284, 285, 283, 0, 0, 226, + 0, 0, 0, 212, 0, 0, 188, 99, 0, 107, + 0, 108, 0, 286, 94, 0, 109, 104, 0, 0, + 0, 0, 0, 87, 57, 27, 0, 0, 0, 0, + 0, 190, 192, 194, 196, 0, 214, 0, 0, 0, + 0, 247, 241, 0, 245, 0, 0, 260, 261, 262, + 259, 263, 258, 0, 257, 0, 125, 224, 0, 0, + 149, 138, 124, 143, 126, 151, 120, 121, 208, 210, + 235, 0, 29, 228, 165, 218, 267, 0, 0, 230, + 249, 0, 0, 96, 0, 148, 0, 90, 86, 19, + 0, 0, 0, 0, 20, 21, 22, 0, 65, 67, + 68, 69, 70, 0, 0, 0, 55, 0, 47, 195, + 203, 0, 0, 0, 0, 0, 270, 272, 273, 274, + 275, 271, 276, 278, 0, 0, 0, 0, 264, 0, + 0, 0, 0, 242, 0, 248, 240, 0, 0, 0, + 129, 0, 139, 145, 135, 130, 131, 133, 0, 0, + 142, 0, 0, 141, 0, 153, 30, 0, 0, 0, + 0, 167, 231, 0, 232, 0, 98, 100, 287, 0, + 0, 0, 0, 95, 0, 72, 75, 73, 292, 293, + 291, 290, 0, 71, 76, 268, 0, 266, 0, 54, + 56, 59, 28, 0, 0, 0, 38, 0, 0, 40, + 46, 48, 26, 202, 191, 193, 277, 279, 0, 0, + 0, 0, 204, 201, 0, 200, 84, 0, 0, 246, + 0, 239, 0, 0, 0, 144, 146, 136, 132, 134, + 0, 150, 0, 0, 140, 0, 0, 155, 35, 34, + 35, 33, 0, 219, 0, 169, 233, 250, 0, 0, + 0, 0, 66, 0, 58, 0, 77, 78, 79, 80, + 81, 0, 0, 61, 39, 0, 42, 41, 0, 45, + 0, 0, 206, 0, 0, 199, 265, 0, 243, 234, + 236, 0, 237, 0, 127, 128, 152, 154, 0, 157, + 0, 36, 32, 31, 166, 0, 172, 171, 164, 0, + 52, 0, 0, 49, 74, 269, 0, 24, 53, 0, + 0, 23, 0, 0, 0, 0, 197, 205, 0, 0, + 0, 0, 0, 159, 37, 168, 179, 182, 0, 0, + 50, 0, 0, 0, 43, 0, 198, 207, 83, 238, + 137, 156, 158, 0, 113, 160, 161, 0, 183, 184, + 185, 0, 0, 0, 0, 0, 82, 0, 63, 64, + 0, 44, 0, 162, 180, 0, 181, 173, 175, 174, + 0, 0, 60, 0, 0, 186, 187, 0, 0, 0, + 170, 0, 0, 165, 176, 178, 177, 0, 0, 0, + 51, 0, 163, 62 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -395, -395, -395, -395, -395, -395, -395, -395, -164, -395, - 349, 180, -395, -395, -271, -395, -395, -395, -395, -395, - -395, -394, 209, -395, -395, -395, -395, -395, -395, -395, - -395, 24, -46, -395, -395, -395, 301, -395, 497, -395, - -395, 435, 259, 433, -28, 498, -395, -395, 397, -395, - -90, -395, -395, -207, 162, -187, -10, -395, -395, -395, - -395, -395, -395, -395, 60, 21, -395, -395, -395, -395, - -395, -395, 84, 62, -395, -395, -54, -395, -145, 282, - 280, 382, -35, 406, 412, 451, -156, -395, -395, -395, - -395, 355, -395, 427, 359, -232, -203, 429, 129, -128, - -395, -395, -395, -395, -395, -136, -4, -395, -395, -395 + -257, -257, -257, -257, -257, -257, -257, -257, -105, -257, + -182, -257, 234, 279, -257, -257, -255, -257, -257, -257, + -257, -257, -257, -256, 304, -257, -257, -257, -257, -257, + -257, -257, -257, 5, -40, -257, -257, -257, 397, -257, + 591, -257, -257, 543, 258, 539, -50, 597, -257, -257, + 515, -257, -101, -257, -257, -180, 270, -191, -10, -257, + -257, -257, -257, -257, -257, -257, 159, 118, -257, -257, + -257, -257, -257, -257, 184, 160, -257, -257, 100, -257, + -131, 398, 392, 482, -15, 521, 517, 572, -257, -257, + -142, -257, -257, -257, -257, -257, 471, -257, 540, 476, + -222, -187, 541, 247, -109, -257, -257, -257, -257, -257, + -129, -4, -257, -257, -257 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 14, 15, 16, 17, 18, 19, 20, 196, 197, - 100, 367, 368, 369, 262, 357, 358, 273, 425, 468, - 516, 265, 266, 267, 268, 269, 270, 422, 464, 21, - 22, 65, 133, 23, 24, 177, 178, 25, 58, 26, - 46, 47, 157, 28, 29, 44, 101, 102, 103, 161, - 104, 323, 318, 232, 233, 312, 313, 234, 325, 403, - 450, 480, 500, 501, 502, 327, 328, 407, 455, 456, - 510, 536, 481, 482, 506, 522, 139, 140, 202, 203, - 204, 205, 206, 106, 107, 108, 109, 110, 111, 112, - 212, 213, 148, 149, 216, 249, 113, 224, 298, 114, - 353, 295, 115, 166, 171, 183, 116, 351, 30, 31 + -1, 14, 15, 16, 17, 18, 19, 20, 185, 186, + 230, 231, 452, 360, 361, 362, 254, 350, 351, 265, + 423, 471, 520, 257, 258, 259, 260, 261, 262, 420, + 467, 21, 22, 65, 121, 23, 24, 166, 167, 25, + 58, 26, 46, 47, 144, 28, 29, 44, 86, 87, + 88, 147, 89, 313, 308, 220, 221, 302, 303, 222, + 315, 397, 449, 483, 504, 505, 506, 320, 321, 405, + 458, 459, 514, 540, 485, 486, 510, 526, 127, 128, + 191, 192, 193, 194, 195, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 201, 202, 136, 137, 205, + 241, 101, 213, 289, 102, 346, 286, 103, 152, 157, + 172, 104, 344, 30, 31 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If @@ -1083,386 +1070,267 @@ static const yytype_int16 yydefgoto[] = number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { - 36, 210, 48, 356, 235, 297, 209, 45, 49, 105, - 207, 33, 282, 34, 330, 56, 282, 33, 207, 34, - 175, 135, 33, 310, 34, 257, 56, 282, 63, 182, - 56, 126, 214, 68, 69, 70, 71, 72, 33, 342, - 34, 343, 321, 127, 143, 147, 168, 169, 320, 163, - 164, 282, 37, 507, 163, 164, 280, 32, 163, 164, - 67, 381, 344, 533, 158, 514, 66, 41, 42, 487, - 231, 207, 128, 207, 235, 284, 285, 286, 287, 288, - 289, 290, 291, 292, 293, 39, 163, 164, 194, 33, - 40, 34, 163, 164, 513, 38, 508, 515, 43, 345, - 60, 167, 129, 61, 442, 146, 534, 237, 48, 50, - 279, 359, 397, 179, 49, 531, 184, 59, 186, 226, - 64, 10, 214, 251, 62, 258, 64, 105, 346, 347, - 322, 228, 195, 198, 57, 532, 400, 176, 184, 255, - 231, 248, 294, 382, 352, 185, 436, 176, 118, 370, - 259, 230, 465, 457, 207, 207, 236, 230, 256, 428, - 348, 239, 242, 235, 490, 300, 281, 211, 243, 447, - 170, 244, 451, 229, 509, 1, 301, 2, 349, 304, - 443, 438, 441, 260, 535, 198, 119, 263, 264, 271, - 33, 410, 34, 387, 138, 211, 53, 117, 360, 10, - 33, 472, 34, 413, 379, 250, 3, 120, 207, 261, - 229, 248, 10, 415, 453, 130, 131, 334, 218, 311, - 454, 418, 4, 5, 419, 420, 236, 49, 54, 231, - 6, 49, 314, 361, 7, 122, 297, 163, 164, 315, - 235, 219, 51, 362, 52, 125, 179, 316, 163, 164, - 335, 189, 190, 132, 8, 220, 221, 448, 377, 27, - 380, 504, 10, 35, 136, 386, 134, 350, 354, 317, - 137, 198, 389, 138, 207, 458, 459, 144, 222, 9, - 363, 145, 469, 150, 505, 55, 434, 308, 10, 462, - 10, 364, 151, 373, 374, 375, 365, 409, 152, 207, - 421, 392, 153, 223, 11, 391, 231, 49, 141, 191, - 192, 12, 121, 156, 13, 236, 154, 366, 159, 49, - 142, 155, 284, 285, 286, 287, 288, 289, 290, 291, - 292, 293, 496, 163, 164, 184, 160, 271, 162, 314, - 432, 172, 33, 248, 34, 184, 315, 253, 254, 207, - 435, -138, 440, 376, 316, 471, 274, 275, 181, 163, - 164, 430, 163, 164, 299, 254, 248, 163, 164, 248, - 188, 165, 163, 164, 331, 332, 317, 340, 341, 383, - 384, 408, 332, 416, 417, 460, 254, 461, 254, 294, - 474, 332, 236, 538, 485, 254, 486, 254, 248, 193, - 473, 543, 33, 73, 34, 74, 208, 184, 184, 493, - 332, 494, 384, 354, 512, 341, 217, 483, 227, 75, - 76, 245, 528, 341, 544, 254, 546, 254, 252, 272, - 282, 305, 283, 78, 79, 296, 492, 306, 307, 309, - 329, 80, 81, 483, 319, 324, 326, 336, 339, 82, - 83, 337, 84, 338, 355, 378, 246, 85, 385, 271, - 390, 388, 86, 396, 398, 87, 491, 393, 483, 399, - 394, 395, 401, 404, 405, 402, 406, 411, 412, 88, - 89, 175, 423, 426, 271, 424, 427, 90, 429, 433, - 91, 445, 449, 437, 439, 518, 446, 452, 463, 466, - 470, 467, 476, 477, 332, 92, 478, 527, 479, 484, - 489, 498, 499, 511, 521, 93, 495, 524, 94, 488, - 523, 95, 96, 503, 526, 184, 517, 525, 529, 530, - 537, 97, 539, 184, 540, 542, 541, 98, 33, 73, - 34, 74, 99, 247, 199, 547, 549, 277, 431, 548, - 414, 333, 123, 180, 124, 75, 76, 187, 444, 238, - 545, 519, 497, 372, 371, 520, 174, 302, 475, 78, - 79, 303, 240, 0, 0, 215, 0, 80, 81, 0, - 0, 278, 225, 241, 0, 82, 83, 0, 84, 0, - 0, 0, 0, 85, 0, 0, 0, 200, 86, 0, - 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 88, 89, 0, 0, 0, - 0, 0, 0, 90, 0, 0, 91, 0, 0, 33, - 73, 34, 74, 0, 0, 199, 0, 0, 0, 0, - 0, 92, 0, 0, 0, 0, 75, 76, 10, 0, - 0, 93, 0, 0, 94, 0, 0, 95, 96, 0, - 78, 79, 0, 0, 0, 0, 0, 97, 80, 81, - 0, 0, 0, 98, 0, 0, 82, 83, 201, 84, - 0, 0, 0, 0, 85, 0, 0, 0, 200, 86, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 88, 89, 0, 0, - 0, 0, 0, 0, 90, 0, 0, 91, 0, 0, - 33, 73, 34, 74, 0, 0, 0, 0, 0, 0, - 0, 0, 92, 0, 0, 0, 0, 75, 76, 77, - 0, 0, 93, 0, 0, 94, 0, 0, 95, 96, - 0, 78, 79, 0, 0, 0, 0, 0, 97, 80, - 81, 0, 0, 0, 98, 0, 0, 82, 83, 201, - 84, 0, 0, 0, 0, 85, 0, 0, 0, 0, - 86, 0, 0, 87, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 88, 89, 0, - 0, 0, 0, 0, 0, 90, 0, 0, 91, 0, - 0, 33, 73, 34, 74, 0, 0, 0, 0, 0, - 0, 0, 0, 92, 0, 0, 0, 0, 75, 76, - 0, 0, 0, 93, 0, 0, 94, 0, 0, 95, - 96, 0, 78, 79, 0, 0, 0, 0, 0, 97, - 80, 81, 0, 0, 0, 98, 0, 0, 82, 83, - 99, 84, 0, 0, 0, 0, 85, 0, 0, 0, - 0, 86, 0, 0, 87, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 88, 89, - 0, 0, 0, 0, 0, 0, 90, 0, 0, 91, - 0, 0, 0, 0, 0, 33, 73, 34, 74, 0, - 0, 0, 0, 0, 92, 0, 0, 0, 0, 0, - 0, 0, 75, 76, 93, 0, 0, 94, 0, 0, - 95, 96, 0, 0, 0, 0, 78, 79, 0, 0, - 97, 146, 0, 0, 80, 81, 98, 0, 0, 0, - 0, 99, 82, 83, 0, 84, 0, 0, 0, 0, - 85, 0, 0, 0, 0, 86, 0, 0, 87, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 88, 89, 0, 0, 0, 0, 0, 0, - 90, 0, 0, 91, 0, 0, 33, 73, 34, 74, - 0, 0, 0, 0, 0, 0, 0, 0, 92, 0, - 0, 0, 0, 75, 76, 10, 0, 0, 93, 0, - 0, 94, 0, 0, 95, 96, 0, 78, 79, 0, - 0, 0, 0, 0, 97, 80, 81, 0, 0, 0, - 98, 0, 0, 82, 83, 99, 84, 0, 0, 0, - 0, 85, 0, 0, 0, 200, 86, 0, 0, 87, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 88, 89, 0, 0, 0, 0, 0, - 0, 90, 0, 0, 91, 0, 0, 33, 73, 34, - 74, 0, 0, 0, 0, 0, 0, 0, 0, 92, - 0, 0, 0, 0, 75, 173, 0, 0, 0, 93, - 0, 0, 94, 0, 0, 95, 96, 0, 78, 79, - 0, 0, 0, 0, 0, 97, 80, 81, 0, 0, - 0, 98, 0, 0, 82, 83, 201, 84, 0, 0, - 0, 0, 85, 0, 0, 0, 0, 86, 0, 0, - 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 88, 89, 0, 0, 0, 0, - 0, 0, 90, 0, 0, 91, 0, 0, 33, 73, - 34, 74, 0, 0, 0, 0, 0, 0, 0, 0, - 92, 0, 0, 0, 0, 75, 76, 0, 0, 0, - 93, 0, 0, 94, 0, 0, 95, 96, 0, 78, - 79, 0, 0, 0, 0, 0, 97, 80, 81, 0, - 0, 0, 98, 0, 0, 82, 83, 99, 84, 0, - 0, 0, 0, 85, 0, 0, 0, 0, 86, 0, - 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 88, 89, 73, 0, 74, - 0, 0, 0, 90, 0, 0, 91, 0, 0, 0, - 0, 0, 0, 75, 173, 0, 78, 79, 0, 0, - 0, 92, 0, 0, 0, 81, 0, 78, 79, 0, - 0, 93, 82, 83, 94, 84, 81, 95, 96, 0, - 85, 0, 0, 82, 83, 0, 84, 97, 87, 0, - 0, 85, 0, 98, 0, 0, 0, 0, 99, 87, - 0, 0, 88, 276, 0, 0, 0, 0, 0, 0, - 90, 0, 0, 88, 89, 0, 0, 0, 0, 0, - 0, 90, 0, 0, 91, 0, 0, 0, 92, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 93, 92, - 0, 0, 0, 0, 95, 96, 0, 0, 0, 93, - 0, 0, 0, 0, 97, 95, 96, 0, 0, 0, - 98, 0, 0, 0, 0, 97, 0, 0, 0, 0, - 0, 98 + 36, 198, 48, 199, 223, 268, 171, 45, 49, 114, + 288, 349, 56, 33, 273, 34, 323, 196, 33, 273, + 34, 33, 131, 34, 273, 196, 273, 123, 63, 90, + 154, 155, 310, 68, 69, 70, 71, 72, 300, 56, + 374, 67, 149, 150, 66, 219, 275, 276, 277, 278, + 279, 280, 281, 282, 283, 284, 511, 149, 150, 271, + 149, 150, 159, 135, 56, 149, 150, 142, 537, 518, + 145, 178, 179, 249, 10, 164, 223, 37, 33, 196, + 34, 196, 183, 42, 117, 535, 153, 450, 270, 129, + 33, 311, 34, 149, 150, 64, 48, 160, 512, 130, + 519, 168, 49, 536, 173, 299, 175, 301, 285, 43, + 538, 57, 149, 150, 174, 382, 375, 219, 10, 38, + 184, 187, 394, 206, 39, 248, 173, 64, 215, 391, + 399, 401, 291, 90, 247, 398, 400, 33, 335, 34, + 336, 363, 224, 218, 156, 233, 460, 227, 218, 434, + 240, 234, 32, 494, 232, 345, 217, 235, 203, 353, + 236, 337, 352, 451, 196, 196, 468, 223, 426, 513, + 216, 217, 312, 446, 187, 272, 255, 256, 263, 440, + 454, 539, 165, 232, 372, 292, 441, 165, 295, 433, + 436, 118, 119, 354, 338, 10, 250, 200, 408, 40, + 355, 149, 150, 411, 203, 115, 207, 380, 219, 475, + 491, 149, 150, 413, 224, 49, 53, 251, 304, 49, + 196, 339, 340, 240, 508, 305, 134, 208, 416, 327, + 116, 417, 418, 306, 41, 356, 517, 73, 168, 74, + 209, 210, 328, 509, 54, 50, 357, 225, 223, 252, + 288, 341, 358, 75, 162, 307, 59, 442, 27, 343, + 347, 106, 35, 187, 211, 447, 243, 342, 432, 370, + 359, 373, 200, 253, 60, 456, 379, 61, 10, 62, + 461, 462, 457, 383, 55, 212, 385, 196, 126, 219, + 33, 386, 34, 232, 472, 149, 150, 49, 242, 105, + 366, 367, 368, 419, 107, 224, 465, 297, 81, 49, + 407, 109, 108, 232, 232, 51, 196, 52, 83, 33, + 73, 34, 74, 180, 181, 188, 10, 474, 173, 110, + 263, 149, 150, 245, 246, 120, 75, 76, 173, 149, + 150, 266, 267, 33, 73, 34, 74, 290, 246, 500, + 316, 317, 113, 430, 428, 369, 240, 78, 79, 122, + 75, 76, 237, 324, 325, 438, 33, 73, 34, 74, + 124, 196, 333, 334, 189, 80, 376, 377, 406, 325, + 240, 78, 79, 75, 162, 125, 224, 240, 414, 415, + 33, 81, 34, 238, 463, 246, 82, 464, 246, 80, + 132, 83, 304, 126, 542, 173, 173, 149, 150, 305, + 133, 347, 547, -129, 138, 81, 240, 306, 476, 151, + 82, 140, 477, 325, 10, 83, 489, 246, 139, 84, + 490, 246, 497, 325, 498, 377, 516, 334, 81, 307, + 487, 532, 334, 548, 246, 146, 550, 246, 83, 190, + 143, 158, 161, 84, 170, 148, 177, 182, 197, 496, + 264, 244, 263, 273, 287, 274, 487, 296, 298, 495, + 309, 318, 314, 85, 239, 319, 33, 73, 34, 74, + 322, 329, 188, 33, 73, 34, 74, 330, 263, 331, + 332, 348, 487, 75, 76, 33, 73, 34, 74, 522, + 75, 76, 77, 371, 378, 381, 384, 33, 73, 34, + 74, 531, 75, 76, 78, 79, 387, 388, 389, 390, + 392, 78, 79, 393, 75, 76, 395, 396, 402, 173, + 403, 189, 80, 78, 79, 404, 164, 173, 424, 80, + 409, 410, 422, 427, 435, 78, 79, 421, 81, 425, + 448, 80, 431, 82, 437, 81, 439, 444, 83, 455, + 82, 445, 466, 80, 469, 83, 470, 81, 473, 479, + 480, 325, 82, 33, 73, 34, 74, 83, 481, 81, + 33, 73, 34, 74, 82, 482, 84, 484, 492, 83, + 75, 76, 488, 84, 493, 502, 499, 75, 76, 507, + 515, 503, 521, 527, 141, 84, 190, 525, 529, 528, + 530, 78, 79, 85, 533, 534, 134, 84, 78, 79, + 541, 544, 543, 546, 545, 85, 551, 552, 553, 80, + 33, 73, 34, 74, 453, 189, 80, 85, 412, 326, + 429, 33, 73, 34, 74, 81, 111, 75, 162, 169, + 82, 176, 81, 112, 1, 83, 2, 82, 75, 76, + 443, 549, 83, 226, 523, 501, 365, 524, 78, 79, + 269, 364, 293, 228, 229, 163, 204, 294, 10, 78, + 79, 214, 0, 84, 478, 3, 80, 0, 0, 0, + 84, 0, 0, 0, 0, 0, 0, 80, 0, 0, + 4, 5, 81, 85, 0, 6, 0, 82, 0, 7, + 190, 0, 83, 81, 0, 0, 0, 0, 82, 0, + 0, 0, 0, 83, 0, 0, 0, 0, 8, 0, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 84, 149, 150, 0, 0, 0, 0, 0, 0, 0, + 0, 84, 9, 0, 0, 0, 0, 0, 0, 0, + 85, 0, 10, 0, 0, 0, 0, 0, 0, 0, + 0, 85, 0, 0, 0, 11, 0, 0, 0, 0, + 0, 12, 0, 13, 0, 0, 0, 0, 0, 0, + 0, 0, 285 }; static const yytype_int16 yycheck[] = { - 4, 146, 12, 274, 160, 208, 142, 11, 12, 44, - 138, 4, 8, 6, 246, 29, 8, 4, 146, 6, - 27, 67, 4, 230, 6, 189, 29, 8, 32, 119, - 29, 59, 61, 37, 38, 39, 40, 41, 4, 5, - 6, 7, 39, 31, 72, 80, 23, 24, 235, 21, - 22, 8, 78, 7, 21, 22, 201, 121, 21, 22, - 36, 10, 28, 7, 99, 74, 71, 83, 28, 463, - 160, 199, 60, 201, 230, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 71, 21, 22, 134, 4, - 121, 6, 21, 22, 488, 121, 50, 106, 58, 65, - 140, 105, 5, 143, 69, 134, 50, 161, 118, 0, - 200, 275, 319, 117, 118, 66, 120, 30, 122, 154, - 125, 114, 61, 177, 3, 45, 125, 162, 94, 95, - 127, 145, 136, 137, 137, 86, 323, 144, 142, 185, - 230, 176, 77, 92, 272, 121, 378, 144, 146, 145, - 70, 144, 423, 145, 282, 283, 160, 144, 186, 362, - 126, 165, 144, 319, 145, 122, 201, 134, 172, 401, - 147, 175, 404, 145, 128, 1, 211, 3, 144, 214, - 145, 384, 145, 103, 128, 189, 33, 191, 192, 193, - 4, 336, 6, 122, 135, 134, 48, 115, 10, 114, - 4, 433, 6, 339, 294, 146, 32, 144, 336, 129, - 145, 246, 114, 349, 106, 118, 119, 252, 53, 33, - 112, 37, 48, 49, 40, 41, 230, 231, 80, 319, - 56, 235, 72, 45, 60, 83, 439, 21, 22, 79, - 396, 76, 140, 55, 142, 104, 250, 87, 21, 22, - 254, 46, 47, 137, 80, 90, 91, 402, 293, 0, - 295, 34, 114, 4, 95, 300, 5, 271, 272, 109, - 144, 275, 307, 135, 402, 411, 412, 7, 113, 105, - 92, 7, 427, 144, 57, 26, 376, 71, 114, 417, - 114, 103, 82, 17, 18, 19, 108, 332, 144, 427, - 116, 311, 5, 138, 130, 145, 396, 311, 132, 46, - 47, 137, 53, 82, 140, 319, 144, 129, 5, 323, - 144, 144, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 477, 21, 22, 339, 71, 341, 146, 72, - 375, 98, 4, 378, 6, 349, 79, 145, 146, 477, - 9, 84, 387, 77, 87, 9, 145, 146, 144, 21, - 22, 365, 21, 22, 145, 146, 401, 21, 22, 404, - 7, 33, 21, 22, 145, 146, 109, 145, 146, 145, - 146, 145, 146, 145, 146, 145, 146, 145, 146, 77, - 145, 146, 396, 529, 145, 146, 145, 146, 433, 144, - 435, 537, 4, 5, 6, 7, 144, 411, 412, 145, - 146, 145, 146, 417, 145, 146, 7, 452, 7, 21, - 22, 23, 145, 146, 145, 146, 145, 146, 11, 144, - 8, 62, 9, 35, 36, 20, 471, 145, 71, 145, - 145, 43, 44, 478, 146, 73, 99, 144, 144, 51, - 52, 85, 54, 85, 131, 144, 58, 59, 132, 463, - 7, 62, 64, 84, 7, 67, 470, 97, 503, 7, - 97, 97, 42, 42, 145, 75, 96, 144, 144, 81, - 82, 27, 146, 92, 488, 137, 144, 89, 85, 144, - 92, 101, 96, 92, 144, 499, 101, 42, 144, 38, - 144, 99, 7, 95, 146, 107, 42, 511, 88, 19, - 42, 7, 136, 108, 93, 117, 145, 110, 120, 144, - 102, 123, 124, 146, 9, 529, 145, 102, 144, 33, - 144, 133, 144, 537, 68, 68, 110, 139, 4, 5, - 6, 7, 144, 145, 10, 100, 7, 198, 368, 145, - 341, 250, 55, 118, 56, 21, 22, 124, 396, 162, - 539, 501, 478, 283, 282, 503, 115, 212, 439, 35, - 36, 212, 166, -1, -1, 148, -1, 43, 44, -1, - -1, 199, 153, 171, -1, 51, 52, -1, 54, -1, - -1, -1, -1, 59, -1, -1, -1, 63, 64, -1, - -1, 67, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 81, 82, -1, -1, -1, - -1, -1, -1, 89, -1, -1, 92, -1, -1, 4, - 5, 6, 7, -1, -1, 10, -1, -1, -1, -1, - -1, 107, -1, -1, -1, -1, 21, 22, 114, -1, - -1, 117, -1, -1, 120, -1, -1, 123, 124, -1, - 35, 36, -1, -1, -1, -1, -1, 133, 43, 44, - -1, -1, -1, 139, -1, -1, 51, 52, 144, 54, - -1, -1, -1, -1, 59, -1, -1, -1, 63, 64, - -1, -1, 67, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 81, 82, -1, -1, - -1, -1, -1, -1, 89, -1, -1, 92, -1, -1, - 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, - -1, -1, 107, -1, -1, -1, -1, 21, 22, 23, - -1, -1, 117, -1, -1, 120, -1, -1, 123, 124, - -1, 35, 36, -1, -1, -1, -1, -1, 133, 43, - 44, -1, -1, -1, 139, -1, -1, 51, 52, 144, - 54, -1, -1, -1, -1, 59, -1, -1, -1, -1, - 64, -1, -1, 67, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 81, 82, -1, - -1, -1, -1, -1, -1, 89, -1, -1, 92, -1, - -1, 4, 5, 6, 7, -1, -1, -1, -1, -1, - -1, -1, -1, 107, -1, -1, -1, -1, 21, 22, - -1, -1, -1, 117, -1, -1, 120, -1, -1, 123, - 124, -1, 35, 36, -1, -1, -1, -1, -1, 133, - 43, 44, -1, -1, -1, 139, -1, -1, 51, 52, - 144, 54, -1, -1, -1, -1, 59, -1, -1, -1, - -1, 64, -1, -1, 67, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 81, 82, - -1, -1, -1, -1, -1, -1, 89, -1, -1, 92, - -1, -1, -1, -1, -1, 4, 5, 6, 7, -1, - -1, -1, -1, -1, 107, -1, -1, -1, -1, -1, - -1, -1, 21, 22, 117, -1, -1, 120, -1, -1, - 123, 124, -1, -1, -1, -1, 35, 36, -1, -1, - 133, 134, -1, -1, 43, 44, 139, -1, -1, -1, - -1, 144, 51, 52, -1, 54, -1, -1, -1, -1, - 59, -1, -1, -1, -1, 64, -1, -1, 67, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 81, 82, -1, -1, -1, -1, -1, -1, - 89, -1, -1, 92, -1, -1, 4, 5, 6, 7, - -1, -1, -1, -1, -1, -1, -1, -1, 107, -1, - -1, -1, -1, 21, 22, 114, -1, -1, 117, -1, - -1, 120, -1, -1, 123, 124, -1, 35, 36, -1, - -1, -1, -1, -1, 133, 43, 44, -1, -1, -1, - 139, -1, -1, 51, 52, 144, 54, -1, -1, -1, - -1, 59, -1, -1, -1, 63, 64, -1, -1, 67, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 81, 82, -1, -1, -1, -1, -1, - -1, 89, -1, -1, 92, -1, -1, 4, 5, 6, - 7, -1, -1, -1, -1, -1, -1, -1, -1, 107, - -1, -1, -1, -1, 21, 22, -1, -1, -1, 117, - -1, -1, 120, -1, -1, 123, 124, -1, 35, 36, - -1, -1, -1, -1, -1, 133, 43, 44, -1, -1, - -1, 139, -1, -1, 51, 52, 144, 54, -1, -1, - -1, -1, 59, -1, -1, -1, -1, 64, -1, -1, - 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 81, 82, -1, -1, -1, -1, - -1, -1, 89, -1, -1, 92, -1, -1, 4, 5, - 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, - 107, -1, -1, -1, -1, 21, 22, -1, -1, -1, - 117, -1, -1, 120, -1, -1, 123, 124, -1, 35, - 36, -1, -1, -1, -1, -1, 133, 43, 44, -1, - -1, -1, 139, -1, -1, 51, 52, 144, 54, -1, - -1, -1, -1, 59, -1, -1, -1, -1, 64, -1, - -1, 67, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 81, 82, 5, -1, 7, - -1, -1, -1, 89, -1, -1, 92, -1, -1, -1, - -1, -1, -1, 21, 22, -1, 35, 36, -1, -1, - -1, 107, -1, -1, -1, 44, -1, 35, 36, -1, - -1, 117, 51, 52, 120, 54, 44, 123, 124, -1, - 59, -1, -1, 51, 52, -1, 54, 133, 67, -1, - -1, 59, -1, 139, -1, -1, -1, -1, 144, 67, - -1, -1, 81, 82, -1, -1, -1, -1, -1, -1, - 89, -1, -1, 81, 82, -1, -1, -1, -1, -1, - -1, 89, -1, -1, 92, -1, -1, -1, 107, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 117, 107, - -1, -1, -1, -1, 123, 124, -1, -1, -1, 117, - -1, -1, -1, -1, 133, 123, 124, -1, -1, -1, - 139, -1, -1, -1, -1, 133, -1, -1, -1, -1, - -1, 139 + 4, 130, 12, 134, 146, 187, 107, 11, 12, 59, + 197, 266, 29, 4, 8, 6, 238, 126, 4, 8, + 6, 4, 72, 6, 8, 134, 8, 67, 32, 44, + 23, 24, 223, 37, 38, 39, 40, 41, 218, 29, + 10, 36, 21, 22, 66, 146, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 7, 21, 22, 190, + 21, 22, 101, 78, 29, 21, 22, 82, 7, 69, + 85, 45, 46, 178, 109, 27, 218, 73, 4, 188, + 6, 190, 122, 28, 5, 62, 90, 10, 189, 124, + 4, 38, 6, 21, 22, 117, 106, 136, 49, 134, + 100, 105, 106, 80, 108, 66, 110, 33, 72, 54, + 49, 128, 21, 22, 109, 297, 86, 218, 109, 115, + 124, 125, 313, 138, 66, 175, 130, 117, 143, 309, + 317, 318, 116, 148, 174, 317, 318, 4, 5, 6, + 7, 135, 146, 134, 137, 160, 135, 151, 134, 371, + 165, 134, 115, 135, 158, 264, 135, 161, 57, 10, + 164, 28, 267, 86, 273, 274, 421, 309, 355, 120, + 135, 135, 119, 395, 178, 190, 180, 181, 182, 135, + 402, 120, 134, 187, 285, 200, 64, 134, 203, 9, + 377, 112, 113, 44, 61, 109, 44, 125, 329, 115, + 51, 21, 22, 332, 57, 31, 50, 116, 309, 431, + 466, 21, 22, 342, 218, 219, 47, 65, 67, 223, + 329, 88, 89, 238, 34, 74, 125, 71, 36, 244, + 56, 39, 40, 82, 77, 86, 492, 5, 242, 7, + 84, 85, 246, 53, 75, 0, 97, 147, 390, 97, + 437, 118, 103, 21, 22, 104, 30, 135, 0, 263, + 264, 136, 4, 267, 108, 396, 166, 134, 369, 284, + 121, 286, 125, 121, 130, 100, 291, 133, 109, 3, + 409, 410, 107, 298, 26, 129, 135, 396, 126, 390, + 4, 301, 6, 297, 425, 21, 22, 301, 136, 110, + 17, 18, 19, 111, 33, 309, 415, 33, 76, 313, + 325, 53, 134, 317, 318, 130, 425, 132, 86, 4, + 5, 6, 7, 45, 46, 10, 109, 9, 332, 77, + 334, 21, 22, 135, 136, 128, 21, 22, 342, 21, + 22, 135, 136, 4, 5, 6, 7, 135, 136, 480, + 135, 136, 98, 368, 358, 72, 371, 42, 43, 5, + 21, 22, 23, 135, 136, 380, 4, 5, 6, 7, + 89, 480, 135, 136, 59, 60, 135, 136, 135, 136, + 395, 42, 43, 21, 22, 134, 390, 402, 135, 136, + 4, 76, 6, 54, 135, 136, 81, 135, 136, 60, + 7, 86, 67, 126, 533, 409, 410, 21, 22, 74, + 7, 415, 541, 78, 134, 76, 431, 82, 433, 33, + 81, 5, 135, 136, 109, 86, 135, 136, 134, 114, + 135, 136, 135, 136, 135, 136, 135, 136, 76, 104, + 455, 135, 136, 135, 136, 66, 135, 136, 86, 134, + 134, 55, 92, 114, 134, 136, 7, 134, 134, 474, + 134, 11, 466, 8, 20, 9, 481, 58, 66, 473, + 136, 134, 68, 134, 135, 93, 4, 5, 6, 7, + 135, 134, 10, 4, 5, 6, 7, 79, 492, 79, + 134, 123, 507, 21, 22, 4, 5, 6, 7, 503, + 21, 22, 23, 134, 124, 58, 7, 4, 5, 6, + 7, 515, 21, 22, 42, 43, 91, 91, 91, 78, + 7, 42, 43, 7, 21, 22, 41, 70, 41, 533, + 135, 59, 60, 42, 43, 90, 27, 541, 86, 60, + 134, 134, 128, 79, 86, 42, 43, 136, 76, 134, + 90, 60, 134, 81, 134, 76, 135, 95, 86, 41, + 81, 95, 134, 60, 37, 86, 93, 76, 134, 7, + 89, 136, 81, 4, 5, 6, 7, 86, 41, 76, + 4, 5, 6, 7, 81, 83, 114, 86, 134, 86, + 21, 22, 19, 114, 41, 7, 135, 21, 22, 136, + 103, 127, 135, 96, 101, 114, 134, 87, 96, 105, + 9, 42, 43, 134, 134, 33, 125, 114, 42, 43, + 134, 63, 134, 63, 105, 134, 94, 135, 7, 60, + 4, 5, 6, 7, 400, 59, 60, 134, 334, 242, + 361, 4, 5, 6, 7, 76, 55, 21, 22, 106, + 81, 112, 76, 56, 1, 86, 3, 81, 21, 22, + 390, 543, 86, 148, 505, 481, 274, 507, 42, 43, + 188, 273, 201, 152, 157, 103, 136, 201, 109, 42, + 43, 140, -1, 114, 437, 32, 60, -1, -1, -1, + 114, -1, -1, -1, -1, -1, -1, 60, -1, -1, + 47, 48, 76, 134, -1, 52, -1, 81, -1, 56, + 134, -1, 86, 76, -1, -1, -1, -1, 81, -1, + -1, -1, -1, 86, -1, -1, -1, -1, 75, -1, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 114, 21, 22, -1, -1, -1, -1, -1, -1, -1, + -1, 114, 99, -1, -1, -1, -1, -1, -1, -1, + 134, -1, 109, -1, -1, -1, -1, -1, -1, -1, + -1, 134, -1, -1, -1, 122, -1, -1, -1, -1, + -1, 128, -1, 130, -1, -1, -1, -1, -1, -1, + -1, -1, 72 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ -static const yytype_uint16 yystos[] = +static const yytype_uint8 yystos[] = { - 0, 1, 3, 32, 48, 49, 56, 60, 80, 105, - 114, 130, 137, 140, 149, 150, 151, 152, 153, 154, - 155, 177, 178, 181, 182, 185, 187, 190, 191, 192, - 256, 257, 121, 4, 6, 190, 254, 78, 121, 71, - 121, 83, 28, 58, 193, 254, 188, 189, 204, 254, - 0, 140, 142, 48, 80, 190, 29, 137, 186, 30, - 140, 143, 3, 254, 125, 179, 71, 179, 254, 254, - 254, 254, 254, 5, 7, 21, 22, 23, 35, 36, - 43, 44, 51, 52, 54, 59, 64, 67, 81, 82, - 89, 92, 107, 117, 120, 123, 124, 133, 139, 144, - 158, 194, 195, 196, 198, 230, 231, 232, 233, 234, - 235, 236, 237, 244, 247, 250, 254, 115, 146, 33, - 144, 190, 83, 186, 193, 104, 192, 31, 60, 5, - 118, 119, 137, 180, 5, 180, 95, 144, 135, 224, - 225, 132, 144, 192, 7, 7, 134, 230, 240, 241, - 144, 82, 144, 5, 144, 144, 82, 190, 230, 5, - 71, 197, 146, 21, 22, 33, 251, 254, 23, 24, - 147, 252, 98, 22, 233, 27, 144, 183, 184, 254, - 189, 144, 198, 253, 254, 179, 254, 191, 7, 46, - 47, 46, 47, 144, 180, 254, 156, 157, 254, 10, - 63, 144, 226, 227, 228, 229, 230, 247, 144, 253, - 226, 134, 238, 239, 61, 241, 242, 7, 53, 76, - 90, 91, 113, 138, 245, 245, 230, 7, 145, 145, - 144, 198, 201, 202, 205, 234, 254, 224, 196, 254, - 231, 232, 144, 254, 254, 23, 58, 145, 230, 243, - 146, 224, 11, 145, 146, 180, 192, 156, 45, 70, - 103, 129, 162, 254, 254, 169, 170, 171, 172, 173, - 174, 254, 144, 165, 145, 146, 82, 158, 229, 198, - 226, 230, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 77, 249, 20, 244, 246, 145, - 122, 230, 239, 242, 230, 62, 145, 71, 71, 145, - 201, 33, 203, 204, 72, 79, 87, 109, 200, 146, - 203, 39, 127, 199, 73, 206, 99, 213, 214, 145, - 243, 145, 146, 184, 230, 254, 144, 85, 85, 144, - 145, 146, 5, 7, 28, 65, 94, 95, 126, 144, - 254, 255, 247, 248, 254, 131, 162, 163, 164, 156, - 10, 45, 55, 92, 103, 108, 129, 159, 160, 161, - 145, 227, 228, 17, 18, 19, 77, 230, 144, 198, - 230, 10, 92, 145, 146, 132, 230, 122, 62, 230, - 7, 145, 204, 97, 97, 97, 84, 201, 7, 7, - 203, 42, 75, 207, 42, 145, 96, 215, 145, 230, - 226, 144, 144, 253, 170, 253, 145, 146, 37, 40, - 41, 116, 175, 146, 137, 166, 92, 144, 244, 85, - 254, 159, 230, 144, 198, 9, 243, 92, 244, 144, - 230, 145, 69, 145, 202, 101, 101, 243, 226, 96, - 208, 243, 42, 106, 112, 216, 217, 145, 253, 253, - 145, 145, 247, 144, 176, 162, 38, 99, 167, 226, - 144, 9, 243, 230, 145, 246, 7, 95, 42, 88, - 209, 220, 221, 230, 19, 145, 145, 169, 144, 42, - 145, 254, 230, 145, 145, 145, 226, 220, 7, 136, - 210, 211, 212, 146, 34, 57, 222, 7, 50, 128, - 218, 108, 145, 169, 74, 106, 168, 145, 254, 212, - 221, 93, 223, 102, 110, 102, 9, 254, 145, 144, - 33, 66, 86, 7, 50, 128, 219, 144, 253, 144, - 68, 110, 68, 253, 145, 213, 145, 100, 145, 7 + 0, 1, 3, 32, 47, 48, 52, 56, 75, 99, + 109, 122, 128, 130, 139, 140, 141, 142, 143, 144, + 145, 169, 170, 173, 174, 177, 179, 182, 183, 184, + 251, 252, 115, 4, 6, 182, 249, 73, 115, 66, + 115, 77, 28, 54, 185, 249, 180, 181, 196, 249, + 0, 130, 132, 47, 75, 182, 29, 128, 178, 30, + 130, 133, 3, 249, 117, 171, 66, 171, 249, 249, + 249, 249, 249, 5, 7, 21, 22, 23, 42, 43, + 60, 76, 81, 86, 114, 134, 186, 187, 188, 190, + 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + 232, 239, 242, 245, 249, 110, 136, 33, 134, 182, + 77, 178, 185, 98, 184, 31, 56, 5, 112, 113, + 128, 172, 5, 172, 89, 134, 126, 216, 217, 124, + 134, 184, 7, 7, 125, 222, 235, 236, 134, 134, + 5, 101, 222, 134, 182, 222, 66, 189, 136, 21, + 22, 33, 246, 249, 23, 24, 137, 247, 55, 101, + 136, 92, 22, 225, 27, 134, 175, 176, 249, 181, + 134, 190, 248, 249, 171, 249, 183, 7, 45, 46, + 45, 46, 134, 172, 249, 146, 147, 249, 10, 59, + 134, 218, 219, 220, 221, 222, 242, 134, 248, 218, + 125, 233, 234, 57, 236, 237, 222, 50, 71, 84, + 85, 108, 129, 240, 240, 222, 135, 135, 134, 190, + 193, 194, 197, 228, 249, 216, 188, 249, 223, 224, + 148, 149, 249, 222, 134, 249, 249, 23, 54, 135, + 222, 238, 136, 216, 11, 135, 136, 172, 184, 146, + 44, 65, 97, 121, 154, 249, 249, 161, 162, 163, + 164, 165, 166, 249, 134, 157, 135, 136, 148, 221, + 190, 218, 222, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 72, 244, 20, 239, 241, + 135, 116, 222, 234, 237, 222, 58, 33, 66, 66, + 193, 33, 195, 196, 67, 74, 82, 104, 192, 136, + 195, 38, 119, 191, 68, 198, 135, 136, 134, 93, + 205, 206, 135, 238, 135, 136, 176, 222, 249, 134, + 79, 79, 134, 135, 136, 5, 7, 28, 61, 88, + 89, 118, 134, 249, 250, 242, 243, 249, 123, 154, + 155, 156, 146, 10, 44, 51, 86, 97, 103, 121, + 151, 152, 153, 135, 219, 220, 17, 18, 19, 72, + 222, 134, 190, 222, 10, 86, 135, 136, 124, 222, + 116, 58, 148, 222, 7, 135, 196, 91, 91, 91, + 78, 193, 7, 7, 195, 41, 70, 199, 148, 239, + 148, 239, 41, 135, 90, 207, 135, 222, 218, 134, + 134, 248, 162, 248, 135, 136, 36, 39, 40, 111, + 167, 136, 128, 158, 86, 134, 239, 79, 249, 151, + 222, 134, 190, 9, 238, 86, 239, 134, 222, 135, + 135, 64, 135, 194, 95, 95, 238, 218, 90, 200, + 10, 86, 150, 150, 238, 41, 100, 107, 208, 209, + 135, 248, 248, 135, 135, 242, 134, 168, 154, 37, + 93, 159, 218, 134, 9, 238, 222, 135, 241, 7, + 89, 41, 83, 201, 86, 212, 213, 222, 19, 135, + 135, 161, 134, 41, 135, 249, 222, 135, 135, 135, + 218, 212, 7, 127, 202, 203, 204, 136, 34, 53, + 214, 7, 49, 120, 210, 103, 135, 161, 69, 100, + 160, 135, 249, 204, 213, 87, 215, 96, 105, 96, + 9, 249, 135, 134, 33, 62, 80, 7, 49, 120, + 211, 134, 248, 134, 63, 105, 63, 248, 135, 205, + 135, 94, 135, 7 }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint16 yyr1[] = +static const yytype_uint8 yyr1[] = { - 0, 148, 149, 149, 149, 149, 149, 149, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 151, 152, - 152, 152, 152, 153, 154, 155, 156, 157, 157, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 159, 159, 159, - 159, 159, 159, 159, 160, 160, 161, 161, 162, 162, - 162, 162, 163, 163, 164, 164, 165, 165, 166, 166, - 167, 167, 168, 168, 169, 169, 170, 170, 170, 170, - 171, 171, 171, 172, 173, 174, 175, 175, 175, 175, - 176, 176, 177, 177, 177, 177, 178, 178, 178, 178, - 179, 179, 179, 180, 180, 181, 182, 183, 183, 184, - 185, 185, 186, 186, 187, 188, 188, 189, 190, 190, - 191, 191, 192, 193, 193, 193, 194, 194, 195, 195, - 196, 196, 196, 197, 198, 199, 199, 199, 200, 200, - 200, 200, 200, 200, 200, 200, 201, 201, 202, 202, - 202, 202, 202, 202, 203, 203, 204, 204, 205, 205, - 206, 206, 207, 207, 208, 208, 209, 209, 210, 210, - 211, 211, 212, 213, 214, 214, 215, 215, 216, 216, - 217, 217, 218, 218, 218, 219, 219, 219, 220, 220, - 221, 222, 222, 222, 223, 223, 223, 224, 224, 225, - 226, 226, 227, 227, 228, 228, 229, 229, 229, 229, - 229, 229, 229, 229, 229, 229, 229, 230, 230, 231, - 231, 232, 232, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 233, 234, 234, 234, 234, 235, 236, 236, - 237, 237, 238, 238, 239, 240, 240, 241, 242, 242, - 243, 243, 244, 244, 244, 244, 244, 244, 244, 244, - 245, 245, 245, 245, 245, 245, 246, 246, 247, 247, - 248, 248, 249, 249, 249, 249, 249, 249, 249, 249, - 249, 249, 250, 251, 251, 252, 252, 252, 253, 253, - 254, 254, 255, 255, 255, 255, 256, 257, 257 + 0, 138, 139, 139, 139, 139, 139, 139, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 141, 142, + 142, 142, 142, 143, 144, 145, 146, 147, 147, 148, + 148, 149, 149, 149, 149, 150, 150, 150, 151, 151, + 151, 151, 151, 151, 151, 152, 152, 153, 153, 154, + 154, 154, 154, 155, 155, 156, 156, 157, 157, 158, + 158, 159, 159, 160, 160, 161, 161, 162, 162, 162, + 162, 163, 163, 163, 164, 165, 166, 167, 167, 167, + 167, 168, 168, 169, 169, 169, 169, 170, 170, 170, + 170, 171, 171, 171, 172, 172, 173, 174, 175, 175, + 176, 177, 177, 178, 178, 179, 180, 180, 181, 182, + 182, 183, 183, 184, 185, 185, 185, 186, 186, 187, + 187, 188, 188, 188, 189, 190, 191, 191, 191, 192, + 192, 192, 192, 192, 192, 192, 192, 193, 193, 194, + 194, 194, 194, 194, 194, 195, 195, 196, 196, 197, + 197, 198, 198, 199, 199, 200, 200, 201, 201, 202, + 202, 203, 203, 204, 205, 206, 206, 207, 207, 208, + 208, 209, 209, 210, 210, 210, 211, 211, 211, 212, + 212, 213, 214, 214, 214, 215, 215, 215, 216, 216, + 217, 218, 218, 219, 219, 220, 220, 221, 221, 221, + 221, 221, 221, 221, 221, 221, 221, 221, 222, 222, + 223, 223, 224, 224, 225, 225, 225, 225, 225, 225, + 225, 225, 225, 225, 225, 225, 226, 226, 227, 227, + 228, 228, 228, 228, 229, 229, 230, 231, 231, 232, + 232, 233, 233, 234, 235, 235, 236, 237, 237, 238, + 238, 239, 239, 239, 239, 239, 239, 239, 240, 240, + 240, 240, 240, 240, 241, 241, 242, 242, 243, 243, + 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, + 245, 246, 246, 247, 247, 247, 248, 248, 249, 249, + 250, 250, 250, 250, 251, 252, 252 }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ @@ -1471,33 +1339,33 @@ static const yytype_uint8 yyr2[] = 0, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 9, 9, 3, 3, 1, 3, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 2, 4, 4, 1, 2, 1, - 2, 2, 4, 5, 2, 1, 0, 1, 4, 5, - 10, 4, 3, 1, 0, 1, 0, 3, 0, 5, - 0, 8, 1, 1, 1, 3, 1, 1, 1, 1, - 2, 2, 2, 4, 2, 2, 1, 1, 1, 1, - 0, 3, 10, 7, 4, 5, 5, 4, 4, 5, - 2, 2, 2, 0, 4, 5, 4, 3, 1, 3, - 2, 3, 0, 3, 2, 1, 3, 3, 4, 1, - 3, 1, 10, 0, 1, 1, 1, 1, 1, 3, - 3, 2, 1, 2, 3, 0, 3, 3, 0, 1, - 1, 2, 1, 2, 1, 2, 6, 1, 2, 3, - 2, 2, 1, 3, 1, 2, 1, 4, 1, 3, - 0, 3, 0, 2, 0, 3, 0, 2, 0, 1, - 1, 2, 6, 3, 0, 3, 0, 3, 0, 5, - 1, 1, 2, 2, 2, 2, 2, 2, 1, 3, - 3, 0, 1, 1, 0, 2, 2, 0, 1, 2, - 3, 1, 3, 1, 2, 1, 5, 6, 4, 3, - 3, 3, 2, 3, 5, 4, 6, 3, 1, 3, - 1, 2, 1, 1, 1, 1, 3, 5, 1, 1, - 1, 3, 1, 3, 4, 4, 5, 6, 6, 8, - 5, 4, 1, 2, 4, 1, 2, 4, 0, 2, - 1, 3, 1, 1, 2, 2, 1, 2, 3, 2, - 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, - 1, 3, 1, 1, 1, 1, 1, 1, 1, 2, - 1, 2, 1, 1, 1, 1, 1, 1, 1, 3, - 1, 1, 1, 1, 1, 1, 2, 2, 0 + 2, 4, 4, 3, 3, 0, 1, 2, 1, 2, + 1, 2, 2, 4, 5, 2, 1, 0, 1, 4, + 5, 10, 4, 3, 1, 0, 1, 0, 3, 0, + 5, 0, 8, 1, 1, 1, 3, 1, 1, 1, + 1, 2, 2, 2, 4, 2, 2, 1, 1, 1, + 1, 0, 3, 10, 7, 4, 5, 5, 4, 4, + 5, 2, 2, 2, 0, 4, 5, 4, 3, 1, + 3, 2, 3, 0, 3, 2, 1, 3, 3, 4, + 1, 3, 1, 10, 0, 1, 1, 1, 1, 1, + 3, 3, 2, 1, 2, 3, 0, 3, 3, 0, + 1, 1, 2, 1, 2, 1, 2, 6, 1, 2, + 3, 2, 2, 1, 3, 1, 2, 1, 4, 1, + 3, 0, 3, 0, 2, 0, 3, 0, 2, 0, + 1, 1, 2, 6, 3, 0, 3, 0, 3, 0, + 5, 1, 1, 2, 2, 2, 2, 2, 2, 1, + 3, 3, 0, 1, 1, 0, 2, 2, 0, 1, + 2, 3, 1, 3, 1, 2, 1, 5, 6, 4, + 3, 3, 3, 2, 3, 5, 4, 6, 3, 1, + 3, 1, 2, 1, 1, 1, 1, 1, 3, 5, + 1, 1, 1, 1, 3, 1, 2, 2, 3, 2, + 3, 4, 4, 5, 6, 3, 6, 6, 8, 5, + 4, 1, 2, 4, 1, 2, 4, 0, 2, 1, + 3, 1, 1, 2, 2, 1, 2, 3, 1, 1, + 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, + 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, + 1, 1, 1, 1, 2, 2, 0 }; @@ -1994,1071 +1862,1129 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio switch (yytype) { case 3: /* TOKEN_COMMAND */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2004 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1872 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; case 4: /* TOKEN_NAME */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2014 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1882 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; case 5: /* TOKEN_STRING_SINGLE_QUOTED */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2024 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1892 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; case 6: /* TOKEN_STRING_DOUBLE_QUOTED */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2034 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1902 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; case 7: /* TOKEN_UNSIGNED_NUMVAL */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).numeric_literal_value_) != nullptr) { delete ((*yyvaluep).numeric_literal_value_); } } -#line 2044 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1912 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 150: /* sql_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 140: /* sql_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).statement_) != nullptr) { delete ((*yyvaluep).statement_); } } -#line 2054 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1922 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 151: /* quit_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 141: /* quit_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).quit_statement_) != nullptr) { delete ((*yyvaluep).quit_statement_); } } -#line 2064 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1932 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 152: /* alter_table_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 142: /* alter_table_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).statement_) != nullptr) { delete ((*yyvaluep).statement_); } } -#line 2074 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1942 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 153: /* create_table_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 143: /* create_table_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).create_table_statement_) != nullptr) { delete ((*yyvaluep).create_table_statement_); } } -#line 2084 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1952 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 154: /* create_index_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 144: /* create_index_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).statement_) != nullptr) { delete ((*yyvaluep).statement_); } } -#line 2094 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1962 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 155: /* drop_table_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 145: /* drop_table_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).drop_table_statement_) != nullptr) { delete ((*yyvaluep).drop_table_statement_); } } -#line 2104 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1972 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 156: /* column_def */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 146: /* column_def */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).attribute_definition_) != nullptr) { delete ((*yyvaluep).attribute_definition_); } } -#line 2114 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1982 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 157: /* column_def_commalist */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 147: /* column_def_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).attribute_definition_list_) != nullptr) { delete ((*yyvaluep).attribute_definition_list_); } } -#line 2124 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 1992 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 158: /* data_type */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 148: /* data_type */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).data_type_) != nullptr) { delete ((*yyvaluep).data_type_); } } -#line 2134 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2002 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 159: /* column_constraint_def */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 149: /* data_type_parameter_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ + { + if (((*yyvaluep).data_type_) != nullptr) { + delete ((*yyvaluep).data_type_); + } +} +#line 2012 "SqlParser_gen.cpp" /* yacc.c:1257 */ + break; + + case 150: /* opt_nullable */ +#line 619 "../SqlParser.ypp" /* yacc.c:1257 */ + { } +#line 2018 "SqlParser_gen.cpp" /* yacc.c:1257 */ + break; + + case 151: /* column_constraint_def */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).column_constraint_) != nullptr) { delete ((*yyvaluep).column_constraint_); } } -#line 2144 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2028 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 160: /* column_constraint_def_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 152: /* column_constraint_def_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).column_constraint_list_) != nullptr) { delete ((*yyvaluep).column_constraint_list_); } } -#line 2154 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2038 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 161: /* opt_column_constraint_def_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 153: /* opt_column_constraint_def_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).column_constraint_list_) != nullptr) { delete ((*yyvaluep).column_constraint_list_); } } -#line 2164 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2048 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 165: /* opt_column_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 157: /* opt_column_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).attribute_list_) != nullptr) { delete ((*yyvaluep).attribute_list_); } } -#line 2174 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2058 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 166: /* opt_block_properties */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 158: /* opt_block_properties */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).block_properties_) != nullptr) { delete ((*yyvaluep).block_properties_); } } -#line 2184 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2068 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 167: /* opt_partition_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 159: /* opt_partition_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).partition_clause_) != nullptr) { delete ((*yyvaluep).partition_clause_); } } -#line 2194 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2078 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 168: /* partition_type */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 160: /* partition_type */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2204 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2088 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 169: /* key_value_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 161: /* key_value_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_value_list_) != nullptr) { delete ((*yyvaluep).key_value_list_); } } -#line 2214 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2098 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 170: /* key_value */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 162: /* key_value */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_value_) != nullptr) { delete ((*yyvaluep).key_value_); } } -#line 2224 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2108 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 171: /* key_string_value */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 163: /* key_string_value */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_string_value_) != nullptr) { delete ((*yyvaluep).key_string_value_); } } -#line 2234 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2118 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 172: /* key_string_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 164: /* key_string_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_string_list_) != nullptr) { delete ((*yyvaluep).key_string_list_); } } -#line 2244 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2128 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 173: /* key_integer_value */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 165: /* key_integer_value */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_integer_value_) != nullptr) { delete ((*yyvaluep).key_integer_value_); } } -#line 2254 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2138 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 174: /* key_bool_value */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 166: /* key_bool_value */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_bool_value_) != nullptr) { delete ((*yyvaluep).key_bool_value_); } } -#line 2264 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2148 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 175: /* index_type */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 167: /* index_type */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2274 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2158 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 176: /* opt_index_properties */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 168: /* opt_index_properties */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_value_list_) != nullptr) { delete ((*yyvaluep).key_value_list_); } } -#line 2284 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2168 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 177: /* insert_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 169: /* insert_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).insert_statement_) != nullptr) { delete ((*yyvaluep).insert_statement_); } } -#line 2294 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2178 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 178: /* copy_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 170: /* copy_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).copy_statement_) != nullptr) { delete ((*yyvaluep).copy_statement_); } } -#line 2304 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2188 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 179: /* copy_to_target */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 171: /* copy_to_target */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2314 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2198 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 180: /* opt_copy_params */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 172: /* opt_copy_params */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).key_value_list_) != nullptr) { delete ((*yyvaluep).key_value_list_); } } -#line 2324 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2208 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 181: /* update_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 173: /* update_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).update_statement_) != nullptr) { delete ((*yyvaluep).update_statement_); } } -#line 2334 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2218 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 182: /* delete_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 174: /* delete_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).delete_statement_) != nullptr) { delete ((*yyvaluep).delete_statement_); } } -#line 2344 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2228 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 183: /* assignment_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 175: /* assignment_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).assignment_list_) != nullptr) { delete ((*yyvaluep).assignment_list_); } } -#line 2354 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2238 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 184: /* assignment_item */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 176: /* assignment_item */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).assignment_) != nullptr) { delete ((*yyvaluep).assignment_); } } -#line 2364 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2248 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 185: /* set_operation_statement */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 177: /* set_operation_statement */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).set_operation_statement_) != nullptr) { delete ((*yyvaluep).set_operation_statement_); } } -#line 2374 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2258 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 186: /* opt_priority_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 178: /* opt_priority_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_priority_clause_) != nullptr) { delete ((*yyvaluep).opt_priority_clause_); } } -#line 2384 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2268 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 187: /* with_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 179: /* with_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).with_list_) != nullptr) { delete ((*yyvaluep).with_list_); } } -#line 2394 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2278 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 188: /* with_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 180: /* with_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).with_list_) != nullptr) { delete ((*yyvaluep).with_list_); } } -#line 2404 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2288 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 189: /* with_list_element */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 181: /* with_list_element */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).with_list_element_) != nullptr) { delete ((*yyvaluep).with_list_element_); } } -#line 2414 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2298 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 190: /* set_operation_union */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 182: /* set_operation_union */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).set_operation_) != nullptr) { delete ((*yyvaluep).set_operation_); } } -#line 2424 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2308 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 191: /* set_operation_intersect */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 183: /* set_operation_intersect */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).set_operation_) != nullptr) { delete ((*yyvaluep).set_operation_); } } -#line 2434 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2318 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 192: /* select_query */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 184: /* select_query */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).select_query_) != nullptr) { delete ((*yyvaluep).select_query_); } } -#line 2444 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2328 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 193: /* opt_all_distinct */ -#line 625 "../SqlParser.ypp" /* yacc.c:1257 */ + case 185: /* opt_all_distinct */ +#line 619 "../SqlParser.ypp" /* yacc.c:1257 */ { } -#line 2450 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2334 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 194: /* selection */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 186: /* selection */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).selection_) != nullptr) { delete ((*yyvaluep).selection_); } } -#line 2460 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2344 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 195: /* selection_item_commalist */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 187: /* selection_item_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).selection_list_) != nullptr) { delete ((*yyvaluep).selection_list_); } } -#line 2470 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2354 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 196: /* selection_item */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 188: /* selection_item */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).selection_item_) != nullptr) { delete ((*yyvaluep).selection_item_); } } -#line 2480 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2364 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 197: /* from_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 189: /* from_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).table_reference_list_) != nullptr) { delete ((*yyvaluep).table_reference_list_); } } -#line 2490 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2374 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 198: /* subquery_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 190: /* subquery_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).subquery_expression_) != nullptr) { delete ((*yyvaluep).subquery_expression_); } } -#line 2500 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2384 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 199: /* opt_sample_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 191: /* opt_sample_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_sample_clause_) != nullptr) { delete ((*yyvaluep).opt_sample_clause_); } } -#line 2510 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2394 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 200: /* join_type */ -#line 629 "../SqlParser.ypp" /* yacc.c:1257 */ + case 192: /* join_type */ +#line 621 "../SqlParser.ypp" /* yacc.c:1257 */ { } -#line 2516 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2400 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 201: /* joined_table_reference */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 193: /* joined_table_reference */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).table_reference_) != nullptr) { delete ((*yyvaluep).table_reference_); } } -#line 2526 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2410 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 202: /* table_reference */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 194: /* table_reference */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).table_reference_) != nullptr) { delete ((*yyvaluep).table_reference_); } } -#line 2536 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2420 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 203: /* table_reference_signature */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 195: /* table_reference_signature */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).table_reference_signature_) != nullptr) { delete ((*yyvaluep).table_reference_signature_); } } -#line 2546 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2430 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 204: /* table_reference_signature_primary */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 196: /* table_reference_signature_primary */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).table_reference_signature_) != nullptr) { delete ((*yyvaluep).table_reference_signature_); } } -#line 2556 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2440 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 205: /* joined_table_reference_commalist */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 197: /* joined_table_reference_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).table_reference_list_) != nullptr) { delete ((*yyvaluep).table_reference_list_); } } -#line 2566 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2450 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 206: /* opt_group_by_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 198: /* opt_group_by_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_group_by_clause_) != nullptr) { delete ((*yyvaluep).opt_group_by_clause_); } } -#line 2576 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2460 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 207: /* opt_having_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 199: /* opt_having_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_having_clause_) != nullptr) { delete ((*yyvaluep).opt_having_clause_); } } -#line 2586 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2470 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 208: /* opt_order_by_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 200: /* opt_order_by_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_order_by_clause_) != nullptr) { delete ((*yyvaluep).opt_order_by_clause_); } } -#line 2596 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2480 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 209: /* opt_limit_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 201: /* opt_limit_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_limit_clause_) != nullptr) { delete ((*yyvaluep).opt_limit_clause_); } } -#line 2606 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2490 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 210: /* opt_window_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 202: /* opt_window_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_window_clause_) != nullptr) { delete ((*yyvaluep).opt_window_clause_); } } -#line 2616 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2500 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 211: /* window_declaration_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 203: /* window_declaration_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).opt_window_clause_) != nullptr) { delete ((*yyvaluep).opt_window_clause_); } } -#line 2626 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2510 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 212: /* window_declaration */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 204: /* window_declaration */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).window_definition_) != nullptr) { delete ((*yyvaluep).window_definition_); } } -#line 2636 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2520 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 213: /* window_definition */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 205: /* window_definition */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).window_definition_) != nullptr) { delete ((*yyvaluep).window_definition_); } } -#line 2646 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2530 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 214: /* opt_window_partition */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 206: /* opt_window_partition */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).window_partition_by_list_) != nullptr) { delete ((*yyvaluep).window_partition_by_list_); } } -#line 2656 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2540 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 215: /* opt_window_order */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 207: /* opt_window_order */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).window_order_by_list_) != nullptr) { delete ((*yyvaluep).window_order_by_list_); } } -#line 2666 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2550 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 216: /* opt_window_frame */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 208: /* opt_window_frame */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).window_frame_info_) != nullptr) { delete ((*yyvaluep).window_frame_info_); } } -#line 2676 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2560 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 217: /* frame_mode */ -#line 625 "../SqlParser.ypp" /* yacc.c:1257 */ + case 209: /* frame_mode */ +#line 619 "../SqlParser.ypp" /* yacc.c:1257 */ { } -#line 2682 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2566 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 218: /* frame_preceding */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 210: /* frame_preceding */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).numeric_literal_value_) != nullptr) { delete ((*yyvaluep).numeric_literal_value_); } } -#line 2692 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2576 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 219: /* frame_following */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 211: /* frame_following */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).numeric_literal_value_) != nullptr) { delete ((*yyvaluep).numeric_literal_value_); } } -#line 2702 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2586 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 220: /* order_commalist */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 212: /* order_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).order_commalist_) != nullptr) { delete ((*yyvaluep).order_commalist_); } } -#line 2712 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2596 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 221: /* order_item */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 213: /* order_item */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).order_item_) != nullptr) { delete ((*yyvaluep).order_item_); } } -#line 2722 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2606 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 222: /* opt_order_direction */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 214: /* opt_order_direction */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).order_direction_) != nullptr) { delete ((*yyvaluep).order_direction_); } } -#line 2732 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2616 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 223: /* opt_nulls_first */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 215: /* opt_nulls_first */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).order_direction_) != nullptr) { delete ((*yyvaluep).order_direction_); } } -#line 2742 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2626 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 224: /* opt_where_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 216: /* opt_where_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).predicate_) != nullptr) { delete ((*yyvaluep).predicate_); } } -#line 2752 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2636 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 225: /* where_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 217: /* where_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).predicate_) != nullptr) { delete ((*yyvaluep).predicate_); } } -#line 2762 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2646 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 226: /* or_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 218: /* or_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).predicate_) != nullptr) { delete ((*yyvaluep).predicate_); } } -#line 2772 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2656 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 227: /* and_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 219: /* and_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).predicate_) != nullptr) { delete ((*yyvaluep).predicate_); } } -#line 2782 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2666 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 228: /* not_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 220: /* not_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).predicate_) != nullptr) { delete ((*yyvaluep).predicate_); } } -#line 2792 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2676 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 229: /* predicate_expression_base */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 221: /* predicate_expression_base */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).predicate_) != nullptr) { delete ((*yyvaluep).predicate_); } } -#line 2802 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2686 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 230: /* add_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 222: /* add_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2812 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2696 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 231: /* multiply_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 223: /* multiply_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2822 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2706 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 232: /* unary_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 224: /* unary_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2832 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2716 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 233: /* expression_base */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 225: /* expression_base */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2842 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2726 "SqlParser_gen.cpp" /* yacc.c:1257 */ + break; + + case 226: /* array_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ + { + if (((*yyvaluep).array_expression_) != nullptr) { + delete ((*yyvaluep).array_expression_); + } +} +#line 2736 "SqlParser_gen.cpp" /* yacc.c:1257 */ + break; + + case 227: /* array_element_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ + { + if (((*yyvaluep).array_expression_) != nullptr) { + delete ((*yyvaluep).array_expression_); + } +} +#line 2746 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 234: /* function_call */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 228: /* function_call */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).function_call_) != nullptr) { delete ((*yyvaluep).function_call_); } } -#line 2852 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2756 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 235: /* extract_function */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 229: /* cast_function */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2862 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2766 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 236: /* substr_function */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 230: /* extract_function */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2872 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2776 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 237: /* case_expression */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 231: /* substr_function */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2882 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2786 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 238: /* simple_when_clause_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 232: /* case_expression */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ + { + if (((*yyvaluep).expression_) != nullptr) { + delete ((*yyvaluep).expression_); + } +} +#line 2796 "SqlParser_gen.cpp" /* yacc.c:1257 */ + break; + + case 233: /* simple_when_clause_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).simple_when_clause_list_) != nullptr) { delete ((*yyvaluep).simple_when_clause_list_); } } -#line 2892 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2806 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 239: /* simple_when_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 234: /* simple_when_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).simple_when_clause_) != nullptr) { delete ((*yyvaluep).simple_when_clause_); } } -#line 2902 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2816 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 240: /* searched_when_clause_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 235: /* searched_when_clause_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).searched_when_clause_list_) != nullptr) { delete ((*yyvaluep).searched_when_clause_list_); } } -#line 2912 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2826 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 241: /* searched_when_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 236: /* searched_when_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).searched_when_clause_) != nullptr) { delete ((*yyvaluep).searched_when_clause_); } } -#line 2922 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2836 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 242: /* opt_else_clause */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 237: /* opt_else_clause */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_) != nullptr) { delete ((*yyvaluep).expression_); } } -#line 2932 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2846 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 243: /* expression_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 238: /* expression_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).expression_list_) != nullptr) { delete ((*yyvaluep).expression_list_); } } -#line 2942 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2856 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 244: /* literal_value */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 239: /* literal_value */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).literal_value_) != nullptr) { delete ((*yyvaluep).literal_value_); } } -#line 2952 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2866 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 245: /* datetime_unit */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 240: /* datetime_unit */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 2962 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2876 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 246: /* literal_value_commalist */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 241: /* literal_value_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).literal_value_list_) != nullptr) { delete ((*yyvaluep).literal_value_list_); } } -#line 2972 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2886 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 247: /* attribute_ref */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 242: /* attribute_ref */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).attribute_) != nullptr) { delete ((*yyvaluep).attribute_); } } -#line 2982 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2896 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 248: /* attribute_ref_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 243: /* attribute_ref_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).attribute_list_) != nullptr) { delete ((*yyvaluep).attribute_list_); } } -#line 2992 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2906 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 249: /* comparison_operation */ -#line 626 "../SqlParser.ypp" /* yacc.c:1257 */ + case 244: /* comparison_operation */ +#line 620 "../SqlParser.ypp" /* yacc.c:1257 */ { } -#line 2998 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2912 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 250: /* unary_operation */ -#line 627 "../SqlParser.ypp" /* yacc.c:1257 */ - { } -#line 3004 "SqlParser_gen.cpp" /* yacc.c:1257 */ + case 245: /* unary_operation */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ + { + if (((*yyvaluep).unary_operation_) != nullptr) { + delete ((*yyvaluep).unary_operation_); + } +} +#line 2922 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 251: /* add_operation */ -#line 628 "../SqlParser.ypp" /* yacc.c:1257 */ - { } -#line 3010 "SqlParser_gen.cpp" /* yacc.c:1257 */ + case 246: /* add_operation */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ + { + if (((*yyvaluep).binary_operation_) != nullptr) { + delete ((*yyvaluep).binary_operation_); + } +} +#line 2932 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 252: /* multiply_operation */ -#line 628 "../SqlParser.ypp" /* yacc.c:1257 */ - { } -#line 3016 "SqlParser_gen.cpp" /* yacc.c:1257 */ + case 247: /* multiply_operation */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ + { + if (((*yyvaluep).binary_operation_) != nullptr) { + delete ((*yyvaluep).binary_operation_); + } +} +#line 2942 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 253: /* name_commalist */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 248: /* name_commalist */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_list_) != nullptr) { delete ((*yyvaluep).string_list_); } } -#line 3026 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2952 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 254: /* any_name */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 249: /* any_name */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).string_value_) != nullptr) { delete ((*yyvaluep).string_value_); } } -#line 3036 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2962 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 255: /* boolean_value */ -#line 625 "../SqlParser.ypp" /* yacc.c:1257 */ + case 250: /* boolean_value */ +#line 619 "../SqlParser.ypp" /* yacc.c:1257 */ { } -#line 3042 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2968 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 256: /* command */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 251: /* command */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).command_) != nullptr) { delete ((*yyvaluep).command_); } } -#line 3052 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2978 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; - case 257: /* command_argument_list */ -#line 631 "../SqlParser.ypp" /* yacc.c:1257 */ + case 252: /* command_argument_list */ +#line 623 "../SqlParser.ypp" /* yacc.c:1257 */ { if (((*yyvaluep).command_argument_list_) != nullptr) { delete ((*yyvaluep).command_argument_list_); } } -#line 3062 "SqlParser_gen.cpp" /* yacc.c:1257 */ +#line 2988 "SqlParser_gen.cpp" /* yacc.c:1257 */ break; @@ -3350,148 +3276,148 @@ YYLTYPE yylloc = yyloc_default; switch (yyn) { case 2: -#line 640 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 632 "../SqlParser.ypp" /* yacc.c:1661 */ { *parsedStatement = (yyvsp[-1].statement_); YYACCEPT; } -#line 3359 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3285 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 3: -#line 644 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 636 "../SqlParser.ypp" /* yacc.c:1661 */ { *parsedStatement = (yyvsp[-1].statement_); YYACCEPT; } -#line 3368 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3294 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 4: -#line 648 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 640 "../SqlParser.ypp" /* yacc.c:1661 */ { *parsedStatement = (yyvsp[-1].command_); YYACCEPT; } -#line 3377 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3303 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 5: -#line 652 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 644 "../SqlParser.ypp" /* yacc.c:1661 */ { *parsedStatement = (yyvsp[-1].command_); YYACCEPT; } -#line 3386 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3312 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 6: -#line 656 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 648 "../SqlParser.ypp" /* yacc.c:1661 */ { YYABORT; } -#line 3394 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3320 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 7: -#line 659 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 651 "../SqlParser.ypp" /* yacc.c:1661 */ { // Regular yyparse() return codes are non-negative, so use a negative one here. return -1; } -#line 3403 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3329 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 8: -#line 666 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 658 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].statement_); } -#line 3411 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3337 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 9: -#line 669 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 661 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].copy_statement_); } -#line 3419 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3345 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 10: -#line 672 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 664 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].create_table_statement_); } -#line 3427 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3353 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 11: -#line 675 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 667 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].statement_); } -#line 3435 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3361 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 12: -#line 678 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 670 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].delete_statement_); } -#line 3443 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3369 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 13: -#line 681 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 673 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].drop_table_statement_); } -#line 3451 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3377 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 14: -#line 684 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 676 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].insert_statement_); } -#line 3459 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3385 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 15: -#line 687 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 679 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].quit_statement_); } -#line 3467 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3393 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 16: -#line 690 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 682 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].set_operation_statement_); } -#line 3475 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3401 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 17: -#line 693 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 685 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.statement_) = (yyvsp[0].update_statement_); } -#line 3483 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3409 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 18: -#line 699 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 691 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.quit_statement_) = new quickstep::ParseStatementQuit((yylsp[0]).first_line, (yylsp[0]).first_column); } -#line 3491 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3417 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 19: -#line 705 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 697 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-3].string_value_); delete (yyvsp[0].attribute_definition_); @@ -3499,22 +3425,22 @@ YYLTYPE yylloc = yyloc_default; NotSupported(&(yylsp[-5]), yyscanner, "ALTER statements"); YYERROR; } -#line 3503 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3429 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 20: -#line 712 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 704 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-3].string_value_); (yyval.statement_) = nullptr; NotSupported(&(yylsp[-5]), yyscanner, "ALTER statements"); YYERROR; } -#line 3514 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3440 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 21: -#line 718 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 710 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-3].string_value_); delete (yyvsp[0].string_value_); @@ -3522,11 +3448,11 @@ YYLTYPE yylloc = yyloc_default; NotSupported(&(yylsp[-5]), yyscanner, "ALTER statements"); YYERROR; } -#line 3526 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3452 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 22: -#line 725 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 717 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-3].string_value_); delete (yyvsp[0].string_value_); @@ -3534,19 +3460,19 @@ YYLTYPE yylloc = yyloc_default; NotSupported(&(yylsp[-5]), yyscanner, "ALTER statements"); YYERROR; } -#line 3538 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3464 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 23: -#line 734 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 726 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.create_table_statement_) = new quickstep::ParseStatementCreateTable((yylsp[-8]).first_line, (yylsp[-8]).first_column, (yyvsp[-6].string_value_), (yyvsp[-4].attribute_definition_list_), (yyvsp[-1].block_properties_), (yyvsp[0].partition_clause_)); } -#line 3546 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3472 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 24: -#line 739 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 731 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[0].key_value_list_)) { (yyval.statement_) = new quickstep::ParseStatementCreateIndex((yylsp[-8]).first_line, (yylsp[-8]).first_column, (yyvsp[-6].string_value_), (yyvsp[-4].string_value_), (yyvsp[-3].attribute_list_), (yyvsp[-1].string_value_), (yylsp[0]).first_line, (yylsp[0]).first_column, (yyvsp[0].key_value_list_)); @@ -3554,290 +3480,185 @@ YYLTYPE yylloc = yyloc_default; (yyval.statement_) = new quickstep::ParseStatementCreateIndex((yylsp[-8]).first_line, (yylsp[-8]).first_column, (yyvsp[-6].string_value_), (yyvsp[-4].string_value_), (yyvsp[-3].attribute_list_), (yyvsp[-1].string_value_)); } } -#line 3558 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3484 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 25: -#line 748 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 740 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.drop_table_statement_) = new quickstep::ParseStatementDropTable((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[0].string_value_)); } -#line 3566 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3492 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 26: -#line 753 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 745 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_definition_) = new quickstep::ParseAttributeDefinition((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-2].string_value_), (yyvsp[-1].data_type_), (yyvsp[0].column_constraint_list_)); } -#line 3574 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3500 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 27: -#line 758 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 750 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_definition_list_) = new quickstep::PtrList(); (yyval.attribute_definition_list_)->push_back((yyvsp[0].attribute_definition_)); } -#line 3583 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3509 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 28: -#line 762 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 754 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_definition_list_) = (yyvsp[-2].attribute_definition_list_); (yyval.attribute_definition_list_)->push_back((yyvsp[0].attribute_definition_)); } -#line 3592 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3518 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 29: -#line 768 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 760 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = nullptr; - NotSupported(&(yylsp[0]), yyscanner, "BIT data type"); - YYERROR; + (yyval.data_type_) = new quickstep::ParseDataType((yylsp[0]).first_line, (yylsp[0]).first_column, (yyvsp[0].string_value_)); } -#line 3602 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3526 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 30: -#line 773 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 763 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDate)); + (yyval.data_type_) = (yyvsp[-1].data_type_); } -#line 3610 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3534 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 31: -#line 776 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 768 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDatetime)); + (yyval.data_type_) = new quickstep::ParseDataType((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-3].string_value_)); + (yyvsp[-1].data_type_)->setNullable((yyvsp[0].boolean_value_)); + (yyval.data_type_)->addParameter( + new quickstep::ParseDataTypeParameterDataType((yyvsp[-1].data_type_)->line_number(), (yyvsp[-1].data_type_)->column_number(), (yyvsp[-1].data_type_))); } -#line 3618 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3545 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 32: -#line 779 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 774 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = nullptr; - NotSupported(&(yylsp[0]), yyscanner, "TIME data type"); - YYERROR; + (yyval.data_type_) = (yyvsp[-3].data_type_); + (yyvsp[-1].data_type_)->setNullable((yyvsp[0].boolean_value_)); + (yyval.data_type_)->addParameter( + new quickstep::ParseDataTypeParameterDataType((yyvsp[-1].data_type_)->line_number(), (yyvsp[-1].data_type_)->column_number(), (yyvsp[-1].data_type_))); } -#line 3628 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3556 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 33: -#line 784 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 780 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDatetime)); + (yyval.data_type_) = new quickstep::ParseDataType((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-2].string_value_)); + (yyval.data_type_)->addParameter( + new quickstep::ParseDataTypeParameterLiteralValue((yyvsp[0].literal_value_)->line_number(), (yyvsp[0].literal_value_)->column_number(), (yyvsp[0].literal_value_))); } -#line 3636 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3566 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 34: -#line 787 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 785 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble)); + (yyval.data_type_) = (yyvsp[-2].data_type_); + (yyval.data_type_)->addParameter( + new quickstep::ParseDataTypeParameterLiteralValue((yyvsp[0].literal_value_)->line_number(), (yyvsp[0].literal_value_)->column_number(), (yyvsp[0].literal_value_))); } -#line 3644 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3576 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 35: -#line 790 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 792 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble)); + (yyval.boolean_value_) = false; // NOT NULL } -#line 3652 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3584 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 36: -#line 793 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 795 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble)); + (yyval.boolean_value_) = true; // NULL } -#line 3660 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3592 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 37: -#line 796 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 798 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kFloat)); + (yyval.boolean_value_) = true; // NOT NULL } -#line 3668 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3600 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 38: -#line 799 "../SqlParser.ypp" /* yacc.c:1661 */ - { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kInt)); - } -#line 3676 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 39: -#line 802 "../SqlParser.ypp" /* yacc.c:1661 */ - { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kInt)); - } -#line 3684 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 40: -#line 805 "../SqlParser.ypp" /* yacc.c:1661 */ - { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kLong)); - } -#line 3692 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 41: -#line 808 "../SqlParser.ypp" /* yacc.c:1661 */ - { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kLong)); - } -#line 3700 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 42: -#line 811 "../SqlParser.ypp" /* yacc.c:1661 */ - { - /** - * NOTE(chasseur): This pattern exhibits a shift/reduce conflict with the - * TOKEN_INTERVAL case in 'literal_value'. Bison prefers to shift rather - * than reduce, so the case in 'literal_value' has precedence over this. - **/ - (yyval.data_type_) = nullptr; - quickstep_yyerror(&(yylsp[0]), yyscanner, nullptr, - "INTERVAL is ambiguous as a column type. Specify either DATETIME INTERVAL " - "or YEARMONTH INTERVAL"); - YYERROR; - } -#line 3717 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 43: -#line 823 "../SqlParser.ypp" /* yacc.c:1661 */ - { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDatetimeInterval)); - } -#line 3725 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 44: -#line 826 "../SqlParser.ypp" /* yacc.c:1661 */ - { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kYearMonthInterval)); - } -#line 3733 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 45: -#line 829 "../SqlParser.ypp" /* yacc.c:1661 */ - { - if ((yyvsp[-1].numeric_literal_value_)->float_like()) { - delete (yyvsp[-1].numeric_literal_value_); - (yyval.data_type_) = NULL; - quickstep_yyerror(&(yylsp[-1]), yyscanner, nullptr, "Non-integer length supplied for CHAR type"); - YYERROR; - } else { - if ((yyvsp[-1].numeric_literal_value_)->long_value() <= 0) { - delete (yyvsp[-1].numeric_literal_value_); - (yyval.data_type_) = NULL; - quickstep_yyerror(&(yylsp[-1]), yyscanner, nullptr, "Length for CHAR type must be at least 1"); - YYERROR; - } else { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kChar, (yyvsp[-1].numeric_literal_value_)->long_value(), false)); - delete (yyvsp[-1].numeric_literal_value_); - } - } - } -#line 3756 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 46: -#line 847 "../SqlParser.ypp" /* yacc.c:1661 */ - { - if ((yyvsp[-1].numeric_literal_value_)->float_like()) { - delete (yyvsp[-1].numeric_literal_value_); - (yyval.data_type_) = NULL; - quickstep_yyerror(&(yylsp[-1]), yyscanner, nullptr, "Non-integer length supplied for VARCHAR type"); - YYERROR; - } else { - if ((yyvsp[-1].numeric_literal_value_)->long_value() < 0) { - delete (yyvsp[-1].numeric_literal_value_); - (yyval.data_type_) = NULL; - quickstep_yyerror(&(yylsp[-1]), yyscanner, nullptr, "Negative length supplied for VARCHAR type"); - YYERROR; - } else { - (yyval.data_type_) = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kVarChar, (yyvsp[-1].numeric_literal_value_)->long_value(), false)); - delete (yyvsp[-1].numeric_literal_value_); - } - } - } -#line 3779 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 47: -#line 867 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 803 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_) = new quickstep::ParseColumnConstraintNull((yylsp[0]).first_line, (yylsp[0]).first_column); } -#line 3787 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3608 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 48: -#line 870 "../SqlParser.ypp" /* yacc.c:1661 */ + case 39: +#line 806 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_) = new quickstep::ParseColumnConstraintNotNull((yylsp[-1]).first_line, (yylsp[-1]).first_column); } -#line 3795 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3616 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 49: -#line 873 "../SqlParser.ypp" /* yacc.c:1661 */ + case 40: +#line 809 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_) = nullptr; NotSupported(&(yylsp[0]), yyscanner, "Column Constraints (UNIQUE)"); YYERROR; } -#line 3805 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3626 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 50: -#line 878 "../SqlParser.ypp" /* yacc.c:1661 */ + case 41: +#line 814 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_) = nullptr; NotSupported(&(yylsp[-1]), yyscanner, "Column Constraints (PRIMARY KEY)"); YYERROR; } -#line 3815 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3636 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 51: -#line 883 "../SqlParser.ypp" /* yacc.c:1661 */ + case 42: +#line 819 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_) = nullptr; delete (yyvsp[0].literal_value_); NotSupported(&(yylsp[-1]), yyscanner, "Column Constraints (DEFAULT)"); YYERROR; } -#line 3826 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3647 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 52: -#line 889 "../SqlParser.ypp" /* yacc.c:1661 */ + case 43: +#line 825 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_) = nullptr; delete (yyvsp[-1].predicate_); NotSupported(&(yylsp[-3]), yyscanner, "Column Constraints (CHECK)"); YYERROR; } -#line 3837 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3658 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 53: -#line 895 "../SqlParser.ypp" /* yacc.c:1661 */ + case 44: +#line 831 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_) = nullptr; delete (yyvsp[-3].string_value_); @@ -3845,65 +3666,65 @@ YYLTYPE yylloc = yyloc_default; NotSupported(&(yylsp[-4]), yyscanner, "Foreign Keys"); YYERROR; } -#line 3849 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3670 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 54: -#line 904 "../SqlParser.ypp" /* yacc.c:1661 */ + case 45: +#line 840 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_list_) = (yyvsp[-1].column_constraint_list_); (yyval.column_constraint_list_)->push_back((yyvsp[0].column_constraint_)); } -#line 3858 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3679 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 55: -#line 908 "../SqlParser.ypp" /* yacc.c:1661 */ + case 46: +#line 844 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_list_) = new quickstep::PtrList(); (yyval.column_constraint_list_)->push_back((yyvsp[0].column_constraint_)); } -#line 3867 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3688 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 56: -#line 914 "../SqlParser.ypp" /* yacc.c:1661 */ + case 47: +#line 850 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_list_) = nullptr; } -#line 3875 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3696 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 57: -#line 917 "../SqlParser.ypp" /* yacc.c:1661 */ + case 48: +#line 853 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.column_constraint_list_) = (yyvsp[0].column_constraint_list_); } -#line 3883 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3704 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 58: -#line 922 "../SqlParser.ypp" /* yacc.c:1661 */ + case 49: +#line 858 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-1].string_list_); NotSupported(&(yylsp[-3]), yyscanner, "Table Constraints (UNIQUE)"); YYERROR; } -#line 3893 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3714 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 59: -#line 927 "../SqlParser.ypp" /* yacc.c:1661 */ + case 50: +#line 863 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-1].string_list_); NotSupported(&(yylsp[-4]), yyscanner, "Table Constraints (PRIMARY KEY)"); YYERROR; } -#line 3903 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3724 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 60: -#line 932 "../SqlParser.ypp" /* yacc.c:1661 */ + case 51: +#line 868 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-6].string_list_); delete (yyvsp[-3].string_value_); @@ -3911,95 +3732,95 @@ YYLTYPE yylloc = yyloc_default; NotSupported(&(yylsp[-9]), yyscanner, "Table Constraints (FOREIGN KEY)"); YYERROR; } -#line 3915 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3736 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 61: -#line 939 "../SqlParser.ypp" /* yacc.c:1661 */ + case 52: +#line 875 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-1].predicate_); NotSupported(&(yylsp[-3]), yyscanner, "Table Constraints (CHECK)"); YYERROR; } -#line 3925 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3746 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 62: -#line 946 "../SqlParser.ypp" /* yacc.c:1661 */ + case 53: +#line 882 "../SqlParser.ypp" /* yacc.c:1661 */ { NotSupported(&(yylsp[-2]), yyscanner, "Table Constraints"); YYERROR; } -#line 3934 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3755 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 63: -#line 950 "../SqlParser.ypp" /* yacc.c:1661 */ + case 54: +#line 886 "../SqlParser.ypp" /* yacc.c:1661 */ { NotSupported(&(yylsp[0]), yyscanner, "Table Constraints"); YYERROR; } -#line 3943 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3764 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 64: -#line 956 "../SqlParser.ypp" /* yacc.c:1661 */ + case 55: +#line 892 "../SqlParser.ypp" /* yacc.c:1661 */ { /* $$ = nullptr; */ } -#line 3951 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3772 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 65: -#line 959 "../SqlParser.ypp" /* yacc.c:1661 */ + case 56: +#line 895 "../SqlParser.ypp" /* yacc.c:1661 */ { /* $$ = $1; */ } -#line 3959 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3780 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 66: -#line 964 "../SqlParser.ypp" /* yacc.c:1661 */ + case 57: +#line 900 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_list_) = nullptr; } -#line 3967 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3788 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 67: -#line 967 "../SqlParser.ypp" /* yacc.c:1661 */ + case 58: +#line 903 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_list_) = (yyvsp[-1].attribute_list_); } -#line 3975 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3796 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 68: -#line 972 "../SqlParser.ypp" /* yacc.c:1661 */ + case 59: +#line 908 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.block_properties_) = nullptr; } -#line 3983 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3804 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 69: -#line 975 "../SqlParser.ypp" /* yacc.c:1661 */ + case 60: +#line 911 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.block_properties_) = new quickstep::ParseBlockProperties((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-1].key_value_list_)); } -#line 3991 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3812 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 70: -#line 980 "../SqlParser.ypp" /* yacc.c:1661 */ + case 61: +#line 916 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.partition_clause_) = nullptr; } -#line 3999 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3820 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 71: -#line 983 "../SqlParser.ypp" /* yacc.c:1661 */ + case 62: +#line 919 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[0].numeric_literal_value_)->float_like()) { delete (yyvsp[0].numeric_literal_value_); @@ -4017,111 +3838,111 @@ YYLTYPE yylloc = yyloc_default; } } } -#line 4021 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3842 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 72: -#line 1002 "../SqlParser.ypp" /* yacc.c:1661 */ + case 63: +#line 938 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, quickstep::kHashPartitionType); } -#line 4029 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3850 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 73: -#line 1005 "../SqlParser.ypp" /* yacc.c:1661 */ + case 64: +#line 941 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, quickstep::kRangePartitionType); } -#line 4037 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3858 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 74: -#line 1010 "../SqlParser.ypp" /* yacc.c:1661 */ + case 65: +#line 946 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_list_) = new quickstep::PtrList(); (yyval.key_value_list_)->push_back((yyvsp[0].key_value_)); } -#line 4046 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3867 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 75: -#line 1014 "../SqlParser.ypp" /* yacc.c:1661 */ - { + case 66: +#line 950 "../SqlParser.ypp" /* yacc.c:1661 */ + { (yyval.key_value_list_) = (yyvsp[-2].key_value_list_); (yyval.key_value_list_)->push_back((yyvsp[0].key_value_)); } -#line 4055 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3876 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 76: -#line 1020 "../SqlParser.ypp" /* yacc.c:1661 */ + case 67: +#line 956 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_) = (yyvsp[0].key_string_value_); } -#line 4063 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3884 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 77: -#line 1023 "../SqlParser.ypp" /* yacc.c:1661 */ + case 68: +#line 959 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_) = (yyvsp[0].key_string_list_); } -#line 4071 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3892 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 78: -#line 1026 "../SqlParser.ypp" /* yacc.c:1661 */ + case 69: +#line 962 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_) = (yyvsp[0].key_integer_value_); } -#line 4079 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3900 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 79: -#line 1029 "../SqlParser.ypp" /* yacc.c:1661 */ + case 70: +#line 965 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_) = (yyvsp[0].key_bool_value_); } -#line 4087 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3908 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 80: -#line 1034 "../SqlParser.ypp" /* yacc.c:1661 */ + case 71: +#line 970 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_string_value_) = new quickstep::ParseKeyStringValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].string_value_)); } -#line 4095 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3916 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 81: -#line 1037 "../SqlParser.ypp" /* yacc.c:1661 */ + case 72: +#line 973 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_string_value_) = new quickstep::ParseKeyStringValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].string_value_)); } -#line 4103 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3924 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 82: -#line 1040 "../SqlParser.ypp" /* yacc.c:1661 */ + case 73: +#line 976 "../SqlParser.ypp" /* yacc.c:1661 */ { // This is a special case to handle the COMPRESS ALL option of the BLOCK PROPERTIES. (yyval.key_string_value_) = new quickstep::ParseKeyStringValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].string_value_), new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, "ALL")); } -#line 4113 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3934 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 83: -#line 1047 "../SqlParser.ypp" /* yacc.c:1661 */ + case 74: +#line 983 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_string_list_) = new quickstep::ParseKeyStringList((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-3].string_value_), (yyvsp[-1].string_list_)); } -#line 4121 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3942 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 84: -#line 1052 "../SqlParser.ypp" /* yacc.c:1661 */ + case 75: +#line 988 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[0].numeric_literal_value_)->float_like()) { delete (yyvsp[0].numeric_literal_value_); @@ -4131,72 +3952,72 @@ YYLTYPE yylloc = yyloc_default; } (yyval.key_integer_value_) = new quickstep::ParseKeyIntegerValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].numeric_literal_value_)); } -#line 4135 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3956 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 85: -#line 1063 "../SqlParser.ypp" /* yacc.c:1661 */ + case 76: +#line 999 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_bool_value_) = new quickstep::ParseKeyBoolValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].boolean_value_)); } -#line 4143 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3964 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 86: -#line 1068 "../SqlParser.ypp" /* yacc.c:1661 */ + case 77: +#line 1004 "../SqlParser.ypp" /* yacc.c:1661 */ { // Defaults to BitWeavingV, but IndexProperties can change this to H. (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::to_string(quickstep::IndexSubBlockType::kBitWeavingV)); } -#line 4153 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3974 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 87: -#line 1073 "../SqlParser.ypp" /* yacc.c:1661 */ + case 78: +#line 1009 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::to_string(quickstep::IndexSubBlockType::kBloomFilter)); } -#line 4162 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3983 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 88: -#line 1077 "../SqlParser.ypp" /* yacc.c:1661 */ + case 79: +#line 1013 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::to_string(quickstep::IndexSubBlockType::kCSBTree)); } -#line 4171 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 3992 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 89: -#line 1081 "../SqlParser.ypp" /* yacc.c:1661 */ + case 80: +#line 1017 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::to_string(quickstep::IndexSubBlockType::kSMA)); } -#line 4180 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4001 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 90: -#line 1087 "../SqlParser.ypp" /* yacc.c:1661 */ + case 81: +#line 1023 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_list_) = nullptr; } -#line 4188 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4009 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 91: -#line 1090 "../SqlParser.ypp" /* yacc.c:1661 */ + case 82: +#line 1026 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_list_) = (yyvsp[-1].key_value_list_); } -#line 4196 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4017 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 92: -#line 1096 "../SqlParser.ypp" /* yacc.c:1661 */ + case 83: +#line 1032 "../SqlParser.ypp" /* yacc.c:1661 */ { delete (yyvsp[-7].string_value_); delete (yyvsp[-5].string_list_); @@ -4205,180 +4026,180 @@ YYLTYPE yylloc = yyloc_default; NotSupported(&(yylsp[-6]), yyscanner, "list of column names in INSERT statement"); YYERROR; } -#line 4209 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4030 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 93: -#line 1104 "../SqlParser.ypp" /* yacc.c:1661 */ + case 84: +#line 1040 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.insert_statement_) = new quickstep::ParseStatementInsertTuple((yylsp[-6]).first_line, (yylsp[-6]).first_column, (yyvsp[-4].string_value_), (yyvsp[-1].literal_value_list_)); } -#line 4217 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4038 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 94: -#line 1107 "../SqlParser.ypp" /* yacc.c:1661 */ + case 85: +#line 1043 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.insert_statement_) = new quickstep::ParseStatementInsertSelection((yylsp[-3]).first_line, (yylsp[-2]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].select_query_), nullptr); } -#line 4225 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4046 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 95: -#line 1110 "../SqlParser.ypp" /* yacc.c:1661 */ + case 86: +#line 1046 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.insert_statement_) = new quickstep::ParseStatementInsertSelection((yylsp[-4]).first_line, (yylsp[-3]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].select_query_), (yyvsp[-4].with_list_)); } -#line 4233 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4054 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 96: -#line 1116 "../SqlParser.ypp" /* yacc.c:1661 */ + case 87: +#line 1052 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.copy_statement_) = new quickstep::ParseStatementCopy((yylsp[-4]).first_line, (yylsp[-4]).first_column, quickstep::ParseStatementCopy::kFrom, (yyvsp[-3].string_value_), (yyvsp[-1].string_value_), (yyvsp[0].key_value_list_)); } -#line 4243 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4064 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 97: -#line 1121 "../SqlParser.ypp" /* yacc.c:1661 */ + case 88: +#line 1057 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.copy_statement_) = new quickstep::ParseStatementCopy((yylsp[-3]).first_line, (yylsp[-3]).first_column, quickstep::ParseStatementCopy::kTo, (yyvsp[-2].string_value_), (yyvsp[-1].string_value_), (yyvsp[0].key_value_list_)); } -#line 4253 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4074 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 98: -#line 1126 "../SqlParser.ypp" /* yacc.c:1661 */ + case 89: +#line 1062 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.copy_statement_) = new quickstep::ParseStatementCopy((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-2].set_operation_), nullptr, (yyvsp[-1].string_value_), (yyvsp[0].key_value_list_)); } -#line 4262 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4083 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 99: -#line 1130 "../SqlParser.ypp" /* yacc.c:1661 */ + case 90: +#line 1066 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.copy_statement_) = new quickstep::ParseStatementCopy((yylsp[-4]).first_line, (yylsp[-4]).first_column, (yyvsp[-2].set_operation_), (yyvsp[-4].with_list_), (yyvsp[-1].string_value_), (yyvsp[0].key_value_list_)); } -#line 4271 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4092 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 100: -#line 1136 "../SqlParser.ypp" /* yacc.c:1661 */ + case 91: +#line 1072 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yyvsp[0].string_value_)->line_number(), (yyvsp[0].string_value_)->column_number(), "@" + (yyvsp[0].string_value_)->value()); delete (yyvsp[0].string_value_); } -#line 4280 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4101 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 101: -#line 1140 "../SqlParser.ypp" /* yacc.c:1661 */ + case 92: +#line 1076 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, "$stdout"); } -#line 4288 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4109 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 102: -#line 1143 "../SqlParser.ypp" /* yacc.c:1661 */ + case 93: +#line 1079 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, "$stderr"); } -#line 4296 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4117 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 103: -#line 1148 "../SqlParser.ypp" /* yacc.c:1661 */ + case 94: +#line 1084 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_list_) = nullptr; } -#line 4304 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4125 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 104: -#line 1151 "../SqlParser.ypp" /* yacc.c:1661 */ + case 95: +#line 1087 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.key_value_list_) = (yyvsp[-1].key_value_list_); } -#line 4312 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4133 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 105: -#line 1156 "../SqlParser.ypp" /* yacc.c:1661 */ + case 96: +#line 1092 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.update_statement_) = new quickstep::ParseStatementUpdate((yylsp[-4]).first_line, (yylsp[-4]).first_column, (yyvsp[-3].string_value_), (yyvsp[-1].assignment_list_), (yyvsp[0].predicate_)); } -#line 4320 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4141 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 106: -#line 1161 "../SqlParser.ypp" /* yacc.c:1661 */ + case 97: +#line 1097 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.delete_statement_) = new quickstep::ParseStatementDelete((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].predicate_)); } -#line 4328 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4149 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 107: -#line 1166 "../SqlParser.ypp" /* yacc.c:1661 */ + case 98: +#line 1102 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.assignment_list_) = (yyvsp[-2].assignment_list_); (yyval.assignment_list_)->push_back((yyvsp[0].assignment_)); } -#line 4337 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4158 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 108: -#line 1170 "../SqlParser.ypp" /* yacc.c:1661 */ + case 99: +#line 1106 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.assignment_list_) = new quickstep::PtrList(); (yyval.assignment_list_)->push_back((yyvsp[0].assignment_)); } -#line 4346 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4167 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 109: -#line 1176 "../SqlParser.ypp" /* yacc.c:1661 */ + case 100: +#line 1112 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.assignment_) = new quickstep::ParseAssignment((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-2].string_value_), (yyvsp[0].expression_)); } -#line 4354 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4175 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 110: -#line 1185 "../SqlParser.ypp" /* yacc.c:1661 */ + case 101: +#line 1121 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.set_operation_statement_) = new quickstep::ParseStatementSetOperation((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].set_operation_), nullptr, (yyvsp[0].opt_priority_clause_)); } -#line 4362 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4183 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 111: -#line 1188 "../SqlParser.ypp" /* yacc.c:1661 */ + case 102: +#line 1124 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.set_operation_statement_) = new quickstep::ParseStatementSetOperation((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-1].set_operation_), (yyvsp[-2].with_list_), (yyvsp[0].opt_priority_clause_)); } -#line 4370 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4191 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 112: -#line 1193 "../SqlParser.ypp" /* yacc.c:1661 */ + case 103: +#line 1129 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_priority_clause_) = nullptr; } -#line 4378 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4199 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 113: -#line 1196 "../SqlParser.ypp" /* yacc.c:1661 */ + case 104: +#line 1132 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[0].numeric_literal_value_)->float_like()) { delete (yyvsp[0].numeric_literal_value_); @@ -4396,46 +4217,46 @@ YYLTYPE yylloc = yyloc_default; } } } -#line 4400 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4221 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 114: -#line 1215 "../SqlParser.ypp" /* yacc.c:1661 */ + case 105: +#line 1151 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.with_list_) = (yyvsp[0].with_list_); } -#line 4408 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4229 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 115: -#line 1220 "../SqlParser.ypp" /* yacc.c:1661 */ + case 106: +#line 1156 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.with_list_) = new quickstep::PtrVector(); (yyval.with_list_)->push_back((yyvsp[0].with_list_element_)); } -#line 4417 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4238 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 116: -#line 1224 "../SqlParser.ypp" /* yacc.c:1661 */ + case 107: +#line 1160 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.with_list_) = (yyvsp[-2].with_list_); (yyval.with_list_)->push_back((yyvsp[0].with_list_element_)); } -#line 4426 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4247 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 117: -#line 1230 "../SqlParser.ypp" /* yacc.c:1661 */ + case 108: +#line 1166 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.with_list_element_) = new quickstep::ParseSubqueryTableReference((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[0].subquery_expression_)); (yyval.with_list_element_)->set_table_reference_signature((yyvsp[-2].table_reference_signature_)); } -#line 4435 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4256 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 118: -#line 1236 "../SqlParser.ypp" /* yacc.c:1661 */ + case 109: +#line 1172 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[-1].boolean_value_)) { (yyval.set_operation_) = new quickstep::ParseSetOperation((yylsp[-3]).first_line, (yylsp[-3]).first_column, quickstep::ParseSetOperation::kUnion); @@ -4445,19 +4266,19 @@ YYLTYPE yylloc = yyloc_default; (yyval.set_operation_)->addOperand((yyvsp[-3].set_operation_)); (yyval.set_operation_)->addOperand((yyvsp[0].set_operation_)); } -#line 4449 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4270 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 119: -#line 1245 "../SqlParser.ypp" /* yacc.c:1661 */ + case 110: +#line 1181 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.set_operation_) = (yyvsp[0].set_operation_); } -#line 4457 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4278 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 120: -#line 1250 "../SqlParser.ypp" /* yacc.c:1661 */ + case 111: +#line 1186 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.set_operation_) = new quickstep::ParseSetOperation((yylsp[-2]).first_line, (yylsp[-2]).first_column, quickstep::ParseSetOperation::kIntersect); quickstep::ParseSetOperation *op = new quickstep::ParseSetOperation( @@ -4466,387 +4287,387 @@ YYLTYPE yylloc = yyloc_default; (yyval.set_operation_)->addOperand((yyvsp[-2].set_operation_)); (yyval.set_operation_)->addOperand(op); } -#line 4470 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4291 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 121: -#line 1258 "../SqlParser.ypp" /* yacc.c:1661 */ + case 112: +#line 1194 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.set_operation_) = new quickstep::ParseSetOperation((yylsp[0]).first_line, (yylsp[0]).first_column, quickstep::ParseSetOperation::kSelect); (yyval.set_operation_)->addOperand((yyvsp[0].select_query_)); } -#line 4479 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4300 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 122: -#line 1265 "../SqlParser.ypp" /* yacc.c:1661 */ + case 113: +#line 1201 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.select_query_) = new quickstep::ParseSelect((yylsp[-9]).first_line, (yylsp[-9]).first_column, (yyvsp[-7].selection_), (yyvsp[-6].table_reference_list_), (yyvsp[-5].predicate_), (yyvsp[-4].opt_group_by_clause_), (yyvsp[-3].opt_having_clause_), (yyvsp[-2].opt_order_by_clause_), (yyvsp[-1].opt_limit_clause_), (yyvsp[0].opt_window_clause_)); } -#line 4487 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4308 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 123: -#line 1270 "../SqlParser.ypp" /* yacc.c:1661 */ + case 114: +#line 1206 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = true; // Distinct } -#line 4495 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4316 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 124: -#line 1273 "../SqlParser.ypp" /* yacc.c:1661 */ + case 115: +#line 1209 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = false; // All } -#line 4503 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4324 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 125: -#line 1276 "../SqlParser.ypp" /* yacc.c:1661 */ + case 116: +#line 1212 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = true; // Distinct } -#line 4511 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4332 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 126: -#line 1281 "../SqlParser.ypp" /* yacc.c:1661 */ + case 117: +#line 1217 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.selection_) = new quickstep::ParseSelectionStar((yylsp[0]).first_line, (yylsp[0]).first_column); } -#line 4519 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4340 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 127: -#line 1284 "../SqlParser.ypp" /* yacc.c:1661 */ + case 118: +#line 1220 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.selection_) = (yyvsp[0].selection_list_); } -#line 4527 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4348 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 128: -#line 1289 "../SqlParser.ypp" /* yacc.c:1661 */ + case 119: +#line 1225 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.selection_list_) = new quickstep::ParseSelectionList((yylsp[0]).first_line, (yylsp[0]).first_column); (yyval.selection_list_)->add((yyvsp[0].selection_item_)); } -#line 4536 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4357 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 129: -#line 1293 "../SqlParser.ypp" /* yacc.c:1661 */ + case 120: +#line 1229 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.selection_list_) = (yyvsp[-2].selection_list_); (yyval.selection_list_)->add((yyvsp[0].selection_item_)); } -#line 4545 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4366 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 130: -#line 1299 "../SqlParser.ypp" /* yacc.c:1661 */ + case 121: +#line 1235 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.selection_item_) = new quickstep::ParseSelectionItem((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-2].expression_), (yyvsp[0].string_value_)); } -#line 4553 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4374 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 131: -#line 1302 "../SqlParser.ypp" /* yacc.c:1661 */ + case 122: +#line 1238 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.selection_item_) = new quickstep::ParseSelectionItem((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].expression_), (yyvsp[0].string_value_)); } -#line 4561 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4382 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 132: -#line 1305 "../SqlParser.ypp" /* yacc.c:1661 */ + case 123: +#line 1241 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.selection_item_) = new quickstep::ParseSelectionItem((yylsp[0]).first_line, (yylsp[0]).first_column, (yyvsp[0].expression_)); } -#line 4569 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4390 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 133: -#line 1310 "../SqlParser.ypp" /* yacc.c:1661 */ + case 124: +#line 1246 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_list_) = (yyvsp[0].table_reference_list_); } -#line 4577 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4398 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 134: -#line 1315 "../SqlParser.ypp" /* yacc.c:1661 */ + case 125: +#line 1251 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.subquery_expression_) = new quickstep::ParseSubqueryExpression((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-1].set_operation_)); } -#line 4585 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4406 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 135: -#line 1320 "../SqlParser.ypp" /* yacc.c:1661 */ + case 126: +#line 1256 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_sample_clause_) = NULL; } -#line 4593 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4414 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 136: -#line 1323 "../SqlParser.ypp" /* yacc.c:1661 */ + case 127: +#line 1259 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_sample_clause_) = new quickstep::ParseSample((yylsp[-2]).first_line, (yylsp[-2]).first_column, true, (yyvsp[-1].numeric_literal_value_)); } -#line 4601 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4422 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 137: -#line 1326 "../SqlParser.ypp" /* yacc.c:1661 */ + case 128: +#line 1262 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_sample_clause_) = new quickstep::ParseSample((yylsp[-2]).first_line, (yylsp[-2]).first_column, false, (yyvsp[-1].numeric_literal_value_)); } -#line 4609 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4430 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 138: -#line 1331 "../SqlParser.ypp" /* yacc.c:1661 */ + case 129: +#line 1267 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kInnerJoin; } -#line 4617 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4438 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 139: -#line 1334 "../SqlParser.ypp" /* yacc.c:1661 */ + case 130: +#line 1270 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kInnerJoin; } -#line 4625 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4446 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 140: -#line 1337 "../SqlParser.ypp" /* yacc.c:1661 */ + case 131: +#line 1273 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kLeftOuterJoin; } -#line 4633 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4454 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 141: -#line 1340 "../SqlParser.ypp" /* yacc.c:1661 */ + case 132: +#line 1276 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kLeftOuterJoin; } -#line 4641 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4462 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 142: -#line 1343 "../SqlParser.ypp" /* yacc.c:1661 */ + case 133: +#line 1279 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kRightOuterJoin; } -#line 4649 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4470 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 143: -#line 1346 "../SqlParser.ypp" /* yacc.c:1661 */ + case 134: +#line 1282 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kRightOuterJoin; } -#line 4657 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4478 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 144: -#line 1349 "../SqlParser.ypp" /* yacc.c:1661 */ + case 135: +#line 1285 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kFullOuterJoin; } -#line 4665 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4486 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 145: -#line 1352 "../SqlParser.ypp" /* yacc.c:1661 */ + case 136: +#line 1288 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.join_type_) = quickstep::ParseJoinedTableReference::JoinType::kFullOuterJoin; } -#line 4673 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4494 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 146: -#line 1357 "../SqlParser.ypp" /* yacc.c:1661 */ + case 137: +#line 1293 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = new quickstep::ParseJoinedTableReference((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-4].join_type_), (yyvsp[-5].table_reference_), (yyvsp[-2].table_reference_), (yyvsp[0].predicate_)); } -#line 4681 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4502 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 147: -#line 1360 "../SqlParser.ypp" /* yacc.c:1661 */ + case 138: +#line 1296 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = (yyvsp[0].table_reference_); } -#line 4689 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4510 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 148: -#line 1365 "../SqlParser.ypp" /* yacc.c:1661 */ + case 139: +#line 1301 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = new quickstep::ParseSubqueryTableReference((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].subquery_expression_)); (yyval.table_reference_)->set_table_reference_signature((yyvsp[0].table_reference_signature_)); } -#line 4698 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4519 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 149: -#line 1369 "../SqlParser.ypp" /* yacc.c:1661 */ + case 140: +#line 1305 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = new quickstep::ParseSimpleTableReference((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-2].string_value_), (yyvsp[-1].opt_sample_clause_)); (yyval.table_reference_)->set_table_reference_signature((yyvsp[0].table_reference_signature_)); } -#line 4707 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4528 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 150: -#line 1373 "../SqlParser.ypp" /* yacc.c:1661 */ + case 141: +#line 1309 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = new quickstep::ParseSimpleTableReference((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].opt_sample_clause_)); } -#line 4715 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4536 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 151: -#line 1376 "../SqlParser.ypp" /* yacc.c:1661 */ + case 142: +#line 1312 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = new quickstep::ParseGeneratorTableReference((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].function_call_)); (yyval.table_reference_)->set_table_reference_signature((yyvsp[0].table_reference_signature_)); } -#line 4724 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4545 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 152: -#line 1380 "../SqlParser.ypp" /* yacc.c:1661 */ + case 143: +#line 1316 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = new quickstep::ParseGeneratorTableReference((yylsp[0]).first_line, (yylsp[0]).first_column, (yyvsp[0].function_call_)); } -#line 4732 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4553 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 153: -#line 1383 "../SqlParser.ypp" /* yacc.c:1661 */ + case 144: +#line 1319 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_) = (yyvsp[-1].table_reference_); } -#line 4740 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4561 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 154: -#line 1388 "../SqlParser.ypp" /* yacc.c:1661 */ + case 145: +#line 1324 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_signature_) = (yyvsp[0].table_reference_signature_); } -#line 4748 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4569 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 155: -#line 1391 "../SqlParser.ypp" /* yacc.c:1661 */ + case 146: +#line 1327 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_signature_) = (yyvsp[0].table_reference_signature_); } -#line 4756 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4577 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 156: -#line 1396 "../SqlParser.ypp" /* yacc.c:1661 */ + case 147: +#line 1332 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_signature_) = new ::quickstep::ParseTableReferenceSignature((yylsp[0]).first_line, (yylsp[0]).first_column, (yyvsp[0].string_value_)); } -#line 4764 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4585 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 157: -#line 1399 "../SqlParser.ypp" /* yacc.c:1661 */ + case 148: +#line 1335 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_signature_) = new ::quickstep::ParseTableReferenceSignature((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-3].string_value_), (yyvsp[-1].string_list_)); } -#line 4772 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4593 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 158: -#line 1404 "../SqlParser.ypp" /* yacc.c:1661 */ + case 149: +#line 1340 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_list_) = new quickstep::PtrList(); (yyval.table_reference_list_)->push_back((yyvsp[0].table_reference_)); } -#line 4781 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4602 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 159: -#line 1408 "../SqlParser.ypp" /* yacc.c:1661 */ + case 150: +#line 1344 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.table_reference_list_) = (yyvsp[-2].table_reference_list_); (yyval.table_reference_list_)->push_back((yyvsp[0].table_reference_)); } -#line 4790 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4611 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 160: -#line 1414 "../SqlParser.ypp" /* yacc.c:1661 */ + case 151: +#line 1350 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_group_by_clause_) = nullptr; } -#line 4798 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4619 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 161: -#line 1417 "../SqlParser.ypp" /* yacc.c:1661 */ + case 152: +#line 1353 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_group_by_clause_) = new quickstep::ParseGroupBy((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[0].expression_list_)); } -#line 4806 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4627 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 162: -#line 1422 "../SqlParser.ypp" /* yacc.c:1661 */ + case 153: +#line 1358 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_having_clause_) = nullptr; } -#line 4814 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4635 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 163: -#line 1425 "../SqlParser.ypp" /* yacc.c:1661 */ + case 154: +#line 1361 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_having_clause_) = new quickstep::ParseHaving((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[0].predicate_)); } -#line 4822 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4643 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 164: -#line 1430 "../SqlParser.ypp" /* yacc.c:1661 */ + case 155: +#line 1366 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_order_by_clause_) = nullptr; } -#line 4830 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4651 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 165: -#line 1433 "../SqlParser.ypp" /* yacc.c:1661 */ + case 156: +#line 1369 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_order_by_clause_) = new quickstep::ParseOrderBy((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[0].order_commalist_)); } -#line 4838 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4659 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 166: -#line 1438 "../SqlParser.ypp" /* yacc.c:1661 */ + case 157: +#line 1374 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_limit_clause_) = nullptr; } -#line 4846 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4667 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 167: -#line 1441 "../SqlParser.ypp" /* yacc.c:1661 */ + case 158: +#line 1377 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[0].numeric_literal_value_)->float_like()) { delete (yyvsp[0].numeric_literal_value_); @@ -4864,258 +4685,258 @@ YYLTYPE yylloc = yyloc_default; } } } -#line 4868 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4689 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 168: -#line 1460 "../SqlParser.ypp" /* yacc.c:1661 */ + case 159: +#line 1396 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_window_clause_) = nullptr; } -#line 4876 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4697 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 169: -#line 1463 "../SqlParser.ypp" /* yacc.c:1661 */ + case 160: +#line 1399 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_window_clause_) = (yyvsp[0].opt_window_clause_); } -#line 4884 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4705 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 170: -#line 1468 "../SqlParser.ypp" /* yacc.c:1661 */ + case 161: +#line 1404 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_window_clause_) = new quickstep::PtrList(); (yyval.opt_window_clause_)->push_back((yyvsp[0].window_definition_)); } -#line 4893 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4714 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 171: -#line 1472 "../SqlParser.ypp" /* yacc.c:1661 */ + case 162: +#line 1408 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.opt_window_clause_) = (yyvsp[-1].opt_window_clause_); (yyval.opt_window_clause_)->push_back((yyvsp[0].window_definition_)); } -#line 4902 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4723 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 172: -#line 1478 "../SqlParser.ypp" /* yacc.c:1661 */ + case 163: +#line 1414 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_definition_) = (yyvsp[-1].window_definition_); (yyval.window_definition_)->setName((yyvsp[-4].string_value_)); } -#line 4911 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4732 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 173: -#line 1484 "../SqlParser.ypp" /* yacc.c:1661 */ + case 164: +#line 1420 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_definition_) = new quickstep::ParseWindow((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-2].window_partition_by_list_), (yyvsp[-1].window_order_by_list_), (yyvsp[0].window_frame_info_)); } -#line 4919 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4740 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 174: -#line 1489 "../SqlParser.ypp" /* yacc.c:1661 */ + case 165: +#line 1425 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_partition_by_list_) = nullptr; } -#line 4927 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4748 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 175: -#line 1492 "../SqlParser.ypp" /* yacc.c:1661 */ + case 166: +#line 1428 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_partition_by_list_) = (yyvsp[0].expression_list_); } -#line 4935 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4756 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 176: -#line 1497 "../SqlParser.ypp" /* yacc.c:1661 */ + case 167: +#line 1433 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_order_by_list_) = nullptr; } -#line 4943 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4764 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 177: -#line 1500 "../SqlParser.ypp" /* yacc.c:1661 */ + case 168: +#line 1436 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_order_by_list_) = (yyvsp[0].order_commalist_); } -#line 4951 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4772 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 178: -#line 1505 "../SqlParser.ypp" /* yacc.c:1661 */ + case 169: +#line 1441 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_frame_info_) = nullptr; } -#line 4959 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4780 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 179: -#line 1508 "../SqlParser.ypp" /* yacc.c:1661 */ + case 170: +#line 1444 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.window_frame_info_) = new quickstep::ParseFrameInfo((yylsp[-4]).first_line, (yylsp[-4]).first_column, (yyvsp[-4].boolean_value_), (yyvsp[-2].numeric_literal_value_)->long_value(), (yyvsp[0].numeric_literal_value_)->long_value()); } -#line 4967 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4788 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 180: -#line 1513 "../SqlParser.ypp" /* yacc.c:1661 */ + case 171: +#line 1449 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = true; } -#line 4975 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4796 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 181: -#line 1516 "../SqlParser.ypp" /* yacc.c:1661 */ + case 172: +#line 1452 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = false; } -#line 4983 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4804 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 183: -#line 1522 "../SqlParser.ypp" /* yacc.c:1661 */ + case 174: +#line 1458 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.numeric_literal_value_) = new quickstep::NumericParseLiteralValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, "-1"); } -#line 4991 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4812 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 184: -#line 1525 "../SqlParser.ypp" /* yacc.c:1661 */ + case 175: +#line 1461 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.numeric_literal_value_) = new quickstep::NumericParseLiteralValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, "0"); } -#line 4999 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4820 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 186: -#line 1531 "../SqlParser.ypp" /* yacc.c:1661 */ + case 177: +#line 1467 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.numeric_literal_value_) = new quickstep::NumericParseLiteralValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, "-1"); } -#line 5007 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4828 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 187: -#line 1534 "../SqlParser.ypp" /* yacc.c:1661 */ + case 178: +#line 1470 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.numeric_literal_value_) = new quickstep::NumericParseLiteralValue((yylsp[-1]).first_line, (yylsp[-1]).first_column, "0"); } -#line 5015 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4836 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 188: -#line 1539 "../SqlParser.ypp" /* yacc.c:1661 */ + case 179: +#line 1475 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_commalist_) = new quickstep::PtrList(); (yyval.order_commalist_)->push_back((yyvsp[0].order_item_)); } -#line 5024 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4845 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 189: -#line 1543 "../SqlParser.ypp" /* yacc.c:1661 */ + case 180: +#line 1479 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_commalist_) = (yyvsp[-2].order_commalist_); (yyval.order_commalist_)->push_back((yyvsp[0].order_item_)); } -#line 5033 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4854 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 190: -#line 1549 "../SqlParser.ypp" /* yacc.c:1661 */ + case 181: +#line 1485 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_item_) = new quickstep::ParseOrderByItem((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[-2].expression_), (yyvsp[-1].order_direction_), (yyvsp[0].order_direction_)); delete (yyvsp[-1].order_direction_); delete (yyvsp[0].order_direction_); } -#line 5043 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4864 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 191: -#line 1556 "../SqlParser.ypp" /* yacc.c:1661 */ + case 182: +#line 1492 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_direction_) = nullptr; } -#line 5051 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4872 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 192: -#line 1559 "../SqlParser.ypp" /* yacc.c:1661 */ + case 183: +#line 1495 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_direction_) = new bool(true); } -#line 5059 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4880 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 193: -#line 1562 "../SqlParser.ypp" /* yacc.c:1661 */ + case 184: +#line 1498 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_direction_) = new bool(false); } -#line 5067 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4888 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 194: -#line 1567 "../SqlParser.ypp" /* yacc.c:1661 */ + case 185: +#line 1503 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_direction_) = nullptr; } -#line 5075 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4896 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 195: -#line 1570 "../SqlParser.ypp" /* yacc.c:1661 */ + case 186: +#line 1506 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_direction_) = new bool(true); } -#line 5083 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4904 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 196: -#line 1573 "../SqlParser.ypp" /* yacc.c:1661 */ + case 187: +#line 1509 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.order_direction_) = new bool(false); } -#line 5091 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4912 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 197: -#line 1579 "../SqlParser.ypp" /* yacc.c:1661 */ + case 188: +#line 1515 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.predicate_) = nullptr; } -#line 5099 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4920 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 198: -#line 1582 "../SqlParser.ypp" /* yacc.c:1661 */ + case 189: +#line 1518 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.predicate_) = (yyvsp[0].predicate_); } -#line 5107 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4928 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 199: -#line 1587 "../SqlParser.ypp" /* yacc.c:1661 */ + case 190: +#line 1523 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.predicate_) = (yyvsp[0].predicate_); } -#line 5115 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4936 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 200: -#line 1592 "../SqlParser.ypp" /* yacc.c:1661 */ + case 191: +#line 1528 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[-2].predicate_)->getParsePredicateType() == quickstep::ParsePredicate::kDisjunction) { (yyval.predicate_) = (yyvsp[-2].predicate_); @@ -5125,19 +4946,19 @@ YYLTYPE yylloc = yyloc_default; } static_cast((yyval.predicate_))->addPredicate((yyvsp[0].predicate_)); } -#line 5129 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4950 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 201: -#line 1601 "../SqlParser.ypp" /* yacc.c:1661 */ + case 192: +#line 1537 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.predicate_) = (yyvsp[0].predicate_); } -#line 5137 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4958 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 202: -#line 1606 "../SqlParser.ypp" /* yacc.c:1661 */ + case 193: +#line 1542 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[-2].predicate_)->getParsePredicateType() == quickstep::ParsePredicate::kConjunction) { (yyval.predicate_) = (yyvsp[-2].predicate_); @@ -5147,453 +4968,542 @@ YYLTYPE yylloc = yyloc_default; } static_cast((yyval.predicate_))->addPredicate((yyvsp[0].predicate_)); } -#line 5151 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4972 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 203: -#line 1615 "../SqlParser.ypp" /* yacc.c:1661 */ + case 194: +#line 1551 "../SqlParser.ypp" /* yacc.c:1661 */ + { + (yyval.predicate_) = (yyvsp[0].predicate_); + } +#line 4980 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 195: +#line 1556 "../SqlParser.ypp" /* yacc.c:1661 */ + { + (yyval.predicate_) = new quickstep::ParsePredicateNegation((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[0].predicate_)); + } +#line 4988 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 196: +#line 1559 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.predicate_) = (yyvsp[0].predicate_); } -#line 5159 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 4996 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 197: +#line 1564 "../SqlParser.ypp" /* yacc.c:1661 */ + { + (yyval.predicate_) = new quickstep::ParsePredicateBetween((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-4].expression_), (yyvsp[-2].expression_), (yyvsp[0].expression_)); + } +#line 5004 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 198: +#line 1567 "../SqlParser.ypp" /* yacc.c:1661 */ + { + (yyval.predicate_) = new quickstep::ParsePredicateNegation( + (yylsp[-4]).first_line, (yylsp[-4]).first_column, + new quickstep::ParsePredicateBetween((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-5].expression_), (yyvsp[-2].expression_), (yyvsp[0].expression_))); + } +#line 5014 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 199: +#line 1572 "../SqlParser.ypp" /* yacc.c:1661 */ + { + delete (yyvsp[-3].attribute_); + (yyval.predicate_) = nullptr; + NotSupported(&(yylsp[-2]), yyscanner, "NULL comparison predicates"); + YYERROR; + } +#line 5025 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 200: +#line 1578 "../SqlParser.ypp" /* yacc.c:1661 */ + { + delete (yyvsp[-2].attribute_); + (yyval.predicate_) = nullptr; + NotSupported(&(yylsp[-1]), yyscanner, "NULL comparison predicates"); + YYERROR; + } +#line 5036 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 201: +#line 1584 "../SqlParser.ypp" /* yacc.c:1661 */ + { + (yyval.predicate_) = new quickstep::ParsePredicateComparison((yylsp[-1]).first_line, (yylsp[-1]).first_column, *(yyvsp[-1].comparison_), (yyvsp[-2].expression_), (yyvsp[0].expression_)); + } +#line 5044 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 202: +#line 1587 "../SqlParser.ypp" /* yacc.c:1661 */ + { + (yyval.predicate_) = (yyvsp[-1].predicate_); + } +#line 5052 "SqlParser_gen.cpp" /* yacc.c:1661 */ + break; + + case 203: +#line 1590 "../SqlParser.ypp" /* yacc.c:1661 */ + { + (yyval.predicate_) = new quickstep::ParsePredicateExists((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[0].subquery_expression_)); + } +#line 5060 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 204: -#line 1620 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1593 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateNegation((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[0].predicate_)); + (yyval.predicate_) = new quickstep::ParsePredicateInTableQuery((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-2].expression_), (yyvsp[0].subquery_expression_)); } -#line 5167 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5068 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 205: -#line 1623 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1596 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = (yyvsp[0].predicate_); + (yyval.predicate_) = new quickstep::ParsePredicateInValueList((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-4].expression_), (yyvsp[-1].expression_list_)); } -#line 5175 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5076 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 206: -#line 1628 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1599 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateBetween((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-4].expression_), (yyvsp[-2].expression_), (yyvsp[0].expression_)); + (yyval.predicate_) = new quickstep::ParsePredicateNegation( + (yylsp[-2]).first_line, + (yylsp[-2]).first_column, + new quickstep::ParsePredicateInTableQuery((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-3].expression_), (yyvsp[0].subquery_expression_))); } -#line 5183 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5087 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 207: -#line 1631 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1605 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.predicate_) = new quickstep::ParsePredicateNegation( - (yylsp[-4]).first_line, (yylsp[-4]).first_column, - new quickstep::ParsePredicateBetween((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-5].expression_), (yyvsp[-2].expression_), (yyvsp[0].expression_))); + (yylsp[-4]).first_line, + (yylsp[-4]).first_column, + new quickstep::ParsePredicateInValueList((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-5].expression_), (yyvsp[-1].expression_list_))); } -#line 5193 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5098 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 208: -#line 1636 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1614 "../SqlParser.ypp" /* yacc.c:1661 */ { - delete (yyvsp[-3].attribute_); - (yyval.predicate_) = nullptr; - NotSupported(&(yylsp[-2]), yyscanner, "NULL comparison predicates"); - YYERROR; + auto *arguments = new quickstep::PtrList(); + arguments->push_back((yyvsp[-2].expression_)); + arguments->push_back((yyvsp[0].expression_)); + (yyval.expression_) = new quickstep::ParseFunctionCall((yylsp[-2]).first_line, (yylsp[-2]).first_column, false, (yyvsp[-1].binary_operation_), arguments); } -#line 5204 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5109 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 209: -#line 1642 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1620 "../SqlParser.ypp" /* yacc.c:1661 */ { - delete (yyvsp[-2].attribute_); - (yyval.predicate_) = nullptr; - NotSupported(&(yylsp[-1]), yyscanner, "NULL comparison predicates"); - YYERROR; + (yyval.expression_) = (yyvsp[0].expression_); } -#line 5215 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5117 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 210: -#line 1648 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1625 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateComparison((yylsp[-1]).first_line, (yylsp[-1]).first_column, *(yyvsp[-1].comparison_), (yyvsp[-2].expression_), (yyvsp[0].expression_)); + auto *arguments = new quickstep::PtrList(); + arguments->push_back((yyvsp[-2].expression_)); + arguments->push_back((yyvsp[0].expression_)); + (yyval.expression_) = new quickstep::ParseFunctionCall((yylsp[-2]).first_line, (yylsp[-2]).first_column, false, (yyvsp[-1].binary_operation_), arguments); } -#line 5223 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5128 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 211: -#line 1651 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1631 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = (yyvsp[-1].predicate_); + (yyval.expression_) = (yyvsp[0].expression_); } -#line 5231 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5136 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 212: -#line 1654 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1636 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateExists((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[0].subquery_expression_)); + auto *arguments = new quickstep::PtrList(); + arguments->push_back((yyvsp[0].expression_)); + (yyval.expression_) = new quickstep::ParseFunctionCall((yylsp[-1]).first_line, (yylsp[-1]).first_column, false, (yyvsp[-1].unary_operation_), arguments); } -#line 5239 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5146 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 213: -#line 1657 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1641 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateInTableQuery((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-2].expression_), (yyvsp[0].subquery_expression_)); + (yyval.expression_) = (yyvsp[0].expression_); } -#line 5247 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5154 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 214: -#line 1660 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1646 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateInValueList((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-4].expression_), (yyvsp[-1].expression_list_)); + (yyval.expression_) = (yyvsp[0].attribute_); } -#line 5255 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5162 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 215: -#line 1663 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1649 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateNegation( - (yylsp[-2]).first_line, - (yylsp[-2]).first_column, - new quickstep::ParsePredicateInTableQuery((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-3].expression_), (yyvsp[0].subquery_expression_))); + (yyval.expression_) = new quickstep::ParseScalarLiteral((yyvsp[0].literal_value_)); } -#line 5266 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5170 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 216: -#line 1669 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1652 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.predicate_) = new quickstep::ParsePredicateNegation( - (yylsp[-4]).first_line, - (yylsp[-4]).first_column, - new quickstep::ParsePredicateInValueList((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-5].expression_), (yyvsp[-1].expression_list_))); + (yyval.expression_) = (yyvsp[0].array_expression_); } -#line 5277 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5178 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 217: -#line 1678 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1655 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = new quickstep::ParseBinaryExpression((yylsp[-1]).first_line, (yylsp[-1]).first_column, *(yyvsp[-1].binary_operation_), (yyvsp[-2].expression_), (yyvsp[0].expression_)); + (yyval.expression_) = (yyvsp[0].function_call_); } -#line 5285 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5186 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 218: -#line 1681 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1658 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[0].expression_); + (yyvsp[-2].function_call_)->setWindowName((yyvsp[0].string_value_)); + (yyval.expression_) = (yyvsp[-2].function_call_); } -#line 5293 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5195 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 219: -#line 1686 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1662 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = new quickstep::ParseBinaryExpression((yylsp[-1]).first_line, (yylsp[-1]).first_column, *(yyvsp[-1].binary_operation_), (yyvsp[-2].expression_), (yyvsp[0].expression_)); + (yyvsp[-4].function_call_)->setWindow((yyvsp[-1].window_definition_)); + (yyval.expression_) = (yyvsp[-4].function_call_); } -#line 5301 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5204 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 220: -#line 1689 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1666 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_) = (yyvsp[0].expression_); } -#line 5309 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5212 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 221: -#line 1694 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1669 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = new quickstep::ParseUnaryExpression((yylsp[-1]).first_line, (yylsp[-1]).first_column, *(yyvsp[-1].unary_operation_), (yyvsp[0].expression_)); + (yyval.expression_) = (yyvsp[0].expression_); } -#line 5317 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5220 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 222: -#line 1697 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1672 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_) = (yyvsp[0].expression_); } -#line 5325 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5228 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 223: -#line 1702 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1675 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[0].attribute_); + (yyval.expression_) = (yyvsp[0].expression_); } -#line 5333 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5236 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 224: -#line 1705 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1678 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = new quickstep::ParseScalarLiteral((yyvsp[0].literal_value_)); + (yyval.expression_) = (yyvsp[-1].expression_); } -#line 5341 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5244 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 225: -#line 1708 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1681 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[0].function_call_); + (yyval.expression_) = (yyvsp[0].subquery_expression_); } -#line 5349 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5252 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 226: -#line 1711 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1686 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyvsp[-2].function_call_)->setWindowName((yyvsp[0].string_value_)); - (yyval.expression_) = (yyvsp[-2].function_call_); + (yyval.array_expression_) = (yyvsp[-1].array_expression_); } -#line 5358 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5260 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 227: -#line 1715 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1689 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyvsp[-4].function_call_)->setWindow((yyvsp[-1].window_definition_)); - (yyval.expression_) = (yyvsp[-4].function_call_); + (yyval.array_expression_) = new quickstep::ParseArray((yylsp[-1]).first_line, (yylsp[-1]).first_column); } -#line 5367 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5268 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 228: -#line 1719 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1695 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[0].expression_); + (yyval.array_expression_) = (yyvsp[-2].array_expression_); + (yyval.array_expression_)->add((yyvsp[0].expression_)); } -#line 5375 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5277 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 229: -#line 1722 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1699 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[0].expression_); + (yyval.array_expression_) = new quickstep::ParseArray((yylsp[-1]).first_line, (yylsp[-1]).first_column); + (yyval.array_expression_)->add((yyvsp[0].expression_)); } -#line 5383 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5286 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 230: -#line 1725 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1706 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[0].expression_); + (yyval.function_call_) = new quickstep::ParseFunctionCall( + (yylsp[-2]).first_line, (yylsp[-2]).first_column, false, (yyvsp[-2].string_value_), new quickstep::PtrList()); } -#line 5391 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5295 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 231: -#line 1728 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1710 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[-1].expression_); + (yyval.function_call_) = new quickstep::ParseFunctionCall( + (yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-3].string_value_), new quickstep::ParseStar((yylsp[-1]).first_line, (yylsp[-1]).first_column)); } -#line 5399 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5304 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 232: -#line 1731 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1714 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = (yyvsp[0].subquery_expression_); + (yyval.function_call_) = new quickstep::ParseFunctionCall((yylsp[-3]).first_line, (yylsp[-3]).first_column, false, (yyvsp[-3].string_value_), (yyvsp[-1].expression_list_)); } -#line 5407 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5312 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 233: -#line 1736 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1717 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.function_call_) = new quickstep::ParseFunctionCall( - (yylsp[-2]).first_line, (yylsp[-2]).first_column, false, (yyvsp[-2].string_value_), new quickstep::PtrList()); + (yyval.function_call_) = new quickstep::ParseFunctionCall((yylsp[-4]).first_line, (yylsp[-4]).first_column, true, (yyvsp[-4].string_value_), (yyvsp[-1].expression_list_)); } -#line 5416 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5320 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 234: -#line 1740 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1722 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.function_call_) = new quickstep::ParseFunctionCall( - (yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-3].string_value_), new quickstep::ParseStar((yylsp[-1]).first_line, (yylsp[-1]).first_column)); + (yyval.expression_) = new quickstep::ParseTypeCast((yylsp[-5]).first_line, (yylsp[-5]).first_column, (yyvsp[-3].expression_), (yyvsp[-1].data_type_)); } -#line 5425 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5328 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 235: -#line 1744 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1725 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.function_call_) = new quickstep::ParseFunctionCall((yylsp[-3]).first_line, (yylsp[-3]).first_column, false, (yyvsp[-3].string_value_), (yyvsp[-1].expression_list_)); + (yyval.expression_) = new quickstep::ParseTypeCast((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-2].expression_), (yyvsp[0].data_type_)); } -#line 5433 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5336 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 236: -#line 1747 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1730 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.function_call_) = new quickstep::ParseFunctionCall((yylsp[-4]).first_line, (yylsp[-4]).first_column, true, (yyvsp[-4].string_value_), (yyvsp[-1].expression_list_)); + auto *arguments = new quickstep::PtrList(); + arguments->push_back((yyvsp[-1].expression_)); + arguments->push_back(new quickstep::ParseScalarLiteral( + new quickstep::StringParseLiteralValue((yyvsp[-3].string_value_), nullptr))); + auto *name = new quickstep::ParseString((yylsp[-5]).first_line, (yylsp[-5]).first_column, "extract"); + (yyval.expression_) = new quickstep::ParseFunctionCall( + (yylsp[-5]).first_line, (yylsp[-5]).first_column, false, name, arguments); } -#line 5441 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5350 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 237: -#line 1752 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1741 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = new quickstep::ParseExtractFunction((yylsp[-5]).first_line, (yylsp[-5]).first_column, (yyvsp[-3].string_value_), (yyvsp[-1].expression_)); + auto *arguments = new quickstep::PtrList(); + arguments->push_back((yyvsp[-3].expression_)); + arguments->push_back(new quickstep::ParseScalarLiteral((yyvsp[-1].numeric_literal_value_))); + auto *name = new quickstep::ParseString((yylsp[-5]).first_line, (yylsp[-5]).first_column, "substring"); + (yyval.expression_) = new quickstep::ParseFunctionCall( + (yylsp[-5]).first_line, (yylsp[-5]).first_column, false, name, arguments); } -#line 5449 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5363 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 238: -#line 1757 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1749 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.expression_) = new quickstep::ParseSubstringFunction( - (yylsp[-5]).first_line, (yylsp[-5]).first_column, (yyvsp[-3].expression_), (yyvsp[-1].numeric_literal_value_)->long_value()); + auto *arguments = new quickstep::PtrList(); + arguments->push_back((yyvsp[-5].expression_)); + arguments->push_back(new quickstep::ParseScalarLiteral((yyvsp[-3].numeric_literal_value_))); + arguments->push_back(new quickstep::ParseScalarLiteral((yyvsp[-1].numeric_literal_value_))); + auto *name = new quickstep::ParseString((yylsp[-7]).first_line, (yylsp[-7]).first_column, "substring"); + (yyval.expression_) = new quickstep::ParseFunctionCall( + (yylsp[-7]).first_line, (yylsp[-7]).first_column, false, name, arguments); } -#line 5458 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5377 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; case 239: -#line 1761 "../SqlParser.ypp" /* yacc.c:1661 */ - { - (yyval.expression_) = new quickstep::ParseSubstringFunction( - (yylsp[-7]).first_line, (yylsp[-7]).first_column, (yyvsp[-5].expression_), (yyvsp[-3].numeric_literal_value_)->long_value(), (yyvsp[-1].numeric_literal_value_)->long_value()); - } -#line 5467 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 240: -#line 1767 "../SqlParser.ypp" /* yacc.c:1661 */ +#line 1760 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_) = new quickstep::ParseSimpleCaseExpression((yylsp[-4]).first_line, (yylsp[-4]).first_column, (yyvsp[-3].expression_), (yyvsp[-2].simple_when_clause_list_), (yyvsp[-1].expression_)); } -#line 5475 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5385 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 241: -#line 1770 "../SqlParser.ypp" /* yacc.c:1661 */ + case 240: +#line 1763 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_) = new quickstep::ParseSearchedCaseExpression((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-2].searched_when_clause_list_), (yyvsp[-1].expression_)); } -#line 5483 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5393 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 242: -#line 1775 "../SqlParser.ypp" /* yacc.c:1661 */ + case 241: +#line 1768 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.simple_when_clause_list_) = new quickstep::PtrVector; (yyval.simple_when_clause_list_)->push_back((yyvsp[0].simple_when_clause_)); } -#line 5492 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5402 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 243: -#line 1779 "../SqlParser.ypp" /* yacc.c:1661 */ + case 242: +#line 1772 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.simple_when_clause_list_) = (yyvsp[-1].simple_when_clause_list_); (yyval.simple_when_clause_list_)->push_back((yyvsp[0].simple_when_clause_)); } -#line 5501 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5411 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 244: -#line 1785 "../SqlParser.ypp" /* yacc.c:1661 */ + case 243: +#line 1778 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.simple_when_clause_) = new quickstep::ParseSimpleWhenClause((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-2].expression_), (yyvsp[0].expression_)); } -#line 5509 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5419 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 245: -#line 1790 "../SqlParser.ypp" /* yacc.c:1661 */ + case 244: +#line 1783 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.searched_when_clause_list_) = new quickstep::PtrVector; (yyval.searched_when_clause_list_)->push_back((yyvsp[0].searched_when_clause_)); } -#line 5518 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5428 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 246: -#line 1794 "../SqlParser.ypp" /* yacc.c:1661 */ + case 245: +#line 1787 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.searched_when_clause_list_) = (yyvsp[-1].searched_when_clause_list_); (yyval.searched_when_clause_list_)->push_back((yyvsp[0].searched_when_clause_)); } -#line 5527 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5437 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 247: -#line 1800 "../SqlParser.ypp" /* yacc.c:1661 */ + case 246: +#line 1793 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.searched_when_clause_) = new quickstep::ParseSearchedWhenClause((yylsp[-3]).first_line, (yylsp[-3]).first_column, (yyvsp[-2].predicate_), (yyvsp[0].expression_)); } -#line 5535 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5445 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 248: -#line 1805 "../SqlParser.ypp" /* yacc.c:1661 */ + case 247: +#line 1798 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_) = NULL; } -#line 5543 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5453 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 249: -#line 1808 "../SqlParser.ypp" /* yacc.c:1661 */ + case 248: +#line 1801 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_) = (yyvsp[0].expression_); } -#line 5551 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5461 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 250: -#line 1813 "../SqlParser.ypp" /* yacc.c:1661 */ + case 249: +#line 1806 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_list_) = new quickstep::PtrList(); (yyval.expression_list_)->push_back((yyvsp[0].expression_)); } -#line 5560 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5470 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 251: -#line 1817 "../SqlParser.ypp" /* yacc.c:1661 */ + case 250: +#line 1810 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.expression_list_) = (yyvsp[-2].expression_list_); (yyval.expression_list_)->push_back((yyvsp[0].expression_)); } -#line 5569 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5479 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 252: -#line 1823 "../SqlParser.ypp" /* yacc.c:1661 */ + case 251: +#line 1816 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.literal_value_) = new quickstep::NullParseLiteralValue((yylsp[0]).first_line, (yylsp[0]).first_column); } -#line 5577 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5487 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 253: -#line 1826 "../SqlParser.ypp" /* yacc.c:1661 */ + case 252: +#line 1819 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.literal_value_) = (yyvsp[0].numeric_literal_value_); } -#line 5585 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5495 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 254: -#line 1829 "../SqlParser.ypp" /* yacc.c:1661 */ + case 253: +#line 1822 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.literal_value_) = (yyvsp[0].numeric_literal_value_); } -#line 5593 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5503 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 255: -#line 1832 "../SqlParser.ypp" /* yacc.c:1661 */ + case 254: +#line 1825 "../SqlParser.ypp" /* yacc.c:1661 */ { /** * NOTE(chasseur): This case exhibits a shift/reduce conflict with the @@ -5606,20 +5516,20 @@ YYLTYPE yylloc = yyloc_default; (yyvsp[0].numeric_literal_value_)->prependMinus(); (yyval.literal_value_) = (yyvsp[0].numeric_literal_value_); } -#line 5610 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5520 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 256: -#line 1844 "../SqlParser.ypp" /* yacc.c:1661 */ + case 255: +#line 1837 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.literal_value_) = new quickstep::StringParseLiteralValue((yyvsp[0].string_value_), nullptr); // No explicit type. } -#line 5619 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5529 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 257: -#line 1848 "../SqlParser.ypp" /* yacc.c:1661 */ + case 256: +#line 1841 "../SqlParser.ypp" /* yacc.c:1661 */ { /** * NOTE(chasseur): This case exhibits a shift/reduce conflict with the @@ -5639,11 +5549,11 @@ YYLTYPE yylloc = yyloc_default; YYERROR; } } -#line 5643 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5553 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 258: -#line 1867 "../SqlParser.ypp" /* yacc.c:1661 */ + case 257: +#line 1860 "../SqlParser.ypp" /* yacc.c:1661 */ { quickstep::StringParseLiteralValue *parse_value; const std::string &datetime_type_value = (yyvsp[0].string_value_)->value(); @@ -5657,209 +5567,191 @@ YYLTYPE yylloc = yyloc_default; YYERROR; } } -#line 5661 "SqlParser_gen.cpp" /* yacc.c:1661 */ - break; - - case 259: -#line 1880 "../SqlParser.ypp" /* yacc.c:1661 */ - { - quickstep::StringParseLiteralValue *parse_value - = new quickstep::StringParseLiteralValue((yyvsp[0].string_value_), &((yyvsp[-1].data_type_)->getType())); - delete (yyvsp[-1].data_type_); - if (!parse_value->tryExplicitTypeParse()) { - delete parse_value; - (yyval.literal_value_) = nullptr; - quickstep_yyerror(&(yylsp[0]), yyscanner, nullptr, "Failed to parse literal as specified type"); - YYERROR; - } else { - (yyval.literal_value_) = parse_value; - } - } -#line 5679 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5571 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 260: -#line 1895 "../SqlParser.ypp" /* yacc.c:1661 */ + case 258: +#line 1875 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("YEAR")); } -#line 5687 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5579 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 261: -#line 1898 "../SqlParser.ypp" /* yacc.c:1661 */ + case 259: +#line 1878 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("MONTH")); } -#line 5695 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5587 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 262: -#line 1901 "../SqlParser.ypp" /* yacc.c:1661 */ + case 260: +#line 1881 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("DAY")); } -#line 5703 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5595 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 263: -#line 1904 "../SqlParser.ypp" /* yacc.c:1661 */ + case 261: +#line 1884 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("HOUR")); } -#line 5711 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5603 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 264: -#line 1907 "../SqlParser.ypp" /* yacc.c:1661 */ + case 262: +#line 1887 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("MINUTE")); } -#line 5719 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5611 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 265: -#line 1910 "../SqlParser.ypp" /* yacc.c:1661 */ + case 263: +#line 1890 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("SECOND")); } -#line 5727 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5619 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 266: -#line 1915 "../SqlParser.ypp" /* yacc.c:1661 */ + case 264: +#line 1895 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.literal_value_list_) = new quickstep::PtrList(); (yyval.literal_value_list_)->push_back(new quickstep::ParseScalarLiteral((yyvsp[0].literal_value_))); } -#line 5736 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5628 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 267: -#line 1919 "../SqlParser.ypp" /* yacc.c:1661 */ + case 265: +#line 1899 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.literal_value_list_) = (yyvsp[-2].literal_value_list_); (yyval.literal_value_list_)->push_back(new quickstep::ParseScalarLiteral((yyvsp[0].literal_value_))); } -#line 5745 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5637 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 268: -#line 1925 "../SqlParser.ypp" /* yacc.c:1661 */ + case 266: +#line 1905 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_) = new quickstep::ParseAttribute((yylsp[0]).first_line, (yylsp[0]).first_column, (yyvsp[0].string_value_)); } -#line 5753 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5645 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 269: -#line 1928 "../SqlParser.ypp" /* yacc.c:1661 */ + case 267: +#line 1908 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_) = new quickstep::ParseAttribute((yylsp[-2]).first_line, (yylsp[-2]).first_column, (yyvsp[0].string_value_), (yyvsp[-2].string_value_)); } -#line 5761 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5653 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 270: -#line 1933 "../SqlParser.ypp" /* yacc.c:1661 */ + case 268: +#line 1913 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_list_) = new quickstep::PtrList(); (yyval.attribute_list_)->push_back((yyvsp[0].attribute_)); } -#line 5770 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5662 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 271: -#line 1937 "../SqlParser.ypp" /* yacc.c:1661 */ + case 269: +#line 1917 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.attribute_list_) = (yyvsp[-2].attribute_list_); (yyval.attribute_list_)->push_back((yyvsp[0].attribute_)); } -#line 5779 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5671 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 272: -#line 1944 "../SqlParser.ypp" /* yacc.c:1661 */ + case 270: +#line 1924 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kEqual); } -#line 5787 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5679 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 273: -#line 1947 "../SqlParser.ypp" /* yacc.c:1661 */ + case 271: +#line 1927 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kNotEqual); } -#line 5795 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5687 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 274: -#line 1950 "../SqlParser.ypp" /* yacc.c:1661 */ + case 272: +#line 1930 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kLess); } -#line 5803 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5695 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 275: -#line 1953 "../SqlParser.ypp" /* yacc.c:1661 */ + case 273: +#line 1933 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kLessOrEqual); } -#line 5811 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5703 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 276: -#line 1956 "../SqlParser.ypp" /* yacc.c:1661 */ + case 274: +#line 1936 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kGreater); } -#line 5819 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5711 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 277: -#line 1959 "../SqlParser.ypp" /* yacc.c:1661 */ + case 275: +#line 1939 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kGreaterOrEqual); } -#line 5827 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5719 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 278: -#line 1962 "../SqlParser.ypp" /* yacc.c:1661 */ + case 276: +#line 1942 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kLike); } -#line 5835 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5727 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 279: -#line 1965 "../SqlParser.ypp" /* yacc.c:1661 */ + case 277: +#line 1945 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kNotLike); } -#line 5843 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5735 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 280: -#line 1968 "../SqlParser.ypp" /* yacc.c:1661 */ + case 278: +#line 1948 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kRegexMatch); } -#line 5851 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5743 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 281: -#line 1971 "../SqlParser.ypp" /* yacc.c:1661 */ + case 279: +#line 1951 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.comparison_) = &quickstep::ComparisonFactory::GetComparison(quickstep::ComparisonID::kNotRegexMatch); } -#line 5859 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5751 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 282: -#line 1976 "../SqlParser.ypp" /* yacc.c:1661 */ + case 280: +#line 1956 "../SqlParser.ypp" /* yacc.c:1661 */ { /** * NOTE(chasseur): This case exhibits a shift/reduce conflict with the @@ -5867,148 +5759,148 @@ YYLTYPE yylloc = yyloc_default; * to shift rather than reduce, the case in 'literal_value' has precedence * over this one. **/ - (yyval.unary_operation_) = &quickstep::UnaryOperationFactory::GetUnaryOperation(quickstep::UnaryOperationID::kNegate); + (yyval.unary_operation_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("-")); } -#line 5873 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5765 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 283: -#line 1987 "../SqlParser.ypp" /* yacc.c:1661 */ + case 281: +#line 1967 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.binary_operation_) = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kAdd); + (yyval.binary_operation_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("+")); } -#line 5881 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5773 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 284: -#line 1990 "../SqlParser.ypp" /* yacc.c:1661 */ + case 282: +#line 1970 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.binary_operation_) = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kSubtract); + (yyval.binary_operation_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("-")); } -#line 5889 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5781 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 285: -#line 1995 "../SqlParser.ypp" /* yacc.c:1661 */ + case 283: +#line 1975 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.binary_operation_) = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kModulo); + (yyval.binary_operation_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("%")); } -#line 5897 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5789 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 286: -#line 1998 "../SqlParser.ypp" /* yacc.c:1661 */ + case 284: +#line 1978 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.binary_operation_) = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kMultiply); + (yyval.binary_operation_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("*")); } -#line 5905 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5797 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 287: -#line 2001 "../SqlParser.ypp" /* yacc.c:1661 */ + case 285: +#line 1981 "../SqlParser.ypp" /* yacc.c:1661 */ { - (yyval.binary_operation_) = &quickstep::BinaryOperationFactory::GetBinaryOperation(quickstep::BinaryOperationID::kDivide); + (yyval.binary_operation_) = new quickstep::ParseString((yylsp[0]).first_line, (yylsp[0]).first_column, std::string("/")); } -#line 5913 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5805 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 288: -#line 2007 "../SqlParser.ypp" /* yacc.c:1661 */ + case 286: +#line 1987 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_list_) = new quickstep::PtrList(); (yyval.string_list_)->push_back((yyvsp[0].string_value_)); } -#line 5922 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5814 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 289: -#line 2011 "../SqlParser.ypp" /* yacc.c:1661 */ + case 287: +#line 1991 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_list_) = (yyvsp[-2].string_list_); (yyval.string_list_)->push_back((yyvsp[0].string_value_)); } -#line 5931 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5823 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 290: -#line 2017 "../SqlParser.ypp" /* yacc.c:1661 */ + case 288: +#line 1997 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.string_value_) = (yyvsp[0].string_value_); } -#line 5939 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5831 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 291: -#line 2020 "../SqlParser.ypp" /* yacc.c:1661 */ + case 289: +#line 2000 "../SqlParser.ypp" /* yacc.c:1661 */ { if ((yyvsp[0].string_value_)->value().empty()) { quickstep_yyerror(&(yylsp[0]), yyscanner, nullptr, "Zero-length identifier"); } (yyval.string_value_) = (yyvsp[0].string_value_); } -#line 5950 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5842 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 292: -#line 2028 "../SqlParser.ypp" /* yacc.c:1661 */ + case 290: +#line 2008 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = true; } -#line 5958 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5850 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 293: -#line 2031 "../SqlParser.ypp" /* yacc.c:1661 */ + case 291: +#line 2011 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = true; } -#line 5966 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5858 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 294: -#line 2034 "../SqlParser.ypp" /* yacc.c:1661 */ + case 292: +#line 2014 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = false; } -#line 5974 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5866 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 295: -#line 2037 "../SqlParser.ypp" /* yacc.c:1661 */ + case 293: +#line 2017 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.boolean_value_) = false; } -#line 5982 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5874 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 296: -#line 2043 "../SqlParser.ypp" /* yacc.c:1661 */ + case 294: +#line 2023 "../SqlParser.ypp" /* yacc.c:1661 */ { (yyval.command_) = new quickstep::ParseCommand((yylsp[-1]).first_line, (yylsp[-1]).first_column, (yyvsp[-1].string_value_), (yyvsp[0].command_argument_list_)); } -#line 5990 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5882 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 297: -#line 2048 "../SqlParser.ypp" /* yacc.c:1661 */ + case 295: +#line 2028 "../SqlParser.ypp" /* yacc.c:1661 */ { quickstep::PtrVector *argument_list = (yyvsp[-1].command_argument_list_); argument_list->push_back((yyvsp[0].string_value_)); (yyval.command_argument_list_) = argument_list; } -#line 6000 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5892 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; - case 298: -#line 2053 "../SqlParser.ypp" /* yacc.c:1661 */ + case 296: +#line 2033 "../SqlParser.ypp" /* yacc.c:1661 */ { /* Epsilon, an empy match. */ (yyval.command_argument_list_) = new quickstep::PtrVector(); } -#line 6008 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5900 "SqlParser_gen.cpp" /* yacc.c:1661 */ break; -#line 6012 "SqlParser_gen.cpp" /* yacc.c:1661 */ +#line 5904 "SqlParser_gen.cpp" /* yacc.c:1661 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -6243,7 +6135,7 @@ YYLTYPE yylloc = yyloc_default; #endif return yyresult; } -#line 2057 "../SqlParser.ypp" /* yacc.c:1906 */ +#line 2037 "../SqlParser.ypp" /* yacc.c:1906 */ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string &feature) { diff --git a/parser/preprocessed/SqlParser_gen.hpp b/parser/preprocessed/SqlParser_gen.hpp index f6b52478..037f6971 100644 --- a/parser/preprocessed/SqlParser_gen.hpp +++ b/parser/preprocessed/SqlParser_gen.hpp @@ -72,113 +72,103 @@ extern int quickstep_yydebug; TOKEN_ALTER = 282, TOKEN_AS = 283, TOKEN_ASC = 284, - TOKEN_BIGINT = 285, - TOKEN_BIT = 286, - TOKEN_BITWEAVING = 287, - TOKEN_BLOCKPROPERTIES = 288, - TOKEN_BLOCKSAMPLE = 289, - TOKEN_BLOOM_FILTER = 290, - TOKEN_CSB_TREE = 291, - TOKEN_BY = 292, - TOKEN_CASE = 293, - TOKEN_CHARACTER = 294, - TOKEN_CHECK = 295, - TOKEN_COLUMN = 296, - TOKEN_CONSTRAINT = 297, - TOKEN_COPY = 298, - TOKEN_CREATE = 299, - TOKEN_CURRENT = 300, - TOKEN_DATE = 301, - TOKEN_DATETIME = 302, - TOKEN_DAY = 303, - TOKEN_DECIMAL = 304, - TOKEN_DEFAULT = 305, - TOKEN_DELETE = 306, - TOKEN_DESC = 307, - TOKEN_DISTINCT = 308, - TOKEN_DOUBLE = 309, - TOKEN_DROP = 310, - TOKEN_ELSE = 311, - TOKEN_END = 312, - TOKEN_EXISTS = 313, - TOKEN_EXTRACT = 314, - TOKEN_FALSE = 315, - TOKEN_FIRST = 316, - TOKEN_FLOAT = 317, - TOKEN_FOLLOWING = 318, - TOKEN_FOR = 319, - TOKEN_FOREIGN = 320, - TOKEN_FROM = 321, - TOKEN_FULL = 322, - TOKEN_GROUP = 323, - TOKEN_HASH = 324, - TOKEN_HAVING = 325, - TOKEN_HOUR = 326, - TOKEN_IN = 327, - TOKEN_INDEX = 328, - TOKEN_INNER = 329, - TOKEN_INSERT = 330, - TOKEN_INTEGER = 331, - TOKEN_INTERVAL = 332, - TOKEN_INTO = 333, - TOKEN_JOIN = 334, - TOKEN_KEY = 335, - TOKEN_LAST = 336, - TOKEN_LEFT = 337, - TOKEN_LIMIT = 338, - TOKEN_LONG = 339, - TOKEN_MINUTE = 340, - TOKEN_MONTH = 341, - TOKEN_NULL = 342, - TOKEN_NULLS = 343, - TOKEN_OFF = 344, - TOKEN_ON = 345, - TOKEN_ORDER = 346, - TOKEN_OUTER = 347, - TOKEN_OVER = 348, - TOKEN_PARTITION = 349, - TOKEN_PARTITIONS = 350, - TOKEN_PERCENT = 351, - TOKEN_PRECEDING = 352, - TOKEN_PRIMARY = 353, - TOKEN_PRIORITY = 354, - TOKEN_QUIT = 355, - TOKEN_RANGE = 356, - TOKEN_REAL = 357, - TOKEN_REFERENCES = 358, - TOKEN_RIGHT = 359, - TOKEN_ROW = 360, - TOKEN_ROW_DELIMITER = 361, - TOKEN_ROWS = 362, - TOKEN_SECOND = 363, - TOKEN_SELECT = 364, - TOKEN_SET = 365, - TOKEN_SMA = 366, - TOKEN_SMALLINT = 367, - TOKEN_STDERR = 368, - TOKEN_STDOUT = 369, - TOKEN_SUBSTRING = 370, - TOKEN_TABLE = 371, - TOKEN_THEN = 372, - TOKEN_TIME = 373, - TOKEN_TIMESTAMP = 374, - TOKEN_TO = 375, - TOKEN_TRUE = 376, - TOKEN_TUPLESAMPLE = 377, - TOKEN_UNBOUNDED = 378, - TOKEN_UNIQUE = 379, - TOKEN_UPDATE = 380, - TOKEN_USING = 381, - TOKEN_VALUES = 382, - TOKEN_VARCHAR = 383, - TOKEN_WHEN = 384, - TOKEN_WHERE = 385, - TOKEN_WINDOW = 386, - TOKEN_WITH = 387, - TOKEN_YEAR = 388, - TOKEN_YEARMONTH = 389, - TOKEN_EOF = 390, - TOKEN_LEX_ERROR = 391 + TOKEN_BIT = 285, + TOKEN_BITWEAVING = 286, + TOKEN_BLOCKPROPERTIES = 287, + TOKEN_BLOCKSAMPLE = 288, + TOKEN_BLOOM_FILTER = 289, + TOKEN_CSB_TREE = 290, + TOKEN_BY = 291, + TOKEN_CASE = 292, + TOKEN_CAST = 293, + TOKEN_CHECK = 294, + TOKEN_COLUMN = 295, + TOKEN_CONSTRAINT = 296, + TOKEN_COPY = 297, + TOKEN_CREATE = 298, + TOKEN_CURRENT = 299, + TOKEN_DAY = 300, + TOKEN_DEFAULT = 301, + TOKEN_DELETE = 302, + TOKEN_DESC = 303, + TOKEN_DISTINCT = 304, + TOKEN_DOUBLECOLON = 305, + TOKEN_DROP = 306, + TOKEN_ELSE = 307, + TOKEN_END = 308, + TOKEN_EXISTS = 309, + TOKEN_EXTRACT = 310, + TOKEN_FALSE = 311, + TOKEN_FIRST = 312, + TOKEN_FOLLOWING = 313, + TOKEN_FOR = 314, + TOKEN_FOREIGN = 315, + TOKEN_FROM = 316, + TOKEN_FULL = 317, + TOKEN_GROUP = 318, + TOKEN_HASH = 319, + TOKEN_HAVING = 320, + TOKEN_HOUR = 321, + TOKEN_IN = 322, + TOKEN_INDEX = 323, + TOKEN_INNER = 324, + TOKEN_INSERT = 325, + TOKEN_INTERVAL = 326, + TOKEN_INTO = 327, + TOKEN_JOIN = 328, + TOKEN_KEY = 329, + TOKEN_LAST = 330, + TOKEN_LBRACE = 331, + TOKEN_LEFT = 332, + TOKEN_LIMIT = 333, + TOKEN_MINUTE = 334, + TOKEN_MONTH = 335, + TOKEN_NULL = 336, + TOKEN_NULLS = 337, + TOKEN_OFF = 338, + TOKEN_ON = 339, + TOKEN_ORDER = 340, + TOKEN_OUTER = 341, + TOKEN_OVER = 342, + TOKEN_PARTITION = 343, + TOKEN_PARTITIONS = 344, + TOKEN_PERCENT = 345, + TOKEN_PRECEDING = 346, + TOKEN_PRIMARY = 347, + TOKEN_PRIORITY = 348, + TOKEN_QUIT = 349, + TOKEN_RANGE = 350, + TOKEN_RBRACE = 351, + TOKEN_REAL = 352, + TOKEN_REFERENCES = 353, + TOKEN_RIGHT = 354, + TOKEN_ROW = 355, + TOKEN_ROW_DELIMITER = 356, + TOKEN_ROWS = 357, + TOKEN_SECOND = 358, + TOKEN_SELECT = 359, + TOKEN_SET = 360, + TOKEN_SMA = 361, + TOKEN_STDERR = 362, + TOKEN_STDOUT = 363, + TOKEN_SUBSTRING = 364, + TOKEN_TABLE = 365, + TOKEN_THEN = 366, + TOKEN_TO = 367, + TOKEN_TRUE = 368, + TOKEN_TUPLESAMPLE = 369, + TOKEN_UNBOUNDED = 370, + TOKEN_UNIQUE = 371, + TOKEN_UPDATE = 372, + TOKEN_USING = 373, + TOKEN_VALUES = 374, + TOKEN_WHEN = 375, + TOKEN_WHERE = 376, + TOKEN_WINDOW = 377, + TOKEN_WITH = 378, + TOKEN_YEAR = 379, + TOKEN_EOF = 380, + TOKEN_LEX_ERROR = 381 }; #endif @@ -187,7 +177,7 @@ extern int quickstep_yydebug; union YYSTYPE { -#line 121 "../SqlParser.ypp" /* yacc.c:1915 */ +#line 116 "../SqlParser.ypp" /* yacc.c:1915 */ quickstep::ParseString *string_value_; @@ -259,9 +249,10 @@ union YYSTYPE quickstep::ParseStatementQuit *quit_statement_; const quickstep::Comparison *comparison_; - const quickstep::UnaryOperation *unary_operation_; - const quickstep::BinaryOperation *binary_operation_; + quickstep::ParseString *unary_operation_; + quickstep::ParseString *binary_operation_; + quickstep::ParseArray *array_expression_; quickstep::ParseFunctionCall *function_call_; quickstep::PtrList *expression_list_; @@ -288,7 +279,7 @@ union YYSTYPE quickstep::ParsePriority *opt_priority_clause_; -#line 292 "SqlParser_gen.hpp" /* yacc.c:1915 */ +#line 283 "SqlParser_gen.hpp" /* yacc.c:1915 */ }; typedef union YYSTYPE YYSTYPE; diff --git a/query_optimizer/ExecutionGenerator.cpp b/query_optimizer/ExecutionGenerator.cpp index 372d5766..d4544a0a 100644 --- a/query_optimizer/ExecutionGenerator.cpp +++ b/query_optimizer/ExecutionGenerator.cpp @@ -1466,7 +1466,8 @@ void ExecutionGenerator::convertInsertTuple( S::Tuple *tuple_proto = query_context_proto_->add_tuples(); for (const E::ScalarLiteralPtr &literal : physical_plan->column_values()) { - tuple_proto->add_attribute_values()->CopyFrom(literal->value().getProto()); + tuple_proto->add_attribute_values()->CopyFrom( + literal->value().toTypedValue().getProto()); } // FIXME(qzeng): A better way is using a traits struct to look up whether a storage diff --git a/query_optimizer/LogicalGenerator.cpp b/query_optimizer/LogicalGenerator.cpp index abeca538..aaad96ab 100644 --- a/query_optimizer/LogicalGenerator.cpp +++ b/query_optimizer/LogicalGenerator.cpp @@ -51,9 +51,12 @@ L::LogicalPtr LogicalGenerator::generatePlan( const CatalogDatabase &catalog_database, const ParseStatement &parse_statement) { resolver::Resolver resolver(catalog_database, optimizer_context_); - DVLOG(4) << "Parse tree:\n" << parse_statement.toString(); +// DVLOG(4) << "Parse tree:\n" << parse_statement.toString(); + std::cerr << "Parse tree:\n" << parse_statement.toString(); logical_plan_ = resolver.resolve(parse_statement); - DVLOG(4) << "Initial logical plan:\n" << logical_plan_->toString(); +// DVLOG(4) << "Initial logical plan:\n" << logical_plan_->toString(); + std::cerr << "Initial logical plan:\n" << logical_plan_->toString(); +// exit(0); optimizePlan(); DVLOG(4) << "Optimized logical plan:\n" << logical_plan_->toString(); diff --git a/query_optimizer/expressions/BinaryExpression.cpp b/query_optimizer/expressions/BinaryExpression.cpp index f49c6a27..634c1895 100644 --- a/query_optimizer/expressions/BinaryExpression.cpp +++ b/query_optimizer/expressions/BinaryExpression.cpp @@ -31,8 +31,8 @@ #include "query_optimizer/expressions/ExprId.hpp" #include "query_optimizer/expressions/Expression.hpp" #include "query_optimizer/expressions/PatternMatcher.hpp" +#include "query_optimizer/expressions/ScalarLiteral.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "utility/HashPair.hpp" #include "glog/logging.h" @@ -44,37 +44,8 @@ class Type; namespace optimizer { namespace expressions { -BinaryExpression::BinaryExpression(const BinaryOperation &operation, - const ScalarPtr &left, - const ScalarPtr &right) - : operation_(operation), left_(left), right_(right) { - DCHECK(operation_.canApplyToTypes(left_->getValueType(), - right_->getValueType())) - << toString(); - addChild(left_); - addChild(right_); -} - std::string BinaryExpression::getName() const { - switch (operation_.getBinaryOperationID()) { - case BinaryOperationID::kAdd: - return "Add"; - case BinaryOperationID::kSubtract: - return "Subtract"; - case BinaryOperationID::kMultiply: - return "Multiply"; - case BinaryOperationID::kDivide: - return "Divide"; - case BinaryOperationID::kModulo: - return "Modulo"; - default: - LOG(FATAL) << "Unknown binary operation"; - } -} - -const Type &BinaryExpression::getValueType() const { - return *operation_.resultTypeForArgumentTypes(left_->getValueType(), - right_->getValueType()); + return op_signature_->getName(); } ExpressionPtr BinaryExpression::copyWithNewChildren( @@ -83,9 +54,11 @@ ExpressionPtr BinaryExpression::copyWithNewChildren( DCHECK(SomeScalar::Matches(new_children[0])); DCHECK(SomeScalar::Matches(new_children[1])); return BinaryExpression::Create( + op_signature_, operation_, std::static_pointer_cast(new_children[0]), - std::static_pointer_cast(new_children[1])); + std::static_pointer_cast(new_children[1]), + static_arguments_); } std::vector BinaryExpression::getReferencedAttributes() const { @@ -102,33 +75,40 @@ std::vector BinaryExpression::getReferencedAttributes() c ::quickstep::Scalar *BinaryExpression::concretize( const std::unordered_map &substitution_map) const { return new ::quickstep::ScalarBinaryExpression( + op_signature_, operation_, left_->concretize(substitution_map), - right_->concretize(substitution_map)); + right_->concretize(substitution_map), + static_arguments_cache_); } std::size_t BinaryExpression::computeHash() const { + std::size_t hash_code = op_signature_->hash(); std::size_t left_hash = left_->hash(); std::size_t right_hash = right_->hash(); - if (operation_.isCommutative() && left_hash > right_hash) { + if (operation_->isCommutative() && left_hash > right_hash) { std::swap(left_hash, right_hash); } + hash_code = CombineHashes(hash_code, left_hash); + hash_code = CombineHashes(hash_code, right_hash); - return CombineHashes( - CombineHashes(static_cast(ExpressionType::kBinaryExpression), - static_cast(operation_.getBinaryOperationID())), - CombineHashes(left_hash, right_hash)); + for (const GenericValue &st_arg : *static_arguments_) { + hash_code = CombineHashes(hash_code, st_arg.getHash()); + } + return hash_code; } bool BinaryExpression::equals(const ScalarPtr &other) const { + // TODO BinaryExpressionPtr expr; if (SomeBinaryExpression::MatchesWithConditionalCast(other, &expr) && - &operation_ == &expr->operation_) { + *op_signature_ == *expr->op_signature_ && + *static_arguments_ == *expr->static_arguments_) { ScalarPtr left = left_; ScalarPtr right = right_; - if (operation_.isCommutative()) { + if (operation_->isCommutative()) { const bool self_order = (left_->hash() < right_->hash()); const bool other_order = (expr->left_->hash() < expr->right_->hash()); if (self_order ^ other_order) { @@ -148,8 +128,25 @@ void BinaryExpression::getFieldStringItems( std::vector *non_container_child_fields, std::vector *container_child_field_names, std::vector> *container_child_fields) const { - container_child_field_names->push_back(""); - container_child_fields->push_back({left_, right_}); + inline_field_names->emplace_back("op_signature"); + inline_field_values->emplace_back(op_signature_->toString()); + + inline_field_names->emplace_back("result_type"); + inline_field_values->emplace_back(result_type_.getName()); + + non_container_child_field_names->emplace_back("left_operand"); + non_container_child_fields->emplace_back(left_); + non_container_child_field_names->emplace_back("right_operand"); + non_container_child_fields->emplace_back(right_); + + if (!static_arguments_->empty()) { + container_child_field_names->emplace_back("static_arguments"); + container_child_fields->emplace_back(); + for (std::size_t i = 0; i < static_arguments_->size(); ++i) { + container_child_fields->back().emplace_back( + ScalarLiteral::Create(static_arguments_->at(i))); + } + } } } // namespace expressions diff --git a/query_optimizer/expressions/BinaryExpression.hpp b/query_optimizer/expressions/BinaryExpression.hpp index 6a37679d..5e59e489 100644 --- a/query_optimizer/expressions/BinaryExpression.hpp +++ b/query_optimizer/expressions/BinaryExpression.hpp @@ -31,6 +31,9 @@ #include "query_optimizer/expressions/Expression.hpp" #include "query_optimizer/expressions/ExpressionType.hpp" #include "query_optimizer/expressions/Scalar.hpp" +#include "types/GenericValue.hpp" +#include "types/operations/OperationSignature.hpp" +#include "types/operations/binary_operations/BinaryOperation.hpp" #include "utility/Macros.hpp" namespace quickstep { @@ -61,7 +64,9 @@ class BinaryExpression : public Scalar { std::string getName() const override; - const Type& getValueType() const override; + const Type& getValueType() const override { + return result_type_; + } bool isConstant() const override { return left_->isConstant() && right_->isConstant(); @@ -70,7 +75,7 @@ class BinaryExpression : public Scalar { /** * @return The binary operation. */ - const BinaryOperation& operation() const { return operation_; } + const BinaryOperationPtr& operation() const { return operation_; } /** * @return The left operand. @@ -92,10 +97,31 @@ class BinaryExpression : public Scalar { bool equals(const ScalarPtr &other) const override; - static BinaryExpressionPtr Create(const BinaryOperation &operation, - const ScalarPtr &left, - const ScalarPtr &right) { - return BinaryExpressionPtr(new BinaryExpression(operation, left, right)); + static BinaryExpressionPtr Create( + const OperationSignaturePtr &op_signature, + const BinaryOperationPtr &operation, + const ScalarPtr &left, + const ScalarPtr &right, + const std::shared_ptr> &static_arguments) { + return BinaryExpressionPtr( + new BinaryExpression(op_signature, + operation, + left, + right, + static_arguments)); + } + + static BinaryExpressionPtr Create( + const OperationSignaturePtr &op_signature, + const BinaryOperationPtr &operation, + const ScalarPtr &left, + const ScalarPtr &right) { + return BinaryExpressionPtr( + new BinaryExpression(op_signature, + operation, + left, + right, + std::make_shared>())); } protected: @@ -110,14 +136,32 @@ class BinaryExpression : public Scalar { std::vector> *container_child_fields) const override; private: - BinaryExpression(const BinaryOperation &operation, + BinaryExpression(const OperationSignaturePtr &op_signature, + const BinaryOperationPtr &operation, const ScalarPtr &left, - const ScalarPtr &right); - - const BinaryOperation &operation_; + const ScalarPtr &right, + const std::shared_ptr> &static_arguments) + : op_signature_(op_signature), + operation_(operation), + left_(left), + right_(right), + static_arguments_(static_arguments), + static_arguments_cache_(ToTypedValue(*static_arguments_)), + result_type_(*(operation_->getResultType(left_->getValueType(), + right_->getValueType(), + *static_arguments_cache_))) { + addChild(left); + addChild(right); + } - ScalarPtr left_; - ScalarPtr right_; + const OperationSignaturePtr op_signature_; + const BinaryOperationPtr operation_; + const ScalarPtr left_; + const ScalarPtr right_; + const std::shared_ptr> static_arguments_; + // TODO(refactor-type): Remove this. + const std::shared_ptr> static_arguments_cache_; + const Type &result_type_; DISALLOW_COPY_AND_ASSIGN(BinaryExpression); }; diff --git a/query_optimizer/expressions/CMakeLists.txt b/query_optimizer/expressions/CMakeLists.txt index 3e7f8e49..889c450e 100644 --- a/query_optimizer/expressions/CMakeLists.txt +++ b/query_optimizer/expressions/CMakeLists.txt @@ -97,12 +97,13 @@ target_link_libraries(quickstep_queryoptimizer_expressions_BinaryExpression quickstep_queryoptimizer_expressions_ExpressionType quickstep_queryoptimizer_expressions_PatternMatcher quickstep_queryoptimizer_expressions_Scalar + quickstep_queryoptimizer_expressions_ScalarLiteral + quickstep_types_GenericValue + quickstep_types_operations_OperationSignature quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_HashPair quickstep_utility_Macros) target_link_libraries(quickstep_queryoptimizer_expressions_Cast - glog quickstep_expressions_scalar_Scalar quickstep_expressions_scalar_ScalarUnaryExpression quickstep_queryoptimizer_OptimizerTree @@ -112,8 +113,11 @@ target_link_libraries(quickstep_queryoptimizer_expressions_Cast quickstep_queryoptimizer_expressions_ExpressionType quickstep_queryoptimizer_expressions_PatternMatcher quickstep_queryoptimizer_expressions_Scalar + quickstep_types_MetaType quickstep_types_Type - quickstep_types_operations_unaryoperations_NumericCastOperation + quickstep_types_operations_OperationFactory + quickstep_types_operations_OperationSignature + quickstep_types_operations_unaryoperations_UnaryOperation quickstep_utility_HashPair quickstep_utility_Macros) target_link_libraries(quickstep_queryoptimizer_expressions_CommonSubexpression @@ -254,6 +258,8 @@ target_link_libraries(quickstep_queryoptimizer_expressions_Scalar glog quickstep_queryoptimizer_expressions_ExprId quickstep_queryoptimizer_expressions_Expression + quickstep_types_GenericValue + quickstep_types_TypedValue quickstep_utility_HashError quickstep_utility_Macros) target_link_libraries(quickstep_queryoptimizer_expressions_ScalarLiteral @@ -266,8 +272,8 @@ target_link_libraries(quickstep_queryoptimizer_expressions_ScalarLiteral quickstep_queryoptimizer_expressions_ExpressionType quickstep_queryoptimizer_expressions_PatternMatcher quickstep_queryoptimizer_expressions_Scalar + quickstep_types_GenericValue quickstep_types_Type - quickstep_types_TypedValue quickstep_utility_HashPair quickstep_utility_Macros) target_link_libraries(quickstep_queryoptimizer_expressions_SearchedCase @@ -325,8 +331,10 @@ target_link_libraries(quickstep_queryoptimizer_expressions_UnaryExpression quickstep_queryoptimizer_expressions_ExpressionType quickstep_queryoptimizer_expressions_PatternMatcher quickstep_queryoptimizer_expressions_Scalar + quickstep_queryoptimizer_expressions_ScalarLiteral + quickstep_types_GenericValue + quickstep_types_operations_OperationSignature quickstep_types_operations_unaryoperations_UnaryOperation - quickstep_types_operations_unaryoperations_UnaryOperationID quickstep_utility_HashPair quickstep_utility_Macros) target_link_libraries(quickstep_queryoptimizer_expressions_WindowAggregateFunction diff --git a/query_optimizer/expressions/Cast.cpp b/query_optimizer/expressions/Cast.cpp index e6eb1bd0..7df4159d 100644 --- a/query_optimizer/expressions/Cast.cpp +++ b/query_optimizer/expressions/Cast.cpp @@ -20,6 +20,7 @@ #include "query_optimizer/expressions/Cast.hpp" #include +#include #include #include #include @@ -32,8 +33,11 @@ #include "query_optimizer/expressions/Expression.hpp" #include "query_optimizer/expressions/PatternMatcher.hpp" #include "query_optimizer/expressions/Scalar.hpp" +#include "types/MetaType.hpp" #include "types/Type.hpp" -#include "types/operations/unary_operations/NumericCastOperation.hpp" +#include "types/operations/OperationSignature.hpp" +#include "types/operations/OperationFactory.hpp" +#include "types/operations/unary_operations/UnaryOperation.hpp" #include "utility/HashPair.hpp" #include "glog/logging.h" @@ -53,8 +57,36 @@ ExpressionPtr Cast::copyWithNewChildren( ::quickstep::Scalar *Cast::concretize( const std::unordered_map &substitution_map) const { - return new ::quickstep::ScalarUnaryExpression(::quickstep::NumericCastOperation::Instance(target_type_), - operand_->concretize(substitution_map)); + const OperationSignaturePtr op_signature = + OperationSignature::Create( + "cast", {operand_->getValueType().getTypeID(), kMetaType}, 1); + const UnaryOperationPtr cast_operation = + OperationFactory::GetUnaryOperation(op_signature); + + std::vector meta_type_value = + { GenericValue::CreateWithLiteral( + MetaType::InstanceNonNullable(), &target_type_).toTypedValue() }; + DCHECK(cast_operation->canApplyTo(operand_->getValueType(), meta_type_value)); + + return new ::quickstep::ScalarUnaryExpression( + op_signature, cast_operation, operand_->concretize(substitution_map), + std::make_shared>(std::move(meta_type_value))); +} + +TypedValue Cast::getConstantValue() const { + DCHECK(isConstant()); + const Type &source_type = operand_->getValueType(); + const UnaryOperationPtr cast_operation = + OperationFactory::GetCastOperation(source_type.getTypeID()); + + std::vector meta_type_value = + { GenericValue::CreateWithLiteral( + MetaType::InstanceNonNullable(), &target_type_).toTypedValue() }; + DCHECK(cast_operation->canApplyTo(source_type, meta_type_value)); + + std::unique_ptr cast_op( + cast_operation->makeUncheckedUnaryOperator(source_type, meta_type_value)); + return cast_op->applyToTypedValue(operand_->getConstantValue()); } std::size_t Cast::computeHash() const { diff --git a/query_optimizer/expressions/Cast.hpp b/query_optimizer/expressions/Cast.hpp index 11be775a..5da0e8c8 100644 --- a/query_optimizer/expressions/Cast.hpp +++ b/query_optimizer/expressions/Cast.hpp @@ -55,13 +55,23 @@ typedef std::shared_ptr CastPtr; */ class Cast : public Scalar { public: - ExpressionType getExpressionType() const override { return ExpressionType::kCast; } + ExpressionType getExpressionType() const override { + return ExpressionType::kCast; + } + + std::string getName() const override { + return "Cast"; + } - std::string getName() const override { return "Cast"; } + const Type& getValueType() const override { + return target_type_; + } - const Type& getValueType() const override { return target_type_; } + bool isConstant() const override { + return operand_->isConstant(); + } - bool isConstant() const override { return operand_->isConstant(); } + TypedValue getConstantValue() const override; /** * @return The expression to be coerced. @@ -78,6 +88,7 @@ class Cast : public Scalar { ::quickstep::Scalar* concretize( const std::unordered_map &substitution_map) const override; + bool equals(const ScalarPtr &other) const override; /** diff --git a/query_optimizer/expressions/Expression.hpp b/query_optimizer/expressions/Expression.hpp index 71270478..fc6fc535 100644 --- a/query_optimizer/expressions/Expression.hpp +++ b/query_optimizer/expressions/Expression.hpp @@ -80,6 +80,11 @@ class Expression : public OptimizerTree { */ virtual bool isConstant() const = 0; + virtual TypedValue getConstantValue() const { + LOG(FATAL) << "Not implemented"; + } + + protected: Expression() {} diff --git a/query_optimizer/expressions/Scalar.hpp b/query_optimizer/expressions/Scalar.hpp index a163b210..23df7c18 100644 --- a/query_optimizer/expressions/Scalar.hpp +++ b/query_optimizer/expressions/Scalar.hpp @@ -29,6 +29,10 @@ #include "utility/HashError.hpp" #include "utility/Macros.hpp" +// TODO(refactor-type): Remove this. +#include "types/TypedValue.hpp" +#include "types/GenericValue.hpp" + namespace quickstep { class CatalogAttribute; @@ -107,6 +111,16 @@ class Scalar : public Expression { throw HashNotSupported("Unsupported computeHash() in " + getName()); } + // TODO(refactor-type): Remove this. + inline static std::shared_ptr> ToTypedValue( + const std::vector &input) { + std::vector values; + for (const auto &item : input) { + values.emplace_back(item.toTypedValue()); + } + return std::make_shared>(std::move(values)); + } + private: mutable std::unique_ptr hash_cache_; diff --git a/query_optimizer/expressions/ScalarLiteral.cpp b/query_optimizer/expressions/ScalarLiteral.cpp index d2ab5277..4dd7ba3f 100644 --- a/query_optimizer/expressions/ScalarLiteral.cpp +++ b/query_optimizer/expressions/ScalarLiteral.cpp @@ -40,18 +40,18 @@ namespace optimizer { namespace expressions { const Type& ScalarLiteral::getValueType() const { - return value_type_; + return value_.getType(); } ExpressionPtr ScalarLiteral::copyWithNewChildren( const std::vector &new_children) const { DCHECK_EQ(new_children.size(), children().size()); - return ScalarLiteral::Create(value_, value_type_); + return ScalarLiteral::Create(value_); } ::quickstep::Scalar *ScalarLiteral::concretize( const std::unordered_map &substitution_map) const { - return new ::quickstep::ScalarLiteral(value_, value_type_); + return new ::quickstep::ScalarLiteral(value_.toTypedValue(), value_.getType()); } std::size_t ScalarLiteral::computeHash() const { @@ -64,12 +64,8 @@ std::size_t ScalarLiteral::computeHash() const { bool ScalarLiteral::equals(const ScalarPtr &other) const { ScalarLiteralPtr lit; - if (SomeScalarLiteral::MatchesWithConditionalCast(other, &lit) && - value_type_.equals(lit->value_type_)) { - if (value_.isNull() || lit->value_.isNull()) { - return value_.isNull() && lit->value_.isNull(); - } - return value_.fastEqualCheck(lit->value_); + if (SomeScalarLiteral::MatchesWithConditionalCast(other, &lit)) { + return value_.equals(lit->value_); } return false; } @@ -85,7 +81,7 @@ void ScalarLiteral::getFieldStringItems( if (value_.isNull()) { inline_field_values->push_back("NULL"); } else { - inline_field_values->push_back(value_type_.printValueToString(value_)); + inline_field_values->push_back(value_.toString()); } inline_field_names->push_back("type"); diff --git a/query_optimizer/expressions/ScalarLiteral.hpp b/query_optimizer/expressions/ScalarLiteral.hpp index bff52bb8..fc9f69a2 100644 --- a/query_optimizer/expressions/ScalarLiteral.hpp +++ b/query_optimizer/expressions/ScalarLiteral.hpp @@ -32,7 +32,7 @@ #include "query_optimizer/expressions/Expression.hpp" #include "query_optimizer/expressions/ExpressionType.hpp" #include "query_optimizer/expressions/Scalar.hpp" -#include "types/TypedValue.hpp" +#include "types/GenericValue.hpp" #include "utility/Macros.hpp" namespace quickstep { @@ -65,12 +65,18 @@ class ScalarLiteral : public Scalar { const Type& getValueType() const override; - bool isConstant() const override { return true; } + bool isConstant() const override { + return true; + } + + TypedValue getConstantValue() const override { + return value_.toTypedValue(); + } /** * @return The literal value. */ - const TypedValue& value() const { return value_; } + const GenericValue& value() const { return value_; } ExpressionPtr copyWithNewChildren( const std::vector &new_children) const override; @@ -89,9 +95,8 @@ class ScalarLiteral : public Scalar { * @param literal_value The literal value. * @return An immutable ScalarLiteral with the given literal value. */ - static const ScalarLiteralPtr Create(const TypedValue &literal_value, - const Type &literal_value_type) { - return ScalarLiteralPtr(new ScalarLiteral(literal_value, literal_value_type)); + static const ScalarLiteralPtr Create(const GenericValue &literal_value) { + return ScalarLiteralPtr(new ScalarLiteral(literal_value)); } protected: @@ -106,13 +111,11 @@ class ScalarLiteral : public Scalar { std::vector> *container_child_fields) const override; private: - ScalarLiteral(const TypedValue &literal_value, - const Type &literal_value_type) - : value_(literal_value), - value_type_(literal_value_type) {} + ScalarLiteral(const GenericValue &literal_value) + : value_(literal_value) {} + + const GenericValue value_; - const TypedValue value_; - const Type &value_type_; DISALLOW_COPY_AND_ASSIGN(ScalarLiteral); }; diff --git a/query_optimizer/expressions/UnaryExpression.cpp b/query_optimizer/expressions/UnaryExpression.cpp index b4485536..38cb65cf 100644 --- a/query_optimizer/expressions/UnaryExpression.cpp +++ b/query_optimizer/expressions/UnaryExpression.cpp @@ -30,8 +30,8 @@ #include "query_optimizer/expressions/Expression.hpp" #include "query_optimizer/expressions/PatternMatcher.hpp" #include "query_optimizer/expressions/Scalar.hpp" +#include "query_optimizer/expressions/ScalarLiteral.hpp" #include "types/operations/unary_operations/UnaryOperation.hpp" -#include "types/operations/unary_operations/UnaryOperationID.hpp" #include "utility/HashPair.hpp" #include "glog/logging.h" @@ -41,7 +41,7 @@ namespace optimizer { namespace expressions { std::string UnaryExpression::getName() const { - return operation_.getName(); + return op_signature_->getName(); } ExpressionPtr UnaryExpression::copyWithNewChildren( @@ -49,26 +49,36 @@ ExpressionPtr UnaryExpression::copyWithNewChildren( DCHECK_EQ(new_children.size(), children().size()); DCHECK(SomeScalar::Matches(new_children[0])); return UnaryExpression::Create( - operation_, std::static_pointer_cast(new_children[0])); + op_signature_, + operation_, + std::static_pointer_cast(new_children[0]), + static_arguments_); } ::quickstep::Scalar* UnaryExpression::concretize( const std::unordered_map &substitution_map) const { return new ::quickstep::ScalarUnaryExpression( - operation_, operand_->concretize(substitution_map)); + op_signature_, + operation_, + operand_->concretize(substitution_map), + static_arguments_cache_); } std::size_t UnaryExpression::computeHash() const { - return CombineHashes( - CombineHashes(static_cast(ExpressionType::kUnaryExpression), - static_cast(operation_.getUnaryOperationID())), - operand_->hash()); + std::size_t hash_code = CombineHashes(op_signature_->hash(), + operand_->hash()); + for (const GenericValue &st_arg : *static_arguments_) { + hash_code = CombineHashes(hash_code, st_arg.getHash()); + } + return hash_code; } bool UnaryExpression::equals(const ScalarPtr &other) const { UnaryExpressionPtr expr; if (SomeUnaryExpression::MatchesWithConditionalCast(other, &expr)) { - return &operation_ == &expr->operation_ && operand_->equals(expr->operand_); + return *op_signature_ == *expr->op_signature_ + && operand_->equals(expr->operand_) + && *static_arguments_ == *expr->static_arguments_; } return false; } @@ -80,8 +90,23 @@ void UnaryExpression::getFieldStringItems( std::vector *non_container_child_fields, std::vector *container_child_field_names, std::vector> *container_child_fields) const { - non_container_child_field_names->push_back("Operand"); - non_container_child_fields->push_back(operand_); + inline_field_names->emplace_back("op_signature"); + inline_field_values->emplace_back(op_signature_->toString()); + + inline_field_names->emplace_back("result_type"); + inline_field_values->emplace_back(result_type_.getName()); + + non_container_child_field_names->emplace_back("operand"); + non_container_child_fields->emplace_back(operand_); + + if (!static_arguments_->empty()) { + container_child_field_names->emplace_back("static_arguments"); + container_child_fields->emplace_back(); + for (std::size_t i = 0; i < static_arguments_->size(); ++i) { + container_child_fields->back().emplace_back( + ScalarLiteral::Create(static_arguments_->at(i))); + } + } } } // namespace expressions diff --git a/query_optimizer/expressions/UnaryExpression.hpp b/query_optimizer/expressions/UnaryExpression.hpp index 14201ff8..9c3bf171 100644 --- a/query_optimizer/expressions/UnaryExpression.hpp +++ b/query_optimizer/expressions/UnaryExpression.hpp @@ -31,6 +31,8 @@ #include "query_optimizer/expressions/Expression.hpp" #include "query_optimizer/expressions/ExpressionType.hpp" #include "query_optimizer/expressions/Scalar.hpp" +#include "types/GenericValue.hpp" +#include "types/operations/OperationSignature.hpp" #include "types/operations/unary_operations/UnaryOperation.hpp" #include "utility/Macros.hpp" @@ -65,7 +67,7 @@ class UnaryExpression : public Scalar { /** * @return The unary operator. */ - const UnaryOperation& operation() const { return operation_; } + const UnaryOperationPtr& operation() const { return operation_; } /** * @return The operand of the unary operator. @@ -73,7 +75,7 @@ class UnaryExpression : public Scalar { const ScalarPtr& operand() const { return operand_; } const Type& getValueType() const override { - return *(operation_.resultTypeForArgumentType(operand_->getValueType())); + return result_type_; } ExpressionPtr copyWithNewChildren( @@ -96,9 +98,16 @@ class UnaryExpression : public Scalar { * @return An immutable UnaryExpression that applies the operation to the * operand. */ - static UnaryExpressionPtr Create(const UnaryOperation &operation, - const ScalarPtr &operand) { - return UnaryExpressionPtr(new UnaryExpression(operation, operand)); + static UnaryExpressionPtr Create( + const OperationSignaturePtr &op_signature, + const UnaryOperationPtr &operation, + const ScalarPtr &operand, + const std::shared_ptr> &static_arguments) { + return UnaryExpressionPtr( + new UnaryExpression(op_signature, + operation, + operand, + static_arguments)); } protected: @@ -113,15 +122,27 @@ class UnaryExpression : public Scalar { std::vector> *container_child_fields) const override; private: - UnaryExpression(const UnaryOperation &operation, - const ScalarPtr &operand) - : operation_(operation), operand_(operand) { - DCHECK(operation_.canApplyToType(operand_->getValueType())) << toString(); + UnaryExpression(const OperationSignaturePtr &op_signature, + const UnaryOperationPtr &operation, + const ScalarPtr &operand, + const std::shared_ptr> &static_arguments) + : op_signature_(op_signature), + operation_(operation), + operand_(operand), + static_arguments_(static_arguments), + static_arguments_cache_(ToTypedValue(*static_arguments_)), + result_type_(*(operation_->getResultType(operand_->getValueType(), + *static_arguments_cache_))) { addChild(operand); } - const UnaryOperation &operation_; - ScalarPtr operand_; + const OperationSignaturePtr op_signature_; + const UnaryOperationPtr operation_; + const ScalarPtr operand_; + const std::shared_ptr> static_arguments_; + // TODO(refactor-type): Remove this. + const std::shared_ptr> static_arguments_cache_; + const Type &result_type_; DISALLOW_COPY_AND_ASSIGN(UnaryExpression); }; diff --git a/query_optimizer/resolver/CMakeLists.txt b/query_optimizer/resolver/CMakeLists.txt index 6feb1e8e..4dd13f22 100644 --- a/query_optimizer/resolver/CMakeLists.txt +++ b/query_optimizer/resolver/CMakeLists.txt @@ -47,6 +47,7 @@ target_link_libraries(quickstep_queryoptimizer_resolver_Resolver quickstep_parser_ParseBasicExpressions quickstep_parser_ParseBlockProperties quickstep_parser_ParseCaseExpressions + quickstep_parser_ParseDataType quickstep_parser_ParseExpression quickstep_parser_ParseGeneratorTableReference quickstep_parser_ParseGroupBy @@ -121,16 +122,22 @@ target_link_libraries(quickstep_queryoptimizer_resolver_Resolver quickstep_queryoptimizer_resolver_NameResolver quickstep_storage_StorageBlockLayout_proto quickstep_storage_StorageConstants + quickstep_types_ArrayType + quickstep_types_GenericValue quickstep_types_IntType + quickstep_types_LongType + quickstep_types_MetaType + quickstep_types_NullType quickstep_types_Type + quickstep_types_TypeUtil quickstep_types_TypedValue quickstep_types_TypeFactory + quickstep_types_operations_OperationFactory + quickstep_types_operations_OperationSignature quickstep_types_operations_binaryoperations_BinaryOperation quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID - quickstep_types_operations_unaryoperations_DateExtractOperation - quickstep_types_operations_unaryoperations_SubstringOperation quickstep_types_operations_unaryoperations_UnaryOperation quickstep_utility_BulkIoConfiguration quickstep_utility_Macros diff --git a/query_optimizer/resolver/Resolver.cpp b/query_optimizer/resolver/Resolver.cpp index 29915688..328953af 100644 --- a/query_optimizer/resolver/Resolver.cpp +++ b/query_optimizer/resolver/Resolver.cpp @@ -43,6 +43,7 @@ #include "parser/ParseBasicExpressions.hpp" #include "parser/ParseBlockProperties.hpp" #include "parser/ParseCaseExpressions.hpp" +#include "parser/ParseDataType.hpp" #include "parser/ParseExpression.hpp" #include "parser/ParseGeneratorTableReference.hpp" #include "parser/ParseGroupBy.hpp" @@ -116,16 +117,22 @@ #include "query_optimizer/resolver/NameResolver.hpp" #include "storage/StorageBlockLayout.pb.h" #include "storage/StorageConstants.hpp" +#include "types/ArrayType.hpp" +#include "types/GenericValue.hpp" #include "types/IntType.hpp" +#include "types/LongType.hpp" +#include "types/MetaType.hpp" +#include "types/NullType.hpp" #include "types/Type.hpp" -#include "types/TypedValue.hpp" #include "types/TypeFactory.hpp" +#include "types/TypeUtil.hpp" +#include "types/TypedValue.hpp" +#include "types/operations/OperationFactory.hpp" +#include "types/operations/OperationSignature.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" #include "types/operations/comparisons/Comparison.hpp" #include "types/operations/comparisons/ComparisonFactory.hpp" #include "types/operations/comparisons/ComparisonID.hpp" -#include "types/operations/unary_operations/DateExtractOperation.hpp" -#include "types/operations/unary_operations/SubstringOperation.hpp" #include "types/operations/unary_operations/UnaryOperation.hpp" #include "utility/BulkIoConfiguration.hpp" #include "utility/PtrList.hpp" @@ -151,16 +158,13 @@ attribute_id GetAttributeIdFromName( const PtrList &attribute_definition_list, const std::string &attribute_name) { const std::string lower_attribute_name = ToLower(attribute_name); - attribute_id attr_id = 0; for (const ParseAttributeDefinition &attribute_definition : attribute_definition_list) { if (lower_attribute_name == ToLower(attribute_definition.name()->value())) { return attr_id; } - ++attr_id; } - return kInvalidAttributeID; } @@ -643,7 +647,7 @@ L::LogicalPtr Resolver::resolveCreateTable( attribute_definition.name()->value(), attribute_definition.name()->value(), relation_name, - attribute_definition.data_type().getType(), + resolveDataType(attribute_definition.data_type()), E::AttributeReferenceScope::kLocal)); attribute_name_set.insert(lower_attribute_name); } @@ -1020,13 +1024,10 @@ L::LogicalPtr Resolver::resolveInsertSelection( cast_expressions.emplace_back(selection_attributes[aid]); } else { // TODO(jianqiao): implement Cast operation for non-numeric types. - if (destination_type.getSuperTypeID() == Type::SuperTypeID::kNumeric && - selection_type.getSuperTypeID() == Type::SuperTypeID::kNumeric && - destination_type.isSafelyCoercibleFrom(selection_type)) { + if (destination_type.isSafelyCoercibleFrom(selection_type)) { // Add cast operation const E::AttributeReferencePtr attr = selection_attributes[aid]; - const E::ExpressionPtr cast_expr = - E::Cast::Create(attr, destination_type); + const E::ExpressionPtr cast_expr = E::Cast::Create(attr, destination_type); cast_expressions.emplace_back( E::Alias::Create(context_->nextExprId(), cast_expr, @@ -1075,6 +1076,7 @@ L::LogicalPtr Resolver::resolveInsertTuple( std::vector resolved_column_values; std::vector::size_type aid = 0; for (const ParseScalarLiteral &parse_literal_value : parse_column_values) { + const Type &attribute_type = relation_attributes[aid]->getValueType(); E::ScalarLiteralPtr resolved_literal_value; ExpressionResolutionInfo expr_resolution_info( name_resolver, @@ -1083,30 +1085,25 @@ L::LogicalPtr Resolver::resolveInsertTuple( // When resolving the literal, use the attribute's Type as a hint. CHECK(E::SomeScalarLiteral::MatchesWithConditionalCast( resolveExpression(parse_literal_value, - &(relation_attributes[aid]->getValueType()), + &attribute_type, &expr_resolution_info), &resolved_literal_value)); // Check that the resolved Type is safely coercible to the attribute's // Type. - if (!relation_attributes[aid]->getValueType().isSafelyCoercibleFrom( - resolved_literal_value->getValueType())) { + if (!attribute_type.isSafelyCoercibleFrom(resolved_literal_value->getValueType())) { THROW_SQL_ERROR_AT(&parse_literal_value) << "The assigned value for the column " << relation_attributes[aid]->attribute_name() << " has the type " << resolved_literal_value->getValueType().getName() << ", which cannot be safely coerced to the column's type " - << relation_attributes[aid]->getValueType().getName(); + << attribute_type.getName(); } // If the Type is not exactly right (but is safely coercible), coerce it. - if (!resolved_literal_value->getValueType().equals( - relation_attributes[aid]->getValueType())) { + if (!resolved_literal_value->getValueType().equals(attribute_type)) { resolved_literal_value = E::ScalarLiteral::Create( - relation_attributes[aid]->getValueType().coerceValue( - resolved_literal_value->value(), - resolved_literal_value->getValueType()), - relation_attributes[aid]->getValueType()); + resolved_literal_value->value().coerce(attribute_type)); } resolved_column_values.push_back(resolved_literal_value); @@ -1121,8 +1118,7 @@ L::LogicalPtr Resolver::resolveInsertTuple( } // Create a NULL value. resolved_column_values.push_back(E::ScalarLiteral::Create( - relation_attributes[aid]->getValueType().makeNullValue(), - relation_attributes[aid]->getValueType())); + GenericValue::CreateNullValue(relation_attributes[aid]->getValueType()))); ++aid; } @@ -1197,6 +1193,72 @@ L::LogicalPtr Resolver::resolveUpdate( resolved_where_predicate); } +const Type& Resolver::resolveDataType(const ParseDataType &parse_data_type) { + const std::string &type_name = ToLower(parse_data_type.type_name().value()); + if (!TypeFactory::TypeNameIsValid(type_name)) { + THROW_SQL_ERROR_AT(&parse_data_type.type_name()) + << "Unrecognized type name: " << type_name; + } + + const TypeID type_id = TypeFactory::GetTypeIDForName(type_name); + const MemoryLayout memory_layout = TypeUtil::GetMemoryLayout(type_id); + + const auto &parse_parameters = parse_data_type.parameters(); + if (memory_layout == kCxxInlinePod) { + if (!parse_parameters.empty()) { + THROW_SQL_ERROR_AT(parse_parameters.front()) + << "Invalid parameter to type " << type_name; + } + return TypeFactory::GetType(type_id, parse_data_type.nullable()); + } + + std::vector values; + for (const auto ¶m : parse_parameters) { + if (param->getParameterType() == ParseDataTypeParameter::kLiteralValue) { + const ParseLiteralValue &literal_value = + static_cast(*param).literal_value(); + const Type *value_type = nullptr; + TypedValue value = literal_value.concretize(nullptr, &value_type); + DCHECK(value_type != nullptr); + values.emplace_back(GenericValue::CreateWithTypedValue(*value_type, value)); + } else { + DCHECK(param->getParameterType() == ParseDataTypeParameter::kDataType); + const ParseDataType &element_type = + static_cast(*param).data_type(); + values.emplace_back( + GenericValue::CreateWithLiteral(MetaType::InstanceNonNullable(), + &resolveDataType(element_type))); + } + } + + if (memory_layout == kParInlinePod || memory_layout == kParOutOfLinePod) { + if (values.size() != 1) { + THROW_SQL_ERROR_AT(parse_parameters.front()) + << "Invalid parameter to type " << type_name; + } + const GenericValue &value = values.front(); + const Type &value_type = value.getType(); + + std::size_t length = 0; + if (value_type.getTypeID() == kInt) { + length = value.getLiteral(); + } else if (value_type.getTypeID() == kLong) { + length = value.getLiteral(); + } else { + THROW_SQL_ERROR_AT(parse_parameters.front()) + << "Invalid parameter to type " << type_name; + } + return TypeFactory::GetType(type_id, length); + } + + DCHECK(memory_layout == kCxxGeneric); + if (!TypeFactory::TypeParametersAreValid(type_id, values)) { + THROW_SQL_ERROR_AT(parse_parameters.front()) + << "Invalid parameter to type " << type_name; + } + return TypeFactory::GetType(type_id, values); +} + L::LogicalPtr Resolver::resolveSelect( const ParseSelect &select_query, const std::string &select_name, @@ -1551,8 +1613,8 @@ L::LogicalPtr Resolver::resolveSetOperations( const Type ¤t_type = attribute_matrix[opid][aid]->getValueType(); const Type &possible_type = possible_attribute->getValueType(); if (!possible_type.equals(current_type)) { - if (possible_type.getSuperTypeID() == Type::SuperTypeID::kNumeric && - current_type.getSuperTypeID() == Type::SuperTypeID::kNumeric) { + if (possible_type.getSuperTypeID() == SuperTypeID::kNumeric && + current_type.getSuperTypeID() == SuperTypeID::kNumeric) { if (possible_type.isSafelyCoercibleFrom(current_type)) { // Cast current_type to possible_type. // Possible_attribute remain the same, nothing needs to change. @@ -2075,7 +2137,7 @@ E::WindowInfo Resolver::resolveWindow(const ParseWindow &parse_window, // needed because -1 might not make sense in this case. if (!parse_frame_info->is_row && (order_by_attributes.empty() || - order_by_attributes[0]->getValueType().getSuperTypeID() != Type::SuperTypeID::kNumeric)) { + order_by_attributes[0]->getValueType().getSuperTypeID() != SuperTypeID::kNumeric)) { THROW_SQL_ERROR_AT(&parse_window) << "A numeric attribute should be specified as the first ORDER BY " << "attribute in FRAME mode"; @@ -2384,6 +2446,11 @@ E::ScalarPtr Resolver::resolveExpression( const Type *type_hint, ExpressionResolutionInfo *expression_resolution_info) { switch (parse_expression.getExpressionType()) { + case ParseExpression::kArray: { + const ParseArray &parse_array = + static_cast(parse_expression); + return resolveArray(parse_array, type_hint, expression_resolution_info); + } case ParseExpression::kAttribute: { const ParseAttribute &parse_attribute_scalar = static_cast(parse_expression); @@ -2444,116 +2511,14 @@ E::ScalarPtr Resolver::resolveExpression( parse_attribute_scalar.attr_name(), parse_attribute_scalar.rel_name()); } - case ParseExpression::kBinaryExpression: { - const ParseBinaryExpression &parse_binary_scalar = - static_cast(parse_expression); - - std::pair argument_type_hints - = parse_binary_scalar.op().pushDownTypeHint(type_hint); - - ExpressionResolutionInfo left_resolution_info( - *expression_resolution_info); - E::ScalarPtr left_argument = resolveExpression( - *parse_binary_scalar.left_operand(), - argument_type_hints.first, - &left_resolution_info); - - ExpressionResolutionInfo right_resolution_info( - *expression_resolution_info); - E::ScalarPtr right_argument = resolveExpression( - *parse_binary_scalar.right_operand(), - argument_type_hints.second, - &right_resolution_info); - - if (left_resolution_info.hasAggregate()) { - expression_resolution_info->parse_aggregate_expression = - left_resolution_info.parse_aggregate_expression; - } else if (right_resolution_info.hasAggregate()) { - expression_resolution_info->parse_aggregate_expression = - right_resolution_info.parse_aggregate_expression; - } - - // Check if either argument is a NULL literal of an unknown type. - const bool left_is_nulltype = (left_argument->getValueType().getTypeID() == kNullType); - const bool right_is_nulltype = (right_argument->getValueType().getTypeID() == kNullType); - - // If either argument is a NULL of unknown type, we try to resolve the - // type of this BinaryExpression as follows: - // - // 1. If there is only one possible result type for the expression - // based on what is known about its argument types, then the - // result is a NULL of that type. - // 2. Otherwise, if there is a type hint for the BinaryExpression's - // result, and if it is a plausible result type based on what we - // know about argument types, then the result is a NULL of the - // hint type. - // 3. Otherwise, check if the BinaryExpression can plausibly be - // applied to the known argument types at all. If so, then the - // result is a NULL of unknown type (i.e. NullType). - // 4. If all of the above steps fail, then the BinaryExpression is - // not possibly applicable to the given arguments. - // - // NOTE(chasseur): Step #3 above does not completely capture knowledge - // about the result type of a BinaryExpression with one or more unknown - // arguments. For instance, DivideBinaryOperation can never return a - // DateTime or any string type, so even if we do not know its specific - // return type, we do know that there are some restrictions on what it - // may be. However, NullType is implicitly convertable to ANY Type, so - // such restrictions could be violated if a parent node in the expression - // tree converts a value of NullType to something that it shouldn't be. - if (left_is_nulltype || right_is_nulltype) { - const Type *fixed_result_type - = parse_binary_scalar.op().resultTypeForPartialArgumentTypes( - left_is_nulltype ? nullptr : &(left_argument->getValueType()), - right_is_nulltype ? nullptr : &(right_argument->getValueType())); - if (fixed_result_type != nullptr) { - return E::ScalarLiteral::Create(fixed_result_type->makeNullValue(), - *fixed_result_type); - } - - if (type_hint != nullptr) { - const Type &nullable_type_hint = type_hint->getNullableVersion(); - if (parse_binary_scalar.op().partialTypeSignatureIsPlausible( - &nullable_type_hint, - left_is_nulltype ? nullptr : &(left_argument->getValueType()), - right_is_nulltype ? nullptr : &(right_argument->getValueType()))) { - return E::ScalarLiteral::Create(nullable_type_hint.makeNullValue(), - nullable_type_hint); - } - } - - if (parse_binary_scalar.op().partialTypeSignatureIsPlausible( - nullptr, - left_is_nulltype ? nullptr : &(left_argument->getValueType()), - right_is_nulltype ? nullptr : &(right_argument->getValueType()))) { - const Type &null_type = TypeFactory::GetType(kNullType, true); - return E::ScalarLiteral::Create(null_type.makeNullValue(), - null_type); - } - - // If nothing above worked, fall through to canApplyToTypes() below, - // which should fail. - } - - if (!parse_binary_scalar.op().canApplyToTypes(left_argument->getValueType(), - right_argument->getValueType())) { - THROW_SQL_ERROR_AT(&parse_binary_scalar) - << "Can not apply binary operation \"" << parse_binary_scalar.op().getName() - << "\" to arguments of types " << left_argument->getValueType().getName() - << " and " << right_argument->getValueType().getName(); - } - - return E::BinaryExpression::Create(parse_binary_scalar.op(), - left_argument, - right_argument); - } case ParseExpression::kScalarLiteral: { const ParseScalarLiteral &parse_literal_scalar = static_cast(parse_expression); const Type *concrete_type = nullptr; TypedValue concrete = parse_literal_scalar.literal_value() ->concretize(type_hint, &concrete_type); - return E::ScalarLiteral::Create(std::move(concrete), *concrete_type); + return E::ScalarLiteral::Create( + GenericValue::CreateWithTypedValue(*concrete_type, concrete)); } case ParseExpression::kSearchedCaseExpression: { const ParseSearchedCaseExpression &parse_searched_case_expression = @@ -2571,57 +2536,6 @@ E::ScalarPtr Resolver::resolveExpression( type_hint, expression_resolution_info); } - case ParseExpression::kUnaryExpression: { - const ParseUnaryExpression &parse_unary_expr = - static_cast(parse_expression); - - E::ScalarPtr argument = resolveExpression( - *parse_unary_expr.operand(), - parse_unary_expr.op().pushDownTypeHint(type_hint), - expression_resolution_info); - - // If the argument is a NULL of unknown Type, try to resolve result Type - // of this UnaryExpression as follows: - // - // 1. If the UnaryExpression can only return one type, then the - // result is a NULL of that type. - // 2. If there is a type hint for the UnaryExpression's result, and - // it is possible for the UnaryExpression to return the hinted - // type, then the result is a NULL of that type. - // 3. Otherwise, the result is a NULL of unknown type (i.e. - // NullType). - // - // NOTE(chasseur): As with binary expressions above, step #3 does not - // always completely capture information about what types the NULL result - // can take on, since NullType is implicitly convertable to any Type. - if (argument->getValueType().getTypeID() == kNullType) { - const Type *fixed_result_type = parse_unary_expr.op().fixedNullableResultType(); - if (fixed_result_type != nullptr) { - return E::ScalarLiteral::Create(fixed_result_type->makeNullValue(), - *fixed_result_type); - } - - if (type_hint != nullptr) { - const Type &nullable_type_hint = type_hint->getNullableVersion(); - if (parse_unary_expr.op().resultTypeIsPlausible(nullable_type_hint)) { - return E::ScalarLiteral::Create(nullable_type_hint.makeNullValue(), - nullable_type_hint); - } - } - - const Type &null_type = TypeFactory::GetType(kNullType, true); - return E::ScalarLiteral::Create(null_type.makeNullValue(), - null_type); - } - - if (!parse_unary_expr.op().canApplyToType(argument->getValueType())) { - THROW_SQL_ERROR_AT(&parse_unary_expr) - << "Can not apply unary operation \"" << parse_unary_expr.op().getName() - << "\" to argument of type " << argument->getValueType().getName(); - } - - return E::UnaryExpression::Create(parse_unary_expr.op(), argument); - } case ParseExpression::kFunctionCall: { return resolveFunctionCall( static_cast(parse_expression), @@ -2635,81 +2549,90 @@ E::ScalarPtr Resolver::resolveExpression( expression_resolution_info, true /* has_single_column */); } - case ParseExpression::kExtract: { - const ParseExtractFunction &parse_extract = - static_cast(parse_expression); - - const ParseString &extract_field = *parse_extract.extract_field(); - const std::string lowered_unit = ToLower(extract_field.value()); - DateExtractUnit extract_unit; - if (lowered_unit == "year") { - extract_unit = DateExtractUnit::kYear; - } else if (lowered_unit == "month") { - extract_unit = DateExtractUnit::kMonth; - } else if (lowered_unit == "day") { - extract_unit = DateExtractUnit::kDay; - } else if (lowered_unit == "hour") { - extract_unit = DateExtractUnit::kHour; - } else if (lowered_unit == "minute") { - extract_unit = DateExtractUnit::kMinute; - } else if (lowered_unit == "second") { - extract_unit = DateExtractUnit::kSecond; - } else { - THROW_SQL_ERROR_AT(&extract_field) - << "Invalid extract unit: " << extract_field.value(); - } - - const DateExtractOperation &op = DateExtractOperation::Instance(extract_unit); - const E::ScalarPtr argument = resolveExpression( - *parse_extract.date_expression(), - op.pushDownTypeHint(type_hint), - expression_resolution_info); - - if (!op.canApplyToType(argument->getValueType())) { - THROW_SQL_ERROR_AT(parse_extract.date_expression()) - << "Can not extract from argument of type: " - << argument->getValueType().getName(); + case ParseExpression::kTypeCast: { + const ParseTypeCast &parse_type_cast = + static_cast(parse_expression); + const E::ScalarPtr operand = + resolveExpression(parse_type_cast.operand(), + nullptr /* type_hint */, + expression_resolution_info); + const Type &target_type = + resolveDataType(parse_type_cast.target_type()); + if (!OperationFactory::CanApplyCastOperation(operand->getValueType(), + target_type)) { + THROW_SQL_ERROR_AT(&parse_type_cast) + << "Cannot cast from " << operand->getValueType().getName() + << " type to " << target_type.getName() << " type"; } - - return E::UnaryExpression::Create(op, argument); + return E::Cast::Create(operand, target_type); } - case ParseExpression::kSubstring: { - const ParseSubstringFunction &parse_substring = - static_cast(parse_expression); + default: + LOG(FATAL) << "Unknown scalar type: " + << parse_expression.getExpressionType(); + } +} - // Validate start position and substring length. - if (parse_substring.start_position() <= 0) { - THROW_SQL_ERROR_AT(&parse_expression) - << "The start position must be greater than 0"; - } - if (parse_substring.length() <= 0) { - THROW_SQL_ERROR_AT(&parse_expression) - << "The substring length must be greater than 0"; +E::ScalarPtr Resolver::resolveArray( + const ParseArray &parse_array, + const Type *type_hint, + ExpressionResolutionInfo *expression_resolution_info) { + const auto &parse_elements = parse_array.elements(); + if (parse_elements.empty()) { + // TODO(jianqiao): Figure out how to handle empty array. + const GenericValue meta_null_type_value = + GenericValue::CreateWithLiteral(MetaType::InstanceNonNullable(), + &NullType::InstanceNullable()); + return E::ScalarLiteral::Create( + GenericValue::CreateWithLiteral( + ArrayType::InstanceNonNullable({meta_null_type_value}), + ArrayLit(NullType::InstanceNullable()))); + } else { + // Currently we only support homogeneous array with literal values. + std::vector literals; + const Type *element_type = nullptr; + for (const auto &parse_element : parse_elements) { + const E::ScalarPtr scalar = + resolveExpression(*parse_element, nullptr, expression_resolution_info); + E::ScalarLiteralPtr literal; + if (E::SomeScalarLiteral::MatchesWithConditionalCast(scalar, &literal)) { + const GenericValue &value = literal->value(); + if (element_type == nullptr) { + element_type = &value.getType(); + } else { + if (!element_type->equals(value.getType())) { + THROW_SQL_ERROR_AT(parse_element) + << "Heterogeneous array is not supported: " + << "array contains elements of at least two types " + << element_type->getName() << " and " + << value.getType().getName(); + } + } + literals.emplace_back(literal); + } else { + THROW_SQL_ERROR_AT(parse_element) + << "Non-static array element is not supported yet"; } + } + DCHECK(element_type != nullptr); - // Convert 1-base position to 0-base position - const std::size_t zero_base_start_position = parse_substring.start_position() - 1; - const SubstringOperation &op = - SubstringOperation::Instance(zero_base_start_position, - parse_substring.length()); + const GenericValue meta_element_type_value = + GenericValue::CreateWithLiteral(MetaType::InstanceNonNullable(), + element_type); + const Type &array_type = + ArrayType::InstanceNonNullable({meta_element_type_value}); - const E::ScalarPtr argument = - resolveExpression(*parse_substring.operand(), - op.pushDownTypeHint(type_hint), - expression_resolution_info); - if (!op.canApplyToType(argument->getValueType())) { - THROW_SQL_ERROR_AT(&parse_substring) - << "Can not apply substring function to argument of type " - << argument->getValueType().getName(); - } - return E::UnaryExpression::Create(op, argument); + // NOTE(refactor-type): Possibly memory leak region, noexcept. + std::unique_ptr array_literal = std::make_unique(*element_type); + for (const auto &literal : literals) { + array_literal->push_back( + element_type->cloneValue(literal->value().getValue())); } - default: - LOG(FATAL) << "Unknown scalar type: " - << parse_expression.getExpressionType(); + return E::ScalarLiteral::Create( + GenericValue::CreateWithOwnedData(array_type, array_literal.release())); } } + E::ScalarPtr Resolver::resolveSearchedCaseExpression( const ParseSearchedCaseExpression &parse_searched_case_expression, const Type *type_hint, @@ -2963,6 +2886,91 @@ E::ScalarPtr Resolver::resolveSimpleCaseExpression( *result_data_type); } +E::ScalarPtr Resolver::resolveScalarFunction( + const ParseFunctionCall &parse_function_call, + const std::string &function_name, + const std::vector &resolved_arguments, + ExpressionResolutionInfo *expression_resolution_info) { + const std::size_t arity = resolved_arguments.size(); + std::vector argument_types; + std::size_t first_static_argument_position = 0; + for (std::size_t i = 0; i < arity; ++i) { + const E::ScalarPtr &argument = resolved_arguments[i]; + if (argument->getExpressionType() != E::ExpressionType::kScalarLiteral) { + first_static_argument_position = i + 1; + } + argument_types.emplace_back(&argument->getValueType()); + } + + std::vector static_arguments; + for (std::size_t i = first_static_argument_position; i < arity; ++i) { + static_arguments.emplace_back( + std::static_pointer_cast( + resolved_arguments[i])->value()); + DCHECK(static_arguments.back().getType().getTypeID() == argument_types[i]->getTypeID()); + } + + std::shared_ptr> coerced_argument_types; + std::shared_ptr> coerced_static_arguments; + std::string message; + const OperationSignaturePtr op_signature = + OperationFactory::ResolveOperation( + function_name, + std::make_shared>(std::move(argument_types)), + std::make_shared>(std::move(static_arguments)), + &coerced_argument_types, + &coerced_static_arguments, + &message); + + if (op_signature == nullptr) { + if (message.empty()) { + THROW_SQL_ERROR_AT(&parse_function_call) << message; + } else { + THROW_SQL_ERROR_AT(&parse_function_call) + << "Cannot resolve scalar function " << function_name; + } + } + + // Add cast if neccessary. + std::vector coerced_arguments; + for (std::size_t i = 0; i < op_signature->getNonStaticArity(); ++i) { + const auto &argument = resolved_arguments[i]; + const Type &target_type = *(*coerced_argument_types)[i]; + if (argument->getValueType().equals(target_type)) { + coerced_arguments.emplace_back(argument); + } else { + coerced_arguments.emplace_back(E::Cast::Create(argument, target_type)); + } + } + + const OperationPtr operation = OperationFactory::GetOperation(op_signature); + switch (operation->getOperationSuperTypeID()) { + case Operation::kUnaryOperation: { + DCHECK_EQ(1u, coerced_arguments.size()); + return E::UnaryExpression::Create( + op_signature, + std::static_pointer_cast(operation), + coerced_arguments[0], + coerced_static_arguments); + } + case Operation::kBinaryOperation: { + DCHECK_EQ(2u, coerced_arguments.size()); + return E::BinaryExpression::Create( + op_signature, + std::static_pointer_cast(operation), + coerced_arguments[0], + coerced_arguments[1], + coerced_static_arguments); + } + default: { + const auto operation_id = + static_cast>( + operation->getOperationSuperTypeID()); + LOG(FATAL) << "Unknown opeation super type id: " << operation_id; + } + } +} + // TODO(chasseur): For now this only handles resolving aggregate functions. In // the future it should be extended to resolve scalar functions as well. // TODO(Shixuan): This will handle resolving window aggregation function as well, @@ -2983,8 +2991,7 @@ E::ScalarPtr Resolver::resolveFunctionCall( } std::vector resolved_arguments; - const PtrList *unresolved_arguments = - parse_function_call.arguments(); + const PtrList *unresolved_arguments = parse_function_call.arguments(); // The first aggregate function and window aggregate function in the arguments. const ParseTreeNode *first_aggregate_function = nullptr; const ParseTreeNode *first_window_aggregate_function = nullptr; @@ -2992,7 +2999,7 @@ E::ScalarPtr Resolver::resolveFunctionCall( for (const ParseExpression &unresolved_argument : *unresolved_arguments) { ExpressionResolutionInfo expr_resolution_info( *expression_resolution_info); - resolved_arguments.push_back( + resolved_arguments.emplace_back( resolveExpression(unresolved_argument, nullptr, // No Type hint. &expr_resolution_info)); @@ -3011,6 +3018,16 @@ E::ScalarPtr Resolver::resolveFunctionCall( } } + if (OperationFactory::HasOperation(function_name, resolved_arguments.size())) { + E::ScalarPtr scalar = resolveScalarFunction(parse_function_call, + function_name, + resolved_arguments, + expression_resolution_info); + expression_resolution_info->parse_aggregate_expression = first_aggregate_function; + expression_resolution_info->parse_window_aggregate_expression = first_window_aggregate_function; + return scalar; + } + if (count_star && !resolved_arguments.empty()) { THROW_SQL_ERROR_AT(&parse_function_call) << "COUNT aggregate has both star (*) and non-star arguments."; @@ -3442,7 +3459,7 @@ void Resolver::rewriteIfOrdinalReference( if (E::SomeScalarLiteral::MatchesWithConditionalCast(*expression, &literal) && literal->getValueType().getTypeID() == kInt && !literal->value().isNull()) { - int position = literal->value().getLiteral(); + int position = literal->value().getLiteral(); if (position < 1 || position > static_cast( select_list_info->select_list_expressions.size())) { diff --git a/query_optimizer/resolver/Resolver.hpp b/query_optimizer/resolver/Resolver.hpp index 1784782d..1844493e 100644 --- a/query_optimizer/resolver/Resolver.hpp +++ b/query_optimizer/resolver/Resolver.hpp @@ -41,6 +41,8 @@ namespace quickstep { class CatalogDatabase; class CatalogRelation; class Comparison; +class ParseArray; +class ParseDataType; class ParseExpression; class ParseFunctionCall; class ParseGeneratorTableReference; @@ -446,6 +448,11 @@ class Resolver { const Type *type_hint, ExpressionResolutionInfo *expression_resolution_info); + expressions::ScalarPtr resolveArray( + const ParseArray &parse_array, + const Type *type_hint, + ExpressionResolutionInfo *expression_resolution_info); + /** * @brief Resolves a searched CASE expression. * @@ -480,9 +487,6 @@ class Resolver { * @brief Resolves a function call. For a non-scalar function, the returned * expression is an AttributeReference to the actual resolved expression. * - * @note This currently only handles resolving aggregate functions and window - * aggregate functions. - * * @param parse_function_call The function call to be resolved. * @param expression_resolution_info Resolution info that contains the name * resolver and info to be updated after @@ -493,6 +497,12 @@ class Resolver { const ParseFunctionCall &parse_function_call, ExpressionResolutionInfo *expression_resolution_info); + expressions::ScalarPtr resolveScalarFunction( + const ParseFunctionCall &parse_function_call, + const std::string &function_name, + const std::vector &resolved_arguments, + ExpressionResolutionInfo *expression_resolution_info); + /** * @brief Resolves a window aggregate function. * @@ -572,6 +582,8 @@ class Resolver { */ const CatalogRelation *resolveRelationName(const ParseString *relation_name); + const Type& resolveDataType(const ParseDataType &parse_data_type); + /** * @brief Determines whether \p op can apply to \p left_operand and \p * right_operand. diff --git a/query_optimizer/rules/CMakeLists.txt b/query_optimizer/rules/CMakeLists.txt index 73a80d28..b7f384c3 100644 --- a/query_optimizer/rules/CMakeLists.txt +++ b/query_optimizer/rules/CMakeLists.txt @@ -186,9 +186,9 @@ target_link_libraries(quickstep_queryoptimizer_rules_Partition quickstep_queryoptimizer_physical_TableReference quickstep_queryoptimizer_physical_TopLevelPlan quickstep_queryoptimizer_rules_BottomUpRule + quickstep_types_operations_OperationFactory + quickstep_types_operations_OperationSignature quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_Cast quickstep_utility_EqualsAnyConstant quickstep_utility_Macros @@ -296,9 +296,9 @@ target_link_libraries(quickstep_queryoptimizer_rules_ReuseAggregateExpressions quickstep_queryoptimizer_physical_Selection quickstep_queryoptimizer_physical_TopLevelPlan quickstep_queryoptimizer_rules_BottomUpRule + quickstep_types_operations_OperationFactory + quickstep_types_operations_OperationSignature quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_utility_HashError quickstep_utility_Macros) target_link_libraries(quickstep_queryoptimizer_rules_Rule diff --git a/query_optimizer/rules/Partition.cpp b/query_optimizer/rules/Partition.cpp index 5f68cd3c..0e21b989 100644 --- a/query_optimizer/rules/Partition.cpp +++ b/query_optimizer/rules/Partition.cpp @@ -49,9 +49,8 @@ #include "query_optimizer/physical/Sort.hpp" #include "query_optimizer/physical/TableReference.hpp" #include "query_optimizer/physical/TopLevelPlan.hpp" +#include "types/operations/OperationFactory.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "utility/Cast.hpp" #include "utility/EqualsAnyConstant.hpp" @@ -410,10 +409,17 @@ P::PhysicalPtr Partition::applyToNode(const P::PhysicalPtr &node) { for (const auto &avg_recompute_expression : avg_recompute_expressions) { const auto &avg_expr = get<0>(avg_recompute_expression); // Obtain AVG by evaluating SUM/COUNT in Selection. - const BinaryOperation ÷_op = - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide); + const OperationSignaturePtr op_sig = + OperationSignature::Create( + "+", + { get<1>(avg_recompute_expression)->getValueType().getTypeID(), + get<2>(avg_recompute_expression)->getValueType().getTypeID() }, + 0); + const BinaryOperationPtr divide_op = + OperationFactory::GetBinaryOperation(op_sig); const E::BinaryExpressionPtr new_avg_expr = - E::BinaryExpression::Create(divide_op, + E::BinaryExpression::Create(op_sig, + divide_op, get<1>(avg_recompute_expression), get<2>(avg_recompute_expression)); project_expressions.emplace_back( diff --git a/query_optimizer/rules/ReuseAggregateExpressions.cpp b/query_optimizer/rules/ReuseAggregateExpressions.cpp index a7c62c64..65832e73 100644 --- a/query_optimizer/rules/ReuseAggregateExpressions.cpp +++ b/query_optimizer/rules/ReuseAggregateExpressions.cpp @@ -44,9 +44,9 @@ #include "query_optimizer/physical/PhysicalType.hpp" #include "query_optimizer/physical/Selection.hpp" #include "query_optimizer/physical/TopLevelPlan.hpp" +#include "types/operations/OperationFactory.hpp" +#include "types/operations/OperationSignature.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "utility/HashError.hpp" #include "gflags/gflags.h" @@ -317,12 +317,19 @@ P::PhysicalPtr ReuseAggregateExpressions::applyToNode( } // Obtain AVG by evaluating SUM/COUNT in Selection. - const BinaryOperation ÷_op = - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide); + const E::AttributeReferencePtr &count_attr = agg_attrs[agg_ref->second_ref]; + const std::vector operand_tids = + { sum_attr->getValueType().getTypeID(), count_attr->getValueType().getTypeID() }; + const OperationSignaturePtr op_sig = + OperationSignature::Create("/", operand_tids, 0); + + const BinaryOperationPtr ÷_op = + OperationFactory::GetBinaryOperation(op_sig); const E::BinaryExpressionPtr avg_expr = - E::BinaryExpression::Create(divide_op, + E::BinaryExpression::Create(op_sig, + divide_op, sum_attr, - agg_attrs[agg_ref->second_ref]); + count_attr); new_select_exprs.emplace_back( E::Alias::Create(agg_expr->id(), avg_expr, diff --git a/query_optimizer/rules/tests/CMakeLists.txt b/query_optimizer/rules/tests/CMakeLists.txt index 42fa9c17..170116fb 100644 --- a/query_optimizer/rules/tests/CMakeLists.txt +++ b/query_optimizer/rules/tests/CMakeLists.txt @@ -87,8 +87,6 @@ target_link_libraries(quickstep_queryoptimizer_rules_tests quickstep_queryoptimizer_rules_tests_PhysicalRuleTest quickstep_queryoptimizer_rules_tests_RuleTest quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID diff --git a/query_optimizer/strategy/tests/CMakeLists.txt b/query_optimizer/strategy/tests/CMakeLists.txt index 97675f03..f5025838 100644 --- a/query_optimizer/strategy/tests/CMakeLists.txt +++ b/query_optimizer/strategy/tests/CMakeLists.txt @@ -73,8 +73,6 @@ target_link_libraries(quickstep_queryoptimizer_strategy_tests quickstep_queryoptimizer_strategy_tests_StrategyTest quickstep_types_TypeID quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID diff --git a/query_optimizer/tests/CMakeLists.txt b/query_optimizer/tests/CMakeLists.txt index 5ef1d0a3..bde0495c 100644 --- a/query_optimizer/tests/CMakeLists.txt +++ b/query_optimizer/tests/CMakeLists.txt @@ -50,8 +50,6 @@ target_link_libraries(quickstep_queryoptimizer_tests_OptimizerTest quickstep_types_TypeFactory quickstep_types_TypeID quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID diff --git a/query_optimizer/tests/OptimizerTest.cpp b/query_optimizer/tests/OptimizerTest.cpp index 7eb7a11d..4c94f2dc 100644 --- a/query_optimizer/tests/OptimizerTest.cpp +++ b/query_optimizer/tests/OptimizerTest.cpp @@ -43,8 +43,6 @@ #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "types/operations/comparisons/Comparison.hpp" #include "types/operations/comparisons/ComparisonFactory.hpp" #include "types/operations/comparisons/ComparisonID.hpp" diff --git a/relational_operators/CMakeLists.txt b/relational_operators/CMakeLists.txt index 7b9ed960..0ce89a19 100644 --- a/relational_operators/CMakeLists.txt +++ b/relational_operators/CMakeLists.txt @@ -714,8 +714,6 @@ target_link_libraries(AggregationOperator_unittest quickstep_types_LongType quickstep_types_TypedValue quickstep_types_containers_Tuple - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID quickstep_utility_Macros diff --git a/relational_operators/TableExportOperator.cpp b/relational_operators/TableExportOperator.cpp index f6a73bfa..419398f3 100644 --- a/relational_operators/TableExportOperator.cpp +++ b/relational_operators/TableExportOperator.cpp @@ -326,7 +326,7 @@ void TableExportToStringWorkOrder::writeToString(ValueAccessor *accessor, if (value.isNull()) { return null_string_; } else { - return value_types[idx]->printValueToString(value); + return value_types[idx]->printTypedValueToString(value); } }); output->push_back('\n'); diff --git a/relational_operators/TextScanOperator.cpp b/relational_operators/TextScanOperator.cpp index 66137d87..38858887 100644 --- a/relational_operators/TextScanOperator.cpp +++ b/relational_operators/TextScanOperator.cpp @@ -474,7 +474,7 @@ std::vector TextScanWorkOrder::parseRow(const char **row_ptr, attribute_values.emplace_back(attr.getType().makeNullValue()); } else { attribute_values.emplace_back(); - if (!attr.getType().parseValueFromString(value_str, &(attribute_values.back()))) { + if (!attr.getType().parseTypedValueFromString(value_str, &(attribute_values.back()))) { // Do not abort if one of the row is faulty. *is_faulty = true; LOG(INFO) << "Failed to parse value."; diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt index fb09e490..e061ff7c 100644 --- a/storage/CMakeLists.txt +++ b/storage/CMakeLists.txt @@ -826,7 +826,7 @@ target_link_libraries(quickstep_storage_PackedPayloadHashTable quickstep_utility_HashPair quickstep_utility_Macros quickstep_utility_PrimeNumber - quickstep_utility_TemplateUtil) + quickstep_utility_meta_Dispatchers) target_link_libraries(quickstep_storage_PartitionedHashTablePool glog quickstep_storage_HashTableBase @@ -870,9 +870,8 @@ target_link_libraries(quickstep_storage_SMAIndexSubBlock quickstep_types_TypeFactory quickstep_types_TypeID quickstep_types_TypedValue + quickstep_types_operations_OperationFactory quickstep_types_operations_binaryoperations_BinaryOperation - quickstep_types_operations_binaryoperations_BinaryOperationFactory - quickstep_types_operations_binaryoperations_BinaryOperationID quickstep_types_operations_comparisons_Comparison quickstep_types_operations_comparisons_ComparisonFactory quickstep_types_operations_comparisons_ComparisonID diff --git a/storage/LinearOpenAddressingHashTable.hpp b/storage/LinearOpenAddressingHashTable.hpp index 044ec6fd..34e60d65 100644 --- a/storage/LinearOpenAddressingHashTable.hpp +++ b/storage/LinearOpenAddressingHashTable.hpp @@ -567,7 +567,8 @@ const ValueT* LinearOpenAddressingHashTablekey_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = this->AdjustHash(key.getHash()); for (std::size_t bucket_num = hash_code % header_->num_buckets; @@ -639,7 +640,8 @@ template ::getAll(const TypedValue &key, std::vector *values) const { DEBUG_ASSERT(this->key_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = this->AdjustHash(key.getHash()); for (std::size_t bucket_num = hash_code % header_->num_buckets; @@ -714,7 +716,8 @@ HashTablePutResult const ValueT &value, HashTablePreallocationState *prealloc_state) { DEBUG_ASSERT(this->key_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. DEBUG_ASSERT(prealloc_state == nullptr); // TODO(chasseur): If allow_duplicate_keys is true, avoid storing more than @@ -831,7 +834,8 @@ ValueT* LinearOpenAddressingHashTablekey_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. // Block is do/while(false) so we can use break. do { @@ -1040,7 +1044,8 @@ bool LinearOpenAddressingHashTablekey_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. if (*entry_num == 0) { *entry_num = hash_code % header_->num_buckets; @@ -1116,7 +1121,8 @@ template ::hasKey(const TypedValue &key) const { DCHECK_EQ(1u, this->key_types_.size()); - DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = this->AdjustHash(key.getHash()); for (std::size_t bucket_num = hash_code % header_->num_buckets; diff --git a/storage/PackedPayloadHashTable.cpp b/storage/PackedPayloadHashTable.cpp index 1df20d0d..77f512b6 100644 --- a/storage/PackedPayloadHashTable.cpp +++ b/storage/PackedPayloadHashTable.cpp @@ -40,7 +40,7 @@ #include "utility/Alignment.hpp" #include "utility/Macros.hpp" #include "utility/PrimeNumber.hpp" -#include "utility/TemplateUtil.hpp" +#include "utility/meta/Dispatchers.hpp" #include "glog/logging.h" @@ -246,7 +246,7 @@ bool PackedPayloadHashTable::upsertValueAccessorCompositeKey( derived_accessor->beginIterationVirtual(); } - return InvokeOnBools( + return meta::InvokeOnBools( handles_.empty(), !all_keys_inline_, [&](auto key_only, // NOLINT(build/c++11) diff --git a/storage/SMAIndexSubBlock.cpp b/storage/SMAIndexSubBlock.cpp index 81cf6c00..2f7c474b 100644 --- a/storage/SMAIndexSubBlock.cpp +++ b/storage/SMAIndexSubBlock.cpp @@ -44,9 +44,8 @@ #include "types/TypeFactory.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" +#include "types/operations/OperationFactory.hpp" #include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationFactory.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" #include "types/operations/comparisons/Comparison.hpp" #include "types/operations/comparisons/ComparisonFactory.hpp" #include "types/operations/comparisons/ComparisonID.hpp" @@ -359,9 +358,9 @@ SMAIndexSubBlock::SMAIndexSubBlock(const TupleStorageSubBlock &tuple_store, TypeID attr_sum_typeid = sma_internal::getTypeForSum(attr_typeid); if (add_operations_.elementIsNullAt(attr_typeid)) { add_operations_.replaceElement(attr_typeid, - BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd) - .makeUncheckedBinaryOperatorForTypes(TypeFactory::GetType(attr_typeid), - TypeFactory::GetType(attr_sum_typeid))); + OperationFactory::GetAddOperation(attr_typeid, attr_sum_typeid) + ->makeUncheckedBinaryOperator(TypeFactory::GetType(attr_typeid), + TypeFactory::GetType(attr_sum_typeid))); } } @@ -640,7 +639,7 @@ Selectivity SMAIndexSubBlock::getSelectivityForPredicate(const ComparisonPredica SMAPredicate *replacement = new SMAPredicate( sma_predicate->attribute, sma_predicate->comparison, - attribute_type.coerceValue(sma_predicate->literal, literal_type)); + attribute_type.coerceTypedValue(sma_predicate->literal, literal_type)); sma_predicate.reset(replacement); } else { // The literal type cannot be converted, so do not evaluate with the SMA. diff --git a/storage/SeparateChainingHashTable.hpp b/storage/SeparateChainingHashTable.hpp index 24036231..d60e40ba 100644 --- a/storage/SeparateChainingHashTable.hpp +++ b/storage/SeparateChainingHashTable.hpp @@ -565,7 +565,8 @@ const ValueT* SeparateChainingHashTablekey_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = key.getHash(); std::size_t bucket_ref = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); @@ -621,7 +622,8 @@ template ::getAll(const TypedValue &key, std::vector *values) const { DEBUG_ASSERT(this->key_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = key.getHash(); std::size_t bucket_ref = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); @@ -680,7 +682,8 @@ HashTablePutResult const ValueT &value, HashTablePreallocationState *prealloc_state) { DEBUG_ASSERT(this->key_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. if (prealloc_state == nullptr) { // Early check for a free bucket. @@ -822,7 +825,8 @@ ValueT* SeparateChainingHashTablekey_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. if (variable_key_size > 0) { // Don't allocate yet, since the key may already be present. However, we @@ -988,7 +992,8 @@ bool SeparateChainingHashTablekey_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. if (*entry_num == 0) { *entry_num = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); @@ -1066,7 +1071,8 @@ template ::hasKey(const TypedValue &key) const { DEBUG_ASSERT(this->key_types_.size() == 1); - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = key.getHash(); std::size_t bucket_ref = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); diff --git a/storage/SimpleScalarSeparateChainingHashTable.hpp b/storage/SimpleScalarSeparateChainingHashTable.hpp index 81f20446..1a515e38 100644 --- a/storage/SimpleScalarSeparateChainingHashTable.hpp +++ b/storage/SimpleScalarSeparateChainingHashTable.hpp @@ -563,7 +563,8 @@ const ValueT* SimpleScalarSeparateChainingHashTable ::getSingle(const TypedValue &key) const { DCHECK(!allow_duplicate_keys); - DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = key.getHashScalarLiteral(); std::size_t bucket_ref = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); @@ -593,7 +594,8 @@ void SimpleScalarSeparateChainingHashTable ::getAll(const TypedValue &key, std::vector *values) const { - DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = key.getHashScalarLiteral(); std::size_t bucket_ref = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); @@ -626,7 +628,8 @@ HashTablePutResult const std::size_t variable_key_size, const ValueT &value, HashTablePreallocationState *prealloc_state) { - DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DEBUG_ASSERT(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. if (prealloc_state == nullptr) { // Early check for a free bucket. @@ -682,7 +685,8 @@ ValueT* SimpleScalarSeparateChainingHashTablekey_types_.front()->getSignature())); +// DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. DCHECK_EQ(0u, variable_key_size); const std::size_t hash_code = key.getHashScalarLiteral(); @@ -752,7 +756,8 @@ bool SimpleScalarSeparateChainingHashTablekey_types_.front()->getSignature())); +// DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. if (*entry_num == 0) { *entry_num = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); @@ -792,7 +797,8 @@ bool SimpleScalarSeparateChainingHashTable ::hasKey(const TypedValue &key) const { DCHECK_EQ(1u, this->key_types_.size()); - DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); +// DCHECK(key.isPlausibleInstanceOf(this->key_types_.front()->getSignature())); + // TODO(refactor-type): fix signature. const std::size_t hash_code = key.getHashScalarLiteral(); std::size_t bucket_ref = slots_[hash_code % header_->num_slots].load(std::memory_order_relaxed); diff --git a/storage/TupleStorageSubBlock.cpp b/storage/TupleStorageSubBlock.cpp index f2eef492..50b84ca5 100644 --- a/storage/TupleStorageSubBlock.cpp +++ b/storage/TupleStorageSubBlock.cpp @@ -101,7 +101,8 @@ void TupleStorageSubBlock::paranoidInsertTypeCheck(const Tuple &tuple) { CatalogRelationSchema::const_iterator attr_it = relation_.begin(); while (value_it != tuple.end()) { - assert(value_it->isPlausibleInstanceOf(attr_it->getType().getSignature())); +// assert(value_it->isPlausibleInstanceOf(attr_it->getType().getSignature())); + // TODO(refactor-type): fix signature. ++value_it; ++attr_it; diff --git a/storage/WindowAggregationOperationState.cpp b/storage/WindowAggregationOperationState.cpp index 30d91dba..2b63a6c7 100644 --- a/storage/WindowAggregationOperationState.cpp +++ b/storage/WindowAggregationOperationState.cpp @@ -261,7 +261,7 @@ void WindowAggregationOperationState::windowAggregateBlocks( for (std::size_t attr_id = 0; attr_id < attribute_vecs.size(); ++attr_id) { ColumnVector *attr_vec = attribute_vecs[attr_id]; - if (attr_vec->isNative()) { + if (attr_vec->getImplementation() == ColumnVector::kNative) { static_cast(attr_vec)->appendTypedValue( tuple_accessor->getTypedValue(attr_id)); } else { @@ -274,7 +274,7 @@ void WindowAggregationOperationState::windowAggregateBlocks( argument_idx < argument_vecs.size(); ++argument_idx) { ColumnVector *argument = argument_vecs[argument_idx]; - if (argument->isNative()) { + if (argument->getImplementation() == ColumnVector::kNative) { static_cast(argument)->appendTypedValue( argument_accessor->getTypedValue(argument_idx)); } else { diff --git a/types/ArrayLit.hpp b/types/ArrayLit.hpp new file mode 100644 index 00000000..b5d35488 --- /dev/null +++ b/types/ArrayLit.hpp @@ -0,0 +1,112 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_ARRAY_LIT_HPP_ +#define QUICKSTEP_TYPES_ARRAY_LIT_HPP_ + +#include +#include + +#include "types/Type.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +typedef void UntypedLiteral; + +class ArrayLit { + public: + using const_iterator = std::vector::const_iterator; + + ArrayLit(const Type &type) + : type_(type) { + } + + ArrayLit(const ArrayLit &other) + : type_(other.type_) { + for (const UntypedLiteral *value :other.elements_) { + elements_.emplace_back(type_.cloneValue(value)); + } + } + + ArrayLit(ArrayLit &&other) + : type_(other.type_), + elements_(std::move(other.elements_)) { + } + + ~ArrayLit() { + clear(); + } + + void clear() { + for (UntypedLiteral *value : elements_) { + type_.destroyValue(value); + } + elements_.clear(); + } + + bool empty() const { + return elements_.empty(); + } + + std::size_t size() const { + return elements_.size(); + } + + + void push_back(UntypedLiteral *value) { + elements_.emplace_back(value); + } + + const UntypedLiteral* operator[](const std::size_t idx) const { + DCHECK_LT(idx, elements_.size()); + return elements_[idx]; + } + + const_iterator begin() const { + return elements_.begin(); + } + + const_iterator end() const { + return elements_.end(); + } + + const UntypedLiteral* front() const { + return elements_.front(); + } + + const UntypedLiteral* back() const { + return elements_.back(); + } + + private: + const Type &type_; + std::vector elements_; +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_NULL_LIT_HPP_ diff --git a/types/ArrayType.cpp b/types/ArrayType.cpp new file mode 100644 index 00000000..8d8313f6 --- /dev/null +++ b/types/ArrayType.cpp @@ -0,0 +1,121 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#include "types/ArrayType.hpp" + +#include +#include + +#include "types/ArrayLit.hpp" +#include "types/Type.pb.h" +#include "types/TypeID.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +std::string ArrayType::getName() const { + std::string name("Array("); + name.append(element_type_.getName()); + name.push_back(')'); + if (nullable_) { + name.append(" NULL"); + } + return name; +} + +bool ArrayType::isCoercibleFrom(const Type &original_type) const { + if (original_type.getTypeID() != kArray) { + return false; + } + const Type &original_element_type = + static_cast(original_type).element_type_; + return element_type_.isCoercibleFrom(original_element_type); +} + +bool ArrayType::TypeParametersAreValid(const std::vector ¶meters) { + if (parameters.size() != 1u) { + return false; + } + return parameters.front().getType().getTypeID() == kMetaType; +} + +bool ArrayType::checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const { + if (!equals(rhs_type)) { + return false; + } + const ArrayLit &lhs_array = castValueToLiteral(lhs); + const ArrayLit &rhs_array = castValueToLiteral(rhs); + if (lhs_array.size() != rhs_array.size()) { + return false; + } + for (std::size_t i = 0; i < lhs_array.size(); ++i) { + if (!element_type_.checkValuesEqual(lhs_array[i], rhs_array[i])) { + return false; + } + } + return true; +} + +TypedValue ArrayType::marshallValue(const UntypedLiteral *value) const { + const ArrayLit &array = *static_cast(value); + serialization::ArrayLit proto; + for (const auto &element : array) { + // TODO(refactor-type): Improve performance. + TypedValue value = element_type_.marshallValue(element); + proto.add_data(value.getDataPtr(), value.getDataSize()); + } + const std::size_t data_size = proto.ByteSize(); + void *data = std::malloc(data_size); + proto.SerializeToArray(data, data_size); + return TypedValue::CreateWithOwnedData(kArray, data, data_size); +} + +UntypedLiteral* ArrayType::unmarshallValue(const void *data, + const std::size_t data_size) const { + std::unique_ptr array = std::make_unique(element_type_); + serialization::ArrayLit proto; + proto.ParseFromArray(data, data_size); + for (int i = 0; i < proto.data_size(); ++i) { + const std::string &element_data = proto.data(i); + array->push_back( + element_type_.unmarshallValue(element_data.c_str(), element_data.size())); + } + return array.release(); +} + +std::string ArrayType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); + + const ArrayLit &literals = castValueToLiteral(value); + std::string ret = "{"; + if (!literals.empty()) { + ret.append(element_type_.printValueToString(literals.front())); + for (std::size_t i = 1; i < literals.size(); ++i) { + ret.append(","); + ret.append(element_type_.printValueToString(literals[i])); + } + } + ret.append("}"); + return ret; +} + +} // namespace quickstep diff --git a/types/ArrayType.hpp b/types/ArrayType.hpp new file mode 100644 index 00000000..e79e3891 --- /dev/null +++ b/types/ArrayType.hpp @@ -0,0 +1,110 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_ARRAY_TYPE_HPP_ +#define QUICKSTEP_TYPES_ARRAY_TYPE_HPP_ + +#include +#include + +#include "types/Type.hpp" +#include "types/TypeID.hpp" +#include "types/TypeRegistrar.hpp" +#include "types/TypeSynthesizer.hpp" +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +class TypedValue; + +/** \addtogroup Types + * @{ + */ + +class ArrayType final : public TypeSynthesizer { + public: + int getPrintWidth() const override { + return 32; + } + + std::string getName() const override; + + bool isCoercibleFrom(const Type &original_type) const override; + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override; + + TypedValue marshallValue(const UntypedLiteral *value) const override; + + UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const override; + + std::string printValueToString(const UntypedLiteral *value) const override; + + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override { + return false; + } + + const Type &getElementType() const { + return element_type_; + } + + static bool TypeParametersAreValid(const std::vector ¶meters); + + private: + ArrayType(const bool nullable, const std::vector ¶meters) + : TypeSynthesizer(nullable, 0, 0x1000, parameters), + element_type_(ExtractType(parameters)) { + } + + static const Type& ExtractType(const std::vector ¶meters) { + DCHECK(TypeParametersAreValid(parameters)); + return **static_cast(parameters.front().getValue()); + } + + const Type &element_type_; + + QUICKSTEP_SYNTHESIZE_TYPE(ArrayType); +}; + + +template +class FirstOrderArrayType { + public: + + + private: + + QUICKSTEP_SYNTHESIZE_TYPE(FirstOrderArrayType); +}; + + + + + + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_ARRAY_TYPE_HPP_ diff --git a/types/AsciiStringSuperType.hpp b/types/AsciiStringSuperType.hpp new file mode 100644 index 00000000..252a1a71 --- /dev/null +++ b/types/AsciiStringSuperType.hpp @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_ASCII_STRING_SUPER_TYPE_HPP_ +#define QUICKSTEP_TYPES_ASCII_STRING_SUPER_TYPE_HPP_ + +#include + +#include "types/Type.hpp" +#include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +/** + * @brief A superclass for ASCII string types. + **/ +template +class AsciiStringSuperType : public TypeSynthesizer { + public: + /** + * @brief Get the character-length of this string type. + * + * @return The maximum length of a string of this type. + **/ + inline std::size_t getStringLength() const { + return TypeSynthesizer::length_; + } + + protected: + AsciiStringSuperType(const bool nullable, + const std::size_t minimum_byte_length, + const std::size_t maximum_byte_length, + const std::size_t string_length) + : TypeSynthesizer( + nullable, minimum_byte_length, maximum_byte_length, string_length) { + } + + private: + DISALLOW_COPY_AND_ASSIGN(AsciiStringSuperType); +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_ASCII_STRING_SUPER_TYPE_HPP_ diff --git a/types/BoolType.cpp b/types/BoolType.cpp new file mode 100644 index 00000000..7687f06c --- /dev/null +++ b/types/BoolType.cpp @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#include "types/BoolType.hpp" + +#include +#include + +#include "types/TypeID.hpp" +#include "types/TypedValue.hpp" +#include "utility/StringUtil.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +std::string BoolType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); + + return castValueToLiteral(value) ? "true" : "false"; +} + +void BoolType::printValueToFile(const UntypedLiteral *value, + FILE *file, + const int padding) const { + DCHECK(value != nullptr); + + std::fprintf(file, + "%*s", + static_cast(padding), + castValueToLiteral(value) ? "true" : "false"); +} + +bool BoolType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { + const std::string lo_value = ToLower(value_string); + if (lo_value == "true") { + *value = TypedValue(true); + return true; + } else if (lo_value == "false") { + *value = TypedValue(false); + return true; + } + return false; +} + +} // namespace quickstep diff --git a/types/BoolType.hpp b/types/BoolType.hpp new file mode 100644 index 00000000..49fbfa38 --- /dev/null +++ b/types/BoolType.hpp @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_BOOL_TYPE_HPP_ +#define QUICKSTEP_TYPES_BOOL_TYPE_HPP_ + +#include +#include +#include +#include + +#include "types/NumericSuperType.hpp" +#include "types/TypeID.hpp" +#include "utility/Macros.hpp" + +namespace quickstep { + +class Type; +class TypedValue; + +/** \addtogroup Types + * @{ + */ + +/** + * @brief A type representing a 8-bit bool. + **/ +class BoolType final : public NumericSuperType { + public: + int getPrintWidth() const override { + // "true" or "false" + return 5; + } + + std::string printValueToString(const UntypedLiteral *value) const override; + + void printValueToFile(const UntypedLiteral *value, + FILE *file, + const int padding = 0) const override; + + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; + + private: + explicit BoolType(const bool nullable) + : NumericSuperType(nullable) {} + + QUICKSTEP_SYNTHESIZE_TYPE(BoolType); +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_BOOL_TYPE_HPP_ diff --git a/types/CMakeLists.txt b/types/CMakeLists.txt index 769187bc..271700b8 100644 --- a/types/CMakeLists.txt +++ b/types/CMakeLists.txt @@ -32,6 +32,10 @@ QS_PROTOBUF_GENERATE_CPP(types_TypedValue_proto_srcs types_TypedValue_proto_hdrs QS_PROTOBUF_GENERATE_CPP(types_Type_proto_srcs types_Type_proto_hdrs Type.proto) # Declare micro-libs: +add_library(quickstep_types_ArrayLit ../empty_src.cpp ArrayLit.hpp) +add_library(quickstep_types_ArrayType ArrayType.cpp ArrayType.hpp) +add_library(quickstep_types_AsciiStringSuperType ../empty_src.cpp AsciiStringSuperType.hpp) +add_library(quickstep_types_BoolType BoolType.cpp BoolType.hpp) add_library(quickstep_types_CharType CharType.cpp CharType.hpp) add_library(quickstep_types_DateOperatorOverloads ../empty_src.cpp DateOperatorOverloads.hpp) add_library(quickstep_types_DateType DateType.cpp DateType.hpp) @@ -40,18 +44,29 @@ add_library(quickstep_types_DatetimeLit ../empty_src.cpp DatetimeLit.hpp) add_library(quickstep_types_DatetimeType DatetimeType.cpp DatetimeType.hpp) add_library(quickstep_types_DoubleType DoubleType.cpp DoubleType.hpp) add_library(quickstep_types_FloatType FloatType.cpp FloatType.hpp) +add_library(quickstep_types_GenericValue GenericValue.cpp GenericValue.hpp) add_library(quickstep_types_IntType IntType.cpp IntType.hpp) add_library(quickstep_types_IntervalLit ../empty_src.cpp IntervalLit.hpp) add_library(quickstep_types_IntervalParser IntervalParser.cpp IntervalParser.hpp) add_library(quickstep_types_LongType LongType.cpp LongType.hpp) +add_library(quickstep_types_MetaType MetaType.cpp MetaType.hpp) +add_library(quickstep_types_MetaType-decl ../empty_src.cpp MetaType-decl.hpp) add_library(quickstep_types_NullCoercibilityCheckMacro ../empty_src.cpp NullCoercibilityCheckMacro.hpp) +add_library(quickstep_types_NullLit ../empty_src.cpp NullLit.hpp) add_library(quickstep_types_NullType ../empty_src.cpp NullType.hpp) add_library(quickstep_types_NumericSuperType ../empty_src.cpp NumericSuperType.hpp) +add_library(quickstep_types_NumericTypeSafeCoercibility ../empty_src.cpp NumericTypeSafeCoercibility.hpp) add_library(quickstep_types_NumericTypeUnifier ../empty_src.cpp NumericTypeUnifier.hpp) +add_library(quickstep_types_TextType TextType.cpp TextType.hpp) add_library(quickstep_types_Type Type.cpp Type.hpp) add_library(quickstep_types_TypeErrors ../empty_src.cpp TypeErrors.hpp) add_library(quickstep_types_TypeFactory TypeFactory.cpp TypeFactory.hpp) +add_library(quickstep_types_TypeFactory-decl ../empty_src.cpp TypeFactory-decl.hpp) add_library(quickstep_types_TypeID TypeID.cpp TypeID.hpp) +add_library(quickstep_types_TypeIDSelectors ../empty_src.cpp TypeIDSelectors.hpp) +add_library(quickstep_types_TypeRegistrar ../empty_src.cpp TypeRegistrar.hpp) +add_library(quickstep_types_TypeSynthesizer ../empty_src.cpp TypeSynthesizer.hpp) +add_library(quickstep_types_TypeUtil ../empty_src.cpp TypeUtil.hpp) add_library(quickstep_types_Type_proto ${types_Type_proto_srcs}) add_library(quickstep_types_TypedValue TypedValue.cpp TypedValue.hpp) add_library(quickstep_types_TypedValue_proto ${types_TypedValue_proto_srcs}) @@ -59,8 +74,27 @@ add_library(quickstep_types_VarCharType VarCharType.cpp VarCharType.hpp) add_library(quickstep_types_YearMonthIntervalType YearMonthIntervalType.cpp YearMonthIntervalType.hpp) # Link dependencies: +target_link_libraries(quickstep_types_ArrayType + quickstep_types_Type + quickstep_types_TypeID + quickstep_types_TypeRegistrar + quickstep_types_TypeSynthesizer + quickstep_types_Type_proto + quickstep_utility_Macros) +target_link_libraries(quickstep_types_AsciiStringSuperType + quickstep_types_Type + quickstep_types_TypeID + quickstep_types_TypeSynthesizer) +target_link_libraries(quickstep_types_BoolType + glog + quickstep_types_NumericSuperType + quickstep_types_TypeID + quickstep_types_TypedValue + quickstep_utility_Macros + quickstep_utility_StringUtil) target_link_libraries(quickstep_types_CharType glog + quickstep_types_AsciiStringSuperType quickstep_types_NullCoercibilityCheckMacro quickstep_types_Type quickstep_types_TypeID @@ -77,9 +111,9 @@ target_link_libraries(quickstep_types_DateOperatorOverloads target_link_libraries(quickstep_types_DateType glog quickstep_types_DatetimeLit - quickstep_types_NullCoercibilityCheckMacro quickstep_types_Type quickstep_types_TypeID + quickstep_types_TypeSynthesizer quickstep_types_TypedValue quickstep_utility_CheckSnprintf quickstep_utility_Macros) @@ -87,9 +121,9 @@ target_link_libraries(quickstep_types_DatetimeIntervalType glog quickstep_types_IntervalLit quickstep_types_IntervalParser - quickstep_types_NullCoercibilityCheckMacro quickstep_types_Type quickstep_types_TypeID + quickstep_types_TypeSynthesizer quickstep_types_TypedValue quickstep_utility_CheckSnprintf quickstep_utility_Macros) @@ -98,35 +132,35 @@ target_link_libraries(quickstep_types_DatetimeLit target_link_libraries(quickstep_types_DatetimeType glog quickstep_types_DatetimeLit - quickstep_types_NullCoercibilityCheckMacro quickstep_types_Type quickstep_types_TypeID + quickstep_types_TypeSynthesizer quickstep_types_TypedValue quickstep_types_port_gmtime_r quickstep_types_port_timegm quickstep_utility_CheckSnprintf quickstep_utility_Macros) target_link_libraries(quickstep_types_DoubleType - quickstep_types_NullCoercibilityCheckMacro quickstep_types_NumericSuperType - quickstep_types_Type quickstep_types_TypeID quickstep_types_TypedValue - quickstep_utility_EqualsAnyConstant quickstep_utility_Macros) target_link_libraries(quickstep_types_FloatType - quickstep_types_NullCoercibilityCheckMacro quickstep_types_NumericSuperType + quickstep_types_TypeID + quickstep_types_TypedValue + quickstep_utility_Macros) +target_link_libraries(quickstep_types_GenericValue quickstep_types_Type quickstep_types_TypeID + quickstep_types_TypeRegistrar + quickstep_types_Type_proto quickstep_types_TypedValue - quickstep_utility_EqualsAnyConstant + quickstep_utility_HashPair quickstep_utility_Macros) target_link_libraries(quickstep_types_IntType glog - quickstep_types_NullCoercibilityCheckMacro quickstep_types_NumericSuperType - quickstep_types_Type quickstep_types_TypeID quickstep_types_TypedValue quickstep_utility_Macros) @@ -138,35 +172,99 @@ target_link_libraries(quickstep_types_IntervalParser quickstep_utility_Macros) target_link_libraries(quickstep_types_LongType glog - quickstep_types_NullCoercibilityCheckMacro quickstep_types_NumericSuperType - quickstep_types_Type quickstep_types_TypeID quickstep_types_TypedValue - quickstep_utility_EqualsAnyConstant quickstep_utility_Macros) -target_link_libraries(quickstep_types_NullCoercibilityCheckMacro +target_link_libraries(quickstep_types_MetaType + quickstep_types_MetaType-decl + quickstep_types_TypeFactory-decl + quickstep_types_TypeID + quickstep_types_TypedValue + quickstep_types_Type_proto) +target_link_libraries(quickstep_types_MetaType-decl quickstep_types_Type - quickstep_types_TypeID) + quickstep_types_TypeID + quickstep_types_TypeSynthesizer + quickstep_types_TypedValue + quickstep_utility_Macros) target_link_libraries(quickstep_types_NullType glog quickstep_types_Type quickstep_types_TypeID + quickstep_types_TypeSynthesizer quickstep_utility_Macros) target_link_libraries(quickstep_types_NumericSuperType quickstep_types_NullCoercibilityCheckMacro + quickstep_types_NumericTypeSafeCoercibility + quickstep_types_Type + quickstep_types_TypeID + quickstep_types_TypeRegistrar + quickstep_types_TypeSynthesizer + quickstep_types_TypedValue + quickstep_utility_Macros + quickstep_utility_meta_TMP) +target_link_libraries(quickstep_types_NumericTypeSafeCoercibility + quickstep_types_TypeRegistrar + quickstep_utility_meta_TMP) +target_link_libraries(quickstep_types_NumericTypeUnifier + quickstep_types_NumericTypeSafeCoercibility) +target_link_libraries(quickstep_types_TextType quickstep_types_Type quickstep_types_TypeID + quickstep_types_TypeSynthesizer quickstep_types_TypedValue quickstep_utility_Macros) target_link_libraries(quickstep_types_Type glog quickstep_types_Type_proto quickstep_types_TypeID + quickstep_types_TypeRegistrar quickstep_types_TypedValue quickstep_utility_Macros) target_link_libraries(quickstep_types_TypeFactory + quickstep_types_GenericValue + quickstep_types_MetaType + quickstep_types_Type + quickstep_types_TypeFactory-decl + quickstep_types_TypeID + quickstep_types_TypeSynthesizer + quickstep_types_TypeUtil + quickstep_types_Type_proto + quickstep_utility_Macros + quickstep_utility_StringUtil) +target_link_libraries(quickstep_types_TypeFactory-decl glog + quickstep_types_GenericValue + quickstep_types_TypeID + quickstep_utility_Macros) +target_link_libraries(quickstep_types_TypeID + quickstep_types_Type_proto + quickstep_utility_Macros) +target_link_libraries(quickstep_types_TypeIDSelectors + quickstep_types_TypeID + quickstep_utility_meta_Common) +target_link_libraries(quickstep_types_TypeRegistrar + quickstep_types_DatetimeLit + quickstep_types_IntervalLit + quickstep_types_NullLit + quickstep_types_TypeID + quickstep_types_TypeIDSelectors + quickstep_utility_meta_Common) +target_link_libraries(quickstep_types_TypeSynthesizer + quickstep_types_GenericValue + quickstep_types_Type + quickstep_types_TypeID + quickstep_types_TypeRegistrar + quickstep_types_TypedValue + quickstep_types_Type_proto + quickstep_types_operations_utility_CastUtil + quickstep_utility_HashPair + quickstep_utility_Macros + quickstep_utility_meta_Common) +target_link_libraries(quickstep_types_TypeUtil + quickstep_types_ArrayType + quickstep_types_BoolType quickstep_types_CharType quickstep_types_DateType quickstep_types_DatetimeIntervalType @@ -175,10 +273,12 @@ target_link_libraries(quickstep_types_TypeFactory quickstep_types_FloatType quickstep_types_IntType quickstep_types_LongType + quickstep_types_MetaType-decl quickstep_types_NullType + quickstep_types_TextType quickstep_types_Type quickstep_types_TypeID - quickstep_types_Type_proto + quickstep_types_TypeRegistrar quickstep_types_VarCharType quickstep_types_YearMonthIntervalType quickstep_utility_Macros) @@ -200,6 +300,7 @@ target_link_libraries(quickstep_types_Type_proto ${PROTOBUF_LIBRARY}) target_link_libraries(quickstep_types_VarCharType glog + quickstep_types_AsciiStringSuperType quickstep_types_NullCoercibilityCheckMacro quickstep_types_Type quickstep_types_TypeID @@ -211,9 +312,9 @@ target_link_libraries(quickstep_types_VarCharType target_link_libraries(quickstep_types_YearMonthIntervalType quickstep_types_IntervalLit quickstep_types_IntervalParser - quickstep_types_NullCoercibilityCheckMacro quickstep_types_Type quickstep_types_TypeID + quickstep_types_TypeSynthesizer quickstep_types_TypedValue quickstep_utility_CheckSnprintf quickstep_utility_Macros) @@ -221,6 +322,9 @@ target_link_libraries(quickstep_types_YearMonthIntervalType # Module all-in-one library: add_library(quickstep_types ../empty_src.cpp TypesModule.hpp) target_link_libraries(quickstep_types + quickstep_types_ArrayType + quickstep_types_AsciiStringSuperType + quickstep_types_BoolType quickstep_types_CharType quickstep_types_DateOperatorOverloads quickstep_types_DateType @@ -229,19 +333,30 @@ target_link_libraries(quickstep_types quickstep_types_DatetimeType quickstep_types_DoubleType quickstep_types_FloatType + quickstep_types_GenericValue quickstep_types_IntType quickstep_types_IntervalLit quickstep_types_IntervalParser quickstep_types_LongType + quickstep_types_MetaType + quickstep_types_MetaType-decl quickstep_types_NullCoercibilityCheckMacro + quickstep_types_NullLit quickstep_types_NullType quickstep_types_NumericSuperType + quickstep_types_NumericTypeSafeCoercibility quickstep_types_NumericTypeUnifier + quickstep_types_TextType quickstep_types_Type + quickstep_types_TypeUtil quickstep_types_Type_proto quickstep_types_TypeErrors quickstep_types_TypeFactory + quickstep_types_TypeFactory-decl quickstep_types_TypeID + quickstep_types_TypeIDSelectors + quickstep_types_TypeRegistrar + quickstep_types_TypeSynthesizer quickstep_types_TypedValue quickstep_types_TypedValue_proto quickstep_types_VarCharType diff --git a/types/CharType.cpp b/types/CharType.cpp index 591c0387..319ae33a 100644 --- a/types/CharType.cpp +++ b/types/CharType.cpp @@ -19,6 +19,7 @@ #include "types/CharType.hpp" +#include #include #include #include @@ -33,47 +34,12 @@ #include "types/port/strnlen.hpp" #include "utility/PtrMap.hpp" -#include "glog/logging.h" +#include "third_party/src/farmhash/farmhash.h" -using std::pair; -using std::size_t; -using std::strcmp; -using std::string; +#include "glog/logging.h" namespace quickstep { -template -const CharType& CharType::InstanceInternal(const std::size_t length) { - static PtrMap instance_map; - PtrMap::iterator imit = instance_map.find(length); - if (imit == instance_map.end()) { - imit = instance_map.insert(length, new CharType(length, nullable_internal)).first; - } - return *(imit->second); -} - -const CharType& CharType::InstanceNonNullable(const std::size_t length) { - return InstanceInternal(length); -} - -const CharType& CharType::InstanceNullable(const std::size_t length) { - return InstanceInternal(length); -} - -const CharType& CharType::InstanceFromProto(const serialization::Type &proto) { - return Instance(proto.GetExtension(serialization::CharType::length), proto.nullable()); -} - -serialization::Type CharType::getProto() const { - serialization::Type proto; - proto.set_type_id(serialization::Type::CHAR); - - proto.set_nullable(nullable_); - - proto.SetExtension(serialization::CharType::length, length_); - return proto; -} - bool CharType::isSafelyCoercibleFrom(const Type &original_type) const { QUICKSTEP_NULL_COERCIBILITY_CHECK(); @@ -87,8 +53,8 @@ bool CharType::isSafelyCoercibleFrom(const Type &original_type) const { } } -string CharType::getName() const { - string name("Char("); +std::string CharType::getName() const { + std::string name("Char("); name.append(std::to_string(length_)); name.push_back(')'); if (nullable_) { @@ -97,17 +63,65 @@ string CharType::getName() const { return name; } -std::string CharType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); +std::size_t CharType::hashValue(const UntypedLiteral *value) const { + const char *cstr = static_cast(castValueToLiteral(value)); + const std::size_t len = strnlen(cstr, length_); + return util::Hash(cstr, len); +} + +bool CharType::checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const { + return std::strncmp(static_cast(castValueToLiteral(lhs)), + static_cast(castValueToLiteral(rhs)), + length_); +} + +UntypedLiteral* CharType::cloneValue(const UntypedLiteral *value) const { + DCHECK(value != nullptr); + + const char *cstr = static_cast(castValueToLiteral(value)); + const std::size_t len = strnlen(cstr, length_); + char *value_copy = static_cast(std::malloc(length_)); + std::memcpy(value_copy, cstr, len); + if (len < length_) { + value_copy[len] = 0; + } + return new cpptype(value_copy); +} + + +TypedValue CharType::marshallValue(const UntypedLiteral *value) const { + DCHECK(value != nullptr); + + const char *cstr = static_cast(castValueToLiteral(value)); + const std::size_t len = std::min(strnlen(cstr, length_) + 1, length_); + return TypedValue(kChar, cstr, len).ensureNotReference(); +} + +UntypedLiteral* CharType::unmarshallValue(const void *data, + const std::size_t length) const { + const char *cstr = static_cast(data); + const std::size_t len = std::min(strnlen(cstr, length), length_); + char *value = static_cast(std::malloc(length_)); + std::memcpy(value, cstr, len); + if (len < length_) { + value[len] = 0; + } + return new cpptype(value); +} + +std::string CharType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); - const char *cstr = static_cast(value.getOutOfLineData()); + const char *cstr = static_cast(castValueToLiteral(value)); return std::string(cstr, strnlen(cstr, length_)); } -void CharType::printValueToFile(const TypedValue &value, +void CharType::printValueToFile(const UntypedLiteral *value, FILE *file, const int padding) const { - DCHECK(!value.isNull()); + DCHECK(value != nullptr); DCHECK_EQ(length_, static_cast(static_cast(length_))) << "Can not convert CHAR Type's maximum length " << length_ << " to int for fprintf()"; @@ -116,11 +130,11 @@ void CharType::printValueToFile(const TypedValue &value, "%*.*s", padding, static_cast(length_), - static_cast(value.getOutOfLineData())); + castValueToLiteral(value)); } -bool CharType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool CharType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { if (value_string.length() > length_) { return false; } @@ -134,8 +148,8 @@ bool CharType::parseValueFromString(const std::string &value_string, return true; } -TypedValue CharType::coerceValue(const TypedValue &original_value, - const Type &original_type) const { +TypedValue CharType::coerceTypedValue(const TypedValue &original_value, + const Type &original_type) const { DCHECK(isCoercibleFrom(original_type)) << "Can't coerce value of Type " << original_type.getName() << " to Type " << getName(); diff --git a/types/CharType.hpp b/types/CharType.hpp index c7321f4c..cfd695ef 100644 --- a/types/CharType.hpp +++ b/types/CharType.hpp @@ -24,8 +24,8 @@ #include #include +#include "types/AsciiStringSuperType.hpp" #include "types/Type.hpp" -#include "types/Type.pb.h" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" #include "utility/Macros.hpp" @@ -43,75 +43,8 @@ namespace quickstep { * represented WITHOUT a null-terminator character. Any strings shorter * than the maximum length will have a null-terminator. **/ -class CharType : public AsciiStringSuperType { +class CharType final : public AsciiStringSuperType { public: - /** - * @brief Get a reference to the non-nullable singleton instance of this Type - * for the specified length. - * - * @param length The length parameter of the CharType. - * @return A reference to the non-nullable singleton instance of this Type - * for the specified length. - **/ - static const CharType& InstanceNonNullable(const std::size_t length); - - /** - * @brief Get a reference to the nullable singleton instance of this Type for - * the specified length. - * - * @param length The length parameter of the CharType. - * @return A reference to the nullable singleton instance of this Type for - * the specified length. - **/ - static const CharType& InstanceNullable(const std::size_t length); - - /** - * @brief Get a reference to the singleton instance of this Type for the - * specified length and nullability. - * - * @param length The length parameter of the CharType. - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the singleton instance of this Type for the - * specified length. - **/ - static const CharType& Instance(const std::size_t length, const bool nullable) { - if (nullable) { - return InstanceNullable(length); - } else { - return InstanceNonNullable(length); - } - } - - /** - * @brief Get a reference to the singleton instance of this Type described - * by the given Protocol Buffer serialization. - * - * @param proto The serialized Protocol Buffer representation of the desired - * CharType. - * @return A reference to the singleton instance of this Type for the given - * Protocol Buffer. - **/ - static const CharType& InstanceFromProto(const serialization::Type &proto); - - /** - * @brief Generate a serialized Protocol Buffer representation of this Type. - * - * @return The serialized Protocol Buffer representation of this Type. - **/ - serialization::Type getProto() const override; - - const Type& getNullableVersion() const override { - return InstanceNullable(length_); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(length_); - } - - std::size_t estimateAverageByteLength() const override { - return length_; - } - bool isSafelyCoercibleFrom(const Type &original_type) const override; std::string getName() const override; @@ -120,27 +53,36 @@ class CharType : public AsciiStringSuperType { return length_; } - std::string printValueToString(const TypedValue &value) const override; + std::size_t hashValue(const UntypedLiteral *value) const override; + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override; + + UntypedLiteral* cloneValue(const UntypedLiteral *value) const override; + + TypedValue marshallValue(const UntypedLiteral *value) const override; - void printValueToFile(const TypedValue &value, + UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const override; + + std::string printValueToString(const UntypedLiteral *value) const override; + + void printValueToFile(const UntypedLiteral *value, FILE *file, const int padding = 0) const override; - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; - TypedValue coerceValue(const TypedValue &original_value, - const Type &original_type) const override; + TypedValue coerceTypedValue(const TypedValue &original_value, + const Type &original_type) const override; private: - CharType(const std::size_t length, const bool nullable) - : AsciiStringSuperType(kChar, nullable, length, length, length) { - } - - template - static const CharType& InstanceInternal(const std::size_t length); + CharType(const bool nullable, const std::size_t length) + : AsciiStringSuperType(nullable, length, length, length) {} - DISALLOW_COPY_AND_ASSIGN(CharType); + QUICKSTEP_SYNTHESIZE_TYPE(CharType); }; /** @} */ diff --git a/types/DateType.cpp b/types/DateType.cpp index 5bb982cf..a88b5bd6 100644 --- a/types/DateType.cpp +++ b/types/DateType.cpp @@ -30,7 +30,6 @@ #include #include "types/DatetimeLit.hpp" -#include "types/NullCoercibilityCheckMacro.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" @@ -46,20 +45,10 @@ using std::snprintf; namespace quickstep { -bool DateType::isCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kDate); -} - -bool DateType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kDate); -} +std::string DateType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); -std::string DateType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); - - const DateLit literal = value.getLiteral(); + const DateLit &literal = castValueToLiteral(value); const std::int32_t year = literal.year; char datebuf[DateLit::kIsoChars + 1]; @@ -86,16 +75,8 @@ std::string DateType::printValueToString(const TypedValue &value) const { return std::string(datebuf); } -void DateType::printValueToFile(const TypedValue &value, - FILE *file, - const int padding) const { - // We simply re-use the logic from printValueToString(), as trying to do - // padding on-the fly with so many different fields is too much of a hassle. - std::fprintf(file, "%*s", padding, printValueToString(value).c_str()); -} - -bool DateType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool DateType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { std::int32_t year; std::uint32_t month, day; diff --git a/types/DateType.hpp b/types/DateType.hpp index 07225d55..b88bb823 100644 --- a/types/DateType.hpp +++ b/types/DateType.hpp @@ -27,6 +27,7 @@ #include "types/DatetimeLit.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" #include "utility/Macros.hpp" namespace quickstep { @@ -40,72 +41,13 @@ class TypedValue; /** * @brief A type representing the date. **/ -class DateType : public Type { +class DateType final : public TypeSynthesizer { public: - typedef DateLit cpptype; - - static const TypeID kStaticTypeID = kDate; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type. - **/ - static const DateType& InstanceNonNullable() { - static DateType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const DateType& InstanceNullable() { - static DateType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type. - * - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the desired singleton instance of this Type. - **/ - static const DateType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - std::size_t estimateAverageByteLength() const override { - return sizeof(DateLit); - } - - bool isCoercibleFrom(const Type &original_type) const override; - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - int getPrintWidth() const override { return DateLit::kIsoChars; } - std::string printValueToString(const TypedValue &value) const override; - - void printValueToFile(const TypedValue &value, - FILE *file, - const int padding = 0) const override; + std::string printValueToString(const UntypedLiteral *value) const override; /** * @note value_string is expected to be in (possibly extended) ISO-8601 @@ -119,15 +61,14 @@ class DateType : public Type { * fail if there are any "extra" characters at the end of the string * after a parsable ISO-8601 date. **/ - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: explicit DateType(const bool nullable) - : Type(Type::kOther, kDate, nullable, sizeof(DateLit), sizeof(DateLit)) { - } + : TypeSynthesizer(nullable) {} - DISALLOW_COPY_AND_ASSIGN(DateType); + QUICKSTEP_SYNTHESIZE_TYPE(DateType); }; /** @} */ diff --git a/types/DatetimeIntervalType.cpp b/types/DatetimeIntervalType.cpp index 1eae03a6..a4b2896c 100644 --- a/types/DatetimeIntervalType.cpp +++ b/types/DatetimeIntervalType.cpp @@ -31,7 +31,6 @@ #include "types/IntervalLit.hpp" #include "types/IntervalParser.hpp" -#include "types/NullCoercibilityCheckMacro.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" @@ -47,20 +46,10 @@ using std::snprintf; namespace quickstep { -bool DatetimeIntervalType::isCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kDatetimeInterval); -} - -bool DatetimeIntervalType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kDatetimeInterval); -} +std::string DatetimeIntervalType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); -std::string DatetimeIntervalType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); - - std::int64_t subseconds = value.getLiteral().interval_ticks; + std::int64_t subseconds = castValueToLiteral(value).interval_ticks; const bool negative_interval = subseconds < 0; if (negative_interval) { subseconds = -subseconds; @@ -121,16 +110,8 @@ std::string DatetimeIntervalType::printValueToString(const TypedValue &value) co return std::string(interval_buf); } -void DatetimeIntervalType::printValueToFile(const TypedValue &value, - FILE *file, - const int padding) const { - // We simply re-use the logic from printValueToString(), as trying to do - // padding on-the fly with so many different fields is too much of a hassle. - std::fprintf(file, "%*s", padding, printValueToString(value).c_str()); -} - -bool DatetimeIntervalType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool DatetimeIntervalType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { // Try simple-format parse first. std::int64_t count; std::string units; diff --git a/types/DatetimeIntervalType.hpp b/types/DatetimeIntervalType.hpp index 005cb31f..b80b2a7b 100644 --- a/types/DatetimeIntervalType.hpp +++ b/types/DatetimeIntervalType.hpp @@ -28,6 +28,7 @@ #include "types/IntervalLit.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" #include "types/TypedValue.hpp" #include "utility/Macros.hpp" @@ -40,86 +41,26 @@ namespace quickstep { /** * @brief A type representing the datetime interval. **/ -class DatetimeIntervalType : public Type { +class DatetimeIntervalType final : public TypeSynthesizer { public: - typedef DatetimeIntervalLit cpptype; - - static const TypeID kStaticTypeID = kDatetimeInterval; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type. - **/ - static const DatetimeIntervalType& InstanceNonNullable() { - static DatetimeIntervalType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const DatetimeIntervalType& InstanceNullable() { - static DatetimeIntervalType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type. - * - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the desired singleton instance of this Type. - **/ - static const DatetimeIntervalType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - std::size_t estimateAverageByteLength() const override { - return sizeof(DatetimeIntervalLit); - } - - bool isCoercibleFrom(const Type &original_type) const override; - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - int getPrintWidth() const override { return DatetimeIntervalLit::kPrintingChars; } - std::string printValueToString(const TypedValue &value) const override; - - void printValueToFile(const TypedValue &value, - FILE *file, - const int padding = 0) const override; + std::string printValueToString(const UntypedLiteral *value) const override; TypedValue makeZeroValue() const override { return TypedValue(DatetimeIntervalLit{0}); } - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: explicit DatetimeIntervalType(const bool nullable) - : Type(Type::kOther, kDatetimeInterval, nullable, sizeof(DatetimeIntervalLit), sizeof(DatetimeIntervalLit)) { - } + : TypeSynthesizer(nullable) {} - DISALLOW_COPY_AND_ASSIGN(DatetimeIntervalType); + QUICKSTEP_SYNTHESIZE_TYPE(DatetimeIntervalType); }; /** @} */ diff --git a/types/DatetimeLit.hpp b/types/DatetimeLit.hpp index 58c852f0..db887eb3 100644 --- a/types/DatetimeLit.hpp +++ b/types/DatetimeLit.hpp @@ -99,6 +99,10 @@ struct DateLit { inline std::int32_t monthField() const { return static_cast(month); } + + inline std::int32_t dayField() const { + return static_cast(day); + } }; /** diff --git a/types/DatetimeType.cpp b/types/DatetimeType.cpp index f54f318a..6d5fc2d1 100644 --- a/types/DatetimeType.cpp +++ b/types/DatetimeType.cpp @@ -33,7 +33,6 @@ #include #include "types/DatetimeLit.hpp" -#include "types/NullCoercibilityCheckMacro.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" @@ -51,20 +50,10 @@ using std::snprintf; namespace quickstep { -bool DatetimeType::isCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kDatetime); -} - -bool DatetimeType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kDatetime); -} +std::string DatetimeType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); -std::string DatetimeType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); - - const DatetimeLit literal = value.getLiteral(); + const DatetimeLit &literal = castValueToLiteral(value); const std::time_t timestamp = literal.epochTime(); struct tm timeinfo; quickstep::gmtime_r(×tamp, &timeinfo); @@ -114,16 +103,8 @@ std::string DatetimeType::printValueToString(const TypedValue &value) const { return std::string(datebuf); } -void DatetimeType::printValueToFile(const TypedValue &value, - FILE *file, - const int padding) const { - // We simply re-use the logic from printValueToString(), as trying to do - // padding on-the fly with so many different fields is too much of a hassle. - std::fprintf(file, "%*s", padding, printValueToString(value).c_str()); -} - -bool DatetimeType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool DatetimeType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { int year; int month; int day; diff --git a/types/DatetimeType.hpp b/types/DatetimeType.hpp index aad536af..dbad0e25 100644 --- a/types/DatetimeType.hpp +++ b/types/DatetimeType.hpp @@ -27,6 +27,7 @@ #include "types/DatetimeLit.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" #include "utility/Macros.hpp" namespace quickstep { @@ -40,72 +41,13 @@ class TypedValue; /** * @brief A type representing the datetime. **/ -class DatetimeType : public Type { +class DatetimeType final : public TypeSynthesizer { public: - typedef DatetimeLit cpptype; - - static const TypeID kStaticTypeID = kDatetime; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type. - **/ - static const DatetimeType& InstanceNonNullable() { - static DatetimeType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const DatetimeType& InstanceNullable() { - static DatetimeType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type. - * - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the desired singleton instance of this Type. - **/ - static const DatetimeType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - std::size_t estimateAverageByteLength() const override { - return sizeof(DatetimeLit); - } - - bool isCoercibleFrom(const Type &original_type) const override; - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - int getPrintWidth() const override { return DatetimeLit::kIsoChars; } - std::string printValueToString(const TypedValue &value) const override; - - void printValueToFile(const TypedValue &value, - FILE *file, - const int padding = 0) const override; + std::string printValueToString(const UntypedLiteral *value) const override; /** * @note value_string is expected to be in (possibly extended) ISO-8601 @@ -127,15 +69,14 @@ class DatetimeType : public Type { * fail if there are any "extra" characters at the end of the string * after a parsable ISO-8601 date/time. **/ - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: explicit DatetimeType(const bool nullable) - : Type(Type::kOther, kDatetime, nullable, sizeof(DatetimeLit), sizeof(DatetimeLit)) { - } + : TypeSynthesizer(nullable) {} - DISALLOW_COPY_AND_ASSIGN(DatetimeType); + QUICKSTEP_SYNTHESIZE_TYPE(DatetimeType); }; /** @} */ diff --git a/types/DoubleType.cpp b/types/DoubleType.cpp index 6a7914c7..82199556 100644 --- a/types/DoubleType.cpp +++ b/types/DoubleType.cpp @@ -25,11 +25,8 @@ #include #include -#include "types/NullCoercibilityCheckMacro.hpp" -#include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" -#include "utility/EqualsAnyConstant.hpp" #include "glog/logging.h" @@ -41,48 +38,15 @@ using std::snprintf; namespace quickstep { -const TypeID DoubleType::kStaticTypeID = kDouble; - -bool DoubleType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return QUICKSTEP_EQUALS_ANY_CONSTANT(original_type.getTypeID(), - kInt, kLong, kFloat, kDouble); -} - -TypedValue DoubleType::coerceValue(const TypedValue &original_value, - const Type &original_type) const { - DCHECK(isCoercibleFrom(original_type)) - << "Can't coerce value of Type " << original_type.getName() - << " to Type " << getName(); - - if (original_value.isNull()) { - return makeNullValue(); - } - - switch (original_type.getTypeID()) { - case kInt: - return TypedValue(static_cast(original_value.getLiteral())); - case kLong: - return TypedValue(static_cast(original_value.getLiteral())); - case kFloat: - return TypedValue(static_cast(original_value.getLiteral())); - case kDouble: - return original_value; - default: - LOG(FATAL) << "Attempted to coerce Type " << original_type.getName() - << " (not recognized as a numeric Type) to " << getName(); - } -} - -std::string DoubleType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); +std::string DoubleType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); char printbuffer[kPrintWidth + 1]; int written = snprintf(printbuffer, sizeof(printbuffer), "%.*g", std::numeric_limits::max_digits10, - value.getLiteral()); + castValueToLiteral(value)); DCHECK_GE(written, 0) << "snprintf() encountered an encoding error"; DCHECK_LT(static_cast(written), sizeof(printbuffer)) << "snprintf() would have written a string of length " << written @@ -90,20 +54,20 @@ std::string DoubleType::printValueToString(const TypedValue &value) const { return std::string(printbuffer); } -void DoubleType::printValueToFile(const TypedValue &value, +void DoubleType::printValueToFile(const UntypedLiteral *value, FILE *file, const int padding) const { - DCHECK(!value.isNull()); + DCHECK(value != nullptr); std::fprintf(file, "%*.*g", padding, std::numeric_limits::max_digits10, - value.getLiteral()); + castValueToLiteral(value)); } -bool DoubleType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool DoubleType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { double parsed_double; int read_chars; int matched = std::sscanf(value_string.c_str(), diff --git a/types/DoubleType.hpp b/types/DoubleType.hpp index b4175b00..3e906dbe 100644 --- a/types/DoubleType.hpp +++ b/types/DoubleType.hpp @@ -26,12 +26,12 @@ #include "types/NumericSuperType.hpp" #include "types/TypeID.hpp" -#include "types/TypedValue.hpp" #include "utility/Macros.hpp" namespace quickstep { class Type; +class TypedValue; /** \addtogroup Types * @{ @@ -40,70 +40,20 @@ class Type; /** * @brief A type representing a double-precision floating-point number. **/ -class DoubleType : public NumericSuperType { +class DoubleType final : public NumericSuperType { public: - static const TypeID kStaticTypeID; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type. - **/ - static const DoubleType& InstanceNonNullable() { - static DoubleType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const DoubleType& InstanceNullable() { - static DoubleType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type. - * - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the desired singleton instance of this Type. - **/ - static const DoubleType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - int getPrintWidth() const override { return kPrintWidth; } - std::string printValueToString(const TypedValue &value) const override; + std::string printValueToString(const UntypedLiteral *value) const override; - void printValueToFile(const TypedValue &value, + void printValueToFile(const UntypedLiteral *value, FILE *file, const int padding = 0) const override; - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; - - TypedValue coerceValue(const TypedValue &original_value, - const Type &original_type) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: static_assert((std::numeric_limits::max_exponent10 < 1000) @@ -122,10 +72,9 @@ class DoubleType : public NumericSuperType { // exponent never takes more than 3 base-10 digits to represent. explicit DoubleType(const bool nullable) - : NumericSuperType(kDouble, nullable) { - } + : NumericSuperType(nullable) {} - DISALLOW_COPY_AND_ASSIGN(DoubleType); + QUICKSTEP_SYNTHESIZE_TYPE(DoubleType); }; /** @} */ diff --git a/types/FloatType.cpp b/types/FloatType.cpp index e904f291..5fcefc97 100644 --- a/types/FloatType.cpp +++ b/types/FloatType.cpp @@ -25,11 +25,8 @@ #include #include -#include "types/NullCoercibilityCheckMacro.hpp" -#include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" -#include "utility/EqualsAnyConstant.hpp" #include "glog/logging.h" @@ -41,48 +38,15 @@ using std::snprintf; namespace quickstep { -const TypeID FloatType::kStaticTypeID = kFloat; - -bool FloatType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return QUICKSTEP_EQUALS_ANY_CONSTANT(original_type.getTypeID(), - kInt, kFloat); -} - -TypedValue FloatType::coerceValue(const TypedValue &original_value, - const Type &original_type) const { - DCHECK(isCoercibleFrom(original_type)) - << "Can't coerce value of Type " << original_type.getName() - << " to Type " << getName(); - - if (original_value.isNull()) { - return makeNullValue(); - } - - switch (original_type.getTypeID()) { - case kInt: - return TypedValue(static_cast(original_value.getLiteral())); - case kLong: - return TypedValue(static_cast(original_value.getLiteral())); - case kFloat: - return original_value; - case kDouble: - return TypedValue(static_cast(original_value.getLiteral())); - default: - LOG(FATAL) << "Attempted to coerce Type " << original_type.getName() - << " (not recognized as a numeric Type) to " << getName(); - } -} - -std::string FloatType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); +std::string FloatType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); char printbuffer[kPrintWidth + 1]; int written = snprintf(printbuffer, sizeof(printbuffer), "%.*g", std::numeric_limits::max_digits10, - value.getLiteral()); + castValueToLiteral(value)); DCHECK_GE(written, 0) << "snprintf() encountered an encoding error"; DCHECK_LT(static_cast(written), sizeof(printbuffer)) << "snprintf() would have written a string of length " << written @@ -90,20 +54,20 @@ std::string FloatType::printValueToString(const TypedValue &value) const { return std::string(printbuffer); } -void FloatType::printValueToFile(const TypedValue &value, +void FloatType::printValueToFile(const UntypedLiteral *value, FILE *file, const int padding) const { - DCHECK(!value.isNull()); + DCHECK(value != nullptr); std::fprintf(file, "%*.*g", static_cast(padding), std::numeric_limits::max_digits10, - value.getLiteral()); + castValueToLiteral(value)); } -bool FloatType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool FloatType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { float parsed_float; int read_chars; int matched = std::sscanf(value_string.c_str(), diff --git a/types/FloatType.hpp b/types/FloatType.hpp index 2a156e15..e9062e08 100644 --- a/types/FloatType.hpp +++ b/types/FloatType.hpp @@ -26,12 +26,12 @@ #include "types/NumericSuperType.hpp" #include "types/TypeID.hpp" -#include "types/TypedValue.hpp" #include "utility/Macros.hpp" namespace quickstep { class Type; +class TypedValue; /** \addtogroup Types * @{ @@ -40,70 +40,20 @@ class Type; /** * @brief A type representing a single-precision floating-point number. **/ -class FloatType : public NumericSuperType { +class FloatType final : public NumericSuperType { public: - static const TypeID kStaticTypeID; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type - **/ - static const FloatType& InstanceNonNullable() { - static FloatType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type - * - * @return A reference to the nullable singleton instance of this Type - **/ - static const FloatType& InstanceNullable() { - static FloatType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type - * - * @param nullable Whether to get the nullable version of this Type - * @return A reference to the desired singleton instance of this Type - **/ - static const FloatType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - int getPrintWidth() const override { return kPrintWidth; } - std::string printValueToString(const TypedValue &value) const override; + std::string printValueToString(const UntypedLiteral *value) const override; - void printValueToFile(const TypedValue &value, + void printValueToFile(const UntypedLiteral *value, FILE *file, const int padding = 0) const override; - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; - - TypedValue coerceValue(const TypedValue &original_value, - const Type &original_type) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: static_assert((std::numeric_limits::max_exponent10 < 100) @@ -122,10 +72,9 @@ class FloatType : public NumericSuperType { // never takes more than 2 base-10 digits to represent. explicit FloatType(const bool nullable) - : NumericSuperType(kFloat, nullable) { - } + : NumericSuperType(nullable) {} - DISALLOW_COPY_AND_ASSIGN(FloatType); + QUICKSTEP_SYNTHESIZE_TYPE(FloatType); }; /** @} */ diff --git a/types/GenericValue.cpp b/types/GenericValue.cpp new file mode 100644 index 00000000..e69de29b diff --git a/types/GenericValue.hpp b/types/GenericValue.hpp new file mode 100644 index 00000000..d289a1bf --- /dev/null +++ b/types/GenericValue.hpp @@ -0,0 +1,184 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_GENERIC_VALUE_HPP_ +#define QUICKSTEP_TYPES_GENERIC_VALUE_HPP_ + +#include +#include +#include +#include + +#include "types/Type.hpp" +#include "types/Type.pb.h" +#include "types/TypeID.hpp" +#include "types/TypeRegistrar.hpp" +#include "types/TypedValue.hpp" +#include "utility/HashPair.hpp" +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +class GenericValue { + public: + static GenericValue CreateNullValue(const Type &type) { + return GenericValue(type, nullptr, true); + } + + static GenericValue CreateWithOwnedData(const Type &type, + const UntypedLiteral *value) { + return GenericValue(type, value, true); + } + + static GenericValue CreateReference(const Type &type, + const UntypedLiteral *value) { + return GenericValue(type, value, false); + } + + static GenericValue CreateWithTypedValue(const Type &type, + const TypedValue &value) { + return GenericValue(type, type.unmarshallTypedValue(value), true); + } + + template + static GenericValue CreateWithLiteral(const TypeClass &type, + const typename TypeClass::cpptype &value) { + return GenericValue(type, type.cloneValue(&value), true); + } + + GenericValue(const GenericValue &other) + : type_(other.type_), + value_((other.owns_ && !other.isNull()) ? type_.cloneValue(other.value_) + : other.value_), + owns_(other.owns_) {} + + GenericValue(GenericValue &&other) + : type_(other.type_), + value_(other.value_), + owns_(other.owns_) { + other.owns_ = false; + } + + ~GenericValue() { + if (owns_ && !isNull()) { + type_.destroyValue(const_cast(value_)); + } + } + + serialization::GenericValue getProto() const { + serialization::GenericValue proto; + proto.mutable_type()->MergeFrom(type_.getProto()); + if (!isNull()) { + TypedValue tv = type_.marshallValue(value_); + proto.set_data(tv.getDataPtr(), tv.getDataSize()); + } + return proto; + } + + inline bool isNull() const { + DCHECK(value_ != nullptr || type_.isNullable()); + return value_ == nullptr; + } + + inline bool isReference() const { + return !owns_; + } + + inline const Type& getType() const { + return type_; + } + + inline TypeID getTypeID() const { + return type_.getTypeID(); + } + + inline const UntypedLiteral* getValue() const { + return value_; + } + + template + inline const typename TypeIDTrait::cpptype& getLiteral() const { + DCHECK_EQ(type_id, type_.getTypeID()); + return *static_cast::cpptype*>(value_); + } + + inline void ensureNotReference() { + if (isReference()) { + if (!isNull()) { + value_ = type_.cloneValue(value_); + } + owns_ = true; + } + } + + inline GenericValue makeReferenceToThis() const { + return GenericValue(type_, value_, false); + } + + inline bool equals(const GenericValue &other) const { + if (isNull() || other.isNull()) { + return isNull() && other.isNull(); + } + return type_.checkValuesEqual(value_, other.value_, other.type_); + } + + inline bool operator==(const GenericValue &other) const { + return equals(other); + } + + inline std::size_t getHash() const { + return isNull() ? 0 : type_.hashValue(value_); + } + + inline GenericValue coerce(const Type &other_type) const { + return GenericValue(other_type, + other_type.coerceValue(value_, type_), + true /* take_ownership */); + } + + inline TypedValue toTypedValue() const { + return isNull() ? type_.makeNullValue() : type_.marshallValue(value_); + } + + inline std::string toString() const { + return isNull() ? "NULL" : type_.printValueToString(value_); + } + + private: + GenericValue(const Type &type, + const UntypedLiteral *value, + const bool take_ownership) + : type_(type), value_(value), owns_(take_ownership) {} + + const Type &type_; + const UntypedLiteral *value_; + bool owns_; +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_GENERIC_VALUE_HPP_ diff --git a/types/IntType.cpp b/types/IntType.cpp index 97816759..07db1335 100644 --- a/types/IntType.cpp +++ b/types/IntType.cpp @@ -19,12 +19,9 @@ #include "types/IntType.hpp" -#include #include #include -#include "types/NullCoercibilityCheckMacro.hpp" -#include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" @@ -32,57 +29,25 @@ namespace quickstep { -const TypeID IntType::kStaticTypeID = kInt; +std::string IntType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); -bool IntType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return original_type.getTypeID() == kInt; + return std::to_string(castValueToLiteral(value)); } -TypedValue IntType::coerceValue(const TypedValue &original_value, - const Type &original_type) const { - DCHECK(isCoercibleFrom(original_type)) - << "Can't coerce value of Type " << original_type.getName() - << " to Type " << getName(); - - if (original_value.isNull()) { - return makeNullValue(); - } - - switch (original_type.getTypeID()) { - case kInt: - return original_value; - case kLong: - return TypedValue(static_cast(original_value.getLiteral())); - case kFloat: - return TypedValue(static_cast(original_value.getLiteral())); - case kDouble: - return TypedValue(static_cast(original_value.getLiteral())); - default: - LOG(FATAL) << "Attempted to coerce Type " << original_type.getName() - << " (not recognized as a numeric Type) to " << getName(); - } -} - -std::string IntType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); - - return std::to_string(value.getLiteral()); -} - -void IntType::printValueToFile(const TypedValue &value, +void IntType::printValueToFile(const UntypedLiteral *value, FILE *file, const int padding) const { - DCHECK(!value.isNull()); + DCHECK(value != nullptr); std::fprintf(file, "%*d", static_cast(padding), - value.getLiteral()); + castValueToLiteral(value)); } -bool IntType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool IntType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { int parsed_int; int read_chars; int matched = std::sscanf(value_string.c_str(), diff --git a/types/IntType.hpp b/types/IntType.hpp index 08d6b3d2..7b42906f 100644 --- a/types/IntType.hpp +++ b/types/IntType.hpp @@ -26,12 +26,12 @@ #include "types/NumericSuperType.hpp" #include "types/TypeID.hpp" -#include "types/TypedValue.hpp" #include "utility/Macros.hpp" namespace quickstep { class Type; +class TypedValue; /** \addtogroup Types * @{ @@ -40,79 +40,28 @@ class Type; /** * @brief A type representing a 32-bit integer. **/ -class IntType : public NumericSuperType { +class IntType final : public NumericSuperType { public: - static const TypeID kStaticTypeID; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type. - **/ - static const IntType& InstanceNonNullable() { - static IntType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const IntType& InstanceNullable() { - static IntType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type. - * - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the desired singleton instance of this Type. - **/ - static const IntType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - int getPrintWidth() const override { // Fully represented digits, single leading digit, and possible '-' // character. return std::numeric_limits::digits10 + 2; } - std::string printValueToString(const TypedValue &value) const override; + std::string printValueToString(const UntypedLiteral *value) const override; - void printValueToFile(const TypedValue &value, + void printValueToFile(const UntypedLiteral *value, FILE *file, const int padding = 0) const override; - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; - - TypedValue coerceValue(const TypedValue &original_value, - const Type &original_type) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: explicit IntType(const bool nullable) - : NumericSuperType(kInt, nullable) { - } + : NumericSuperType(nullable) {} - DISALLOW_COPY_AND_ASSIGN(IntType); + QUICKSTEP_SYNTHESIZE_TYPE(IntType); }; /** @} */ diff --git a/types/LongType.cpp b/types/LongType.cpp index fbf8d300..ffb9eb76 100644 --- a/types/LongType.cpp +++ b/types/LongType.cpp @@ -28,68 +28,32 @@ #include #include -#include "types/NullCoercibilityCheckMacro.hpp" -#include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" -#include "utility/EqualsAnyConstant.hpp" #include "glog/logging.h" namespace quickstep { -const TypeID LongType::kStaticTypeID = kLong; +std::string LongType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); -bool LongType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return QUICKSTEP_EQUALS_ANY_CONSTANT(original_type.getTypeID(), - kInt, kLong); + return std::to_string(castValueToLiteral(value)); } -TypedValue LongType::coerceValue(const TypedValue &original_value, - const Type &original_type) const { - DCHECK(isCoercibleFrom(original_type)) - << "Can't coerce value of Type " << original_type.getName() - << " to Type " << getName(); - - if (original_value.isNull()) { - return makeNullValue(); - } - - switch (original_type.getTypeID()) { - case kInt: - return TypedValue(static_cast(original_value.getLiteral())); - case kLong: - return original_value; - case kFloat: - return TypedValue(static_cast(original_value.getLiteral())); - case kDouble: - return TypedValue(static_cast(original_value.getLiteral())); - default: - LOG(FATAL) << "Attempted to coerce Type " << original_type.getName() - << " (not recognized as a numeric Type) to " << getName(); - } -} - -std::string LongType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); - - return std::to_string(value.getLiteral()); -} - -void LongType::printValueToFile(const TypedValue &value, +void LongType::printValueToFile(const UntypedLiteral *value, FILE *file, const int padding) const { - DCHECK(!value.isNull()); + DCHECK(value != nullptr); std::fprintf(file, "%*" PRId64, static_cast(padding), - value.getLiteral()); + castValueToLiteral(value)); } -bool LongType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool LongType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { std::int64_t parsed_long; int read_chars; int matched = std::sscanf(value_string.c_str(), diff --git a/types/LongType.hpp b/types/LongType.hpp index a90dd324..3cd3fc04 100644 --- a/types/LongType.hpp +++ b/types/LongType.hpp @@ -27,12 +27,12 @@ #include "types/NumericSuperType.hpp" #include "types/TypeID.hpp" -#include "types/TypedValue.hpp" #include "utility/Macros.hpp" namespace quickstep { class Type; +class TypedValue; /** \addtogroup Types * @{ @@ -41,79 +41,28 @@ class Type; /** * @brief A type representing a 64-bit integer. **/ -class LongType : public NumericSuperType { +class LongType final : public NumericSuperType { public: - static const TypeID kStaticTypeID; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type. - **/ - static const LongType& InstanceNonNullable() { - static LongType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const LongType& InstanceNullable() { - static LongType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type. - * - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the desired singleton instance of this Type. - **/ - static const LongType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - // Fully represented digits, single leading digit, and possible '-' // character. int getPrintWidth() const override { return std::numeric_limits::digits10 + 2; } - std::string printValueToString(const TypedValue &value) const override; + std::string printValueToString(const UntypedLiteral *value) const override; - void printValueToFile(const TypedValue &value, + void printValueToFile(const UntypedLiteral *value, FILE *file, const int padding = 0) const override; - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; - - TypedValue coerceValue(const TypedValue &original_value, - const Type &original_type) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: explicit LongType(const bool nullable) - : NumericSuperType(kLong, nullable) { - } + : NumericSuperType(nullable) {} - DISALLOW_COPY_AND_ASSIGN(LongType); + QUICKSTEP_SYNTHESIZE_TYPE(LongType); }; /** @} */ diff --git a/types/MetaType-decl.hpp b/types/MetaType-decl.hpp new file mode 100644 index 00000000..569c956e --- /dev/null +++ b/types/MetaType-decl.hpp @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_META_TYPE_DECL_HPP_ +#define QUICKSTEP_TYPES_META_TYPE_DECL_HPP_ + +#include +#include + +#include "types/Type.hpp" +#include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" +#include "types/TypedValue.hpp" +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +class MetaType final : public TypeSynthesizer { + public: + int getPrintWidth() const override { + return 16; + } + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override; + + TypedValue marshallValue(const UntypedLiteral *value) const override; + + UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const override; + + std::string printValueToString(const UntypedLiteral *value) const override; + + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override { + return false; + } + + private: + MetaType(const bool nullable) + : TypeSynthesizer(nullable, sizeof(TypeID), 0x100) { + // TODO(refactor-type): Possibly infinite maximum size. + } + + QUICKSTEP_SYNTHESIZE_TYPE(MetaType); +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_META_TYPE_DECL_HPP_ diff --git a/types/MetaType.cpp b/types/MetaType.cpp new file mode 100644 index 00000000..f3da71b1 --- /dev/null +++ b/types/MetaType.cpp @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#include "types/MetaType.hpp" + +#include +#include + +#include "types/Type.pb.h" +#include "types/TypeFactory-decl.hpp" +#include "types/TypeID.hpp" +#include "types/TypedValue.hpp" + +namespace quickstep { + +bool MetaType::checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const { + if (!equals(rhs_type)) { + return false; + } + return castValueToLiteral(lhs)->equals(*castValueToLiteral(rhs)); +} + +TypedValue MetaType::marshallValue(const UntypedLiteral *value) const { + const Type *type = castValueToLiteral(value); + serialization::Type proto = type->getProto(); + const std::size_t data_size = proto.ByteSize(); + void *data = std::malloc(data_size); + proto.SerializeToArray(data, data_size); + return TypedValue::CreateWithOwnedData(kMetaType, data, data_size); +} + +UntypedLiteral* MetaType::unmarshallValue(const void *data, + const std::size_t data_size) const { + serialization::Type proto; + proto.ParseFromArray(data, data_size); + return new MetaTypeLit(&TypeFactory::ReconstructFromProto(proto)); +} + +std::string MetaType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); + + return castValueToLiteral(value)->getName(); +} + +} // namespace quickstep diff --git a/types/MetaType.hpp b/types/MetaType.hpp new file mode 100644 index 00000000..7ccf9f5b --- /dev/null +++ b/types/MetaType.hpp @@ -0,0 +1,25 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_META_TYPE_HPP_ +#define QUICKSTEP_TYPES_META_TYPE_HPP_ + +#include "types/MetaType-decl.hpp" + +#endif // QUICKSTEP_TYPES_META_TYPE_HPP_ diff --git a/types/NullCoercibilityCheckMacro.hpp b/types/NullCoercibilityCheckMacro.hpp index 70e1bebd..9cdd152f 100644 --- a/types/NullCoercibilityCheckMacro.hpp +++ b/types/NullCoercibilityCheckMacro.hpp @@ -20,9 +20,6 @@ #ifndef QUICKSTEP_TYPES_NULL_COERCIBILITY_CHECK_MACRO_HPP_ #define QUICKSTEP_TYPES_NULL_COERCIBILITY_CHECK_MACRO_HPP_ -#include "types/Type.hpp" -#include "types/TypeID.hpp" - /** \addtogroup Types * @{ */ @@ -34,7 +31,7 @@ **/ #define QUICKSTEP_NULL_COERCIBILITY_CHECK() \ do { \ - if (original_type.isNullable() && !nullable_) { \ + if (original_type.isNullable() && !this->nullable_) { \ return false; \ } else if (original_type.getTypeID() == kNullType) { \ return true; \ diff --git a/types/operations/unary_operations/UnaryOperationID.cpp b/types/NullLit.hpp similarity index 77% rename from types/operations/unary_operations/UnaryOperationID.cpp rename to types/NullLit.hpp index b47a848b..8713c726 100644 --- a/types/operations/unary_operations/UnaryOperationID.cpp +++ b/types/NullLit.hpp @@ -17,16 +17,22 @@ * under the License. **/ -#include "types/operations/unary_operations/UnaryOperationID.hpp" +#ifndef QUICKSTEP_TYPES_NULL_LIT_HPP_ +#define QUICKSTEP_TYPES_NULL_LIT_HPP_ namespace quickstep { -const char *kUnaryOperationNames[] = { - "Negate", "Cast", "DateExtract", "Substring" -}; +/** \addtogroup Types + * @{ + */ -const char *kUnaryOperationShortNames[] = { - "-", "Cast", "DateExtract", "Substring" -}; +/** + * @brief An empty struct representing the null value. + **/ +struct NullLit {}; + +/** @} */ } // namespace quickstep + +#endif // QUICKSTEP_TYPES_NULL_LIT_HPP_ diff --git a/types/NullType.hpp b/types/NullType.hpp index c27a5841..ae448ea8 100644 --- a/types/NullType.hpp +++ b/types/NullType.hpp @@ -17,8 +17,8 @@ * under the License. **/ -#ifndef QUICKSTEP_TYPES_NULLTYPE_HPP_ -#define QUICKSTEP_TYPES_NULLTYPE_HPP_ +#ifndef QUICKSTEP_TYPES_NULL_TYPE_HPP_ +#define QUICKSTEP_TYPES_NULL_TYPE_HPP_ #include #include @@ -26,6 +26,7 @@ #include "types/Type.hpp" #include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" #include "utility/Macros.hpp" #include "glog/logging.h" @@ -48,72 +49,54 @@ class TypedValue; * a particular operation may accept. It is also assumed that applying * any operation to an argument of NullType always yields NULL values. **/ -class NullType : public Type { +class NullType final : public TypeSynthesizer { public: - static const TypeID kStaticTypeID = kNullType; - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * @note Unlike other Types, there is no corresponding method to get a - * non-nullable version of NullType. NullType is ALWAYS nullable. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const NullType& InstanceNullable() { - static NullType instance; - return instance; + static const NullType& InstanceNonNullable() { + LOG(FATAL) << "Called NullType::InstanceNonNullable(), " + << "which is not allowed."; } - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - LOG(FATAL) << "Called NullType::getNonNullableVersion(), which is not allowed."; - } - - std::size_t estimateAverageByteLength() const override { - return 0; - } - - bool isCoercibleFrom(const Type &original_type) const override { - return original_type.getTypeID() == kNullType; - } - - bool isSafelyCoercibleFrom(const Type &original_type) const override { - return original_type.getTypeID() == kNullType; + static const NullType& Instance(const bool nullable) { + if (nullable) { + return InstanceNullable(); + } else { + LOG(FATAL) << "Called NullType::Instance(nullable = true), " + << "which is not allowed."; + } } int getPrintWidth() const override { return 0; } - std::string printValueToString(const TypedValue &value) const override { + std::string printValueToString(const UntypedLiteral *value) const override { LOG(FATAL) << "NullType is not printable"; } - void printValueToFile(const TypedValue &value, + void printValueToFile(const UntypedLiteral *value, FILE *file, const int padding = 0) const override { LOG(FATAL) << "NullType is not printable"; } - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override { + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override { return false; } private: // NOTE(chasseur): NullType requires 0 bytes of inherent storage. It does, // however, require a bit in NULL bitmaps. - NullType() : Type(Type::kOther, kNullType, true, 0, 0) { + NullType(const bool nullable) + : TypeSynthesizer(nullable) { + DCHECK(nullable); } - DISALLOW_COPY_AND_ASSIGN(NullType); + QUICKSTEP_SYNTHESIZE_TYPE(NullType); }; /** @} */ } // namespace quickstep -#endif // QUICKSTEP_TYPES_NULLTYPE_HPP_ +#endif // QUICKSTEP_TYPES_NULL_TYPE_HPP_ diff --git a/types/NumericSuperType.hpp b/types/NumericSuperType.hpp index 0cc1546c..6a6ad96f 100644 --- a/types/NumericSuperType.hpp +++ b/types/NumericSuperType.hpp @@ -21,12 +21,18 @@ #define QUICKSTEP_TYPES_NUMERIC_SUPER_TYPE_HPP_ #include +#include +#include #include "types/NullCoercibilityCheckMacro.hpp" +#include "types/NumericTypeSafeCoercibility.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" +#include "types/TypeRegistrar.hpp" +#include "types/TypeSynthesizer.hpp" #include "types/TypedValue.hpp" #include "utility/Macros.hpp" +#include "utility/meta/TMP.hpp" namespace quickstep { @@ -38,30 +44,67 @@ namespace quickstep { * @brief Templatized superclass for Numeric types. Contains code common to all * Numeric types. **/ -template -class NumericSuperType : public Type { +template +class NumericSuperType : public TypeSynthesizer { public: - typedef CppType cpptype; - - std::size_t estimateAverageByteLength() const override { - return sizeof(CppType); - } - - bool isCoercibleFrom(const Type &original_type) const override { + bool isSafelyCoercibleFrom(const Type &original_type) const override { QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getSuperTypeID() == kNumeric); + const auto it = safe_coerce_cache_.find(original_type.getTypeID()); + return it != safe_coerce_cache_.end(); } TypedValue makeZeroValue() const override { - return TypedValue(static_cast(0)); + return TypedValue(static_cast::cpptype>(0)); } - protected: - NumericSuperType(const TypeID type_id, const bool nullable) - : Type(Type::kNumeric, type_id, nullable, sizeof(CppType), sizeof(CppType)) { + TypedValue coerceTypedValue(const TypedValue &original_value, + const Type &original_type) const override { + if (original_type.getSuperTypeID() != SuperTypeID::kNumeric) { + LOG(FATAL) << "Attempted to coerce Type " << original_type.getName() + << " (not recognized as a numeric Type) to " << Type::getName(); + } + + if (original_value.isNull()) { + return Type::makeNullValue(); + } + + return InvokeOnTypeID( + original_type.getTypeID(), + [&](auto orig_tid) -> TypedValue { // NOLINT(build/c++11) + using OrigCppType = typename TypeIDTrait::cpptype; + using TargetCppType = typename TypeIDTrait::cpptype; + + return TypedValue( + static_cast(original_value.getLiteral())); + }); } + protected: + explicit NumericSuperType(const bool nullable) + : TypeSynthesizer(nullable), + safe_coerce_cache_(CreateSafeCoercibilityCache()) {} + private: + using TargetType = typename TypeIDTrait::TypeClass; + + template + struct SafeCoercibilityFilter { + static constexpr bool value = + NumericTypeSafeCoercibility< + typename TypeIDTrait::TypeClass, + TargetType>::value; + }; + + inline static auto CreateSafeCoercibilityCache() { + using SourceTypeIDs = TypeIDSequenceAll::template bind_to; + using ResultTypeIDs = SourceTypeIDs::template filter; + + return ResultTypeIDs::template as_sequence + ::template Instantiate>(); + }; + + const std::unordered_set safe_coerce_cache_; + DISALLOW_COPY_AND_ASSIGN(NumericSuperType); }; diff --git a/types/NumericTypeSafeCoercibility.hpp b/types/NumericTypeSafeCoercibility.hpp new file mode 100644 index 00000000..b8ff876c --- /dev/null +++ b/types/NumericTypeSafeCoercibility.hpp @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_NUMERIC_TYPE_SAFE_COERCIBILITY_HPP_ +#define QUICKSTEP_TYPES_NUMERIC_TYPE_SAFE_COERCIBILITY_HPP_ + +#include "utility/meta/TMP.hpp" +#include "types/TypeRegistrar.hpp" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +template +using IsSafelyCoercible = meta::TypeList; + +using NumericTypeSafeCoersionPartialOrder = meta::TypeList< + IsSafelyCoercible, + IsSafelyCoercible, + IsSafelyCoercible, + IsSafelyCoercible, + IsSafelyCoercible +>; + +using NumericTypeSafeCoersionClosure = + meta::TransitiveClosure; + +template +struct NumericTypeSafeCoercibility { + static constexpr bool value = + NumericTypeSafeCoersionClosure::contains< + IsSafelyCoercible>::value; +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_NUMERIC_TYPE_SAFE_COERCIBILITY_HPP_ diff --git a/types/NumericTypeUnifier.hpp b/types/NumericTypeUnifier.hpp index 168dfb11..0c3f13f7 100644 --- a/types/NumericTypeUnifier.hpp +++ b/types/NumericTypeUnifier.hpp @@ -20,16 +20,9 @@ #ifndef QUICKSTEP_TYPES_NUMERIC_TYPE_UNIFIER_HPP_ #define QUICKSTEP_TYPES_NUMERIC_TYPE_UNIFIER_HPP_ -namespace quickstep { - -class DoubleType; -class FloatType; -class IntType; -class LongType; +#include "types/NumericTypeSafeCoercibility.hpp" -/** \addtogroup Types - * @{ - */ +namespace quickstep { /** * @brief A traits template that resolves what the "unifying" Type of two @@ -51,92 +44,47 @@ class LongType; * @tparam RightType The second Quickstep numeric Type class to unify. **/ template -struct NumericTypeUnifier { -}; +struct NumericTypeUnifier; -/** @} */ -// Explicit template specializations for all combinations of builtin numeric -// types. -template<> -struct NumericTypeUnifier { - typedef IntType type; -}; +namespace internal { -template<> -struct NumericTypeUnifier { - typedef LongType type; -}; - -template<> -struct NumericTypeUnifier { - typedef FloatType type; -}; +template +struct NumericTypeUnifierHelper; -template<> -struct NumericTypeUnifier { - typedef DoubleType type; -}; - -template<> -struct NumericTypeUnifier { - typedef LongType type; -}; - -template<> -struct NumericTypeUnifier { - typedef LongType type; -}; - -template<> -struct NumericTypeUnifier { - typedef DoubleType type; -}; - -template<> -struct NumericTypeUnifier { - typedef DoubleType type; -}; - -template<> -struct NumericTypeUnifier { - typedef FloatType type; -}; - -template<> -struct NumericTypeUnifier { - typedef DoubleType type; +template +struct NumericTypeUnifierHelper< + LeftType, RightType, + std::enable_if_t::value>> { + typedef RightType type; }; -template<> -struct NumericTypeUnifier { - typedef FloatType type; +template +struct NumericTypeUnifierHelper< + LeftType, RightType, + std::enable_if_t::value && + NumericTypeSafeCoercibility::value>> { + typedef LeftType type; }; +// Explicit template specializations template<> -struct NumericTypeUnifier { +struct NumericTypeUnifierHelper { typedef DoubleType type; }; template<> -struct NumericTypeUnifier { +struct NumericTypeUnifierHelper { typedef DoubleType type; }; -template<> -struct NumericTypeUnifier { - typedef DoubleType type; -}; +} // namespace internal -template<> -struct NumericTypeUnifier { - typedef DoubleType type; -}; +template +struct NumericTypeUnifier + : internal::NumericTypeUnifierHelper {}; -template<> -struct NumericTypeUnifier { - typedef DoubleType type; -}; +/** @} */ } // namespace quickstep diff --git a/types/TextType.cpp b/types/TextType.cpp new file mode 100644 index 00000000..b806ea83 --- /dev/null +++ b/types/TextType.cpp @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#include "types/TextType.hpp" + +#include +#include + +#include "types/Type.hpp" +#include "types/TypeID.hpp" +#include "utility/EqualsAnyConstant.hpp" + +namespace quickstep { + +bool TextType::isSafelyCoercibleFrom(const Type &original_type) const { + return QUICKSTEP_EQUALS_ANY_CONSTANT(original_type.getTypeID(), + kChar, kVarChar, kText); +} + +bool TextType::checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const { + if (!equals(rhs_type)) { + return false; + } + return castValueToLiteral(lhs) == castValueToLiteral(rhs); +} + +TypedValue TextType::marshallValue(const UntypedLiteral *value) const { + const std::string &str = castValueToLiteral(value); + return TypedValue(kText, str.c_str(), str.length()).ensureNotReference(); +} + +UntypedLiteral* TextType::unmarshallValue(const void *data, + const std::size_t length) const { + return new std::string(static_cast(data), length); +} + +std::string TextType::printValueToString(const UntypedLiteral *value) const { + return castValueToLiteral(value); +} + +} // namespace quickstep diff --git a/types/TextType.hpp b/types/TextType.hpp new file mode 100644 index 00000000..620420eb --- /dev/null +++ b/types/TextType.hpp @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_TEXT_TYPE_HPP_ +#define QUICKSTEP_TYPES_TEXT_TYPE_HPP_ + +#include +#include +#include + +#include "types/Type.hpp" +#include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" +#include "types/TypedValue.hpp" +#include "utility/Macros.hpp" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +class TextType final : public TypeSynthesizer { + public: + int getPrintWidth() const override { + return 32; + } + + bool isSafelyCoercibleFrom(const Type &original_type) const override; + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override; + + TypedValue marshallValue(const UntypedLiteral *value) const override; + + UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const override; + + std::string printValueToString(const UntypedLiteral *value) const override; + + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override { + return false; + } + + private: + TextType(const bool nullable) + : TypeSynthesizer(nullable, 0, 0x1000) { + // TODO(refactor-type): Possibly infinite maximum size. + } + + QUICKSTEP_SYNTHESIZE_TYPE(TextType); +}; + + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_TEXT_TYPE_HPP_ diff --git a/types/Type.cpp b/types/Type.cpp index f3d3f1bc..cbfd8dda 100644 --- a/types/Type.cpp +++ b/types/Type.cpp @@ -28,47 +28,35 @@ namespace quickstep { -serialization::Type Type::getProto() const { - serialization::Type proto; - switch (type_id_) { - case kInt: - proto.set_type_id(serialization::Type::INT); - break; - case kLong: - proto.set_type_id(serialization::Type::LONG); - break; - case kFloat: - proto.set_type_id(serialization::Type::FLOAT); - break; - case kDouble: - proto.set_type_id(serialization::Type::DOUBLE); - break; - case kDate: - proto.set_type_id(serialization::Type::DATE); - break; - case kDatetime: - proto.set_type_id(serialization::Type::DATETIME); - break; - case kDatetimeInterval: - proto.set_type_id(serialization::Type::DATETIME_INTERVAL); - break; - case kYearMonthInterval: - proto.set_type_id(serialization::Type::YEAR_MONTH_INTERVAL); - break; - case kNullType: - proto.set_type_id(serialization::Type::NULL_TYPE); - break; - default: - FATAL_ERROR("Unrecognized TypeID in Type::getProto"); +bool Type::isSafelyCoercibleFrom(const Type &original_type) const { + if (original_type.isNullable() && !this->nullable_) { + return false; + } + if (original_type.getTypeID() == kNullType) { + return true; } + return (original_type.getTypeID() == type_id_); +} - proto.set_nullable(nullable_); +std::size_t Type::estimateAverageByteLength() const { + if (minimum_byte_length_ == maximum_byte_length_) { + return maximum_byte_length_; + } + if (maximum_byte_length_ > 160) { + return 80; + } else { + return (maximum_byte_length_ >> 1) + 1; + } +} - return proto; +void Type::printValueToFile(const UntypedLiteral *value, + FILE *file, + const int padding) const { + std::fprintf(file, "%*s", padding, printValueToString(value).c_str()); } -TypedValue Type::coerceValue(const TypedValue &original_value, - const Type &original_type) const { +TypedValue Type::coerceTypedValue(const TypedValue &original_value, + const Type &original_type) const { DCHECK(isCoercibleFrom(original_type)) << "Can't coerce value of Type " << original_type.getName() << " to Type " << getName(); @@ -85,12 +73,12 @@ TypedValue Type::coerceValue(const TypedValue &original_value, return original_value; } -bool AsciiStringSuperType::isCoercibleFrom(const Type &original_type) const { - if (original_type.isNullable() && !nullable_) { - return false; - } - return (original_type.getSuperTypeID() == kAsciiString) - || (original_type.getTypeID() == kNullType); +UntypedLiteral* Type::coerceValue(const UntypedLiteral *original_value, + const Type &original_type) const { + // TODO(refactor-type): Implement coerceValue based on CastFunctor. + TypedValue original_tv = original_type.marshallValue(original_value); + TypedValue target_tv = coerceTypedValue(original_tv, original_type); + return unmarshallTypedValue(target_tv); } } // namespace quickstep diff --git a/types/Type.hpp b/types/Type.hpp index 0e8c4e5c..0929bc76 100644 --- a/types/Type.hpp +++ b/types/Type.hpp @@ -24,10 +24,13 @@ #include #include #include +#include #include "types/Type.pb.h" #include "types/TypeID.hpp" +#include "types/TypeRegistrar.hpp" #include "types/TypedValue.hpp" +#include "utility/CharStream.hpp" #include "utility/Macros.hpp" #include "glog/logging.h" @@ -92,15 +95,6 @@ struct YearMonthIntervalLit; **/ class Type { public: - /** - * @brief Categories of intermediate supertypes. - **/ - enum SuperTypeID { - kNumeric = 0, // Fixed-length numeric types (Int, Long, Float, Double) - kAsciiString, // ASCII strings (Char, VarChar) - kOther // Others (Date, Datetime, DatetimeInterval, YearMonthInterval) - }; - /** * @brief Virtual destructor. **/ @@ -112,7 +106,7 @@ class Type { * * @return The serialized Protocol Buffer representation of this Type. **/ - virtual serialization::Type getProto() const; + virtual serialization::Type getProto() const = 0; /** * @brief Determine what supertype this type belongs to. @@ -132,6 +126,10 @@ class Type { return type_id_; } + inline MemoryLayout getMemoryLayout() const { + return memory_layout_; + } + /** * @brief Determine whether this Type allows NULL values. * @@ -141,32 +139,6 @@ class Type { return nullable_; } - /** - * @brief Get this Type's signature. - * - * @note The signature does not necessarily uniquely identify this Type. It - * merely provides some basic information for debugging that can be - * passed to TypedValue::isPlausibleInstanceOf(). - * - * @return This Type's signature. - **/ - inline TypeSignature getSignature() const { - TypeSignature sig; - sig.id = type_id_; - sig.nullable = nullable_; - switch (type_id_) { - case kChar: - sig.length = maximum_byte_length_; - break; - case kVarChar: - sig.length = maximum_byte_length_ - 1; - break; - default: - sig.length = 0; - } - return sig; - } - /** * @brief Get a nullable (but otherwise identical) version of this type. * @@ -227,7 +199,7 @@ class Type { * @return An estimate of the average number of bytes used by data items of * this type. **/ - virtual std::size_t estimateAverageByteLength() const = 0; + virtual std::size_t estimateAverageByteLength() const; /** * @brief Determine whether this Type is exactly the same as another. @@ -264,7 +236,7 @@ class Type { * @note It is NOT possible to coerce a nullable type to a non-nullable type, * even if coercion would otherwise be possible. * @note Integer types are safely coercible to other integer or - * floating-poin types of equal or greater length. + * floating-point types of equal or greater length. * @note Floating-point types are safely coercible to other floating-point * types of equal or greater precision. * @note ASCII string types are safely coercible to other ASCII string types @@ -277,7 +249,7 @@ class Type { * @param original_type The original Type for coercion to this Type. * @return true if coercion is supported, false otherwise. **/ - virtual bool isSafelyCoercibleFrom(const Type &original_type) const = 0; + virtual bool isSafelyCoercibleFrom(const Type &original_type) const; /** * @brief Determine whether data items of this type are always guaranteed to @@ -322,34 +294,19 @@ class Type { **/ virtual int getPrintWidth() const = 0; - /** - * @brief "Print" a value of this Type as a human-readable string. - * @warning It is an error to call this with a NULL value. This method prints - * non-NULL values only. - * - * @param value A value of this Type. - * @return The human-readable string representation of value. - **/ - virtual std::string printValueToString(const TypedValue &value) const = 0; - /** - * @brief Print the human-readable string representation of a value of this - * type to a FILE stream. - * @warning It is an error to call this with a NULL value. This method prints - * non-NULL values only. - * - * @param value A value of this Type. - * @param file An open FILE stream to print to. - * @param padding If nonzero, left-pad the printed value with spaces up to - * this length. If padding is less than the number of characters - * needed to print the value, then more than padding characters will - * be printed (see getPrintWidth() for information about how long a - * printed string may be). - **/ - virtual void printValueToFile(const TypedValue &value, + virtual std::string printValueToString(const UntypedLiteral *value) const = 0; + + virtual std::string printTypedValueToString(const TypedValue &value) const = 0; + + + virtual void printValueToFile(const UntypedLiteral *value, FILE *file, - const int padding = 0) const = 0; + const int padding = 0) const; + virtual void printTypedValueToFile(const TypedValue &value, + FILE *file, + const int padding = 0) const = 0; /** * @brief Make a TypedValue of this Type. * @@ -426,8 +383,8 @@ class Type { * @return true if value_string was successfully parsed and value was * written. false if value_string was not in the correct format. **/ - virtual bool parseValueFromString(const std::string &value_string, - TypedValue *value) const = 0; + virtual bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const = 0; /** * @brief Coerce a value of another Type to this Type. @@ -445,17 +402,46 @@ class Type { * @return A new TypedValue that represents original_value as an instance of * this Type. **/ - virtual TypedValue coerceValue(const TypedValue &original_value, - const Type &original_type) const; + virtual TypedValue coerceTypedValue(const TypedValue &original_value, + const Type &original_type) const; + + virtual std::size_t getHash() const = 0; + + virtual bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const = 0; + + inline bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs) const { + return checkValuesEqual(lhs, rhs, *this); + } + + virtual UntypedLiteral* coerceValue(const UntypedLiteral *original_value, + const Type &original_type) const; + + virtual UntypedLiteral* cloneValue(const UntypedLiteral *value) const = 0; + + virtual void destroyValue(UntypedLiteral *value) const = 0; + + virtual std::size_t hashValue(const UntypedLiteral *value) const = 0; + + virtual TypedValue marshallValue(const UntypedLiteral *value) const = 0; + + virtual UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const = 0; + + virtual UntypedLiteral* unmarshallTypedValue(const TypedValue &value) const = 0; protected: Type(const SuperTypeID super_type_id, const TypeID type_id, + const MemoryLayout memory_layout, const bool nullable, const std::size_t minimum_byte_length, const std::size_t maximum_byte_length) : super_type_id_(super_type_id), type_id_(type_id), + memory_layout_(memory_layout), nullable_(nullable), minimum_byte_length_(minimum_byte_length), maximum_byte_length_(maximum_byte_length) { @@ -463,6 +449,7 @@ class Type { const SuperTypeID super_type_id_; const TypeID type_id_; + const MemoryLayout memory_layout_; const bool nullable_; const std::size_t minimum_byte_length_; const std::size_t maximum_byte_length_; @@ -471,38 +458,6 @@ class Type { DISALLOW_COPY_AND_ASSIGN(Type); }; -/** - * @brief A superclass for ASCII string types. - **/ -class AsciiStringSuperType : public Type { - public: - bool isCoercibleFrom(const Type &original_type) const override; - - /** - * @brief Get the character-length of this string type. - * - * @return The maximum length of a string of this type. - **/ - inline std::size_t getStringLength() const { - return length_; - } - - protected: - AsciiStringSuperType(const TypeID type_id, - const bool nullable, - const std::size_t minimum_byte_length, - const std::size_t maximum_byte_length, - const std::size_t string_length) - : Type(Type::kAsciiString, type_id, nullable, minimum_byte_length, maximum_byte_length), - length_(string_length) { - } - - const std::size_t length_; - - private: - DISALLOW_COPY_AND_ASSIGN(AsciiStringSuperType); -}; - /** @} */ } // namespace quickstep diff --git a/types/Type.proto b/types/Type.proto index d03b5a40..5882b8cf 100644 --- a/types/Type.proto +++ b/types/Type.proto @@ -19,39 +19,22 @@ syntax = "proto2"; package quickstep.serialization; -message Type { - enum TypeID { - INT = 0; - LONG = 1; - FLOAT = 2; - DOUBLE = 3; - CHAR = 4; - VAR_CHAR = 5; - DATETIME = 6; - DATETIME_INTERVAL = 7; - YEAR_MONTH_INTERVAL = 8; - NULL_TYPE = 9; - DATE = 10; - } +message TypeID { + required int32 id = 1; +} +message Type { required TypeID type_id = 1; required bool nullable = 2; - - // The convention for extension numbering is that extensions for a particular - // TypeID should begin from (type_id + 1) * 32. - extensions 32 to max; + optional uint64 length = 3; + repeated GenericValue parameters = 4; } -message CharType { - extend Type { - // Required when type_id == CHAR. - optional uint64 length = 160; - } +message GenericValue { + required Type type = 1; + optional bytes data = 2; } -message VarCharType { - extend Type { - // Required when type_id == VAR_CHAR. - optional uint64 length = 192; - } +message ArrayLit { + repeated bytes data = 1; } diff --git a/types/TypeFactory-decl.hpp b/types/TypeFactory-decl.hpp new file mode 100644 index 00000000..f67208e0 --- /dev/null +++ b/types/TypeFactory-decl.hpp @@ -0,0 +1,153 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_TYPE_FACTORY_DECL_HPP_ +#define QUICKSTEP_TYPES_TYPE_FACTORY_DECL_HPP_ + +#include +#include +#include +#include + +#include "types/GenericValue.hpp" +#include "types/TypeID.hpp" +#include "utility/Macros.hpp" + +namespace quickstep { + +class Type; + +namespace serialization { class Type; } + +/** \addtogroup Types + * @{ + */ + +/** + * @brief All-static factory object that provides access to Types, as well as + * methods for determining coercibility of Types. + **/ +class TypeFactory { + public: + static bool TypeNameIsValid(const std::string &type_name); + + static TypeID GetTypeIDForName(const std::string &type_name); + + /** + * @brief Determine if a length parameter is required when getting a Type of + * the specified TypeID. + * + * @param id The id of the desired Type. + * @return Whether a length must be specified for Types of the given id. + **/ + static bool TypeRequiresLengthParameter(const TypeID id); + + static bool TypeParametersAreValid(const TypeID id, + const std::vector ¶meters); + + /** + * @brief Factory method to get a Type by its TypeID. + * @note This version is for Types without a length parameter (currently + * IntType, LongType, FloatType, and DoubleType). It is an error to + * call this with a Type which requires a length parameter. + * + * @param id The id of the desired Type. + * @param nullable Whether to get the nullable version of the Type. + * @return The Type corresponding to id. + **/ + static const Type& GetType(const TypeID id, const bool nullable = false); + + /** + * @brief Factory method to get a Type by its TypeID and length. + * @note This version is for Types with a length parameter (currently + * CharType and VarCharType). It is an error to call this with a Type + * which does not require a length parameter. + * + * @param id The id of the desired Type. + * @param length The length parameter of the desired Type. + * @param nullable Whether to get the nullable version of the Type. + * @return The Type corresponding to id and length. + **/ + static const Type& GetType(const TypeID id, + const std::size_t length, + const bool nullable = false); + + static const Type& GetType(const TypeID id, + const std::vector ¶meters, + const bool nullable = false); + + /** + * @brief Get a reference to a Type from that Type's serialized Protocol Buffer + * representation. + * + * @param proto A serialized Protocol Buffer representation of a Type, + * originally generated by getProto(). + * @return The Type described by proto. + **/ + static const Type& ReconstructFromProto(const serialization::Type &proto); + + static GenericValue ReconstructValueFromProto(const serialization::GenericValue &proto); + + /** + * @brief Check whether a serialization::Type is fully-formed and + * all parts are valid. + * + * @param proto A serialized Protocol Buffer representation of a Type, + * originally generated by getProto(). + * @return Whether proto is fully-formed and valid. + **/ + static bool ProtoIsValid(const serialization::Type &proto); + + /** + * @brief Determine which of two types is most specific, i.e. which + * isSafelyCoercibleFrom() the other. + * + * @param first The first type to check. + * @param second The second type to check. + * @return The most precise type, or NULL if neither Type + * isSafelyCoercibleFrom() the other. + **/ + static const Type* GetMostSpecificType(const Type &first, const Type &second); + + /** + * @brief Determine a type, if any exists, which both arguments can be safely + * coerced to. It is possible that the resulting type may not be + * either argument. + * + * @param first The first type to check. + * @param second The second type to check. + * @return The unifying type, or NULL if none exists. + **/ + static const Type* GetUnifyingType(const Type &first, const Type &second); + + private: + // Undefined default constructor. Class is all-static and should not be + // instantiated. + TypeFactory(); + + static const std::unordered_map& GetTypeNameMap(); + + DISALLOW_COPY_AND_ASSIGN(TypeFactory); +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_TYPE_FACTORY_DECL_HPP_ diff --git a/types/TypeFactory.cpp b/types/TypeFactory.cpp index 7403dc9b..90294089 100644 --- a/types/TypeFactory.cpp +++ b/types/TypeFactory.cpp @@ -21,67 +21,87 @@ #include #include +#include +#include -#include "types/CharType.hpp" -#include "types/DateType.hpp" -#include "types/DatetimeIntervalType.hpp" -#include "types/DatetimeType.hpp" -#include "types/DoubleType.hpp" -#include "types/FloatType.hpp" -#include "types/IntType.hpp" -#include "types/LongType.hpp" -#include "types/NullType.hpp" +#include "types/GenericValue.hpp" #include "types/Type.hpp" #include "types/Type.pb.h" #include "types/TypeID.hpp" -#include "types/VarCharType.hpp" -#include "types/YearMonthIntervalType.hpp" +#include "types/TypeSynthesizer.hpp" +#include "types/TypeUtil.hpp" #include "utility/Macros.hpp" +#include "utility/StringUtil.hpp" #include "glog/logging.h" namespace quickstep { +bool TypeFactory::TypeNameIsValid(const std::string &type_name) { + const auto &type_name_map = GetTypeNameMap(); + return type_name_map.find(type_name) != type_name_map.end(); +} + +TypeID TypeFactory::GetTypeIDForName(const std::string &type_name) { + DCHECK(TypeNameIsValid(type_name)); + return GetTypeNameMap().at(type_name); +} + +bool TypeFactory::TypeRequiresLengthParameter(const TypeID id) { + return TypeUtil::IsParameterizedPod(id); +} + +bool TypeFactory::TypeParametersAreValid( + const TypeID id, const std::vector ¶meters) { + if (TypeUtil::GetMemoryLayout(id) != kCxxGeneric) { + return false; + } + + return InvokeOnTypeID>( + id, + [&](auto id) -> bool { // NOLINT(build/c++11) + using TypeClass = typename TypeIDTrait::TypeClass; + return TypeClass::TypeParametersAreValid(parameters); + }); +} + + const Type& TypeFactory::GetType(const TypeID id, const bool nullable) { - switch (id) { - case kInt: - return IntType::Instance(nullable); - case kLong: - return LongType::Instance(nullable); - case kFloat: - return FloatType::Instance(nullable); - case kDouble: - return DoubleType::Instance(nullable); - case kDate: - return DateType::Instance(nullable); - case kDatetime: - return DatetimeType::Instance(nullable); - case kDatetimeInterval: - return DatetimeIntervalType::Instance(nullable); - case kYearMonthInterval: - return YearMonthIntervalType::Instance(nullable); - case kNullType: - DCHECK(nullable); - return NullType::InstanceNullable(); - default: - FATAL_ERROR("Called TypeFactory::GetType() for a type which requires " - " a length parameter without specifying one."); - } + DCHECK(TypeUtil::GetMemoryLayout(id) == kCxxInlinePod) + << "Called TypeFactory::GetType() with incorrect parameters."; + + return *InvokeOnTypeID>( + id, + [&](auto id) -> const Type* { // NOLINT(build/c++11) + return &TypeIDTrait::TypeClass::Instance(nullable); + }); } const Type& TypeFactory::GetType(const TypeID id, const std::size_t length, const bool nullable) { - switch (id) { - case kChar: - return CharType::Instance(length, nullable); - case kVarChar: - return VarCharType::Instance(length, nullable); - default: - FATAL_ERROR("Provided a length parameter to TypeFactory::GetType() for " - "a type which does not take one."); - } + DCHECK(TypeRequiresLengthParameter(id)) + << "Called TypeFactory::GetType() with incorrect parameters."; + + return *InvokeOnTypeID>( + id, + [&](auto id) -> const Type* { // NOLINT(build/c++11) + return &TypeIDTrait::TypeClass::Instance(nullable, length); + }); +} + +const Type& TypeFactory::GetType(const TypeID id, + const std::vector ¶meters, + const bool nullable) { + DCHECK(TypeUtil::GetMemoryLayout(id) == kCxxGeneric) + << "Called TypeFactory::GetType() with incorrect parameters."; + + return *InvokeOnTypeID>( + id, + [&](auto id) -> const Type* { // NOLINT(build/c++11) + return &TypeIDTrait::TypeClass::Instance(nullable, parameters); + }); } bool TypeFactory::ProtoIsValid(const serialization::Type &proto) { @@ -90,26 +110,18 @@ bool TypeFactory::ProtoIsValid(const serialization::Type &proto) { return false; } - // Check that the type_id is valid, and extensions if any. - switch (proto.type_id()) { - case serialization::Type::INT: - case serialization::Type::LONG: - case serialization::Type::FLOAT: - case serialization::Type::DOUBLE: - case serialization::Type::DATE: - case serialization::Type::DATETIME: - case serialization::Type::DATETIME_INTERVAL: - case serialization::Type::YEAR_MONTH_INTERVAL: - return true; - case serialization::Type::CHAR: - return proto.HasExtension(serialization::CharType::length); - case serialization::Type::VAR_CHAR: - return proto.HasExtension(serialization::VarCharType::length); - case serialization::Type::NULL_TYPE: - return proto.nullable(); - default: - return false; + // Check that the type_id is valid, and has length if parameterized. + const TypeID type_id = TypeIDFactory::ReconstructFromProto(proto.type_id()); + + if (type_id == kNullType) { + return proto.nullable(); } + + if (TypeRequiresLengthParameter(type_id)) { + return proto.has_length(); + } + + return true; } const Type& TypeFactory::ReconstructFromProto(const serialization::Type &proto) { @@ -117,32 +129,32 @@ const Type& TypeFactory::ReconstructFromProto(const serialization::Type &proto) << "Attempted to create Type from an invalid proto description:\n" << proto.DebugString(); - switch (proto.type_id()) { - case serialization::Type::INT: - return IntType::Instance(proto.nullable()); - case serialization::Type::LONG: - return LongType::Instance(proto.nullable()); - case serialization::Type::FLOAT: - return FloatType::Instance(proto.nullable()); - case serialization::Type::DOUBLE: - return DoubleType::Instance(proto.nullable()); - case serialization::Type::DATE: - return DateType::Instance(proto.nullable()); - case serialization::Type::DATETIME: - return DatetimeType::Instance(proto.nullable()); - case serialization::Type::DATETIME_INTERVAL: - return DatetimeIntervalType::Instance(proto.nullable()); - case serialization::Type::YEAR_MONTH_INTERVAL: - return YearMonthIntervalType::Instance(proto.nullable()); - case serialization::Type::CHAR: - return CharType::InstanceFromProto(proto); - case serialization::Type::VAR_CHAR: - return VarCharType::InstanceFromProto(proto); - case serialization::Type::NULL_TYPE: - DCHECK(proto.nullable()); - return NullType::InstanceNullable(); - default: - FATAL_ERROR("Unrecognized TypeID in TypeFactory::ReconstructFromProto"); + const TypeID type_id = TypeIDFactory::ReconstructFromProto(proto.type_id()); + + switch (TypeUtil::GetMemoryLayout(type_id)) { + case kCxxInlinePod: + return GetType(type_id, proto.nullable()); + case kParInlinePod: // Fall through + case kParOutOfLinePod: + return GetType(type_id, proto.length(), proto.nullable()); + case kCxxGeneric: { + std::vector parameters; + for (int i = 0; i < proto.parameters_size(); ++i) { + parameters.emplace_back(ReconstructValueFromProto(proto.parameters(i))); + } + return GetType(type_id, parameters, proto.nullable()); + } + } +} + +GenericValue TypeFactory::ReconstructValueFromProto( + const serialization::GenericValue &proto) { + const Type &type = ReconstructFromProto(proto.type()); + if (proto.has_data()) { + return GenericValue::CreateWithOwnedData( + type, type.unmarshallValue(proto.data().c_str(), proto.data().size())); + } else { + return GenericValue::CreateNullValue(type); } } @@ -157,9 +169,11 @@ const Type* TypeFactory::GetMostSpecificType(const Type &first, const Type &seco } const Type* TypeFactory::GetUnifyingType(const Type &first, const Type &second) { + // TODO: cache const Type *unifier = nullptr; if (first.isNullable() || second.isNullable()) { - unifier = GetMostSpecificType(first.getNullableVersion(), second.getNullableVersion()); + unifier = GetMostSpecificType(first.getNullableVersion(), + second.getNullableVersion()); if (unifier == nullptr) { if (((first.getTypeID() == kLong) && (second.getTypeID() == kFloat)) || ((first.getTypeID() == kFloat) && (second.getTypeID() == kLong))) { @@ -179,4 +193,14 @@ const Type* TypeFactory::GetUnifyingType(const Type &first, const Type &second) return unifier; } +const std::unordered_map& TypeFactory::GetTypeNameMap() { + static std::unordered_map type_name_map; + if (type_name_map.empty()) { + for (std::size_t i = 0; i < static_cast(kNumTypeIDs); ++i) { + type_name_map.emplace(ToLower(kTypeNames[i]), static_cast(i)); + } + } + return type_name_map; +} + } // namespace quickstep diff --git a/types/TypeFactory.hpp b/types/TypeFactory.hpp index 742348e0..1b997f65 100644 --- a/types/TypeFactory.hpp +++ b/types/TypeFactory.hpp @@ -20,131 +20,6 @@ #ifndef QUICKSTEP_TYPES_TYPE_FACTORY_HPP_ #define QUICKSTEP_TYPES_TYPE_FACTORY_HPP_ -#include - -#include "types/TypeID.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { - -class Type; - -namespace serialization { class Type; } - -/** \addtogroup Types - * @{ - */ - -/** - * @brief All-static factory object that provides access to Types, as well as - * methods for determining coercibility of Types. - **/ -class TypeFactory { - public: - /** - * @brief Determine if a length parameter is required when getting a Type of - * the specified TypeID. - * - * @param id The id of the desired Type. - * @return Whether a length must be specified for Types of the given id. - **/ - static bool TypeRequiresLengthParameter(const TypeID id) { - switch (id) { - case kInt: - case kLong: - case kFloat: - case kDouble: - case kDate: - case kDatetime: - case kDatetimeInterval: - case kYearMonthInterval: - case kNullType: - return false; - case kChar: - case kVarChar: - return true; - default: - FATAL_ERROR("Unrecognized TypeID in TypeFactory::TypeRequiresLengthParameter"); - } - } - - /** - * @brief Factory method to get a Type by its TypeID. - * @note This version is for Types without a length parameter (currently - * IntType, LongType, FloatType, and DoubleType). It is an error to - * call this with a Type which requires a length parameter. - * - * @param id The id of the desired Type. - * @param nullable Whether to get the nullable version of the Type. - * @return The Type corresponding to id. - **/ - static const Type& GetType(const TypeID id, const bool nullable = false); - - /** - * @brief Factory method to get a Type by its TypeID and length. - * @note This version is for Types with a length parameter (currently - * CharType and VarCharType). It is an error to call this with a Type - * which does not require a length parameter. - * - * @param id The id of the desired Type. - * @param length The length parameter of the desired Type. - * @param nullable Whether to get the nullable version of the Type. - * @return The Type corresponding to id and length. - **/ - static const Type& GetType(const TypeID id, const std::size_t length, const bool nullable = false); - - /** - * @brief Get a reference to a Type from that Type's serialized Protocol Buffer - * representation. - * - * @param proto A serialized Protocol Buffer representation of a Type, - * originally generated by getProto(). - * @return The Type described by proto. - **/ - static const Type& ReconstructFromProto(const serialization::Type &proto); - - /** - * @brief Check whether a serialization::Type is fully-formed and - * all parts are valid. - * - * @param proto A serialized Protocol Buffer representation of a Type, - * originally generated by getProto(). - * @return Whether proto is fully-formed and valid. - **/ - static bool ProtoIsValid(const serialization::Type &proto); - - /** - * @brief Determine which of two types is most specific, i.e. which - * isSafelyCoercibleFrom() the other. - * - * @param first The first type to check. - * @param second The second type to check. - * @return The most precise type, or NULL if neither Type - * isSafelyCoercibleFrom() the other. - **/ - static const Type* GetMostSpecificType(const Type &first, const Type &second); - - /** - * @brief Determine a type, if any exists, which both arguments can be safely - * coerced to. It is possible that the resulting type may not be - * either argument. - * - * @param first The first type to check. - * @param second The second type to check. - * @return The unifying type, or NULL if none exists. - **/ - static const Type* GetUnifyingType(const Type &first, const Type &second); - - private: - // Undefined default constructor. Class is all-static and should not be - // instantiated. - TypeFactory(); - - DISALLOW_COPY_AND_ASSIGN(TypeFactory); -}; - -/** @} */ - -} // namespace quickstep +#include "types/TypeFactory-decl.hpp" #endif // QUICKSTEP_TYPES_TYPE_FACTORY_HPP_ diff --git a/types/TypeID.cpp b/types/TypeID.cpp index ff2f8e6b..08c619a1 100644 --- a/types/TypeID.cpp +++ b/types/TypeID.cpp @@ -22,6 +22,7 @@ namespace quickstep { const char *kTypeNames[] = { + "Bool", "Int", "Long", "Float", @@ -32,6 +33,9 @@ const char *kTypeNames[] = { "Datetime", "DatetimeInterval", "YearMonthInterval", + "Text", + "Array", + "MetaType", "NullType" }; diff --git a/types/TypeID.hpp b/types/TypeID.hpp index c54d8a51..13e0e3c3 100644 --- a/types/TypeID.hpp +++ b/types/TypeID.hpp @@ -21,16 +21,30 @@ #define QUICKSTEP_TYPES_TYPE_ID_HPP_ #include +#include + +#include "types/Type.pb.h" +#include "utility/Macros.hpp" namespace quickstep { +/** + * @brief Categories of intermediate supertypes. + **/ +enum class SuperTypeID { + kNumeric = 0, // Fixed-length numeric types (Int, Long, Float, Double) + kAsciiString, // ASCII strings (Char, VarChar) + kOther // Others (Date, Datetime, DatetimeInterval, YearMonthInterval) +}; + /** * @brief Concrete Types. * * @note TypedValue assumes that this doesn't exceed 64 TypeIDs. **/ enum TypeID { - kInt = 0, + kBool = 0, + kInt, kLong, kFloat, kDouble, @@ -40,10 +54,20 @@ enum TypeID { kDatetime, kDatetimeInterval, kYearMonthInterval, + kText, + kArray, + kMetaType, kNullType, kNumTypeIDs // Not a real TypeID, exists for counting purposes. }; +enum MemoryLayout { + kCxxInlinePod, + kParInlinePod, + kParOutOfLinePod, + kCxxGeneric +}; + /** * @brief Provides basic information about a Type in the Quickstep type system. * @@ -65,6 +89,37 @@ struct TypeSignature { **/ extern const char *kTypeNames[kNumTypeIDs]; +class TypeIDFactory { + public: + inline static serialization::TypeID GetProto(const TypeID type_id) { + serialization::TypeID proto; + proto.set_id(static_cast>(type_id)); + return proto; + } + + inline static TypeID ReconstructFromProto(const serialization::TypeID &proto) { + return static_cast(proto.id()); + } + + inline static bool ProtoIsValid(const serialization::TypeID &proto) { + return proto.id() < static_cast>(kNumTypeIDs); + } + + private: + DISALLOW_COPY_AND_ASSIGN(TypeIDFactory); +}; + } // namespace quickstep +namespace std { + +template <> +struct hash { + size_t operator()(const quickstep::TypeID &arg) const { + return static_cast::type>(arg); + } +}; + +} // namespace std + #endif // QUICKSTEP_TYPES_TYPE_ID_HPP_ diff --git a/types/TypeIDSelectors.hpp b/types/TypeIDSelectors.hpp new file mode 100644 index 00000000..bb1cf805 --- /dev/null +++ b/types/TypeIDSelectors.hpp @@ -0,0 +1,145 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_TYPE_ID_SELECTORS_HPP_ +#define QUICKSTEP_TYPES_TYPE_ID_SELECTORS_HPP_ + +#include + +#include "types/TypeID.hpp" +#include "utility/meta/Common.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +struct TypeIDSelectorAll; + +struct TypeIDSelectorNumeric; + +struct TypeIDSelectorParameterized; + +struct TypeIDSelectorNonParameterized; + +template +struct TypeIDSelector; + + +// Forward declaration +template +struct TypeIDTrait; + +struct TypeIDSelectorAll { + template + struct Implementation { + inline static auto Invoke(const FunctorT &functor) { + return functor(TypeIDConstant()); + } + }; +}; + +struct TypeIDSelectorNumeric { + template + struct Implementation { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" + inline static auto Invoke(const FunctorT &functor) + -> decltype(functor(TypeIDConstant())) { + DLOG(FATAL) << "Unexpected TypeID: " + << kTypeNames[static_cast(TypeIDConstant::value)]; + } +#pragma GCC diagnostic pop + }; +}; + +template +struct TypeIDSelectorNumeric::Implementation< + TypeIDConstant, FunctorT, + std::enable_if_t + ::kStaticSuperTypeID == SuperTypeID::kNumeric>> { + inline static auto Invoke(const FunctorT &functor) { + return functor(TypeIDConstant()); + } +}; + +template +struct TypeIDSelector { + template + struct Implementation { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" + inline static auto Invoke(const FunctorT &functor) + -> decltype(functor(TypeIDConstant())) { + DLOG(FATAL) << "Unexpected TypeID: " + << kTypeNames[static_cast(TypeIDConstant::value)]; + } +#pragma GCC diagnostic pop + }; +}; + +template +template +struct TypeIDSelector::Implementation< + TypeIDConstant, FunctorT, + std::enable_if_t< + meta::EqualsAny...>::value>> { + inline static auto Invoke(const FunctorT &functor) { + return functor(TypeIDConstant()); + } +}; + +template +struct TypeIDSelectorMemoryLayout { + template + struct Implementation { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" + inline static auto Invoke(const FunctorT &functor) + -> decltype(functor(TypeIDConstant())) { + DLOG(FATAL) << "Unexpected TypeID: " + << kTypeNames[static_cast(TypeIDConstant::value)]; + } +#pragma GCC diagnostic pop + }; +}; + +template +template +struct TypeIDSelectorMemoryLayout::Implementation< + TypeIDConstant, FunctorT, + std::enable_if_t< + meta::EqualsAny< + std::integral_constant::kMemoryLayout>, + std::integral_constant...>::value>> { + inline static auto Invoke(const FunctorT &functor) { + return functor(TypeIDConstant()); + } +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_TYPE_ID_SELECTORS_HPP_ diff --git a/types/TypeRegistrar.hpp b/types/TypeRegistrar.hpp new file mode 100644 index 00000000..d72788be --- /dev/null +++ b/types/TypeRegistrar.hpp @@ -0,0 +1,142 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_TYPE_REGISTRAR_HPP_ +#define QUICKSTEP_TYPES_TYPE_REGISTRAR_HPP_ + +#include +#include +#include +#include +#include + +#include "types/DatetimeLit.hpp" +#include "types/IntervalLit.hpp" +#include "types/NullLit.hpp" +#include "types/TypeID.hpp" +#include "types/TypeIDSelectors.hpp" +#include "utility/meta/Common.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +class Type; +class TypedValue; +class ArrayLit; + +using UntypedLiteral = void; + +using MetaTypeLit = const Type*; +using ParInlinePodLit = const void*; +using ParOutOfLinePodLit = TypedValue; + +template +struct TypeIDTrait; + +#define REGISTER_TYPE(type_class, type_id, super_type_id, memory_layout, cpp_type) \ + class type_class; \ + template <> struct TypeIDTrait { \ + typedef type_class TypeClass; \ + typedef cpp_type cpptype; \ + static constexpr TypeID kStaticTypeID = type_id; \ + static constexpr SuperTypeID kStaticSuperTypeID = super_type_id; \ + static constexpr MemoryLayout kMemoryLayout = memory_layout; \ + static constexpr bool kIsParPod = \ + (memory_layout == kParInlinePod || memory_layout == kParOutOfLinePod); \ + }; + +REGISTER_TYPE(BoolType, kBool, + SuperTypeID::kNumeric, kCxxInlinePod, bool); +REGISTER_TYPE(IntType, kInt, + SuperTypeID::kNumeric, kCxxInlinePod, int); +REGISTER_TYPE(LongType, kLong, + SuperTypeID::kNumeric, kCxxInlinePod, std::int64_t); +REGISTER_TYPE(FloatType, kFloat, + SuperTypeID::kNumeric, kCxxInlinePod, float); +REGISTER_TYPE(DoubleType, kDouble, + SuperTypeID::kNumeric, kCxxInlinePod, double); +REGISTER_TYPE(DateType, kDate, + SuperTypeID::kOther, kCxxInlinePod, DateLit); +REGISTER_TYPE(DatetimeType, kDatetime, + SuperTypeID::kOther, kCxxInlinePod, DatetimeLit); +REGISTER_TYPE(DatetimeIntervalType, kDatetimeInterval, + SuperTypeID::kOther, kCxxInlinePod, DatetimeIntervalLit); +REGISTER_TYPE(YearMonthIntervalType, kYearMonthInterval, + SuperTypeID::kOther, kCxxInlinePod, YearMonthIntervalLit); +REGISTER_TYPE(CharType, kChar, + SuperTypeID::kAsciiString, kParInlinePod, ParInlinePodLit); +REGISTER_TYPE(VarCharType, kVarChar, + SuperTypeID::kAsciiString, kParOutOfLinePod, ParOutOfLinePodLit); +REGISTER_TYPE(TextType, kText, + SuperTypeID::kOther, kCxxGeneric, std::string); +REGISTER_TYPE(ArrayType, kArray, + SuperTypeID::kOther, kCxxGeneric, ArrayLit); +REGISTER_TYPE(MetaType, kMetaType, + SuperTypeID::kOther, kCxxGeneric, MetaTypeLit); +REGISTER_TYPE(NullType, kNullType, + SuperTypeID::kOther, kCxxInlinePod, NullLit); + +#undef REGISTER_TYPE + +using TypeIDSequenceAll = + meta::MakeSequence(kNumTypeIDs)> + ::type::template cast_to; + +template +auto InvokeOnTypeID(const TypeID type_id, const FunctorT &functor); + +namespace internal { + +template +inline auto InvokeOnTypeIDInternal(const int value, + const FunctorT &functor) { + DCHECK_LE(l, r); + if (l == r) { + constexpr TypeID type_id = static_cast(r); + return Selector::template Implementation< + std::integral_constant, FunctorT>::Invoke(functor); + } + constexpr int m = (l + r) >> 1; + if (value <= m) { + return InvokeOnTypeIDInternal(value, functor); + } else { + return InvokeOnTypeIDInternal(value, functor); + } +} + +} // namespace internal + +template +auto InvokeOnTypeID(const TypeID type_id, + const FunctorT &functor) { + return internal::InvokeOnTypeIDInternal<0, static_cast(kNumTypeIDs)-1, + Selector, FunctorT>( + static_cast(type_id), functor); +} + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_TYPE_REGISTRAR_HPP_ diff --git a/types/TypeSynthesizer.hpp b/types/TypeSynthesizer.hpp new file mode 100644 index 00000000..23d072cf --- /dev/null +++ b/types/TypeSynthesizer.hpp @@ -0,0 +1,733 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_TYPE_SYNTHESIZER_HPP_ +#define QUICKSTEP_TYPES_TYPE_SYNTHESIZER_HPP_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "types/ArrayLit.hpp" +#include "types/GenericValue.hpp" +#include "types/Type.hpp" +#include "types/Type.pb.h" +#include "types/TypeID.hpp" +#include "types/TypeRegistrar.hpp" +#include "types/TypedValue.hpp" +#include "types/operations/utility/CastUtil.hpp" +#include "utility/Cast.hpp" +#include "utility/HashPair.hpp" +#include "utility/Macros.hpp" +#include "utility/meta/Common.hpp" + +#include "third_party/src/farmhash/farmhash.h" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +template +class TypeSynthesizePolicy; + + +//////////////////////////////////////////////////////////////////////////////// +///////////////////////////////// CxxInlinePod /////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +template +class TypeSynthesizePolicy< + type_id, + std::enable_if_t::kMemoryLayout == kCxxInlinePod>> : public Type { + private: + using Trait = TypeIDTrait; + using TypeClass = typename Trait::TypeClass; + using cpptype = typename Trait::cpptype; + + public: + static const TypeClass& InstanceNonNullable() { + return InstanceInternal(); + } + + static const TypeClass& InstanceNullable() { + return InstanceInternal(); + } + + static const TypeClass& Instance(const bool nullable) { + if (nullable) { + return InstanceNullable(); + } else { + return InstanceNonNullable(); + } + } + + std::size_t getHash() const override { + return static_cast(getTypeID()); + } + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override { + DCHECK(lhs != nullptr); + DCHECK(rhs != nullptr); + // TODO(refactor-type): Operator == overloading. + if (type_id_ != rhs_type.getTypeID()) { + return false; + } + return !std::memcmp(lhs, rhs, sizeof(cpptype)); + } + + UntypedLiteral* cloneValue(const UntypedLiteral *value) const override { + DCHECK(value != nullptr); + UntypedLiteral* clone = std::malloc(sizeof(cpptype)); + std::memcpy(clone, value, sizeof(cpptype)); + return clone; + } + + void destroyValue(UntypedLiteral *value) const override { + DCHECK(value != nullptr); + std::free(value); + } + + std::size_t hashValue(const UntypedLiteral *value) const override { + DCHECK(value != nullptr); + return hashValueInl(value); + } + + TypedValue marshallValue(const UntypedLiteral *value) const override { + DCHECK(value != nullptr); + return makeValue(value, sizeof(cpptype)).ensureNotReference(); + } + + UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const override { + DCHECK(data != nullptr); + DCHECK_EQ(sizeof(cpptype), length); + UntypedLiteral *value = std::malloc(sizeof(cpptype)); + std::memcpy(value, data, sizeof(cpptype)); + return value; + } + + protected: + explicit TypeSynthesizePolicy(const bool nullable) + : Type(Trait::kStaticSuperTypeID, type_id, kCxxInlinePod, nullable, + sizeof(cpptype), sizeof(cpptype)) {} + + inline const Type& getInstance(const bool nullable) const { + return nullable ? InstanceNullable() : InstanceNonNullable(); + } + + inline void mergeIntoProto(serialization::Type *proto) const {} + + inline UntypedLiteral* unmarshallTypedValueInl(const TypedValue &value) const { + return cloneValue(value.getDataPtr()); + } + + template + inline auto invokeOnUnmarshalledTypedValue(const TypedValue &value, + const Functor &functor) const { + return functor(value.getDataPtr()); + } + + private: + template + inline static const TypeClass& InstanceInternal() { + static TypeClass instance(nullable); + return instance; + } + + template + inline std::size_t hashValueInl( + const UntypedLiteral *value, + std::enable_if_t::value> * = 0) const { + using CxxUIntType = typename meta::UnsignedInteger::type; + CxxUIntType buffer; + std::memcpy(&buffer, value, size); + return buffer; + } + + template + inline std::size_t hashValueInl( + const UntypedLiteral *value, + std::enable_if_t::value> * = 0) const { + return util::Hash(static_cast(value), size); + } +}; + + +//////////////////////////////////////////////////////////////////////////////// +///////////////////////////////// ParInlinePod /////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +template +class TypeSynthesizePolicy< + type_id, + std::enable_if_t::kMemoryLayout == kParInlinePod>> : public Type { + private: + using Trait = TypeIDTrait; + using TypeClass = typename Trait::TypeClass; + using cpptype = typename Trait::cpptype; + + static_assert(std::is_same::value, + "Unexpected cpptype for ParInlinePod."); + + public: + static const TypeClass& InstanceNonNullable(const std::size_t length) { + return InstanceInternal(length); + } + + static const TypeClass& InstanceNullable(const std::size_t length) { + return InstanceInternal(length); + } + + static const TypeClass& Instance(const bool nullable, const std::size_t length) { + if (nullable) { + return InstanceNullable(length); + } else { + return InstanceNonNullable(length); + } + } + + std::size_t length() const { + return length_; + } + + std::size_t getHash() const override { + return CombineHashes(static_cast(type_id), length_); + } + + std::size_t hashValue(const UntypedLiteral *value) const override { + // TODO(refactor-type): Implementation. + DCHECK(value != nullptr); + return TypedValue(type_id_, + *static_cast(value), + maximum_byte_length_).getHash(); + } + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override { + DCHECK(lhs != nullptr); + DCHECK(rhs != nullptr); + if (!equals(rhs_type)) { + return false; + } + return !std::memcmp(*static_cast(lhs), + *static_cast(rhs), + maximum_byte_length_); + } + + UntypedLiteral* cloneValue(const UntypedLiteral *value) const override { + DCHECK(value != nullptr); + void *value_copy = std::malloc(maximum_byte_length_); + std::memcpy(value_copy, + *static_cast(value), + maximum_byte_length_); + return new cpptype(value_copy); + } + + void destroyValue(UntypedLiteral *value) const override { + DCHECK(value != nullptr); + cpptype *value_ptr = static_cast(value); + std::free(const_cast(*value_ptr)); + delete value_ptr; + } + + TypedValue marshallValue(const UntypedLiteral *value) const override { + return TypedValue(type_id_, value, maximum_byte_length_).ensureNotReference(); + } + + UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const override { + DCHECK(data != nullptr); + DCHECK_EQ(maximum_byte_length_, length); + void *value = std::malloc(maximum_byte_length_); + std::memcpy(value, data, length); + return new cpptype(value); + } + + protected: + TypeSynthesizePolicy(const bool nullable, + const std::size_t minimum_byte_length, + const std::size_t maximum_byte_length, + const std::size_t length) + : Type(Trait::kStaticSuperTypeID, type_id, kParInlinePod, nullable, + minimum_byte_length, maximum_byte_length), + length_(length) {} + + const std::size_t length_; + + inline const Type& getInstance(const bool nullable) const { + return nullable ? InstanceNullable(length_) : InstanceNonNullable(length_); + } + + inline void mergeIntoProto(serialization::Type *proto) const { + proto->set_length(length_); + } + + inline UntypedLiteral* unmarshallTypedValueInl(const TypedValue &value) const { + return unmarshallValue(value.getDataPtr(), value.getDataSize()); + } + + template + inline auto invokeOnUnmarshalledTypedValue(const TypedValue &value, + const Functor &functor) const { + return functor(&value); + } + + private: + template + inline static const TypeClass& InstanceInternal(const std::size_t length) { + static std::unordered_map> instance_map; + auto imit = instance_map.find(length); + if (imit == instance_map.end()) { + std::unique_ptr instance(new TypeClass(nullable, length)); + imit = instance_map.emplace(length, std::move(instance)).first; + } + return *(imit->second); + } +}; + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////// ParOutOfLinePod ///////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +template +class TypeSynthesizePolicy< + type_id, + std::enable_if_t::kMemoryLayout == kParOutOfLinePod>> : public Type { + private: + using Trait = TypeIDTrait; + using TypeClass = typename Trait::TypeClass; + using cpptype = typename Trait::cpptype; + + static_assert(std::is_same::value, + "Unexpected cpptype for ParOutOfLinePod."); + + public: + static const TypeClass& InstanceNonNullable(const std::size_t length) { + return InstanceInternal(length); + } + + static const TypeClass& InstanceNullable(const std::size_t length) { + return InstanceInternal(length); + } + + static const TypeClass& Instance(const bool nullable, const std::size_t length) { + if (nullable) { + return InstanceNullable(length); + } else { + return InstanceNonNullable(length); + } + } + + std::size_t length() const { + return length_; + } + + std::size_t getHash() const override { + return CombineHashes(static_cast(type_id), length_); + } + + std::size_t hashValue(const UntypedLiteral *value) const override { + // TODO(refactor-type): Better implementation. + DCHECK(value != nullptr); + return static_cast(value)->getHash(); + } + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override { + // TODO(refactor-type): Better implementation. + const TypedValue *lhs_value = static_cast(lhs); + const TypedValue *rhs_value = static_cast(rhs); + return lhs_value->fastEqualCheck(*rhs_value); + } + + UntypedLiteral* cloneValue(const UntypedLiteral *value) const override { + DCHECK(value != nullptr); + return new TypedValue(*static_cast(value)); + } + + void destroyValue(UntypedLiteral *value) const override { + DCHECK(value != nullptr); + delete static_cast(value); + } + + TypedValue marshallValue(const UntypedLiteral *value) const override { + DCHECK(value != nullptr); + return *static_cast(value); + } + + UntypedLiteral* unmarshallValue(const void *data, + const std::size_t length) const override { + DCHECK(data != nullptr); + TypedValue *value = new TypedValue(makeValue(data, length)); + value->ensureNotReference(); + return value; + } + + protected: + TypeSynthesizePolicy(const bool nullable, + const std::size_t minimum_byte_length, + const std::size_t maximum_byte_length, + const std::size_t length) + : Type(Trait::kStaticSuperTypeID, type_id, kParOutOfLinePod, nullable, + minimum_byte_length, maximum_byte_length), + length_(length) {} + + const std::size_t length_; + + inline const Type& getInstance(const bool nullable) const { + return nullable ? InstanceNullable(length_) : InstanceNonNullable(length_); + } + + inline void mergeIntoProto(serialization::Type *proto) const { + proto->set_length(length_); + } + + inline UntypedLiteral* unmarshallTypedValueInl(const TypedValue &value) const { + return new TypedValue(value); + } + + template + inline auto invokeOnUnmarshalledTypedValue(const TypedValue &value, + const Functor &functor) const { + return functor(&value); + } + + private: + template + inline static const TypeClass& InstanceInternal(const std::size_t length) { + static std::unordered_map> instance_map; + auto imit = instance_map.find(length); + if (imit == instance_map.end()) { + std::unique_ptr instance(new TypeClass(nullable, length)); + imit = instance_map.emplace(length, std::move(instance)).first; + } + return *(imit->second); + } +}; + + +//////////////////////////////////////////////////////////////////////////////// +////////////////////////////////// CxxGeneric //////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +template +class TypeSynthesizePolicy< + type_id, + std::enable_if_t::kMemoryLayout == kCxxGeneric>> : public Type { + private: + using Trait = TypeIDTrait; + using TypeClass = typename Trait::TypeClass; + using cpptype = typename Trait::cpptype; + + public: + static const TypeClass& InstanceNonNullable( + const std::vector ¶meters = {}) { + return InstanceInternal(parameters); + } + + static const TypeClass& InstanceNullable( + const std::vector ¶meters = {}) { + return InstanceInternal(parameters); + } + + static const TypeClass& Instance( + const bool nullable, + const std::vector ¶meters = {}) { + if (nullable) { + return InstanceNullable(parameters); + } else { + return InstanceNonNullable(parameters); + } + } + + const std::vector& parameters() const { + return parameters_; + } + + std::size_t getHash() const override { + return CombineHashes(static_cast(type_id_), + ParametersHasher::ComputeHash(parameters_)); + } + + bool checkValuesEqual(const UntypedLiteral *lhs, + const UntypedLiteral *rhs, + const Type &rhs_type) const override { + LOG(FATAL) << "Not implemented"; + } + + UntypedLiteral* cloneValue(const UntypedLiteral *value) const override { + DCHECK(value != nullptr); + return new cpptype(*static_cast(value)); + } + + void destroyValue(UntypedLiteral *value) const override { + DCHECK(value != nullptr); + delete static_cast(value); + } + + std::size_t hashValue(const UntypedLiteral *value) const override { + // TODO(refactor-type): Add note that it is a shallow hash. + return util::Hash(static_cast(value), sizeof(cpptype)); + } + +// TypedValue marshallValue(const UntypedLiteral *value) const override { +// LOG(FATAL) << "Not implemented"; +// } +// +// UntypedLiteral* unmarshallValue(const void *data, +// const std::size_t length) const override { +// LOG(FATAL) << "Not implemented"; +// } + + template + static bool TypeParametersAreValid(const std::vector ¶meters, + decltype(new T(true)) * = 0) { + return parameters.empty(); + } + + protected: + TypeSynthesizePolicy(const bool nullable, + const std::size_t minimum_byte_length, + const std::size_t maximum_byte_length, + const std::vector ¶meters) + : Type(Trait::kStaticSuperTypeID, type_id, kCxxGeneric, nullable, + minimum_byte_length, maximum_byte_length), + parameters_(parameters) {} + + inline const Type& getInstance(const bool nullable) const { + return nullable ? InstanceNullable(parameters_) + : InstanceNonNullable(parameters_); + } + + inline void mergeIntoProto(serialization::Type *proto) const { + for (const auto ¶m : parameters_) { + proto->add_parameters()->MergeFrom(param.getProto()); + } + } + + inline UntypedLiteral* unmarshallTypedValueInl(const TypedValue &value) const { + return unmarshallValue(value.getOutOfLineData(), value.getDataSize()); + } + + template + inline auto invokeOnUnmarshalledTypedValue(const TypedValue &value, + const Functor &functor) const { + std::unique_ptr literal( + static_cast(unmarshallValue(value.getOutOfLineData(), + value.getDataSize()))); + return functor(literal.get()); + } + + const std::vector parameters_; + + private: + struct ParametersHasher { + inline static std::size_t ComputeHash( + const std::vector ¶meters) { + std::size_t hash_code = 0; + for (const GenericValue &value : parameters) { + hash_code = CombineHashes(hash_code, value.getHash()); + } + return hash_code; + } + inline std::size_t operator()( + const std::vector ¶meters) const { + return ComputeHash(parameters); + } + }; + + template + inline static TypeClass* CreateInstance( + const bool nullable, + const std::vector ¶meters, + decltype(new T(nullable)) * = 0) { + DCHECK(parameters.empty()); + return new T(nullable); + } + + template + inline static TypeClass* CreateInstance( + const bool nullable, + const std::vector ¶meters, + decltype(new T(nullable, parameters)) * = 0) { + return new T(nullable, parameters); + } + + template + inline static const TypeClass& InstanceInternal( + const std::vector ¶meters) { + static std::unordered_map, + std::unique_ptr, + ParametersHasher> instance_map; + auto imit = instance_map.find(parameters); + if (imit == instance_map.end()) { + std::unique_ptr instance( + TypeSynthesizePolicy::template CreateInstance( + nullable, parameters)); + imit = instance_map.emplace(parameters, std::move(instance)).first; + } + return *(imit->second); + } +}; + + +//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////// TypeSynthesizer ////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +template +class TypeSynthesizer : public TypeSynthesizePolicy { + private: + using Trait = TypeIDTrait; + using SynthesizePolicy = TypeSynthesizePolicy; + + public: + static constexpr SuperTypeID kStaticSuperTypeID = Trait::kStaticSuperTypeID; + static constexpr TypeID kStaticTypeID = Trait::kStaticTypeID; + static constexpr bool kIsParPod = Trait::kIsParPod; + static constexpr MemoryLayout kMemoryLayout = Trait::kMemoryLayout; + + using TypeClass = typename Trait::TypeClass; + using cpptype = typename Trait::cpptype; + + serialization::Type getProto() const override { + serialization::Type proto; + proto.mutable_type_id()->CopyFrom(TypeIDFactory::GetProto(Type::type_id_)); + proto.set_nullable(Type::nullable_); + SynthesizePolicy::mergeIntoProto(&proto); + return proto; + } + + const Type& getNullableVersion() const override { + return SynthesizePolicy::getInstance(true); + } + + const Type& getNonNullableVersion() const override { + return SynthesizePolicy::getInstance(false); + } + + bool isCoercibleFrom(const Type &original_type) const override { + auto it = kCoercibleSourceTypeIDs.find(original_type.getTypeID()); + return it != kCoercibleSourceTypeIDs.end(); + }; + + UntypedLiteral* unmarshallTypedValue(const TypedValue &value) const override { + return SynthesizePolicy::unmarshallTypedValueInl(value); + } + + std::string printTypedValueToString(const TypedValue &value) const override { + return SynthesizePolicy::invokeOnUnmarshalledTypedValue( + value, + [&](const UntypedLiteral *value) -> std::string { + return this->printValueToString(value); + }); + } + + void printTypedValueToFile(const TypedValue &value, + FILE *file, + const int padding = 0) const override { + SynthesizePolicy::invokeOnUnmarshalledTypedValue( + value, + [&](const UntypedLiteral *value) -> void { + this->printValueToFile(value, file, padding); + }); + } + + const cpptype& castValueToLiteral(const UntypedLiteral *value) const { + return *static_cast(value); + } + + cpptype& castValueToLiteral(UntypedLiteral *value) const { + return *static_cast(value); + } + + protected: + template + explicit TypeSynthesizer(const bool nullable, + std::enable_if_t* = 0) + : TypeSynthesizePolicy(nullable) { + } + + template + TypeSynthesizer(const bool nullable, + const std::size_t minimum_byte_length, + const std::size_t maximum_byte_length, + const std::size_t parameter, + std::enable_if_t* = 0) + : TypeSynthesizePolicy(nullable, minimum_byte_length, + maximum_byte_length, parameter) { + } + + template + TypeSynthesizer(const bool nullable, + const std::size_t minimum_byte_length, + const std::size_t maximum_byte_length, + const std::vector ¶meters = {}, + std::enable_if_t* = 0) + : TypeSynthesizePolicy(nullable, minimum_byte_length, + maximum_byte_length, parameters) { + } + + private: + template friend class TypeSynthesizePolicy; + + static const std::unordered_set kCoercibleSourceTypeIDs; + + DISALLOW_COPY_AND_ASSIGN(TypeSynthesizer); +}; + +template +constexpr SuperTypeID TypeSynthesizer::kStaticSuperTypeID; + +template +constexpr TypeID TypeSynthesizer::kStaticTypeID; + +template +constexpr bool TypeSynthesizer::kIsParPod; + +template +constexpr MemoryLayout TypeSynthesizer::kMemoryLayout; + +template +const std::unordered_set TypeSynthesizer::kCoercibleSourceTypeIDs = + CastSTLContainer>( + CastUtil::GetCoercibleSourceTypeIDs(type_id)); + +#define QUICKSTEP_SYNTHESIZE_TYPE(type) \ + template friend class TypeSynthesizePolicy; \ + DISALLOW_COPY_AND_ASSIGN(type) + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_TYPE_SYNTHESIZER_HPP_ diff --git a/types/TypeUtil.hpp b/types/TypeUtil.hpp new file mode 100644 index 00000000..496844f1 --- /dev/null +++ b/types/TypeUtil.hpp @@ -0,0 +1,108 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_TYPE_UTIL_HPP_ +#define QUICKSTEP_TYPES_TYPE_UTIL_HPP_ + +#include + +#include "types/ArrayType.hpp" +#include "types/BoolType.hpp" +#include "types/CharType.hpp" +#include "types/DateType.hpp" +#include "types/DatetimeIntervalType.hpp" +#include "types/DatetimeType.hpp" +#include "types/DoubleType.hpp" +#include "types/FloatType.hpp" +#include "types/IntType.hpp" +#include "types/LongType.hpp" +#include "types/MetaType-decl.hpp" +#include "types/NullType.hpp" +#include "types/TextType.hpp" +#include "types/Type.hpp" +#include "types/TypeID.hpp" +#include "types/TypeRegistrar.hpp" +#include "types/VarCharType.hpp" +#include "types/YearMonthIntervalType.hpp" +#include "utility/Macros.hpp" +#include "utility/meta/TypeList.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +namespace internal { + +// TODO(refactor-type): Organize selector predicates, refactor the old design. +template +struct MemoryLayoutSelector { + template + struct type { + static constexpr bool value = + TypeIDTrait::kMemoryLayout == layout; + }; +}; + +} // namespace internal + + +class TypeUtil { + public: + template + using TypeIDSequenceMemoryLayout = + TypeIDSequenceAll::bind_to + ::filter::type> + ::as_sequence; + + static MemoryLayout GetMemoryLayout(const TypeID type_id) { + return InvokeOnTypeID( + type_id, + [&](auto tid) -> MemoryLayout { // NOLINT(build/c++11) + return TypeIDTrait::kMemoryLayout; + }); + } + + template + static std::vector GetTypeIDVectorOfMemoryLayout(){ + return TypeIDSequenceMemoryLayout::Instantiate>(); + } + + static bool IsParameterizedPod(const TypeID type_id) { + return InvokeOnTypeID( + type_id, + [&](auto tid) -> bool { // NOLINT(build/c++11) + return TypeIDTrait::kIsParPod; + }); + } + + private: + TypeUtil() {} + + DISALLOW_COPY_AND_ASSIGN(TypeUtil); +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_TYPE_UTIL_HPP_ diff --git a/types/TypedValue.cpp b/types/TypedValue.cpp index 8dd8b60b..79e80a34 100644 --- a/types/TypedValue.cpp +++ b/types/TypedValue.cpp @@ -47,6 +47,7 @@ bool TypedValue::isPlausibleInstanceOf(const TypeSignature type) const { } switch (type_id) { + case kBool: case kInt: case kLong: case kFloat: @@ -82,33 +83,34 @@ serialization::TypedValue TypedValue::getProto() const { // NOTE(chasseur): To represent a NULL value, only the 'type_id' field of the // proto is filled in, and all the optional value fields are omitted. + proto.mutable_type_id()->CopyFrom(TypeIDFactory::GetProto(getTypeID())); switch (getTypeID()) { + case kBool: + if (!isNull()) { + proto.set_int_value(getLiteral()); + } + break; case kInt: - proto.set_type_id(serialization::Type::INT); if (!isNull()) { proto.set_int_value(getLiteral()); } break; case kLong: - proto.set_type_id(serialization::Type::LONG); if (!isNull()) { proto.set_long_value(getLiteral()); } break; case kFloat: - proto.set_type_id(serialization::Type::FLOAT); if (!isNull()) { proto.set_float_value(getLiteral()); } break; case kDouble: - proto.set_type_id(serialization::Type::DOUBLE); if (!isNull()) { proto.set_double_value(getLiteral()); } break; case kDate: - proto.set_type_id(serialization::Type::DATE); if (!isNull()) { serialization::TypedValue::DateLit *literal_date_proto = proto.mutable_date_value(); literal_date_proto->set_year(value_union_.date_value.year); @@ -117,42 +119,40 @@ serialization::TypedValue TypedValue::getProto() const { } break; case kDatetime: - proto.set_type_id(serialization::Type::DATETIME); if (!isNull()) { proto.set_datetime_value(value_union_.datetime_value.ticks); } break; case kDatetimeInterval: - proto.set_type_id(serialization::Type::DATETIME_INTERVAL); if (!isNull()) { proto.set_datetime_interval_value(value_union_.datetime_interval_value.interval_ticks); } break; case kYearMonthInterval: - proto.set_type_id(serialization::Type::YEAR_MONTH_INTERVAL); if (!isNull()) { proto.set_year_month_interval_value(value_union_.year_month_interval_value.months); } break; case kChar: - proto.set_type_id(serialization::Type::CHAR); if (!isNull()) { proto.set_out_of_line_data(static_cast(getOutOfLineData()), getDataSize()); } break; case kVarChar: - proto.set_type_id(serialization::Type::VAR_CHAR); if (!isNull()) { proto.set_out_of_line_data(static_cast(getOutOfLineData()), getDataSize()); } break; case kNullType: - proto.set_type_id(serialization::Type::NULL_TYPE); DCHECK(isNull()); break; default: - FATAL_ERROR("Unrecognized TypeID in TypedValue::getProto"); - } +// FATAL_ERROR("Unrecognized TypeID in TypedValue::getProto"); + if (!isNull()) { + proto.set_out_of_line_data(static_cast(getOutOfLineData()), getDataSize()); + } + break; +} return proto; } @@ -166,24 +166,29 @@ TypedValue TypedValue::ReconstructFromProto(const serialization::TypedValue &pro << "Attempted to create TypedValue from an invalid proto description:\n" << proto.DebugString(); - switch (proto.type_id()) { - case serialization::Type::INT: + const TypeID type_id = TypeIDFactory::ReconstructFromProto(proto.type_id()); + switch (type_id) { + case kBool: + return proto.has_bool_value() ? + TypedValue(static_cast(proto.bool_value())) : + TypedValue(kBool); + case kInt: return proto.has_int_value() ? TypedValue(static_cast(proto.int_value())) : TypedValue(kInt); - case serialization::Type::LONG: + case kLong: return proto.has_long_value() ? TypedValue(static_cast(proto.long_value())) : TypedValue(kLong); - case serialization::Type::FLOAT: + case kFloat: return proto.has_float_value() ? TypedValue(static_cast(proto.float_value())) : TypedValue(kFloat); - case serialization::Type::DOUBLE: + case kDouble: return proto.has_double_value() ? TypedValue(static_cast(proto.double_value())) : TypedValue(kDouble); - case serialization::Type::DATE: + case kDate: if (proto.has_date_value()) { return TypedValue(DateLit::Create(proto.date_value().year(), proto.date_value().month(), @@ -191,7 +196,7 @@ TypedValue TypedValue::ReconstructFromProto(const serialization::TypedValue &pro } else { return TypedValue(kDate); } - case serialization::Type::DATETIME: + case kDatetime: if (proto.has_datetime_value()) { DatetimeLit datetime; datetime.ticks = proto.datetime_value(); @@ -199,7 +204,7 @@ TypedValue TypedValue::ReconstructFromProto(const serialization::TypedValue &pro } else { return TypedValue(kDatetime); } - case serialization::Type::DATETIME_INTERVAL: + case kDatetimeInterval: if (proto.has_datetime_interval_value()) { DatetimeIntervalLit interval; interval.interval_ticks = proto.datetime_interval_value(); @@ -207,7 +212,7 @@ TypedValue TypedValue::ReconstructFromProto(const serialization::TypedValue &pro } else { return TypedValue(kDatetimeInterval); } - case serialization::Type::YEAR_MONTH_INTERVAL: + case kYearMonthInterval: if (proto.has_year_month_interval_value()) { YearMonthIntervalLit interval; interval.months = proto.year_month_interval_value(); @@ -215,22 +220,27 @@ TypedValue TypedValue::ReconstructFromProto(const serialization::TypedValue &pro } else { return TypedValue(kYearMonthInterval); } - case serialization::Type::CHAR: + case kChar: return proto.has_out_of_line_data() ? TypedValue(kChar, static_cast(proto.out_of_line_data().c_str()), proto.out_of_line_data().size()).ensureNotReference() : TypedValue(kChar); - case serialization::Type::VAR_CHAR: + case kVarChar: return proto.has_out_of_line_data() ? TypedValue(kVarChar, static_cast(proto.out_of_line_data().c_str()), proto.out_of_line_data().size()).ensureNotReference() : TypedValue(kVarChar); - case serialization::Type::NULL_TYPE: + case kNullType: return TypedValue(kNullType); default: - FATAL_ERROR("Unrecognized TypeID in TypedValue::ReconstructFromProto"); +// FATAL_ERROR("Unrecognized TypeID in TypedValue::ReconstructFromProto"); + return proto.has_out_of_line_data() ? + TypedValue(type_id, + static_cast(proto.out_of_line_data().c_str()), + proto.out_of_line_data().size()).ensureNotReference() : + TypedValue(type_id); } } diff --git a/types/TypedValue.hpp b/types/TypedValue.hpp index 0ba3d536..d0e8b984 100644 --- a/types/TypedValue.hpp +++ b/types/TypedValue.hpp @@ -89,6 +89,16 @@ class TypedValue { orig.value_info_ = 0; } + /** + * @brief Constructor for a literal value of BoolType. + **/ + explicit TypedValue(const bool literal_bool) + : value_info_(static_cast(kBool)) { + // Zero-out all bytes in the union for getHash() and fastEqualCheck(). + value_union_.hash64 = 0; + value_union_.bool_value = literal_bool; + } + /** * @brief Constructor for a literal value of IntType. **/ @@ -264,9 +274,9 @@ class TypedValue { * TypedValue will take ownership of this memory. * @param value_size The number of bytes of data at value_ptr. **/ - static TypedValue CreateWithOwnedData(const TypeID type_id, - void *value_ptr, - const std::size_t value_size) { + inline static TypedValue CreateWithOwnedData(const TypeID type_id, + void *value_ptr, + const std::size_t value_size) { TypedValue val(type_id, value_ptr, value_size); val.value_info_ |= kOwnershipMask; return val; @@ -282,6 +292,7 @@ class TypedValue { **/ static bool RepresentedInline(const TypeID type_id) { switch (type_id) { + case kBool: case kInt: case kLong: case kFloat: @@ -313,6 +324,8 @@ class TypedValue { **/ static bool HashIsReversible(const TypeID type_id) { switch (type_id) { + case kBool: + return true; case kInt: case kFloat: return sizeof(value_union_.int_value) <= sizeof(std::size_t); @@ -391,6 +404,8 @@ class TypedValue { inline std::size_t getDataSize() const { DCHECK(!isNull()); switch (getTypeID()) { + case kBool: + return sizeof(bool); case kInt: case kFloat: return sizeof(int); @@ -478,7 +493,8 @@ class TypedValue { * @return The out-of-line data this TypedValue points to. **/ inline const void* getOutOfLineData() const { - DCHECK(!(getTypeID() == kInt + DCHECK(!(getTypeID() == kBool + || getTypeID() == kInt || getTypeID() == kLong || getTypeID() == kFloat || getTypeID() == kDouble @@ -490,6 +506,28 @@ class TypedValue { return value_union_.out_of_line_data; } + inline void* releaseOutOfLineData() { + DCHECK(!(getTypeID() == kBool + || getTypeID() == kInt + || getTypeID() == kLong + || getTypeID() == kFloat + || getTypeID() == kDouble + || getTypeID() == kDate + || getTypeID() == kDatetime + || getTypeID() == kDatetimeInterval + || getTypeID() == kYearMonthInterval)); + DCHECK(!isNull()); + if (ownsOutOfLineData()) { + value_info_ &= ~kOwnershipMask; + return const_cast(value_union_.out_of_line_data); + } else { + const std::size_t length = value_info_ >> kSizeShift; + void *data = std::malloc(length); + std::memcpy(data, value_union_.out_of_line_data, length); + return data; + } + } + /** * @brief Get the length of the ASCII string this TypedValue represents, * not counting a null terminator character, if any (same behavior @@ -547,6 +585,10 @@ class TypedValue { value_info_ >> kSizeShift); } else { switch (getTypeID()) { + case kBool: + // 1 byte copy. + *static_cast(destination) = value_union_.bool_value; + break; case kInt: case kFloat: // 4 bytes byte-for-byte copy. @@ -574,6 +616,7 @@ class TypedValue { **/ inline std::size_t getHash() const { switch (getTypeID()) { + case kBool: case kInt: case kLong: case kFloat: @@ -670,6 +713,7 @@ class TypedValue { DCHECK(!other.isNull()); DCHECK_EQ(getTypeID(), other.getTypeID()); switch (getTypeID()) { + case kBool: case kInt: case kLong: case kFloat: @@ -710,6 +754,16 @@ class TypedValue { } } + bool operator==(const TypedValue &other) const { + if (getTypeID() != other.getTypeID()) { + return false; + } + if (isNull() || other.isNull()) { + return isNull() == other.isNull(); + } + return fastEqualCheck(other); + } + /** * @brief Generate a serialized Protocol Buffer representation * of this TypedValue. @@ -789,6 +843,7 @@ class TypedValue { inline void reverseHash(const std::size_t hash); union ValueUnion { + bool bool_value; int int_value; std::int64_t long_value; float float_value; @@ -841,6 +896,13 @@ class TypedValue { /** @} */ // Explicit specializations of getLiteral(). +template <> +inline bool TypedValue::getLiteral() const { + DCHECK_EQ(kBool, getTypeID()); + DCHECK(!isNull()); + return value_union_.bool_value; +} + template <> inline int TypedValue::getLiteral() const { DCHECK_EQ(kInt, getTypeID()); diff --git a/types/TypedValue.proto b/types/TypedValue.proto index 7f3ab7ad..7cf3eca7 100644 --- a/types/TypedValue.proto +++ b/types/TypedValue.proto @@ -22,17 +22,18 @@ package quickstep.serialization; import "types/Type.proto"; message TypedValue { - required Type.TypeID type_id = 1; + required TypeID type_id = 1; // NOTE(zuyu): For a NULL value, none of the optional fields are filled in. - optional int32 int_value = 2; - optional int64 long_value = 3; - optional float float_value = 4; - optional double double_value = 5; - optional bytes out_of_line_data = 6; - optional int64 datetime_value = 7; - optional int64 datetime_interval_value = 8; - optional int64 year_month_interval_value = 9; + optional bool bool_value = 2; + optional int32 int_value = 3; + optional int64 long_value = 4; + optional float float_value = 5; + optional double double_value = 6; + optional bytes out_of_line_data = 7; + optional int64 datetime_value = 8; + optional int64 datetime_interval_value = 9; + optional int64 year_month_interval_value = 10; message DateLit { required int32 year = 1; @@ -40,5 +41,5 @@ message TypedValue { required uint32 day = 3; } - optional DateLit date_value = 10; + optional DateLit date_value = 11; } diff --git a/types/VarCharType.cpp b/types/VarCharType.cpp index 02845b1f..6f5f9fbf 100644 --- a/types/VarCharType.cpp +++ b/types/VarCharType.cpp @@ -42,38 +42,6 @@ using std::string; namespace quickstep { -template -const VarCharType& VarCharType::InstanceInternal(const std::size_t length) { - static PtrMap instance_map; - PtrMap::iterator imit = instance_map.find(length); - if (imit == instance_map.end()) { - imit = instance_map.insert(length, new VarCharType(length, nullable_internal)).first; - } - return *(imit->second); -} - -const VarCharType& VarCharType::InstanceNonNullable(const std::size_t length) { - return InstanceInternal(length); -} - -const VarCharType& VarCharType::InstanceNullable(const std::size_t length) { - return InstanceInternal(length); -} - -const VarCharType& VarCharType::InstanceFromProto(const serialization::Type &proto) { - return Instance(proto.GetExtension(serialization::VarCharType::length), proto.nullable()); -} - -serialization::Type VarCharType::getProto() const { - serialization::Type proto; - proto.set_type_id(serialization::Type::VAR_CHAR); - - proto.set_nullable(nullable_); - - proto.SetExtension(serialization::VarCharType::length, length_); - return proto; -} - size_t VarCharType::estimateAverageByteLength() const { if (length_ > 160) { return 80; @@ -118,25 +86,25 @@ string VarCharType::getName() const { return name; } -std::string VarCharType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); +std::string VarCharType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); - return std::string(static_cast(value.getOutOfLineData())); + return std::string(static_cast(castValueToLiteral(value).getOutOfLineData())); } -void VarCharType::printValueToFile(const TypedValue &value, +void VarCharType::printValueToFile(const UntypedLiteral *value, FILE *file, const int padding) const { - DCHECK(!value.isNull()); + DCHECK(value != nullptr); std::fprintf(file, "%*s", static_cast(padding), - static_cast(value.getOutOfLineData())); + static_cast(castValueToLiteral(value).getOutOfLineData())); } -bool VarCharType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool VarCharType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { if (value_string.length() > length_) { return false; } @@ -146,8 +114,8 @@ bool VarCharType::parseValueFromString(const std::string &value_string, return true; } -TypedValue VarCharType::coerceValue(const TypedValue &original_value, - const Type &original_type) const { +TypedValue VarCharType::coerceTypedValue(const TypedValue &original_value, + const Type &original_type) const { DCHECK(isCoercibleFrom(original_type)) << "Can't coerce value of Type " << original_type.getName() << " to Type " << getName(); diff --git a/types/VarCharType.hpp b/types/VarCharType.hpp index bb50e926..639d0fbc 100644 --- a/types/VarCharType.hpp +++ b/types/VarCharType.hpp @@ -24,8 +24,8 @@ #include #include +#include "types/AsciiStringSuperType.hpp" #include "types/Type.hpp" -#include "types/Type.pb.h" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" #include "utility/Macros.hpp" @@ -43,71 +43,8 @@ namespace quickstep { * character. This means that the VARCHAR(X) type requires from 1 to X+1 * bytes of storage, depending on string length. **/ -class VarCharType : public AsciiStringSuperType { +class VarCharType final : public AsciiStringSuperType { public: - /** - * @brief Get a reference to the non-nullable singleton instance of this Type - * for the specified length. - * - * @param length The length parameter of the VarCharType. - * @return A reference to the non-nullable singleton instance of this Type - * for the specified length. - **/ - static const VarCharType& InstanceNonNullable(const std::size_t length); - - /** - * @brief Get a reference to the nullable singleton instance of this Type for - * the specified length. - * - * @param length The length parameter of the VarCharType. - * @return A reference to the nullable singleton instance of this Type for - * the specified length. - **/ - static const VarCharType& InstanceNullable(const std::size_t length); - - /** - * @brief Get a reference to the singleton instance of this Type for the - * specified length and nullability. - * - * @param length The length parameter of the VarCharType. - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the singleton instance of this Type for the - * specified length and nullability. - **/ - static const VarCharType& Instance(const std::size_t length, const bool nullable) { - if (nullable) { - return InstanceNullable(length); - } else { - return InstanceNonNullable(length); - } - } - - /** - * @brief Get a reference to the singleton instance of this Type described - * by the given Protocol Buffer serialization. - * - * @param type The serialized Protocol Buffer representation of the desired - * VarCharType. - * @return A reference to the singleton instance of this Type for the given - * Protocol Buffer. - **/ - static const VarCharType& InstanceFromProto(const serialization::Type &type); - - /** - * @brief Generate a serialized Protocol Buffer representation of this Type. - * - * @return The serialized Protocol Buffer representation of this Type. - **/ - serialization::Type getProto() const override; - - const Type& getNullableVersion() const override { - return InstanceNullable(length_); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(length_); - } - /** * @note Includes an extra byte for a terminating null character. **/ @@ -123,27 +60,23 @@ class VarCharType : public AsciiStringSuperType { return length_; } - std::string printValueToString(const TypedValue &value) const override; + std::string printValueToString(const UntypedLiteral *value) const override; - void printValueToFile(const TypedValue &value, + void printValueToFile(const UntypedLiteral *value, FILE *file, const int padding = 0) const override; - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; - TypedValue coerceValue(const TypedValue &original_value, - const Type &original_type) const override; + TypedValue coerceTypedValue(const TypedValue &original_value, + const Type &original_type) const override; private: - VarCharType(const std::size_t length, const bool nullable) - : AsciiStringSuperType(kVarChar, nullable, 1, length + 1, length) { - } - - template - static const VarCharType& InstanceInternal(const std::size_t length); + VarCharType(const bool nullable, const std::size_t length) + : AsciiStringSuperType(nullable, 1, length + 1, length) {} - DISALLOW_COPY_AND_ASSIGN(VarCharType); + QUICKSTEP_SYNTHESIZE_TYPE(VarCharType); }; /** @} */ diff --git a/types/YearMonthIntervalType.cpp b/types/YearMonthIntervalType.cpp index 3c15a914..f266bf12 100644 --- a/types/YearMonthIntervalType.cpp +++ b/types/YearMonthIntervalType.cpp @@ -30,7 +30,6 @@ #include "types/IntervalLit.hpp" #include "types/IntervalParser.hpp" -#include "types/NullCoercibilityCheckMacro.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" #include "types/TypedValue.hpp" @@ -46,20 +45,10 @@ using std::snprintf; namespace quickstep { -bool YearMonthIntervalType::isCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kYearMonthInterval); -} - -bool YearMonthIntervalType::isSafelyCoercibleFrom(const Type &original_type) const { - QUICKSTEP_NULL_COERCIBILITY_CHECK(); - return (original_type.getTypeID() == kYearMonthInterval); -} +std::string YearMonthIntervalType::printValueToString(const UntypedLiteral *value) const { + DCHECK(value != nullptr); -std::string YearMonthIntervalType::printValueToString(const TypedValue &value) const { - DCHECK(!value.isNull()); - - std::int64_t months = value.getLiteral().months; + std::int64_t months = castValueToLiteral(value).months; const bool negative_interval = months < 0; if (negative_interval) { months = -months; @@ -127,16 +116,8 @@ std::string YearMonthIntervalType::printValueToString(const TypedValue &value) c return std::string(interval_buf); } -void YearMonthIntervalType::printValueToFile(const TypedValue &value, - FILE *file, - const int padding) const { - // We simply re-use the logic from printValueToString(), as trying to do - // padding on-the fly with so many different fields is too much of a hassle. - std::fprintf(file, "%*s", static_cast(padding), printValueToString(value).c_str()); -} - -bool YearMonthIntervalType::parseValueFromString(const std::string &value_string, - TypedValue *value) const { +bool YearMonthIntervalType::parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const { // Try simple-format parse first. std::int64_t count; std::string units; diff --git a/types/YearMonthIntervalType.hpp b/types/YearMonthIntervalType.hpp index a2ba1759..c729411f 100644 --- a/types/YearMonthIntervalType.hpp +++ b/types/YearMonthIntervalType.hpp @@ -27,6 +27,7 @@ #include "types/IntervalLit.hpp" #include "types/Type.hpp" #include "types/TypeID.hpp" +#include "types/TypeSynthesizer.hpp" #include "types/TypedValue.hpp" #include "utility/Macros.hpp" @@ -39,86 +40,26 @@ namespace quickstep { /** * @brief A type representing the year-month interval. **/ -class YearMonthIntervalType : public Type { +class YearMonthIntervalType final : public TypeSynthesizer { public: - typedef YearMonthIntervalLit cpptype; - - static const TypeID kStaticTypeID = kYearMonthInterval; - - /** - * @brief Get a reference to the non-nullable singleton instance of this - * Type. - * - * @return A reference to the non-nullable singleton instance of this Type. - **/ - static const YearMonthIntervalType& InstanceNonNullable() { - static YearMonthIntervalType instance(false); - return instance; - } - - /** - * @brief Get a reference to the nullable singleton instance of this Type. - * - * @return A reference to the nullable singleton instance of this Type. - **/ - static const YearMonthIntervalType& InstanceNullable() { - static YearMonthIntervalType instance(true); - return instance; - } - - /** - * @brief Get a reference to a singleton instance of this Type. - * - * @param nullable Whether to get the nullable version of this Type. - * @return A reference to the desired singleton instance of this Type. - **/ - static const YearMonthIntervalType& Instance(const bool nullable) { - if (nullable) { - return InstanceNullable(); - } else { - return InstanceNonNullable(); - } - } - - const Type& getNullableVersion() const override { - return InstanceNullable(); - } - - const Type& getNonNullableVersion() const override { - return InstanceNonNullable(); - } - - std::size_t estimateAverageByteLength() const override { - return sizeof(YearMonthIntervalLit); - } - - bool isCoercibleFrom(const Type &original_type) const override; - - bool isSafelyCoercibleFrom(const Type &original_type) const override; - int getPrintWidth() const override { return YearMonthIntervalLit::kPrintingChars; } - std::string printValueToString(const TypedValue &value) const override; - - void printValueToFile(const TypedValue &value, - FILE *file, - const int padding = 0) const override; + std::string printValueToString(const UntypedLiteral *value) const override; TypedValue makeZeroValue() const override { return TypedValue(YearMonthIntervalLit{0}); } - bool parseValueFromString(const std::string &value_string, - TypedValue *value) const override; + bool parseTypedValueFromString(const std::string &value_string, + TypedValue *value) const override; private: explicit YearMonthIntervalType(const bool nullable) - : Type(Type::kOther, kYearMonthInterval, nullable, sizeof(YearMonthIntervalLit), sizeof(YearMonthIntervalLit)) { - } + : TypeSynthesizer(nullable) {} - DISALLOW_COPY_AND_ASSIGN(YearMonthIntervalType); + QUICKSTEP_SYNTHESIZE_TYPE(YearMonthIntervalType); }; /** @} */ diff --git a/types/containers/CMakeLists.txt b/types/containers/CMakeLists.txt index 97841c22..675805aa 100644 --- a/types/containers/CMakeLists.txt +++ b/types/containers/CMakeLists.txt @@ -29,6 +29,7 @@ add_library(quickstep_types_containers_Tuple_proto ${types_containers_Tuple_prot target_link_libraries(quickstep_types_containers_ColumnVector glog quickstep_types_Type + quickstep_types_TypeRegistrar quickstep_types_TypedValue quickstep_utility_BitVector quickstep_utility_Macros) diff --git a/types/containers/ColumnVector.cpp b/types/containers/ColumnVector.cpp index dfc0fae6..476acccb 100644 --- a/types/containers/ColumnVector.cpp +++ b/types/containers/ColumnVector.cpp @@ -21,6 +21,12 @@ #include +#include "types/TypeID.hpp" +#include "types/TypeUtil.hpp" +#include "types/TypeRegistrar.hpp" +#include "types/TypeIDSelectors.hpp" +#include "utility/Macros.hpp" + namespace quickstep { class Type; @@ -30,15 +36,36 @@ ColumnVector* ColumnVector::MakeVectorOfValue( const Type &value_type, const TypedValue &value, const std::size_t num_copies) { - if (NativeColumnVector::UsableForType(value_type)) { - NativeColumnVector *result = new NativeColumnVector(value_type, num_copies); - result->fillWithValue(value); - return result; - } else { - IndirectColumnVector *result = new IndirectColumnVector(value_type, num_copies); - result->fillWithValue(value); - return result; + switch (value_type.getMemoryLayout()) { + case kCxxInlinePod: // Fall through + case kParInlinePod: { + NativeColumnVector *result = new NativeColumnVector(value_type, num_copies); + result->fillWithValue(value); + return result; + } + case kParOutOfLinePod: { + IndirectColumnVector *result = new IndirectColumnVector(value_type, num_copies); + result->fillWithValue(value); + return result; + } + case kCxxGeneric: { + // TODO(refactor-type): Omit non-supported types. + return InvokeOnTypeID>( + value_type.getTypeID(), + [&](auto tid) -> ColumnVector* { + using TypeClass = typename TypeIDTrait::TypeClass; + GenericColumnVector *result = + new GenericColumnVector(value_type, num_copies); + result->fillWithValue(value); + return result; + }); + } } + QUICKSTEP_UNREACHABLE(); } +constexpr ColumnVector::Implementation NativeColumnVector::kImplementation; + +constexpr ColumnVector::Implementation IndirectColumnVector::kImplementation; + } // namespace quickstep diff --git a/types/containers/ColumnVector.hpp b/types/containers/ColumnVector.hpp index 5ef98717..18b8b864 100644 --- a/types/containers/ColumnVector.hpp +++ b/types/containers/ColumnVector.hpp @@ -28,6 +28,7 @@ #include #include "types/Type.hpp" +#include "types/TypeRegistrar.hpp" #include "types/TypedValue.hpp" #include "utility/BitVector.hpp" #include "utility/Macros.hpp" @@ -70,13 +71,25 @@ typedef std::shared_ptr ColumnVectorPtr; **/ class ColumnVector { public: + /** + * @brief Enum with cases for different subclasses of ColumnVector. + */ + enum Implementation { + kNative = 0, + kIndirect, + kGeneric + }; + /** * @brief Constructor. * * @param type The Type of values to hold. **/ - explicit ColumnVector(const Type &type) - : type_(type) { + explicit ColumnVector(const Implementation implementation, + const Type &type) + : implementation_(implementation), + type_(type) { + // TODO: check that impl matches type. } /** @@ -101,14 +114,15 @@ class ColumnVector { const TypedValue &value, const std::size_t num_copies); + /** - * @brief Check whether this ColumnVector is a NativeColumnVector or an - * IndirectColumnVector. + * @brief Determine the concrete type of this ColumnVector. * - * @return true if this is a NativeColumnVector, false if this is an - * IndirectColumnVector. + * @return The implementation type of this ColumnVector. **/ - virtual bool isNative() const = 0; + inline Implementation getImplementation() const { + return implementation_; + } /** * @brief Get the number of values in this ColumnVector. @@ -117,7 +131,12 @@ class ColumnVector { **/ virtual std::size_t size() const = 0; + virtual TypedValue getTypedValueVirtual(const std::size_t position) const { + LOG(FATAL) << "Unexpected call to ColumnVector::getTypedValueVirtual()"; + } + protected: + const Implementation implementation_; const Type &type_; private: @@ -129,6 +148,8 @@ class ColumnVector { **/ class NativeColumnVector : public ColumnVector { public: + static constexpr Implementation kImplementation = ColumnVector::kNative; + /** * @brief Constructor for a NativeColumnVector which owns its own array of * values. @@ -138,16 +159,13 @@ class NativeColumnVector : public ColumnVector { * NativeColumnVector will hold. **/ NativeColumnVector(const Type &type, const std::size_t reserved_length) - : ColumnVector(type), + : ColumnVector(kImplementation, type), type_length_(type.maximumByteLength()), - values_(std::malloc(type.maximumByteLength() * reserved_length)), reserved_length_(reserved_length), + values_(std::malloc(type.maximumByteLength() * reserved_length)), actual_length_(0u), null_bitmap_(type.isNullable() ? new BitVector(reserved_length) : nullptr) { DCHECK(UsableForType(type_)); - if (null_bitmap_) { - null_bitmap_->clear(); - } } /** @@ -165,11 +183,8 @@ class NativeColumnVector : public ColumnVector { * IndirectColumnVector must be used instead. **/ static bool UsableForType(const Type &type) { - return !type.isVariableLength(); - } - - bool isNative() const override { - return true; + return type.getMemoryLayout() == kCxxInlinePod || + type.getMemoryLayout() == kParInlinePod; } /** @@ -256,7 +271,8 @@ class NativeColumnVector : public ColumnVector { **/ inline void appendTypedValue(const TypedValue &value) { DCHECK_LT(actual_length_, reserved_length_); - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. if (null_bitmap_ && value.isNull()) { null_bitmap_->setBit(actual_length_, true); } else { @@ -295,7 +311,8 @@ class NativeColumnVector : public ColumnVector { * @param value A value to fill this ColumnVector with. **/ inline void fillWithValue(const TypedValue &value) { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. if (value.isNull()) { fillWithNulls(); } else { @@ -384,7 +401,8 @@ class NativeColumnVector : public ColumnVector { inline void positionalWriteTypedValue(const std::size_t position, const TypedValue &value) { DCHECK_LT(position, actual_length_); - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. if (null_bitmap_ && value.isNull()) { null_bitmap_->setBit(position, true); } else { @@ -395,8 +413,9 @@ class NativeColumnVector : public ColumnVector { private: const std::size_t type_length_; - void *values_; const std::size_t reserved_length_; + + void *values_; std::size_t actual_length_; std::unique_ptr> null_bitmap_; @@ -409,6 +428,8 @@ class NativeColumnVector : public ColumnVector { **/ class IndirectColumnVector : public ColumnVector { public: + static constexpr Implementation kImplementation = ColumnVector::kIndirect; + /** * @brief Constructor. * @@ -416,7 +437,7 @@ class IndirectColumnVector : public ColumnVector { * @param reserved_length The number of values to reserve space for. **/ IndirectColumnVector(const Type &type, const std::size_t reserved_length) - : ColumnVector(type), + : ColumnVector(kImplementation, type), type_is_nullable_(type.isNullable()), reserved_length_(reserved_length) { values_.reserve(reserved_length); @@ -428,10 +449,6 @@ class IndirectColumnVector : public ColumnVector { ~IndirectColumnVector() override { } - bool isNative() const override { - return false; - } - /** * @brief Determine if this IndirectColumnVector's Type is nullable. * @@ -492,7 +509,8 @@ class IndirectColumnVector : public ColumnVector { * @param value A value to append to this NativeColumnVector. **/ inline void appendTypedValue(const TypedValue &value) { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. DCHECK_LT(values_.size(), reserved_length_); values_.emplace_back(value); } @@ -503,18 +521,30 @@ class IndirectColumnVector : public ColumnVector { * @param value A value to append to this NativeColumnVector. **/ inline void appendTypedValue(TypedValue &&value) { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())) << type_.getName(); + // TODO(refactor-type): fix signature. DCHECK_LT(values_.size(), reserved_length_); values_.emplace_back(std::move(value)); } + inline void appendNullValue() { + DCHECK(type_.isNullable()); + DCHECK_LT(values_.size(), reserved_length_); + values_.emplace_back(type_.makeNullValue()); + } + + inline void fillWithNulls() { + fillWithValue(type_.makeNullValue()); + } + /** * @brief Fill this entire ColumnVector with copies of value. * * @param value A value to fill this ColumnVector with. **/ inline void fillWithValue(const TypedValue &value) { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. values_.assign(reserved_length_, value); } @@ -543,7 +573,8 @@ class IndirectColumnVector : public ColumnVector { **/ inline void positionalWriteTypedValue(const std::size_t position, const TypedValue &value) { - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. DCHECK_LT(position, values_.size()); values_[position] = value; } @@ -561,7 +592,8 @@ class IndirectColumnVector : public ColumnVector { **/ inline void positionalWriteTypedValue(const std::size_t position, TypedValue &&value) { // NOLINT(whitespace/operators) - DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); +// DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); + // TODO(refactor-type): fix signature. DCHECK_LT(position, values_.size()); values_[position] = std::move(value); } @@ -569,11 +601,108 @@ class IndirectColumnVector : public ColumnVector { private: const bool type_is_nullable_; const std::size_t reserved_length_; + std::vector values_; DISALLOW_COPY_AND_ASSIGN(IndirectColumnVector); }; +template +class GenericColumnVector : public ColumnVector { + public: + static constexpr Implementation kImplementation = ColumnVector::kGeneric; + + using cpptype = typename TypeClass::cpptype; + + GenericColumnVector(const Type &type, const std::size_t reserved_length) + : ColumnVector(kImplementation, type), + type_(static_cast(type)), + reserved_length_(reserved_length) { + DCHECK(TypeClass::kStaticTypeID == type.getTypeID()); + values_.reserve(reserved_length_); + if (type.isNullable()) { + null_bitmap_ = std::make_unique>(reserved_length_); + } + } + + static bool UsableForType(const Type &type) { + return type.getMemoryLayout() == kCxxGeneric; + } + + inline bool typeIsNullable() const { + return null_bitmap_.get() != nullptr; + } + + inline std::size_t size() const override { + return values_.size(); + } + + template + inline cpptype& getLiteralValue(const std::size_t position) const { + DCHECK_LT(position, values_.size()); + return (check_null && null_bitmap_ && null_bitmap_->getBit(position)) + ? nullptr + : values_[position]; + } + + TypedValue getTypedValueVirtual(const std::size_t position) const override { + return getTypedValue(position); + } + + inline TypedValue getTypedValue(const std::size_t position) const { + DCHECK_LT(position, values_.size()); + // TODO(refactor-type): Implement marshallValueMaybeReference() to improve performance. + return (null_bitmap_ && null_bitmap_->getBit(position)) + ? type_.makeNullValue() + : type_.marshallValue(&values_[position]); + } + + inline void appendNullValue() { + DCHECK_LT(values_.size(), reserved_length_); + DCHECK(null_bitmap_); + null_bitmap_->setBit(values_.size(), true); + // TODO(refactor-type): Specialize nullable GenericColumnVector. + LOG(FATAL) << "Not implemented"; + } + + inline void fillWithNulls() { + DCHECK(null_bitmap_); + null_bitmap_->setBitRange(0, reserved_length_, true); + // TODO(refactor-type): Specialize nullable GenericColumnVector. + LOG(FATAL) << "Not implemented"; + } + + inline void fillWithValue(const TypedValue &value) { + std::unique_ptr cppvalue = std::unique_ptr( + static_cast(type_.unmarshallTypedValue(value))); + for (std::size_t i = 0; i < reserved_length_; ++i) { + values_.emplace_back(*cppvalue); + } + } + + inline void appendLiteralValue(const cpptype &value) { + DCHECK_LT(values_.size(), reserved_length_); + values_.emplace_back(value); + } + + inline void appendLiteralValue(cpptype &&value) { + DCHECK_LT(values_.size(), reserved_length_); + values_.emplace_back(std::move(value)); + } + + private: + const TypeClass &type_; + const std::size_t reserved_length_; + + std::vector values_; + std::unique_ptr> null_bitmap_; + + DISALLOW_COPY_AND_ASSIGN(GenericColumnVector); +}; + +template +constexpr ColumnVector::Implementation GenericColumnVector::kImplementation; + /** @} */ } // namespace quickstep diff --git a/types/containers/ColumnVectorUtil.hpp b/types/containers/ColumnVectorUtil.hpp index 5a560a47..e241a216 100644 --- a/types/containers/ColumnVectorUtil.hpp +++ b/types/containers/ColumnVectorUtil.hpp @@ -22,6 +22,8 @@ #include "types/containers/ColumnVector.hpp" +#include "glog/logging.h" + namespace quickstep { /** \addtogroup Types @@ -43,9 +45,11 @@ namespace quickstep { template auto InvokeOnColumnVector(const ColumnVector &column_vector, const FunctorT &functor) { - if (column_vector.isNative()) { + // TODO(refactor-type): + if (column_vector.getImplementation() == ColumnVector::kNative) { return functor(static_cast(column_vector)); } else { + DCHECK(column_vector.getImplementation() == ColumnVector::kIndirect); return functor(static_cast(column_vector)); } } diff --git a/types/containers/ColumnVectorsValueAccessor.hpp b/types/containers/ColumnVectorsValueAccessor.hpp index ebd46d4d..bec232f8 100644 --- a/types/containers/ColumnVectorsValueAccessor.hpp +++ b/types/containers/ColumnVectorsValueAccessor.hpp @@ -38,6 +38,7 @@ namespace quickstep { class TupleIdSequence; +typedef void UntypedLiteral; /** * @brief Implementation of ValueAccessor as a group of equal-length @@ -73,12 +74,12 @@ class ColumnVectorsValueAccessor : public ValueAccessor { * this value-accessor is responsible for freeing this column * vector. **/ - void addColumn(ColumnVectorPtr column) { + void addColumn(const ColumnVectorPtr &column) { // If this is not the first column to be added, make sure it is the same // length as the others. DCHECK(columns_.empty() || column->size() == column_length_); - columns_.push_back(column); - column_native_.push_back(column->isNative()); + columns_.emplace_back(column); + column_impl_.emplace_back(column->getImplementation()); column_length_ = column->size(); } @@ -151,10 +152,15 @@ class ColumnVectorsValueAccessor : public ValueAccessor { const tuple_id tid) const { DCHECK(attributeIdInRange(attr_id)); DCHECK(tupleIdInRange(tid)); - if (column_native_[attr_id]) { - return static_cast(*columns_[attr_id]).getUntypedValue(tid); - } else { - return static_cast(*columns_[attr_id]).getUntypedValue(tid); + // TODO(jianqiao): Implement specialized column accessors to improve performance. + switch (column_impl_[attr_id]) { + case ColumnVector::kNative: + return static_cast(*columns_[attr_id]).getUntypedValue(tid); + case ColumnVector::kIndirect: + return static_cast(*columns_[attr_id]).getUntypedValue(tid); + default: + LOG(FATAL) << "Can not apply getUntypedValueAtAbsolutionPosition() to " + << "GenericColumnVector"; } } @@ -162,14 +168,18 @@ class ColumnVectorsValueAccessor : public ValueAccessor { const tuple_id tid) const { DCHECK(attributeIdInRange(attr_id)); DCHECK(tupleIdInRange(tid)); - if (column_native_[attr_id]) { - return static_cast(*columns_[attr_id]) - .getTypedValue(tid) - .makeReferenceToThis(); - } else { - return static_cast(*columns_[attr_id]) - .getTypedValue(tid) - .makeReferenceToThis(); + // TODO(jianqiao): Implement specialized column accessors to improve performance. + switch (column_impl_[attr_id]) { + case ColumnVector::kNative: + return static_cast(*columns_[attr_id]) + .getTypedValue(tid) + .makeReferenceToThis(); + case ColumnVector::kIndirect: + return static_cast(*columns_[attr_id]) + .getTypedValue(tid) + .makeReferenceToThis(); + case ColumnVector::kGeneric: + return columns_[attr_id]->getTypedValueVirtual(tid); } } @@ -304,7 +314,7 @@ class ColumnVectorsValueAccessor : public ValueAccessor { } std::vector columns_; - std::vector column_native_; + std::vector column_impl_; std::size_t column_length_; std::size_t current_position_; diff --git a/types/operations/CMakeLists.txt b/types/operations/CMakeLists.txt index c5dad0f8..1e622dd6 100644 --- a/types/operations/CMakeLists.txt +++ b/types/operations/CMakeLists.txt @@ -18,6 +18,7 @@ add_subdirectory(binary_operations) add_subdirectory(comparisons) add_subdirectory(unary_operations) +add_subdirectory(utility) QS_PROTOBUF_GENERATE_CPP(types_operations_Operation_proto_srcs types_operations_Operation_proto_hdrs @@ -25,20 +26,56 @@ QS_PROTOBUF_GENERATE_CPP(types_operations_Operation_proto_srcs # Declare micro-libs: add_library(quickstep_types_operations_Operation Operation.cpp Operation.hpp) +add_library(quickstep_types_operations_OperationFactory OperationFactory.cpp OperationFactory.hpp) +add_library(quickstep_types_operations_OperationSignature OperationSignature.cpp OperationSignature.hpp) add_library(quickstep_types_operations_Operation_proto ${types_operations_Operation_proto_srcs}) # Link dependencies: target_link_libraries(quickstep_types_operations_Operation + quickstep_types_operations_OperationSignature + quickstep_utility_Macros) +target_link_libraries(quickstep_types_operations_OperationFactory + quickstep_types_Type + quickstep_types_TypeFactory + quickstep_types_TypeID + quickstep_types_TypeUtil + quickstep_types_operations_Operation + quickstep_types_operations_OperationSignature + quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctors + quickstep_types_operations_binaryoperations_AsciiStringBinaryFunctors + quickstep_types_operations_binaryoperations_BinaryOperation + quickstep_types_operations_binaryoperations_BinaryOperationSynthesizer + quickstep_types_operations_binaryoperations_CMathBinaryFunctors + quickstep_types_operations_unaryoperations_ArithmeticUnaryFunctors + quickstep_types_operations_unaryoperations_AsciiStringUnaryFunctors + quickstep_types_operations_unaryoperations_CMathUnaryFunctors + quickstep_types_operations_unaryoperations_CastOperation + quickstep_types_operations_unaryoperations_DateExtractOperation + quickstep_types_operations_unaryoperations_SubstringOperation + quickstep_types_operations_unaryoperations_UnaryOperation + quickstep_types_operations_unaryoperations_UnaryOperationSynthesizer + quickstep_utility_HashPair + quickstep_utility_Macros + quickstep_utility_StringUtil) +target_link_libraries(quickstep_types_operations_OperationSignature + quickstep_types_TypeID + quickstep_types_Type_proto + quickstep_types_operations_Operation_proto + quickstep_utility_HashPair quickstep_utility_Macros) target_link_libraries(quickstep_types_operations_Operation_proto quickstep_types_Type_proto + quickstep_types_TypedValue_proto ${PROTOBUF_LIBRARY}) # Module all-in-one library: add_library(quickstep_types_operations ../../empty_src.cpp) target_link_libraries(quickstep_types_operations quickstep_types_operations_Operation + quickstep_types_operations_OperationFactory + quickstep_types_operations_OperationSignature quickstep_types_operations_Operation_proto quickstep_types_operations_binaryoperations quickstep_types_operations_comparisons - quickstep_types_operations_unaryoperations) + quickstep_types_operations_unaryoperations + quickstep_types_operations_utility) diff --git a/types/operations/Operation.hpp b/types/operations/Operation.hpp index 51178b5a..6da0f4c4 100644 --- a/types/operations/Operation.hpp +++ b/types/operations/Operation.hpp @@ -20,6 +20,10 @@ #ifndef QUICKSTEP_TYPES_OPERATIONS_OPERATION_HPP_ #define QUICKSTEP_TYPES_OPERATIONS_OPERATION_HPP_ +#include +#include + +#include "types/operations/OperationSignature.hpp" #include "utility/Macros.hpp" namespace quickstep { @@ -28,6 +32,9 @@ namespace quickstep { * @{ */ +class Operation; +typedef std::shared_ptr OperationPtr; + /** * @brief An operation which can be applied to typed values. Each exact * concrete Operation is a singleton. @@ -72,7 +79,7 @@ class Operation { * @return The human-readable name of this Operation. **/ inline const char* getName() const { - return name_; + return "NoName"; } /** @@ -81,7 +88,11 @@ class Operation { * @return The short name of this Operation. **/ inline const char* getShortName() const { - return short_name_; + return "NoShortName"; + } + + virtual std::vector getSignatures() const { + return {}; } /** @@ -98,19 +109,12 @@ class Operation { } protected: - Operation(const OperationSuperTypeID super_type_id, - const char *name, - const char *short_name) - : super_type_id_(super_type_id), - name_(name), - short_name_(short_name) { + explicit Operation(const OperationSuperTypeID super_type_id) + : super_type_id_(super_type_id) { } private: const OperationSuperTypeID super_type_id_; - const char *name_; - const char *short_name_; - DISALLOW_COPY_AND_ASSIGN(Operation); }; diff --git a/types/operations/Operation.proto b/types/operations/Operation.proto index d6391f00..da2a2828 100644 --- a/types/operations/Operation.proto +++ b/types/operations/Operation.proto @@ -20,6 +20,7 @@ syntax = "proto2"; package quickstep.serialization; import "types/Type.proto"; +import "types/TypedValue.proto"; message Comparison { enum ComparisonID { @@ -38,58 +39,8 @@ message Comparison { required ComparisonID comparison_id = 1; } -message UnaryOperation { - enum UnaryOperationID { - NEGATE = 0; - CAST = 1; - DATE_EXTRACT = 2; - SUBSTRING = 3; - } - - required UnaryOperationID operation_id = 1; - - extensions 32 to max; -} - -message CastOperation { - extend UnaryOperation { - // Required when operation_id = CAST. - optional Type target_type = 64; - } -} - -message DateExtractOperation { - enum Unit { - YEAR = 0; - MONTH = 1; - DAY = 2; - HOUR = 3; - MINUTE = 4; - SECOND = 5; - } - - extend UnaryOperation { - // Required when operation_id = DATE_EXTRACT. - optional Unit unit = 96; - } -} - -message SubstringOperation { - extend UnaryOperation { - // Required when operation_id = SUBSTRING. - optional int64 start_position = 100; - optional int64 substring_length = 101; - } -} - -message BinaryOperation { - enum BinaryOperationID { - ADD = 0; - SUBTRACT = 1; - MULTIPLY = 2; - DIVIDE = 3; - MODULO = 4; - } - - required BinaryOperationID operation_id = 1; +message OperationSignature { + required string operation_name = 1; + repeated TypeID argument_type_ids = 2; + required uint32 num_static_arguments = 3; } diff --git a/types/operations/OperationFactory.cpp b/types/operations/OperationFactory.cpp new file mode 100644 index 00000000..af0ddc9c --- /dev/null +++ b/types/operations/OperationFactory.cpp @@ -0,0 +1,579 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#include "types/operations/OperationFactory.hpp" + +#include +#include +#include +#include + +#include "types/GenericValue.hpp" +#include "types/Type.hpp" +#include "types/TypeFactory.hpp" +#include "types/TypeID.hpp" +#include "types/TypeUtil.hpp" +#include "types/operations/Operation.hpp" +#include "types/operations/OperationSignature.hpp" +#include "types/operations/binary_operations/ArithmeticBinaryFunctors.hpp" +#include "types/operations/binary_operations/AsciiStringBinaryFunctors.hpp" +#include "types/operations/binary_operations/BinaryOperationSynthesizer.hpp" +#include "types/operations/binary_operations/CMathBinaryFunctors.hpp" +#include "types/operations/unary_operations/ArithmeticUnaryFunctors.hpp" +#include "types/operations/unary_operations/AsciiStringUnaryFunctors.hpp" +#include "types/operations/unary_operations/CMathUnaryFunctors.hpp" +#include "types/operations/unary_operations/CastOperation.hpp" +#include "types/operations/unary_operations/DateExtractOperation.hpp" +#include "types/operations/unary_operations/SubstringOperation.hpp" +#include "types/operations/unary_operations/UnaryOperationSynthesizer.hpp" +#include "utility/StringUtil.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +namespace { + +struct FunctorPackDispatcher { + template + inline static std::list Generate( + std::enable_if_t* = 0) { + return { std::make_shared>() }; + } + + template + inline static std::list Generate( + std::enable_if_t* = 0) { + return { std::make_shared>() }; + } + + template + inline static std::list Generate( + decltype(FunctorT::template GenerateOperations())* = 0) { + return FunctorT::template GenerateOperations(); + } +}; + +// TODO(refactor-type): Remove this. +inline static std::shared_ptr> ToTypedValue( + const std::vector &input) { + std::vector values; + for (const auto &item : input) { + values.emplace_back(item.toTypedValue()); + } + return std::make_shared>(std::move(values)); +} + +} // namespace + +OperationFactory::OperationFactory() { + registerOperation(); + registerOperation(); + registerOperation(); + + registerFunctorPack(); + registerFunctorPack(); + registerFunctorPack(); + + registerFunctorPack(); + registerFunctorPack(); + registerFunctorPack(); + + initializeTypeIDSafeCoercibility(); +} + +bool OperationFactory::HasOperation(const std::string &operation_name, + const std::size_t arity) { + const auto &primary_index = Instance().primary_index_; + const auto indices_it = + primary_index.find(std::make_pair(operation_name, arity)); + return indices_it != primary_index.end(); +} + +bool OperationFactory::HasOperation(const OperationSignaturePtr &op_signature) { + const auto &operations = Instance().operations_; + return operations.find(op_signature) != operations.end(); +} + +bool OperationFactory::CanApplyUnaryOperation( + const std::string &operation_name, + const Type &type, + const std::vector &static_arguments) { + std::vector argument_type_ids = {type.getTypeID()}; + std::vector static_tv_arguments; + for (const auto &value : static_arguments) { + argument_type_ids.emplace_back(value.getTypeID()); + // TODO(refactor-type): Remove this. + static_tv_arguments.emplace_back(value.toTypedValue()); + } + const OperationSignaturePtr op_signature = + OperationSignature::Create( + operation_name, argument_type_ids, static_arguments.size()); + if (!HasOperation(op_signature)) { + return false; + } + return GetUnaryOperation(op_signature)->canApplyTo(type, static_tv_arguments); +} + +bool OperationFactory::CanApplyBinaryOperation( + const std::string &operation_name, + const Type &left, const Type &right, + const std::vector &static_arguments) { + std::vector argument_type_ids = {left.getTypeID(), right.getTypeID()}; + std::vector static_tv_arguments; + for (const auto &value : static_arguments) { + argument_type_ids.emplace_back(value.getTypeID()); + // TODO(refactor-type): Remove this. + static_tv_arguments.emplace_back(value.toTypedValue()); + } + // TODO(refactor-type): Handle this. + DCHECK_EQ(0u, static_arguments.size()); + const OperationSignaturePtr op_signature = + OperationSignature::Create( + operation_name, argument_type_ids, static_arguments.size()); + if (!HasOperation(op_signature)) { + return false; + } + return GetBinaryOperation(op_signature)->canApplyTo(left, right, static_tv_arguments); +} + +OperationPtr OperationFactory::GetOperation( + const OperationSignaturePtr &op_signature) { + DCHECK(HasOperation(op_signature)); + return Instance().operations_.at(op_signature); +} + + +UnaryOperationPtr OperationFactory::GetUnaryOperation( + const OperationSignaturePtr &op_signature) { + const OperationPtr operation = GetOperation(op_signature); + DCHECK(operation->getOperationSuperTypeID() == Operation::kUnaryOperation); + return std::static_pointer_cast(operation); +} + +BinaryOperationPtr OperationFactory::GetBinaryOperation( + const OperationSignaturePtr &op_signature) { + const OperationPtr operation = GetOperation(op_signature); + DCHECK(operation->getOperationSuperTypeID() == Operation::kBinaryOperation); + return std::static_pointer_cast(operation); +} + +OperationSignaturePtr OperationFactory::ResolveOperation( + const std::string &operation_name, + const std::shared_ptr> &argument_types, + const std::shared_ptr> &static_arguments, + std::shared_ptr> *coerced_argument_types, + std::shared_ptr> *coerced_static_arguments, + std::string *message) { + return Instance().resolveOperation(operation_name, + argument_types, + static_arguments, + coerced_argument_types, + coerced_static_arguments, + message); +} + + +OperationSignaturePtr OperationFactory::resolveOperation( + const std::string &operation_name, + const std::shared_ptr> &argument_types, + const std::shared_ptr> &static_arguments, + std::shared_ptr> *coerced_argument_types, + std::shared_ptr> *coerced_static_arguments, + std::string *message) const { + const std::string lower_case_name = ToLower(operation_name); + const std::size_t arity = argument_types->size(); + const auto &indices_it = + primary_index_.find(std::make_pair(lower_case_name, arity)); + + if (indices_it == primary_index_.end()) { + *message = "Unrecognized function " + operation_name + + " with " + std::to_string(arity) + " arguments"; + } + + ResolveStatus status; + OperationSignaturePtr op_signature = nullptr; + + std::vector argument_type_ids; + for (const auto *type : *argument_types) { + argument_type_ids.emplace_back(type->getTypeID()); + } + + // First, try full exact matching. + status = resolveOperationWithFullTypeMatch(indices_it->second.partial_signature_index, + argument_type_ids, + *argument_types, + *static_arguments, + coerced_static_arguments, + &op_signature, + message); + if (status == ResolveStatus::kSuccess) { + DCHECK(op_signature != nullptr); + *coerced_argument_types = argument_types; + return op_signature; + } else if (status == ResolveStatus::kError) { + return nullptr; + } + + // Otherwise, try partial (non-static arguments) exact matching. + status = resolveOperationWithPartialTypeMatch(indices_it->second.static_arity_index, + argument_type_ids, + *argument_types, + *static_arguments, + coerced_argument_types, + coerced_static_arguments, + &op_signature, + message); + if (status == ResolveStatus::kSuccess) { + DCHECK(op_signature != nullptr); + return op_signature; + } else if (status == ResolveStatus::kError) { + return nullptr; + } + + // TODO(refactor-type): More informative error message. + *message = "Unexpected argument types for function " + operation_name; + return nullptr; +} + +OperationFactory::ResolveStatus OperationFactory::resolveOperationWithFullTypeMatch( + const PartialSignatureIndex &partial_signature_index, + const std::vector &argument_type_ids, + const std::vector &argument_types, + const std::vector &static_arguments, + std::shared_ptr> *coerced_static_arguments, + OperationSignaturePtr *resolved_op_signature, + std::string *message) const { + const std::size_t max_num_static_arguments = static_arguments.size(); + auto it = partial_signature_index.lower_bound( + PartialSignature(&argument_type_ids, max_num_static_arguments)); + + if (it != partial_signature_index.end() && + *it->first.argument_type_ids == argument_type_ids) { + const OperationSignaturePtr op_signature = it->second; + const OperationPtr operation = operations_.at(op_signature); + + *coerced_static_arguments = + std::make_shared>( + static_arguments.begin() + + (max_num_static_arguments - op_signature->getNumStaticArguments()), + static_arguments.end()); + + if (canApplyOperationTo(operation, + argument_types, + **coerced_static_arguments, + message)) { + *resolved_op_signature = op_signature; + return ResolveStatus::kSuccess; + } else { + return ResolveStatus::kError; + } + } + + return ResolveStatus::kNotFound; +} + +OperationFactory::ResolveStatus OperationFactory::resolveOperationWithPartialTypeMatch( + const StaticArityIndex &static_arity_index, + const std::vector &argument_type_ids, + const std::vector &argument_types, + const std::vector &static_arguments, + std::shared_ptr> *coerced_argument_types, + std::shared_ptr> *coerced_static_arguments, + OperationSignaturePtr *resolved_op_signature, + std::string *message) const { + const std::size_t arity = argument_types.size(); + const std::size_t max_num_static_arguments = static_arguments.size(); + const std::size_t first_static_argument_position = arity - max_num_static_arguments; + + const OperationSignaturePtr *best_match_op_sig = nullptr; + const std::vector *best_match_type_ids = nullptr; + std::size_t best_match_num_static_arguments = max_num_static_arguments; + + auto it = static_arity_index.lower_bound(max_num_static_arguments); + while (it != static_arity_index.end()) { + if (it->first != best_match_num_static_arguments) { + if (best_match_op_sig != nullptr) { + break; + } else { + best_match_num_static_arguments = it->first; + } + } + + const auto ¤t_type_ids = it->second->getArgumentTypeIDs(); + + if (canSafelyCoerceTypes(argument_type_ids, current_type_ids)) { + if (best_match_type_ids == nullptr) { + DCHECK(best_match_op_sig == nullptr); + best_match_op_sig = &it->second; + best_match_type_ids = ¤t_type_ids; + } else { + const bool cur_to_best_safe = + canSafelyCoerceTypes(current_type_ids, *best_match_type_ids); + const bool best_to_cur_safe = + canSafelyCoerceTypes(*best_match_type_ids, current_type_ids); + if (cur_to_best_safe == best_to_cur_safe) { + *message = "Ambiguous call to overloaded function " + + it->second->getName() + ", candidates: " + + (*best_match_op_sig)->toString() + " v.s. " + + it->second->toString(); + return ResolveStatus::kError; + } + if (cur_to_best_safe) { + best_match_op_sig = &it->second; + best_match_type_ids = ¤t_type_ids; + } + } + } + + ++it; + } + + if (best_match_op_sig == nullptr) { + return ResolveStatus::kNotFound; + } + + DCHECK(best_match_type_ids != nullptr); + DCHECK_EQ(arity, best_match_type_ids->size()); + std::vector coerced_arg_types; + for (std::size_t i = 0; i < arity; ++i) { + const Type &source_type = *argument_types[i]; + const TypeID target_type_id = (*best_match_type_ids)[i]; + // TODO(refactor-type): Figure out how to better handle this. + if (source_type.getTypeID() == target_type_id) { + coerced_arg_types.emplace_back(&source_type); + } else if (TypeUtil::GetMemoryLayout(target_type_id) == kCxxInlinePod) { + coerced_arg_types.emplace_back( + &TypeFactory::GetType(target_type_id, source_type.isNullable())); + } else if (target_type_id == kChar && source_type.getTypeID() == kVarChar) { + coerced_arg_types.emplace_back( + &CharType::Instance(source_type.isNullable(), + source_type.maximumByteLength() - 1)); + } else if (target_type_id == kVarChar && source_type.getTypeID() == kChar) { + coerced_arg_types.emplace_back( + &VarCharType::Instance(source_type.isNullable(), + source_type.maximumByteLength() + 1)); + } else if (target_type_id == kText) { + coerced_arg_types.emplace_back( + &TextType::Instance(source_type.isNullable())); + } else { + LOG(FATAL) << "Unexpected casting"; + } + } + + std::vector coerced_static_args; + for (std::size_t i = arity - best_match_num_static_arguments; i < arity; ++i) { + const auto &value = static_arguments[i - first_static_argument_position]; + if (coerced_arg_types[i]->equals(*argument_types[i])) { + coerced_static_args.emplace_back(value); + } else { + coerced_static_args.emplace_back(value.coerce(*coerced_arg_types[i])); + } + } + + const OperationPtr operation = operations_.at(*best_match_op_sig); + // TODO(refactor-type): Fix. + if (canApplyOperationTo(operation, + coerced_arg_types, + coerced_static_args, + message)) { + *coerced_argument_types = + std::make_shared>(std::move(coerced_arg_types)); + *coerced_static_arguments = + std::make_shared>(std::move(coerced_static_args)); + *resolved_op_signature = *best_match_op_sig; + return ResolveStatus::kSuccess; + } + + return ResolveStatus::kNotFound; +} + +bool OperationFactory::canSafelyCoerceTypes(const std::vector &source_type_ids, + const std::vector &target_type_ids) const { + if (source_type_ids.size() != target_type_ids.size()) { + return false; + } + for (std::size_t i = 0; i < source_type_ids.size(); ++i) { + const TypeID source_id = source_type_ids[i]; + const TypeID target_id = target_type_ids[i]; + if (source_id != target_id) { + const auto it = type_id_safe_coercibility_.find( + std::make_pair(source_id, target_id)); + if (it == type_id_safe_coercibility_.end()) { + return false; + } + } + } + return true; +} + +void OperationFactory::initializeTypeIDSafeCoercibility() { + // TODO(refactor-type): Figure out how to better handle this. + const std::vector cxx_inline_pod_type_ids = + TypeUtil::GetTypeIDVectorOfMemoryLayout(); + + std::vector cxx_line_pod_types; + for (const TypeID tid : cxx_inline_pod_type_ids) { + cxx_line_pod_types.emplace_back(&TypeFactory::GetType(tid, true)); + } + + for (const Type *source_type : cxx_line_pod_types) { + for (const Type *target_type : cxx_line_pod_types) { + if (target_type->isSafelyCoercibleFrom(*source_type)) { + type_id_safe_coercibility_.emplace( + std::make_pair(source_type->getTypeID(), target_type->getTypeID())); + } + } + } + + for (const TypeID source_id : std::vector({kChar, kVarChar})) { + for (const TypeID target_id : std::vector({kChar, kVarChar, kText})) { + type_id_safe_coercibility_.emplace(std::make_pair(source_id, target_id)); + } + } + type_id_safe_coercibility_.emplace(std::make_pair(kText, kText)); +} + +bool OperationFactory::canApplyOperationTo( + const OperationPtr operation, + const std::vector &argument_types, + const std::vector &static_arguments, + std::string *message) const { + switch (operation->getOperationSuperTypeID()) { + case Operation::kUnaryOperation: { + const UnaryOperationPtr unary_operation = + std::static_pointer_cast(operation); + return unary_operation->canApplyTo(*argument_types[0], + *ToTypedValue(static_arguments), + message); + } + case Operation::kBinaryOperation: { + const BinaryOperationPtr binary_operation = + std::static_pointer_cast(operation); + return binary_operation->canApplyTo(*argument_types[0], + *argument_types[1], + *ToTypedValue(static_arguments), + message); + } + default: { + const auto operation_id = + static_cast>( + operation->getOperationSuperTypeID()); + LOG(FATAL) << "Unknown opeation super type id: " << operation_id; + } + } +} + + +const OperationFactory& OperationFactory::Instance() { + static OperationFactory instance; + return instance; +} + +template +void OperationFactory::registerOperation() { + registerOperationInternal(std::make_shared()); +} + +template +void OperationFactory::registerFunctorPack() { + for (const OperationPtr &operation : + FunctorPackT::template GenerateOperations()) { + registerOperationInternal(operation); + } +} + +void OperationFactory::registerOperationInternal(const OperationPtr &operation) { + DCHECK(operation->getOperationSuperTypeID() == Operation::kUnaryOperation || + operation->getOperationSuperTypeID() == Operation::kBinaryOperation); + + for (const OperationSignaturePtr op_sig_orig : operation->getSignatures()) { + DCHECK(operation->getOperationSuperTypeID() != Operation::kUnaryOperation || + op_sig_orig->getNonStaticArity() == 1u); + DCHECK(operation->getOperationSuperTypeID() != Operation::kBinaryOperation || + op_sig_orig->getNonStaticArity() == 2u); + + const OperationSignaturePtr op_sig = + OperationSignature::Create(ToLower(op_sig_orig->getName()), + op_sig_orig->getArgumentTypeIDs(), + op_sig_orig->getNumStaticArguments()); + + // TODO: print error message for collision + operations_.emplace(op_sig, operation); + primary_index_[std::make_pair(op_sig->getName(), + op_sig->getArity())].addSignature(op_sig); + } +} + + +// ---------------------------------------------------------------------------- +// Implemenation of utility short-cuts. + +bool OperationFactory::CanApplyCastOperation(const Type &source_type, + const Type &target_type) { + const GenericValue target_meta_type_value = + GenericValue::CreateWithLiteral(MetaType::InstanceNonNullable(), + &target_type); + return CanApplyUnaryOperation("cast", source_type, {target_meta_type_value}); +} + +UnaryOperationPtr OperationFactory::GetCastOperation(const TypeID source_id) { + const OperationSignaturePtr op_signature = + OperationSignature::Create("cast", {source_id, kMetaType}, 1); + DCHECK(HasOperation(op_signature)); + return GetUnaryOperation(op_signature); +} + +bool OperationFactory::CanApplyAddOperation(const Type &left, const Type &right) { + return CanApplyBinaryOperation("+", left, right); +} + +BinaryOperationPtr OperationFactory::GetAddOperation(const TypeID left_id, + const TypeID right_id) { + return GetBinaryOperation(OperationSignature::Create("+", {left_id, right_id}, 0)); +} + +bool OperationFactory::CanApplySubtractOperation(const Type &left, const Type &right) { + return CanApplyBinaryOperation("-", left, right); +} + +BinaryOperationPtr OperationFactory::GetSubtractOperation(const TypeID left_id, + const TypeID right_id) { + return GetBinaryOperation(OperationSignature::Create("-", {left_id, right_id}, 0)); +} + +bool OperationFactory::CanApplyMultiplyOperation(const Type &left, const Type &right) { + return CanApplyBinaryOperation("*", left, right); +} + +BinaryOperationPtr OperationFactory::GetMultiplyOperation(const TypeID left_id, + const TypeID right_id) { + return GetBinaryOperation(OperationSignature::Create("*", {left_id, right_id}, 0)); +} + +bool OperationFactory::CanApplyDivideOperation(const Type &left, const Type &right) { + return CanApplyBinaryOperation("/", left, right); +} + +BinaryOperationPtr OperationFactory::GetDivideOperation(const TypeID left_id, + const TypeID right_id) { + return GetBinaryOperation(OperationSignature::Create("/", {left_id, right_id}, 0)); +} + +} // namespace quickstep diff --git a/types/operations/OperationFactory.hpp b/types/operations/OperationFactory.hpp new file mode 100644 index 00000000..f124e9a5 --- /dev/null +++ b/types/operations/OperationFactory.hpp @@ -0,0 +1,243 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_OPERATIONS_OPERATION_FACTORY_HPP_ +#define QUICKSTEP_TYPES_OPERATIONS_OPERATION_FACTORY_HPP_ + +#include +#include +#include +#include +#include + +#include "types/GenericValue.hpp" +#include "types/TypeID.hpp" +#include "types/operations/Operation.hpp" +#include "types/operations/OperationSignature.hpp" +#include "types/operations/binary_operations/BinaryOperation.hpp" +#include "types/operations/unary_operations/UnaryOperation.hpp" +#include "utility/HashPair.hpp" +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +class Type; + +/** \addtogroup Types + * @{ + */ + +class OperationFactory { + public: + static bool HasOperation(const std::string &operation_name, + const std::size_t arity); + + static bool HasOperation(const OperationSignaturePtr &op_signature); + + static bool CanApplyUnaryOperation( + const std::string &operation_name, + const Type &type, + const std::vector &static_arguments = {}); + + static bool CanApplyBinaryOperation( + const std::string &operation_name, + const Type &left, const Type &right, + const std::vector &static_arguments = {}); + + /** + * @brief Get the Operation for a specified operation signature. + */ + static OperationPtr GetOperation(const OperationSignaturePtr &op_signature); + + + /** + * @brief Get the UnaryOperation for a specified operation signature. + */ + static UnaryOperationPtr GetUnaryOperation(const OperationSignaturePtr &op_signature); + + /** + * @brief Get the BinaryOperation for a specified operation signature. + */ + static BinaryOperationPtr GetBinaryOperation(const OperationSignaturePtr &op_signature); + + /** + * @brief Resolve an operation from its name and arguments. + */ + static OperationSignaturePtr ResolveOperation( + const std::string &operation_name, + const std::shared_ptr> &argument_types, + const std::shared_ptr> &static_arguments, + std::shared_ptr> *coerced_argument_types, + std::shared_ptr> *coerced_static_arguments, + std::string *message); + + + // --------------------------------------------------------------------------- + // Utility short-cuts. + + + static bool CanApplyCastOperation(const Type &source_type, const Type &target_type); + + static UnaryOperationPtr GetCastOperation(const TypeID source_id); + + + static bool CanApplyAddOperation(const Type &left, const Type &right); + + static BinaryOperationPtr GetAddOperation(const TypeID left_id, + const TypeID right_id); + + + static bool CanApplySubtractOperation(const Type &left, const Type &right); + + static BinaryOperationPtr GetSubtractOperation(const TypeID left_id, + const TypeID right_id); + + + static bool CanApplyMultiplyOperation(const Type &left, const Type &right); + + static BinaryOperationPtr GetMultiplyOperation(const TypeID left_id, + const TypeID right_id); + + static bool CanApplyDivideOperation(const Type &left, const Type &right); + + static BinaryOperationPtr GetDivideOperation(const TypeID left_id, + const TypeID right_id); + + private: + OperationFactory(); + + static const OperationFactory& Instance(); + + template + void registerOperation(); + + template + void registerFunctorPack(); + + void registerOperationInternal(const OperationPtr &operation); + + struct PartialSignature { + PartialSignature(const std::vector *argument_type_ids_in, + const std::size_t num_static_arguments_in) + : argument_type_ids(argument_type_ids_in), + num_static_arguments(num_static_arguments_in) { + } + inline bool operator<(const PartialSignature &rhs) const { + const PartialSignature &lhs = *this; + const std::vector &lhs_ids = *lhs.argument_type_ids; + const std::vector &rhs_ids = *rhs.argument_type_ids; + int cmp_code = static_cast(lhs_ids.size()) - static_cast(rhs_ids.size()); + if (cmp_code != 0) { + return cmp_code < 0; + } + for (std::size_t i = 0; i < lhs.argument_type_ids->size(); ++i) { + cmp_code = static_cast(lhs_ids[i]) - static_cast(rhs_ids[i]); + if (cmp_code != 0) { + return cmp_code < 0; + } + } + return lhs.num_static_arguments > rhs.num_static_arguments; + } + const std::vector *argument_type_ids; + const std::size_t num_static_arguments; + }; + + using PartialSignatureIndex = std::map; + using StaticArityIndex = std::multimap>; + + struct SecondaryIndex { + inline void addSignature(const OperationSignaturePtr &op_sig) { + partial_signature_index.emplace( + PartialSignature(&op_sig->getArgumentTypeIDs(), + op_sig->getNumStaticArguments()), + op_sig); + static_arity_index.emplace(op_sig->getNumStaticArguments(), op_sig); + } + PartialSignatureIndex partial_signature_index; + StaticArityIndex static_arity_index; + }; + + enum class ResolveStatus { + kSuccess = 0, + kError, + kNotFound + }; + + OperationSignaturePtr resolveOperation( + const std::string &operation_name, + const std::shared_ptr> &argument_types, + const std::shared_ptr> &static_arguments, + std::shared_ptr> *coerced_argument_types, + std::shared_ptr> *coerced_static_arguments, + std::string *message) const; + + ResolveStatus resolveOperationWithFullTypeMatch( + const PartialSignatureIndex &partial_signature_index, + const std::vector &argument_type_ids, + const std::vector &argument_types, + const std::vector &static_arguments, + std::shared_ptr> *coerced_static_arguments, + OperationSignaturePtr *resolved_op_signature, + std::string *message) const; + + ResolveStatus resolveOperationWithPartialTypeMatch( + const StaticArityIndex &static_arity_index, + const std::vector &argument_type_ids, + const std::vector &argument_types, + const std::vector &static_arguments, + std::shared_ptr> *coerced_argument_types, + std::shared_ptr> *coerced_static_arguments, + OperationSignaturePtr *resolved_op_signature, + std::string *message) const; + + bool canSafelyCoerceTypes(const std::vector &source_type_ids, + const std::vector &target_type_ids) const; + + void initializeTypeIDSafeCoercibility(); + + bool canApplyOperationTo(const OperationPtr operation, + const std::vector &argument_types, + const std::vector &static_arguments, + std::string *message) const; + + std::unordered_map operations_; + + std::unordered_map, + SecondaryIndex> primary_index_; + + std::unordered_set> type_id_safe_coercibility_; + + DISALLOW_COPY_AND_ASSIGN(OperationFactory); +}; + + + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_OPERATIONS_OPERATION_FACTORY_HPP_ diff --git a/types/operations/OperationSignature.cpp b/types/operations/OperationSignature.cpp new file mode 100644 index 00000000..6b6c4a61 --- /dev/null +++ b/types/operations/OperationSignature.cpp @@ -0,0 +1,91 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#include "types/operations/OperationSignature.hpp" + +#include +#include +#include +#include + +#include "types/TypeID.hpp" +#include "types/Type.pb.h" +#include "types/operations/Operation.pb.h" + +namespace quickstep { + +serialization::OperationSignature OperationSignature::getProto() const { + serialization::OperationSignature op_signature; + + op_signature.set_operation_name(operation_name_); + for (const TypeID tid : argument_type_ids_) { + op_signature.add_argument_type_ids()->CopyFrom(TypeIDFactory::GetProto(tid)); + } + op_signature.set_num_static_arguments( + static_cast(num_static_arguments_)); + + return op_signature; +} + +OperationSignaturePtr OperationSignature::ReconstructFromProto( + const serialization::OperationSignature &proto) { + std::vector argument_type_ids; + for (int i = 0; i < proto.argument_type_ids_size(); ++i) { + argument_type_ids.emplace_back( + TypeIDFactory::ReconstructFromProto(proto.argument_type_ids(i))); + } + + return Create(proto.operation_name(), + argument_type_ids, + proto.num_static_arguments()); +} + +std::string OperationSignature::toString() const { + const std::size_t num_regular_arguments = + argument_type_ids_.size() - num_static_arguments_; + + std::string str; + str.append(operation_name_); + str.push_back('('); + for (std::size_t i = 0; i < num_regular_arguments; ++i) { + if (i != 0) { + str.append(", "); + } + str.append( + kTypeNames[static_cast>( + argument_type_ids_[i])]); + } + if (num_static_arguments_ > 0) { + str.append(", static("); + for (std::size_t i = 0; i < num_static_arguments_; ++i) { + if (i != 0) { + str.append(", "); + } + str.append( + kTypeNames[static_cast>( + argument_type_ids_[i + num_regular_arguments])]); + } + str.push_back(')'); + } + str.push_back(')'); + + return str; +} + +} // namespace quickstep diff --git a/types/operations/OperationSignature.hpp b/types/operations/OperationSignature.hpp new file mode 100644 index 00000000..6659a85e --- /dev/null +++ b/types/operations/OperationSignature.hpp @@ -0,0 +1,182 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_OPERATIONS_OPERATION_SIGNATURE_HPP_ +#define QUICKSTEP_TYPES_OPERATIONS_OPERATION_SIGNATURE_HPP_ + +#include +#include +#include +#include + +#include "types/TypeID.hpp" +#include "types/operations/Operation.pb.h" + +#include "utility/HashPair.hpp" +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +class OperationSignature; +typedef std::shared_ptr OperationSignaturePtr; + +class OperationSignature { + public: + serialization::OperationSignature getProto() const; + + static OperationSignaturePtr ReconstructFromProto( + const serialization::OperationSignature &proto); + + inline const std::string& getName() const { + return operation_name_; + } + + inline std::size_t getArity() const { + return argument_type_ids_.size(); + } + + inline std::size_t getNonStaticArity() const { + return argument_type_ids_.size() - num_static_arguments_; + } + + inline const std::vector& getArgumentTypeIDs() const { + return argument_type_ids_; + } + + inline std::size_t getNumStaticArguments() const { + return num_static_arguments_; + } + + inline bool operator==(const OperationSignature &r) const { + return operation_name_ == r.operation_name_ + && argument_type_ids_ == r.argument_type_ids_ + && num_static_arguments_ == r.num_static_arguments_; + } + + inline bool operator!=(const OperationSignature &r) const { + return !(*this == r); + } + + inline bool operator<(const OperationSignature &r) const { + int cmp_code = operation_name_.compare(r.operation_name_); + if (cmp_code != 0) { + return cmp_code < 0; + } + cmp_code = static_cast(getArity() - r.getArity()); + if (cmp_code != 0) { + return cmp_code < 0; + } + cmp_code = static_cast(num_static_arguments_ - r.num_static_arguments_); + if (cmp_code != 0) { + return cmp_code > 0; + } + for (std::size_t i = 0; i < getArity(); ++i) { + const auto l_tid = + static_cast>(argument_type_ids_.at(i)); + const auto r_tid = + static_cast>(r.argument_type_ids_.at(i)); + if (l_tid != r_tid) { + return l_tid < r_tid; + } + } + return false; + } + + inline std::size_t hash() const { + std::size_t hash_code = std::hash()(operation_name_); + for (const TypeID tid : argument_type_ids_) { + hash_code = CombineHashes(hash_code, static_cast(tid)); + } + hash_code = CombineHashes(hash_code, num_static_arguments_); + return hash_code; + } + + std::string toString() const; + + static OperationSignaturePtr Create( + const std::string &operation_name, + const std::vector &argument_type_ids, + const std::size_t num_static_arguments) { + return OperationSignaturePtr( + new OperationSignature(operation_name, + argument_type_ids, + num_static_arguments)); + } + + static OperationSignaturePtr Create( + const std::string &operation_name, + const std::vector ®ular_argument_type_ids, + const std::vector &static_argument_type_ids) { + std::vector argument_type_ids = regular_argument_type_ids; + argument_type_ids.insert(argument_type_ids.end(), + static_argument_type_ids.begin(), + static_argument_type_ids.end()); + return OperationSignaturePtr( + new OperationSignature(operation_name, + argument_type_ids, + static_argument_type_ids.size())); + } + + private: + OperationSignature(const std::string &operation_name, + const std::vector &argument_type_ids, + const std::size_t num_static_arguments) + : operation_name_(operation_name), + argument_type_ids_(argument_type_ids), + num_static_arguments_(num_static_arguments) { + DCHECK_GE(argument_type_ids_.size(), num_static_arguments_); + } + + const std::string operation_name_; + const std::vector argument_type_ids_; + const std::size_t num_static_arguments_; + + DISALLOW_COPY_AND_ASSIGN(OperationSignature); +}; + +/** + * @brief Implements the equal function for operation signatures. + */ +struct OperationSignatureEqual { + inline bool operator()(const OperationSignaturePtr &lhs, + const OperationSignaturePtr &rhs) const { + return *lhs == *rhs; + } +}; + +/** + * @brief Implements the hash function for operation signatures. + */ +struct OperationSignatureHash { + inline std::size_t operator()(const OperationSignaturePtr &op_sig) const { + return op_sig->hash(); + } +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_OPERATIONS_OPERATION_SIGNATURE_HPP_ diff --git a/types/operations/binary_operations/AddBinaryOperation.cpp b/types/operations/binary_operations/AddBinaryOperation.cpp deleted file mode 100644 index 8f56a619..00000000 --- a/types/operations/binary_operations/AddBinaryOperation.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "types/operations/binary_operations/AddBinaryOperation.hpp" - -#include -#include - -#include "types/DateOperatorOverloads.hpp" -#include "types/DateType.hpp" -#include "types/DatetimeIntervalType.hpp" -#include "types/DatetimeLit.hpp" -#include "types/DatetimeType.hpp" -#include "types/IntervalLit.hpp" -#include "types/Type.hpp" -#include "types/TypeErrors.hpp" -#include "types/TypeFactory.hpp" -#include "types/TypeID.hpp" -#include "types/YearMonthIntervalType.hpp" -#include "types/operations/binary_operations/ArithmeticBinaryOperators.hpp" -#include "utility/EqualsAnyConstant.hpp" - -#include "glog/logging.h" - -namespace quickstep { - -bool AddBinaryOperation::canApplyToTypes(const Type &left, const Type &right) const { - switch (left.getTypeID()) { - case kInt: // Fall through. - case kLong: - case kFloat: - case kDouble: { - return (right.getSuperTypeID() == Type::kNumeric); - } - case kDate: { - return (right.getTypeID() == kYearMonthInterval); - } - case kDatetime: { - return (right.getTypeID() == kDatetimeInterval || - right.getTypeID() == kYearMonthInterval); - } - case kDatetimeInterval: { - return (right.getTypeID() == kDatetime || - right.getTypeID() == kDatetimeInterval); - } - case kYearMonthInterval: { - return (right.getTypeID() == kDate || - right.getTypeID() == kDatetime || - right.getTypeID() == kYearMonthInterval); - } - default: - return false; - } -} - -const Type* AddBinaryOperation::resultTypeForArgumentTypes(const Type &left, const Type &right) const { - if (left.getSuperTypeID() == Type::kNumeric && right.getSuperTypeID() == Type::kNumeric) { - return TypeFactory::GetUnifyingType(left, right); - } else if ((left.getTypeID() == kDatetime && right.getTypeID() == kDatetimeInterval) || - (left.getTypeID() == kDatetimeInterval && right.getTypeID() == kDatetime) || - (left.getTypeID() == kDatetime && right.getTypeID() == kYearMonthInterval) || - (left.getTypeID() == kYearMonthInterval && right.getTypeID() == kDatetime)) { - return &(DatetimeType::Instance(left.isNullable() || right.isNullable())); - } else if ((left.getTypeID() == kDate && right.getTypeID() == kYearMonthInterval) || - (left.getTypeID() == kYearMonthInterval && right.getTypeID() == kDate)) { - return &(DateType::Instance(left.isNullable() || right.isNullable())); - } else if (left.getTypeID() == kDatetimeInterval && right.getTypeID() == kDatetimeInterval) { - return &(DatetimeIntervalType::Instance(left.isNullable() || right.isNullable())); - } else if (left.getTypeID() == kYearMonthInterval && right.getTypeID() == kYearMonthInterval) { - return &(YearMonthIntervalType::Instance(left.isNullable() || right.isNullable())); - } else { - return nullptr; - } -} - -const Type* AddBinaryOperation::resultTypeForPartialArgumentTypes(const Type *left, - const Type *right) const { - if ((left == nullptr) && (right == nullptr)) { - return nullptr; - } - - if ((left != nullptr) && (right != nullptr)) { - return resultTypeForArgumentTypes(*left, *right); - } - - // Addition is commutative, so we just determine based on the known type, - // left or right. - const Type *known_type = (left != nullptr) ? left : right; - switch (known_type->getTypeID()) { - case kDouble: - // Double has highest precedence of the numeric types. - return &TypeFactory::GetType(kDouble, true); - case kDatetime: - // Datetime can be added with either interval type, and always yields - // Datetime. - return &TypeFactory::GetType(kDatetime, true); - case kDate: - // Date can be added with YearMonthInterval type only, and always yields - // Date. - return &TypeFactory::GetType(kDate, true); - default: - // Ambiguous or inapplicable. - return nullptr; - } -} - -bool AddBinaryOperation::partialTypeSignatureIsPlausible( - const Type *result_type, - const Type *left_argument_type, - const Type *right_argument_type) const { - if ((left_argument_type == nullptr) && (right_argument_type == nullptr)) { - if (result_type == nullptr) { - return true; - } else if (!result_type->isNullable()) { - // Unknown arguments are assumed to be nullable, since they arise from - // untyped NULL literals in the parser. Therefore, a non-nullable result - // Type is not plausible with unknown arguments. - return false; - } else { - return QUICKSTEP_EQUALS_ANY_CONSTANT(result_type->getTypeID(), - kInt, - kLong, - kFloat, - kDouble, - kDate, - kDatetime, - kDatetimeInterval, - kYearMonthInterval); - } - } - - if ((left_argument_type != nullptr) && (right_argument_type != nullptr)) { - const Type *actual_result_type = resultTypeForArgumentTypes(*left_argument_type, - *right_argument_type); - if (actual_result_type == nullptr) { - // Both argument Types are known, but this operation is NOT applicable to - // them. No matter what the result_type is, the signature is not - // plausible. - return false; - } else if (result_type == nullptr) { - return true; - } else { - return result_type->equals(*actual_result_type); - } - } - - // Addition is commutative, so we just determine based on the known type, - // left or right. - const Type *known_argument_type = (left_argument_type != nullptr) - ? left_argument_type - : right_argument_type; - if (result_type == nullptr) { - return QUICKSTEP_EQUALS_ANY_CONSTANT(known_argument_type->getTypeID(), - kInt, - kLong, - kFloat, - kDouble, - kDate, - kDatetime, - kDatetimeInterval, - kYearMonthInterval); - } - - if (!result_type->isNullable()) { - // One of the arguments is unknown, but it is nevertheless assumed - // nullable, since unknown argument Types arise from untyped NULL literals - // in the parser. Therefore, a non-nullable result Type is not plausible - // with an unknown argument. - return false; - } - - switch (result_type->getTypeID()) { - case kInt: - return (known_argument_type->getTypeID() == kInt); - case kLong: - return QUICKSTEP_EQUALS_ANY_CONSTANT( - known_argument_type->getTypeID(), - kInt, kLong); - case kFloat: - return QUICKSTEP_EQUALS_ANY_CONSTANT( - known_argument_type->getTypeID(), - kInt, kFloat); - case kDouble: - return QUICKSTEP_EQUALS_ANY_CONSTANT( - known_argument_type->getTypeID(), - kInt, kLong, kFloat, kDouble); - case kDate: - return (known_argument_type->getTypeID() == kDate); - case kDatetime: - return QUICKSTEP_EQUALS_ANY_CONSTANT( - known_argument_type->getTypeID(), - kDatetime, kDatetimeInterval); - case kDatetimeInterval: - return (known_argument_type->getTypeID() == kDatetimeInterval); - case kYearMonthInterval: - return (known_argument_type->getTypeID() == kYearMonthInterval); - default: - return false; - } -} - -std::pair AddBinaryOperation::pushDownTypeHint( - const Type *result_type_hint) const { - if (result_type_hint == nullptr) { - return std::pair(nullptr, nullptr); - } - - switch (result_type_hint->getTypeID()) { - case kInt: - case kLong: - case kFloat: - case kDouble: - case kDatetimeInterval: - case kYearMonthInterval: - // Hint the same as the result type. Note that, for numeric types, one of - // the argument Types can be a less precise Type and still yield the - // specified result Type (e.g. DoubleType + IntType = DoubleType). We - // choose the highest-precision suitable Type (i.e. the same as the - // result type) in such cases. - return std::pair(result_type_hint, result_type_hint); - case kDate: - // Hint is ambiguous: one argument should be a Date, other has to be - // kYearMonthInterval, but order is not important. - return std::pair(nullptr, nullptr); - case kDatetime: - // Hint is ambiguous: one argument should be a Datetime, the other should - // be one of the interval types, but either order is acceptable. - // Fortunately, the 3 types in question have syntactically distinct - // representations in the SQL parser, so their literals don't need - // disambiguation anyway. - return std::pair(nullptr, nullptr); - default: - // Inapplicable. - return std::pair(nullptr, nullptr); - } -} - -TypedValue AddBinaryOperation::applyToChecked(const TypedValue &left, - const Type &left_type, - const TypedValue &right, - const Type &right_type) const { - switch (left_type.getTypeID()) { - case kInt: - case kLong: - case kFloat: - case kDouble: { - switch (right_type.getTypeID()) { - case kInt: - case kLong: - case kFloat: - case kDouble: - return applyToCheckedNumericHelper(left, left_type, - right, right_type); - default: - break; - } - break; - } - case kDate: { - if (right_type.getTypeID() == kYearMonthInterval) { - if (left.isNull() || right.isNull()) { - return TypedValue(kDate); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } - break; - } - case kDatetime: { - if (right_type.getTypeID() == kDatetimeInterval) { - if (left.isNull() || right.isNull()) { - return TypedValue(kDatetime); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } else if (right_type.getTypeID() == kYearMonthInterval) { - if (left.isNull() || right.isNull()) { - return TypedValue(kDatetime); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } - break; - } - case kDatetimeInterval: { - if (right_type.getTypeID() == kDatetime) { - if (left.isNull() || right.isNull()) { - return TypedValue(kDatetime); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } else if (right_type.getTypeID() == kDatetimeInterval) { - if (left.isNull() || right.isNull()) { - return TypedValue(kDatetimeInterval); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } - break; - } - case kYearMonthInterval: { - if (right_type.getTypeID() == kDate) { - if (left.isNull() || right.isNull()) { - return TypedValue(kDatetime); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } else if (right_type.getTypeID() == kDatetime) { - if (left.isNull() || right.isNull()) { - return TypedValue(kDatetime); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } else if (right_type.getTypeID() == kYearMonthInterval) { - if (left.isNull() || right.isNull()) { - return TypedValue(kYearMonthInterval); - } - - return TypedValue(left.getLiteral() + right.getLiteral()); - } - break; - } - default: - break; - } - - LOG(FATAL) << "Can not apply " << getName() << " to arguments of types " - << left_type.getName() << " and " << right_type.getName(); -} - -UncheckedBinaryOperator* AddBinaryOperation::makeUncheckedBinaryOperatorForTypes(const Type &left, - const Type &right) const { - switch (left.getTypeID()) { - case kInt: - case kLong: - case kFloat: - case kDouble: { - if (right.getSuperTypeID() == Type::kNumeric) { - return makeNumericBinaryOperatorOuterHelper(left, right); - } - break; - } - case kDate: { - if (right.getTypeID() == kYearMonthInterval) { - return makeDateBinaryOperatorOuterHelper< - AddArithmeticUncheckedBinaryOperator, - DateType, - DateLit, - YearMonthIntervalLit>(left, right); - } - break; - } - case kDatetime: { - if (right.getTypeID() == kDatetimeInterval) { - return makeDateBinaryOperatorOuterHelper(left, right); - } else if (right.getTypeID() == kYearMonthInterval) { - return makeDateBinaryOperatorOuterHelper(left, right); - } - break; - } - case kDatetimeInterval: { - if (right.getTypeID() == kDatetime) { - return makeDateBinaryOperatorOuterHelper(left, right); - } else if (right.getTypeID() == kDatetimeInterval) { - return makeDateBinaryOperatorOuterHelper(left, right); - } - break; - } - case kYearMonthInterval: { - if (right.getTypeID() == kDate) { - return makeDateBinaryOperatorOuterHelper< - AddArithmeticUncheckedBinaryOperator, - DateType, - YearMonthIntervalLit, - DateLit>(left, right); - } else if (right.getTypeID() == kDatetime) { - return makeDateBinaryOperatorOuterHelper(left, right); - } else if (right.getTypeID() == kYearMonthInterval) { - return makeDateBinaryOperatorOuterHelper(left, right); - } - break; - } - default: - break; - } - - throw OperationInapplicableToType(getName(), 2, left.getName().c_str(), right.getName().c_str()); -} - -} // namespace quickstep diff --git a/types/operations/binary_operations/AddBinaryOperation.hpp b/types/operations/binary_operations/AddBinaryOperation.hpp deleted file mode 100644 index 23095637..00000000 --- a/types/operations/binary_operations/AddBinaryOperation.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ADD_BINARY_OPERATION_HPP_ -#define QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ADD_BINARY_OPERATION_HPP_ - -#include - -#include "types/TypedValue.hpp" -#include "types/operations/binary_operations/ArithmeticBinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { - -class Type; -class UncheckedBinaryOperator; - -/** \addtogroup Types - * @{ - */ - -/** - * @brief The BinaryOperation for addition. - **/ -class AddBinaryOperation : public ArithmeticBinaryOperation { - public: - /** - * @brief Get a reference to the singleton instance of this Operation. - * - * @return A reference to the singleton instance of this Operation. - **/ - static const AddBinaryOperation& Instance() { - static AddBinaryOperation instance; - return instance; - } - - bool isCommutative() const override { - return true; - } - - bool canApplyToTypes(const Type &left, - const Type &right) const override; - - const Type* resultTypeForArgumentTypes(const Type &left, - const Type &right) const override; - - const Type* resultTypeForPartialArgumentTypes(const Type *left, - const Type *right) const override; - - bool partialTypeSignatureIsPlausible(const Type *result_type, - const Type *left_argument_type, - const Type *right_argument_type) const override; - - std::pair pushDownTypeHint( - const Type *result_type_hint) const override; - - TypedValue applyToChecked(const TypedValue &left, - const Type &left_type, - const TypedValue &right, - const Type &right_type) const override; - - UncheckedBinaryOperator* makeUncheckedBinaryOperatorForTypes(const Type &left, - const Type &right) const override; - - private: - AddBinaryOperation() - : ArithmeticBinaryOperation(BinaryOperationID::kAdd) { - } - - DISALLOW_COPY_AND_ASSIGN(AddBinaryOperation); -}; - -/** @} */ - -} // namespace quickstep - -#endif // QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ADD_BINARY_OPERATION_HPP_ diff --git a/types/operations/binary_operations/ArithmeticBinaryFunctorOverloads.hpp b/types/operations/binary_operations/ArithmeticBinaryFunctorOverloads.hpp new file mode 100644 index 00000000..4c6f76ce --- /dev/null +++ b/types/operations/binary_operations/ArithmeticBinaryFunctorOverloads.hpp @@ -0,0 +1,176 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_FUNCTOR_OVERLOADS_HPP_ +#define QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_FUNCTOR_OVERLOADS_HPP_ + +#include +#include +#include +#include +#include + +#include "types/DateOperatorOverloads.hpp" +#include "utility/meta/Common.hpp" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +// We use these functors instead of the standard-library ones, because the +// standard-library functors in have to be instantiated for the +// most specific argument type, which would unnecessisarily introduce +// multiple copies of distinct template instantiations of operators. +template +struct AddFunctorOverloads { + inline auto operator() (const LeftCppType &left, + const RightCppType &right) const -> decltype(left + right) { + return left + right; + } +}; + +// NOTE(zuyu): The C++ compiler in general converts all integers to floats +// when doing the following operations, +// but we could like to return double instead. +template <> +struct AddFunctorOverloads { + inline double operator() (const std::int64_t &left, const float &right) const { + return static_cast(left) + static_cast(right); + } +}; + +template <> +struct AddFunctorOverloads { + inline double operator() (const float &left, const std::int64_t &right) const { + return static_cast(left) + static_cast(right); + } +}; + +template +struct SubtractFunctorOverloads { + inline auto operator() (const LeftCppType &left, + const RightCppType &right) const -> decltype(left - right) { + return left - right; + } +}; + +// NOTE(zuyu): The C++ compiler in general converts all integers to floats +// when doing the following operations, +// but we could like to return double instead. +template <> +struct SubtractFunctorOverloads { + inline double operator() (const std::int64_t &left, const float &right) const { + return static_cast(left) - static_cast(right); + } +}; + +template <> +struct SubtractFunctorOverloads { + inline double operator() (const float &left, const std::int64_t &right) const { + return static_cast(left) - static_cast(right); + } +}; + +template +struct MultiplyFunctorOverloads { + inline auto operator() (const LeftCppType &left, + const RightCppType &right) const -> decltype(left * right) { + return left * right; + } +}; + +// NOTE(zuyu): The C++ compiler in general converts all integers to floats +// when doing the following operations, +// but we could like to return double instead. +template <> +struct MultiplyFunctorOverloads { + inline double operator() (const std::int64_t &left, const float &right) const { + return static_cast(left) * static_cast(right); + } +}; + +template <> +struct MultiplyFunctorOverloads { + inline double operator() (const float &left, const std::int64_t &right) const { + return static_cast(left) * static_cast(right); + } +}; + +template +struct DivideFunctorOverloads { + inline auto operator() (const LeftCppType &left, + const RightCppType &right) const -> decltype(left / right) { + return left / right; + } +}; + +// NOTE(zuyu): The C++ compiler in general converts all integers to floats +// when doing the following operations, +// but we could like to return double instead. +template <> +struct DivideFunctorOverloads { + inline double operator() (const std::int64_t &left, const float &right) const { + return static_cast(left) / static_cast(right); + } +}; + +template <> +struct DivideFunctorOverloads { + inline double operator() (const float &left, const std::int64_t &right) const { + return static_cast(left) / static_cast(right); + } +}; + +template +struct ModuloFunctorOverloads; + +template +struct ModuloFunctorOverloads< + LeftCppType, RightCppType, + std::enable_if_t::value && + meta::EqualsAny::value>> { + inline auto operator() (const LeftCppType &left, + const RightCppType &right) const -> decltype(left % right) { + return left % right; + } +}; + +// NOTE(jianqiao): The C++11 standard specifies the following type signatures for fmod: +// (1) (double, double) -> double +// (2) (float, float) -> float +// (3) (long double, long double) -> long double +// (3) (Arithmetic, Arithmetic) -> double +template +struct ModuloFunctorOverloads< + LeftCppType, RightCppType, + std::enable_if_t::value || + meta::EqualsAny::value>> { + inline auto operator() (const LeftCppType &left, + const RightCppType &right) const -> decltype(std::fmod(left, right)) { + return std::fmod(left, right); + } +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_FUNCTOR_OVERLOADS_HPP_ diff --git a/types/operations/binary_operations/ArithmeticBinaryFunctors.hpp b/types/operations/binary_operations/ArithmeticBinaryFunctors.hpp new file mode 100644 index 00000000..bab71cec --- /dev/null +++ b/types/operations/binary_operations/ArithmeticBinaryFunctors.hpp @@ -0,0 +1,182 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_FUNCTORS_HPP_ +#define QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_FUNCTORS_HPP_ + +#include +#include + +#include "types/DateType.hpp" +#include "types/DatetimeIntervalType.hpp" +#include "types/DatetimeLit.hpp" +#include "types/DatetimeType.hpp" +#include "types/IntervalLit.hpp" +#include "types/NumericTypeUnifier.hpp" +#include "types/Type.hpp" +#include "types/TypeErrors.hpp" +#include "types/TypeFactory.hpp" +#include "types/TypeID.hpp" +#include "types/TypedValue.hpp" +#include "types/YearMonthIntervalType.hpp" +#include "types/operations/binary_operations/ArithmeticBinaryFunctorOverloads.hpp" +#include "types/operations/binary_operations/BinaryOperationSynthesizer.hpp" +#include "utility/meta/Common.hpp" + +namespace quickstep { + +/** \addtogroup Types + * @{ + */ + +template class FunctorOverload, + typename FunctorName> +struct ArithmeticBinaryFunctor : public BinaryFunctor { + ArithmeticBinaryFunctor() : spec() {} + inline typename ResultT::cpptype apply(const typename LeftT::cpptype &left, + const typename RightT::cpptype &right) const { + return spec(left, right); + } + inline static std::string GetName() { + return FunctorName::ToString(); + } + const FunctorOverload spec; +}; + +template +using AddFunctor = ArithmeticBinaryFunctor>; + +template +using SubtractFunctor = ArithmeticBinaryFunctor>; + +template +using MultiplyFunctor = ArithmeticBinaryFunctor>; + +template +using DivideFunctor = ArithmeticBinaryFunctor>; + +template +using ModuloFunctor = ArithmeticBinaryFunctor>; + +// ---------------------------------------------------------------------------- +// Packs of functors: + +using AddBinaryFunctorPack = FunctorPack< +// Numeric + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + AddFunctor, NumericTypeUnifier>, +// Date + AddFunctor, + AddFunctor, +// Datetime + AddFunctor, + AddFunctor, + AddFunctor, + AddFunctor, +// DatetimeInterval + AddFunctor, +// YearMonthInterval + AddFunctor +>; + +using SubtractBinaryFunctorPack = FunctorPack< +// Numeric + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + SubtractFunctor, NumericTypeUnifier>, +// Date + SubtractFunctor, + // TODO(quickstep-team): + // Implement SubtractFunctor, +// Datetime + SubtractFunctor, + SubtractFunctor, + SubtractFunctor, +// DatetimeInterval + SubtractFunctor, +// YearMonthInterval + SubtractFunctor +>; + +using MultiplyBinaryFunctorPack = FunctorPack< +// Numeric + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + MultiplyFunctor, NumericTypeUnifier>, +// DatetimeInterval and YearMonthInterval + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + MultiplyFunctor, meta::PairSelectorLeft>, + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + MultiplyFunctor, meta::PairSelectorRight> +>; + +using DivideBinaryFunctorPack = FunctorPack< +// Numeric + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + DivideFunctor, NumericTypeUnifier>, +// DatetimeInterval and YearMonthInterval + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + DivideFunctor, meta::PairSelectorLeft> +>; + +using ModuloBinaryFunctorPack = FunctorPack< +// Numeric + BinaryFunctorCrossProductPack< + std::tuple, + std::tuple, + ModuloFunctor, NumericTypeUnifier> +>; + +using ArithmeticBinaryFunctorPack = FunctorPack< + AddBinaryFunctorPack, + SubtractBinaryFunctorPack, + MultiplyBinaryFunctorPack, + DivideBinaryFunctorPack, + ModuloBinaryFunctorPack +>; + +} // namespace quickstep + +#endif // QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_FUNCTORS_HPP_ diff --git a/types/operations/binary_operations/ArithmeticBinaryOperation.hpp b/types/operations/binary_operations/ArithmeticBinaryOperation.hpp deleted file mode 100644 index f9a27a87..00000000 --- a/types/operations/binary_operations/ArithmeticBinaryOperation.hpp +++ /dev/null @@ -1,404 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_OPERATION_HPP_ -#define QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_ARITHMETIC_BINARY_OPERATION_HPP_ - -#include - -#include "types/DoubleType.hpp" -#include "types/FloatType.hpp" -#include "types/IntType.hpp" -#include "types/LongType.hpp" -#include "types/NumericTypeUnifier.hpp" -#include "types/Type.hpp" -#include "types/TypeErrors.hpp" -#include "types/TypeFactory.hpp" -#include "types/TypeID.hpp" -#include "types/TypedValue.hpp" -#include "types/operations/binary_operations/BinaryOperation.hpp" -#include "types/operations/binary_operations/BinaryOperationID.hpp" -#include "utility/Macros.hpp" - -#include "glog/logging.h" - -namespace quickstep { - -/** \addtogroup Types - * @{ - */ - -/** - * @brief A BinaryOperation which applies to and yields values - * including numeric, datetime, and intervals. - **/ -class ArithmeticBinaryOperation : public BinaryOperation { - protected: - explicit ArithmeticBinaryOperation(const BinaryOperationID operation_id) - : BinaryOperation(operation_id) { - } - - template