quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianq...@apache.org
Subject [50/51] [abbrv] incubator-quickstep git commit: More updates, refactor names
Date Thu, 05 Oct 2017 22:03:45 GMT
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/binary_operations/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/CMakeLists.txt b/types/operations/binary_operations/CMakeLists.txt
index 09566aa..c6fd4e2 100644
--- a/types/operations/binary_operations/CMakeLists.txt
+++ b/types/operations/binary_operations/CMakeLists.txt
@@ -16,30 +16,30 @@
 # under the License.
 
 # Declare micro-libs:
-add_library(quickstep_types_operations_binaryoperations_ArithmeticBinaryOperations
+add_library(quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctors
             ../../../empty_src.cpp
-            ArithmeticBinaryOperations.hpp)
+            ArithmeticBinaryFunctors.hpp)
 add_library(quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctorOverloads
             ../../../empty_src.cpp
             ArithmeticBinaryFunctorOverloads.hpp)
-add_library(quickstep_types_operations_binaryoperations_AsciiStringBinaryOperations
+add_library(quickstep_types_operations_binaryoperations_AsciiStringBinaryFunctors
             ../../../empty_src.cpp
-            AsciiStringBinaryOperations.hpp)
+            AsciiStringBinaryFunctors.hpp)
 add_library(quickstep_types_operations_binaryoperations_BinaryOperation
             BinaryOperation.cpp
             BinaryOperation.hpp)
 add_library(quickstep_types_operations_binaryoperations_BinaryOperationWrapper
             ../../../empty_src.cpp
             BinaryOperationWrapper.hpp)
-add_library(quickstep_types_operations_binaryoperations_CMathBinaryOperations
+add_library(quickstep_types_operations_binaryoperations_CMathBinaryFunctors
             ../../../empty_src.cpp
-            CMathBinaryOperations.hpp)
+            CMathBinaryFunctors.hpp)
 
 # Link dependencies:
 target_link_libraries(quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctorOverloads
                       quickstep_types_DateOperatorOverloads
                       quickstep_utility_meta_Common)
-target_link_libraries(quickstep_types_operations_binaryoperations_ArithmeticBinaryOperations
+target_link_libraries(quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctors
                       quickstep_types_DateType
                       quickstep_types_DatetimeIntervalType
                       quickstep_types_DatetimeLit
@@ -55,7 +55,7 @@ target_link_libraries(quickstep_types_operations_binaryoperations_ArithmeticBina
                       quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctorOverloads
                       quickstep_types_operations_binaryoperations_BinaryOperationWrapper
                       quickstep_utility_meta_Common)
-target_link_libraries(quickstep_types_operations_binaryoperations_AsciiStringBinaryOperations
+target_link_libraries(quickstep_types_operations_binaryoperations_AsciiStringBinaryFunctors
                       glog
                       quickstep_types_CharType
                       quickstep_types_IntType
@@ -63,8 +63,8 @@ target_link_libraries(quickstep_types_operations_binaryoperations_AsciiStringBin
                       quickstep_types_TypeFactory
                       quickstep_types_TypeID
                       quickstep_types_VarCharType
-                      quickstep_types_operations_OperationUtil
                       quickstep_types_operations_unaryoperations_UnaryOperationWrapper
+                      quickstep_types_operations_utility_OperationSynthesizeUtil
                       quickstep_types_port_strnlen)
 target_link_libraries(quickstep_types_operations_binaryoperations_BinaryOperation
                       quickstep_catalog_CatalogTypedefs
@@ -84,29 +84,29 @@ target_link_libraries(quickstep_types_operations_binaryoperations_BinaryOperatio
                       quickstep_types_TypedValue
                       quickstep_types_containers_ColumnVector
                       quickstep_types_operations_OperationSignature
-                      quickstep_types_operations_OperationUtil
                       quickstep_types_operations_binaryoperations_BinaryOperation
+                      quickstep_types_operations_utility_OperationSynthesizeUtil
                       quickstep_utility_Macros
                       quickstep_utility_meta_Common)
-target_link_libraries(quickstep_types_operations_binaryoperations_CMathBinaryOperations
+target_link_libraries(quickstep_types_operations_binaryoperations_CMathBinaryFunctors
                       quickstep_types_DoubleType
                       quickstep_types_FloatType
                       quickstep_types_IntType
                       quickstep_types_LongType
-                      quickstep_types_operations_OperationUtil
                       quickstep_types_operations_binaryoperations_BinaryOperationWrapper
+                      quickstep_types_operations_utility_OperationSynthesizeUtil
                       quickstep_utility_meta_Common)
 
 # Module all-in-one library:
 add_library(quickstep_types_operations_binaryoperations ../../../empty_src.cpp)
 target_link_libraries(quickstep_types_operations_binaryoperations
                       quickstep_types_operations_binaryoperations_AddBinaryOperation
-                      quickstep_types_operations_binaryoperations_ArithmeticBinaryOperations
+                      quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctors
                       quickstep_types_operations_binaryoperations_ArithmeticBinaryFunctorOverloads
-                      quickstep_types_operations_binaryoperations_AsciiStringBinaryOperations
+                      quickstep_types_operations_binaryoperations_AsciiStringBinaryFunctors
                       quickstep_types_operations_binaryoperations_BinaryOperation
                       quickstep_types_operations_binaryoperations_BinaryOperationWrapper
-                      quickstep_types_operations_binaryoperations_CMathBinaryOperations)
+                      quickstep_types_operations_binaryoperations_CMathBinaryFunctors)
 
 # Tests:
 add_library(quickstep_types_operations_binaryoperations_tests_BinaryOperationTestUtil

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/binary_operations/CMathBinaryFunctors.hpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/CMathBinaryFunctors.hpp b/types/operations/binary_operations/CMathBinaryFunctors.hpp
new file mode 100644
index 0000000..c6fff3b
--- /dev/null
+++ b/types/operations/binary_operations/CMathBinaryFunctors.hpp
@@ -0,0 +1,78 @@
+/**
+ * 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_CMATH_BINARY_FUNCTORS_HPP_
+#define QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_CMATH_BINARY_FUNCTORS_HPP_
+
+#include <cmath>
+#include <string>
+
+#include "types/DoubleType.hpp"
+#include "types/FloatType.hpp"
+#include "types/IntType.hpp"
+#include "types/LongType.hpp"
+#include "types/operations/binary_operations/BinaryOperationWrapper.hpp"
+#include "types/operations/utility/OperationSynthesizeUtil.hpp"
+#include "utility/meta/Common.hpp"
+
+namespace quickstep {
+
+/** \addtogroup Types
+ *  @{
+ */
+
+template <typename LeftT, typename RightT, typename ResultT,
+          typename ResultT::cpptype f(typename LeftT::cpptype,
+                                      typename RightT::cpptype),
+          typename FunctorNameT>
+struct CMathBinaryFunctorWrapper {
+  struct Implemenation : public BinaryFunctor<LeftT, RightT, ResultT> {
+    inline typename ResultT::cpptype apply(
+        const typename LeftT::cpptype &left,
+        const typename RightT::cpptype &right) const {
+      return f(left, right);
+    }
+    inline static std::string GetName() {
+      return FunctorNameT::ToString();
+    }
+  };
+
+  typedef Implemenation type;
+};
+
+template <typename LeftT, typename RightT, typename ResultT,
+          typename ResultT::cpptype f(typename LeftT::cpptype,
+                                      typename RightT::cpptype),
+          typename FunctorNameT>
+using CMathBinaryFunctor =
+    typename CMathBinaryFunctorWrapper<LeftT, RightT, ResultT, f, FunctorNameT>::type;
+
+using CMathBinaryFunctorPack = FunctorPack<
+// pow
+    CMathBinaryFunctor<FloatType, FloatType, FloatType,
+                       std::pow, meta::StringLiteral<'p','o','w'>>,
+    CMathBinaryFunctor<DoubleType, DoubleType, DoubleType,
+                       std::pow, meta::StringLiteral<'p','o','w'>>
+>;
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_CMATH_BINARY_FUNCTORS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/binary_operations/CMathBinaryOperations.hpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/CMathBinaryOperations.hpp b/types/operations/binary_operations/CMathBinaryOperations.hpp
deleted file mode 100644
index 9a90a12..0000000
--- a/types/operations/binary_operations/CMathBinaryOperations.hpp
+++ /dev/null
@@ -1,78 +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_CMATH_BINARY_OPERATIONS_HPP_
-#define QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_CMATH_BINARY_OPERATIONS_HPP_
-
-#include <cmath>
-#include <string>
-
-#include "types/DoubleType.hpp"
-#include "types/FloatType.hpp"
-#include "types/IntType.hpp"
-#include "types/LongType.hpp"
-#include "types/operations/OperationUtil.hpp"
-#include "types/operations/binary_operations/BinaryOperationWrapper.hpp"
-#include "utility/meta/Common.hpp"
-
-namespace quickstep {
-
-/** \addtogroup Types
- *  @{
- */
-
-template <typename LeftT, typename RightT, typename ResultT,
-          typename ResultT::cpptype f(typename LeftT::cpptype,
-                                      typename RightT::cpptype),
-          typename FunctorNameT>
-struct CMathBinaryFunctorWrapper {
-  struct Implemenation : public BinaryFunctor<LeftT, RightT, ResultT> {
-    inline typename ResultT::cpptype apply(
-        const typename LeftT::cpptype &left,
-        const typename RightT::cpptype &right) const {
-      return f(left, right);
-    }
-    inline static std::string GetName() {
-      return FunctorNameT::ToString();
-    }
-  };
-
-  typedef Implemenation type;
-};
-
-template <typename LeftT, typename RightT, typename ResultT,
-          typename ResultT::cpptype f(typename LeftT::cpptype,
-                                      typename RightT::cpptype),
-          typename FunctorNameT>
-using CMathBinaryFunctor =
-    typename CMathBinaryFunctorWrapper<LeftT, RightT, ResultT, f, FunctorNameT>::type;
-
-using CMathBinaryFunctorPack = FunctorPack<
-// pow
-    CMathBinaryFunctor<FloatType, FloatType, FloatType,
-                       std::pow, meta::StringLiteral<'p','o','w'>>,
-    CMathBinaryFunctor<DoubleType, DoubleType, DoubleType,
-                       std::pow, meta::StringLiteral<'p','o','w'>>
->;
-
-/** @} */
-
-}  // namespace quickstep
-
-#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_CMATH_UNARY_OPERATIONS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/binary_operations/MultiplyBinaryOperation.hpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/MultiplyBinaryOperation.hpp b/types/operations/binary_operations/MultiplyBinaryOperation.hpp
deleted file mode 100644
index cc005e2..0000000
--- a/types/operations/binary_operations/MultiplyBinaryOperation.hpp
+++ /dev/null
@@ -1,102 +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_MULTIPLY_BINARY_OPERATION_HPP_
-#define QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_MULTIPLY_BINARY_OPERATION_HPP_
-
-#include <utility>
-
-#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 multiplication.
- **/
-class MultiplyBinaryOperation : 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 MultiplyBinaryOperation& Instance() {
-    static MultiplyBinaryOperation 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<const Type*, const Type*> 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:
-  MultiplyBinaryOperation()
-      : ArithmeticBinaryOperation(BinaryOperationID::kMultiply) {
-  }
-
-  // NOTE(zuyu): left is an Interval TypedValue, either DatetimeInterval
-  // or YearMonthInterval, while right is a Numeric.
-  template <typename IntervalType>
-  TypedValue applyToCheckedIntervalMultiplyNumericHelper(const TypedValue &left,
-                                                         const Type &left_type,
-                                                         const TypedValue &right,
-                                                         const Type &right_type) const;
-
-  DISALLOW_COPY_AND_ASSIGN(MultiplyBinaryOperation);
-};
-
-/** @} */
-
-}  // namespace quickstep
-
-#endif  // QUICKSTEP_TYPES_OPERATIONS_BINARY_OPERATIONS_MULTIPLY_BINARY_OPERATION_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/ArithmeticUnaryFunctors.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/ArithmeticUnaryFunctors.hpp b/types/operations/unary_operations/ArithmeticUnaryFunctors.hpp
new file mode 100644
index 0000000..ad45535
--- /dev/null
+++ b/types/operations/unary_operations/ArithmeticUnaryFunctors.hpp
@@ -0,0 +1,80 @@
+/**
+ * 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_UNARY_OPERATIONS_ARITHMETIC_UNARY_FUNCTORS_HPP_
+#define QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ARITHMETIC_UNARY_FUNCTORS_HPP_
+
+#include <string>
+
+#include "types/DatetimeIntervalType.hpp"
+#include "types/DoubleType.hpp"
+#include "types/FloatType.hpp"
+#include "types/IntType.hpp"
+#include "types/LongType.hpp"
+#include "types/YearMonthIntervalType.hpp"
+#include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
+#include "types/operations/utility/OperationSynthesizeUtil.hpp"
+
+namespace quickstep {
+
+/** \addtogroup Types
+ *  @{
+ */
+
+template <typename T>
+struct NegateFunctor : public UnaryFunctor<T, T> {
+  inline typename T::cpptype apply(const typename T::cpptype &argument) const {
+    return -argument;
+  }
+  inline static std::string GetName() {
+    return "-";
+  }
+};
+
+template <typename ArgumentT>
+struct SgnFunctor : public UnaryFunctor<ArgumentT, IntType> {
+  inline int apply(const typename ArgumentT::cpptype &argument) const {
+    return (argument > 0) - (argument < 0);
+  }
+  inline static std::string GetName() {
+    return "Sgn";
+  }
+};
+
+using ArithmeticUnaryFunctorPack = FunctorPack<
+// negate
+  NegateFunctor<IntType>,
+  NegateFunctor<LongType>,
+  NegateFunctor<FloatType>,
+  NegateFunctor<DoubleType>,
+  NegateFunctor<DatetimeIntervalType>,
+  NegateFunctor<YearMonthIntervalType>,
+
+// sgn (Sign of a numeric value)
+  SgnFunctor<IntType>,
+  SgnFunctor<LongType>,
+  SgnFunctor<FloatType>,
+  SgnFunctor<DoubleType>
+>;
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ARITHMETIC_UNARY_FUNCTORS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/ArithmeticUnaryOperations.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/ArithmeticUnaryOperations.hpp b/types/operations/unary_operations/ArithmeticUnaryOperations.hpp
deleted file mode 100644
index 4c212c0..0000000
--- a/types/operations/unary_operations/ArithmeticUnaryOperations.hpp
+++ /dev/null
@@ -1,81 +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_UNARY_OPERATIONS_ARITHMETIC_UNARY_OPERATIONS_HPP_
-#define QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ARITHMETIC_UNARY_OPERATIONS_HPP_
-
-#include <string>
-
-#include "types/DatetimeIntervalType.hpp"
-#include "types/DoubleType.hpp"
-#include "types/FloatType.hpp"
-#include "types/IntType.hpp"
-#include "types/LongType.hpp"
-#include "types/YearMonthIntervalType.hpp"
-#include "types/operations/OperationUtil.hpp"
-#include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
-
-namespace quickstep {
-
-/** \addtogroup Types
- *  @{
- */
-
-template <typename ArgumentT, typename ResultT>
-struct NegateFunctor : public UnaryFunctor<ArgumentT, ResultT> {
-  inline typename ResultT::cpptype apply(
-      const typename ArgumentT::cpptype &argument) const {
-    return -argument;
-  }
-  inline static std::string GetName() {
-    return "-";
-  }
-};
-
-template <typename ArgumentT>
-struct SgnFunctor : public UnaryFunctor<ArgumentT, IntType> {
-  inline int apply(const typename ArgumentT::cpptype &argument) const {
-    return (argument > 0) - (argument < 0);
-  }
-  inline static std::string GetName() {
-    return "Sgn";
-  }
-};
-
-using ArithmeticUnaryFunctorPack = FunctorPack<
-// negate
-  NegateFunctor<IntType, IntType>,
-  NegateFunctor<LongType, LongType>,
-  NegateFunctor<FloatType, FloatType>,
-  NegateFunctor<DoubleType, DoubleType>,
-  NegateFunctor<DatetimeIntervalType, DatetimeIntervalType>,
-  NegateFunctor<YearMonthIntervalType, YearMonthIntervalType>,
-
-// sgn (Sign of a numeric value)
-  SgnFunctor<IntType>,
-  SgnFunctor<LongType>,
-  SgnFunctor<FloatType>,
-  SgnFunctor<DoubleType>
->;
-
-/** @} */
-
-}  // namespace quickstep
-
-#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ARITHMETIC_UNARY_OPERATIONS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/AsciiStringUnaryFunctors.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/AsciiStringUnaryFunctors.hpp b/types/operations/unary_operations/AsciiStringUnaryFunctors.hpp
new file mode 100644
index 0000000..34a78ab
--- /dev/null
+++ b/types/operations/unary_operations/AsciiStringUnaryFunctors.hpp
@@ -0,0 +1,122 @@
+/**
+ * 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_UNARY_OPERATIONS_ASCII_STRING_UNARY_FUNCTORS_HPP_
+#define QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ASCII_STRING_UNARY_FUNCTORS_HPP_
+
+#include <cctype>
+#include <cstring>
+#include <string>
+
+#include "types/CharType.hpp"
+#include "types/IntType.hpp"
+#include "types/Type.hpp"
+#include "types/TypeFactory.hpp"
+#include "types/TypeID.hpp"
+#include "types/VarCharType.hpp"
+#include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
+#include "types/operations/utility/OperationSynthesizeUtil.hpp"
+#include "types/port/strnlen.hpp"
+#include "utility/meta/Common.hpp"
+
+namespace quickstep {
+
+/** \addtogroup Types
+ *  @{
+ */
+
+template <typename ArgumentT>
+struct AsciiStringLengthFunctor : public UnaryFunctor<ArgumentT, IntType> {
+  explicit AsciiStringLengthFunctor(const ArgumentT &argument_type)
+      : max_string_length_(argument_type.getStringLength()) {}
+  inline int apply(const void *argument) const {
+    return strnlen(static_cast<const char*>(argument), max_string_length_);
+  }
+  inline int apply(const TypedValue &argument) const {
+    DCHECK(argument.getTypeID() == kVarChar);
+    return std::strlen(static_cast<const char*>(argument.getOutOfLineData()));
+  }
+  inline static std::string GetName() {
+    return "length";
+  }
+  const std::size_t max_string_length_;
+};
+
+template <typename ArgumentT, int transform(int), typename FunctorNameT>
+struct AsciiStringTranformFunctor : public UnaryFunctor<ArgumentT, ArgumentT> {
+  explicit AsciiStringTranformFunctor(const ArgumentT &argument_type)
+      : max_string_length_(argument_type.getStringLength()) {}
+  inline void apply(const void *argument, void *result) const {
+    DCHECK(ArgumentT::kStaticTypeID == kChar);
+    const char *argument_str = static_cast<const char*>(argument);
+    char *result_str = static_cast<char*>(result);
+    for (std::size_t i = 0; i < max_string_length_; ++i) {
+      if ((result_str[i] = transform(argument_str[i])) == 0) {
+        break;
+      }
+    }
+  }
+  inline TypedValue apply(const TypedValue &argument) const {
+    DCHECK(argument.getTypeID() == kVarChar);
+    const char *argument_str = static_cast<const char*>(argument.getOutOfLineData());
+    const std::size_t length = argument.getDataSize();
+    char *buf = static_cast<char*>(std::malloc(length));
+
+    for (std::size_t i = 0; i < length; ++i) {
+      buf[i] = transform(argument_str[i]);
+    }
+    return TypedValue::CreateWithOwnedData(kVarChar, buf, length);
+  }
+  inline static std::string GetName() {
+    return FunctorNameT::ToString();
+  }
+  inline static const Type* GetResultType(const Type &argument_type) {
+    DCHECK(argument_type.getTypeID() == ArgumentT::kStaticTypeID);
+    return &argument_type;
+  }
+  const std::size_t max_string_length_;
+};
+
+template <typename ArgumentT>
+using AsciiStringToLowerCaseFunctor =
+    AsciiStringTranformFunctor<ArgumentT, std::tolower,
+                               meta::StringLiteral<'t', 'o', 'l', 'o', 'w', 'e', 'r'>>;
+
+template <typename ArgumentT>
+using AsciiStringToUpperCaseFunctor =
+    AsciiStringTranformFunctor<ArgumentT, std::toupper,
+                               meta::StringLiteral<'t', 'o', 'u', 'p', 'p', 'e', 'r'>>;
+
+using AsciiStringUnaryFunctorPack = FunctorPack<
+// length
+    AsciiStringLengthFunctor<CharType>,
+    AsciiStringLengthFunctor<VarCharType>,
+// tolower
+    AsciiStringToLowerCaseFunctor<CharType>,
+    AsciiStringToLowerCaseFunctor<VarCharType>,
+// toupper
+    AsciiStringToUpperCaseFunctor<CharType>,
+    AsciiStringToUpperCaseFunctor<VarCharType>
+>;
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ASCII_STRING_UNARY_FUNCTORS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/AsciiStringUnaryOperations.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/AsciiStringUnaryOperations.hpp b/types/operations/unary_operations/AsciiStringUnaryOperations.hpp
deleted file mode 100644
index 1ee1867..0000000
--- a/types/operations/unary_operations/AsciiStringUnaryOperations.hpp
+++ /dev/null
@@ -1,122 +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_UNARY_OPERATIONS_ASCII_STRING_UNARY_OPERATIONS_HPP_
-#define QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ASCII_STRING_UNARY_OPERATIONS_HPP_
-
-#include <cctype>
-#include <cstring>
-#include <string>
-
-#include "types/CharType.hpp"
-#include "types/IntType.hpp"
-#include "types/Type.hpp"
-#include "types/TypeFactory.hpp"
-#include "types/TypeID.hpp"
-#include "types/VarCharType.hpp"
-#include "types/operations/OperationUtil.hpp"
-#include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
-#include "types/port/strnlen.hpp"
-#include "utility/meta/Common.hpp"
-
-namespace quickstep {
-
-/** \addtogroup Types
- *  @{
- */
-
-template <typename ArgumentT>
-struct AsciiStringLengthFunctor : public UnaryFunctor<ArgumentT, IntType> {
-  explicit AsciiStringLengthFunctor(const ArgumentT &argument_type)
-      : max_string_length_(argument_type.getStringLength()) {}
-  inline int apply(const void *argument) const {
-    return strnlen(static_cast<const char*>(argument), max_string_length_);
-  }
-  inline int apply(const TypedValue &argument) const {
-    DCHECK(argument.getTypeID() == kVarChar);
-    return std::strlen(static_cast<const char*>(argument.getOutOfLineData()));
-  }
-  inline static std::string GetName() {
-    return "length";
-  }
-  const std::size_t max_string_length_;
-};
-
-template <typename ArgumentT, int transform(int), typename FunctorNameT>
-struct AsciiStringTranformFunctor : public UnaryFunctor<ArgumentT, ArgumentT> {
-  explicit AsciiStringTranformFunctor(const ArgumentT &argument_type)
-      : max_string_length_(argument_type.getStringLength()) {}
-  inline void apply(const void *argument, void *result) const {
-    DCHECK(ArgumentT::kStaticTypeID == kChar);
-    const char *argument_str = static_cast<const char*>(argument);
-    char *result_str = static_cast<char*>(result);
-    for (std::size_t i = 0; i < max_string_length_; ++i) {
-      if ((result_str[i] = transform(argument_str[i])) == 0) {
-        break;
-      }
-    }
-  }
-  inline TypedValue apply(const TypedValue &argument) const {
-    DCHECK(argument.getTypeID() == kVarChar);
-    const char *argument_str = static_cast<const char*>(argument.getOutOfLineData());
-    const std::size_t length = argument.getDataSize();
-    char *buf = static_cast<char*>(std::malloc(length));
-
-    for (std::size_t i = 0; i < length; ++i) {
-      buf[i] = transform(argument_str[i]);
-    }
-    return TypedValue::CreateWithOwnedData(kVarChar, buf, length);
-  }
-  inline static std::string GetName() {
-    return FunctorNameT::ToString();
-  }
-  inline static const Type* GetResultType(const Type &argument_type) {
-    DCHECK(argument_type.getTypeID() == ArgumentT::kStaticTypeID);
-    return &argument_type;
-  }
-  const std::size_t max_string_length_;
-};
-
-template <typename ArgumentT>
-using AsciiStringToLowerCaseFunctor =
-    AsciiStringTranformFunctor<ArgumentT, std::tolower,
-                               meta::StringLiteral<'t', 'o', 'l', 'o', 'w', 'e', 'r'>>;
-
-template <typename ArgumentT>
-using AsciiStringToUpperCaseFunctor =
-    AsciiStringTranformFunctor<ArgumentT, std::toupper,
-                               meta::StringLiteral<'t', 'o', 'u', 'p', 'p', 'e', 'r'>>;
-
-using AsciiStringUnaryFunctorPack = FunctorPack<
-// length
-    AsciiStringLengthFunctor<CharType>,
-    AsciiStringLengthFunctor<VarCharType>,
-// tolower
-    AsciiStringToLowerCaseFunctor<CharType>,
-    AsciiStringToLowerCaseFunctor<VarCharType>,
-// toupper
-    AsciiStringToUpperCaseFunctor<CharType>,
-    AsciiStringToUpperCaseFunctor<VarCharType>
->;
-
-/** @} */
-
-}  // namespace quickstep
-
-#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_ASCII_STRING_UNARY_OPERATIONS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/CMakeLists.txt b/types/operations/unary_operations/CMakeLists.txt
index bcd756e..fbfd091 100644
--- a/types/operations/unary_operations/CMakeLists.txt
+++ b/types/operations/unary_operations/CMakeLists.txt
@@ -16,15 +16,18 @@
 # under the License.
 
 # Declare micro-libs:
-add_library(quickstep_types_operations_unaryoperations_ArithmeticUnaryOperations
+add_library(quickstep_types_operations_unaryoperations_ArithmeticUnaryFunctors
             ../../../empty_src.cpp
-            ArithmeticUnaryOperations.hpp)
-add_library(quickstep_types_operations_unaryoperations_AsciiStringUnaryOperations
+            ArithmeticUnaryFunctors.hpp)
+add_library(quickstep_types_operations_unaryoperations_AsciiStringUnaryFunctors
             ../../../empty_src.cpp
-            AsciiStringUnaryOperations.hpp)
-add_library(quickstep_types_operations_unaryoperations_CMathUnaryOperations
+            AsciiStringUnaryFunctors.hpp)
+add_library(quickstep_types_operations_unaryoperations_CMathUnaryFunctors
             ../../../empty_src.cpp
-            CMathUnaryOperations.hpp)
+            CMathUnaryFunctors.hpp)
+add_library(quickstep_types_operations_unaryoperations_CastFunctorOverloads
+            ../../../empty_src.cpp
+            CastFunctorOverloads.hpp)
 add_library(quickstep_types_operations_unaryoperations_CastOperation CastOperation.cpp CastOperation.hpp)
 add_library(quickstep_types_operations_unaryoperations_DateExtractOperation
             DateExtractOperation.cpp
@@ -38,7 +41,7 @@ add_library(quickstep_types_operations_unaryoperations_UnaryOperationWrapper
             UnaryOperationWrapper.hpp)
 
 # Link dependencies:
-target_link_libraries(quickstep_types_operations_unaryoperations_ArithmeticUnaryOperations
+target_link_libraries(quickstep_types_operations_unaryoperations_ArithmeticUnaryFunctors
                       glog
                       quickstep_types_DatetimeIntervalType
                       quickstep_types_DoubleType
@@ -46,26 +49,26 @@ target_link_libraries(quickstep_types_operations_unaryoperations_ArithmeticUnary
                       quickstep_types_IntType
                       quickstep_types_LongType
                       quickstep_types_YearMonthIntervalType
-                      quickstep_types_operations_OperationUtil
-                      quickstep_types_operations_unaryoperations_UnaryOperationWrapper)
-target_link_libraries(quickstep_types_operations_unaryoperations_AsciiStringUnaryOperations
+                      quickstep_types_operations_unaryoperations_UnaryOperationWrapper
+                      quickstep_types_operations_utility_OperationSynthesizeUtil)
+target_link_libraries(quickstep_types_operations_unaryoperations_AsciiStringUnaryFunctors
                       quickstep_types_CharType
                       quickstep_types_IntType
                       quickstep_types_Type
                       quickstep_types_TypeFactory
                       quickstep_types_TypeID
                       quickstep_types_VarCharType
-                      quickstep_types_operations_OperationUtil
                       quickstep_types_operations_unaryoperations_UnaryOperationWrapper
+                      quickstep_types_operations_utility_OperationSynthesizeUtil
                       quickstep_types_port_strnlen
                       quickstep_utility_meta_Common)
-target_link_libraries(quickstep_types_operations_unaryoperations_CMathUnaryOperations
+target_link_libraries(quickstep_types_operations_unaryoperations_CMathUnaryFunctors
                       quickstep_types_DoubleType
                       quickstep_types_FloatType
                       quickstep_types_IntType
                       quickstep_types_LongType
-                      quickstep_types_operations_OperationUtil
                       quickstep_types_operations_unaryoperations_UnaryOperationWrapper
+                      quickstep_types_operations_utility_OperationSynthesizeUtil
                       quickstep_utility_meta_Common)
 target_link_libraries(quickstep_types_operations_unaryoperations_CastOperation
                       glog
@@ -134,16 +137,17 @@ target_link_libraries(quickstep_types_operations_unaryoperations_UnaryOperationW
                       quickstep_types_TypedValue
                       quickstep_types_containers_ColumnVector
                       quickstep_types_operations_OperationSignature
-                      quickstep_types_operations_OperationUtil
                       quickstep_types_operations_unaryoperations_UnaryOperation
+                      quickstep_types_operations_utility_OperationSynthesizeUtil
                       quickstep_utility_Macros)
 
 # Module all-in-one library:
 add_library(quickstep_types_operations_unaryoperations ../../../empty_src.cpp)
 target_link_libraries(quickstep_types_operations_unaryoperations
-                      quickstep_types_operations_unaryoperations_ArithmeticUnaryOperations
-                      quickstep_types_operations_unaryoperations_AsciiStringUnaryOperations
-                      quickstep_types_operations_unaryoperations_CMathUnaryOperations
+                      quickstep_types_operations_unaryoperations_ArithmeticUnaryFunctors
+                      quickstep_types_operations_unaryoperations_AsciiStringUnaryFunctors
+                      quickstep_types_operations_unaryoperations_CMathUnaryFunctors
+                      quickstep_types_operations_unaryoperations_CastFunctorOverloads
                       quickstep_types_operations_unaryoperations_CastOperation
                       quickstep_types_operations_unaryoperations_DateExtractOperation
                       quickstep_types_operations_unaryoperations_SubstringOperation
@@ -172,7 +176,7 @@ target_link_libraries(UnaryOperation_tests
                       quickstep_types_TypedValue
                       quickstep_types_containers_ColumnVector
                       quickstep_types_operations_Operation_proto
-                      quickstep_types_operations_unaryoperations_ArithmeticUnaryOperations
+                      quickstep_types_operations_unaryoperations_ArithmeticUnaryFunctors
                       quickstep_types_operations_unaryoperations_CastOperation
                       quickstep_types_operations_unaryoperations_DateExtractOperation
                       quickstep_types_operations_unaryoperations_UnaryOperation

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/CMathUnaryFunctors.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/CMathUnaryFunctors.hpp b/types/operations/unary_operations/CMathUnaryFunctors.hpp
new file mode 100644
index 0000000..5ed8b50
--- /dev/null
+++ b/types/operations/unary_operations/CMathUnaryFunctors.hpp
@@ -0,0 +1,116 @@
+/**
+ * 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_UNARY_OPERATIONS_CMATH_UNARY_FUNCTORS_HPP_
+#define QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_CMATH_UNARY_FUNCTORS_HPP_
+
+#include <cmath>
+#include <string>
+
+#include "types/DoubleType.hpp"
+#include "types/FloatType.hpp"
+#include "types/IntType.hpp"
+#include "types/LongType.hpp"
+#include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
+#include "types/operations/utility/OperationSynthesizeUtil.hpp"
+#include "utility/meta/Common.hpp"
+
+namespace quickstep {
+
+/** \addtogroup Types
+ *  @{
+ */
+
+template <typename ArgumentT, typename ResultT,
+          typename ResultT::cpptype f(typename ArgumentT::cpptype),
+          typename FunctorNameT>
+struct CMathUnaryFunctorWrapper {
+  struct Implemenation : public UnaryFunctor<ArgumentT, ResultT> {
+    inline typename ResultT::cpptype apply(
+        const typename ArgumentT::cpptype &argument) const {
+      return f(argument);
+    }
+    inline static std::string GetName() {
+      return FunctorNameT::ToString();
+    }
+  };
+
+  typedef Implemenation type;
+};
+
+template <typename ArgumentT, typename ResultT,
+          typename ResultT::cpptype f(typename ArgumentT::cpptype),
+          typename FunctorNameT>
+using CMathUnaryFunctor =
+    typename CMathUnaryFunctorWrapper<ArgumentT, ResultT, f, FunctorNameT>::type;
+
+inline std::int64_t CMathRound(const float arg) {
+  return std::llround(arg);
+}
+inline std::int64_t CMathRound(const double arg) {
+  return std::llround(arg);
+}
+
+using CMathUnaryFunctorPack = FunctorPack<
+// abs
+    CMathUnaryFunctor<IntType, IntType,
+                      std::abs, meta::StringLiteral<'a','b','s'>>,
+    CMathUnaryFunctor<LongType, LongType,
+                      std::abs, meta::StringLiteral<'a','b','s'>>,
+    CMathUnaryFunctor<FloatType, FloatType,
+                      std::fabs, meta::StringLiteral<'a','b','s'>>,
+    CMathUnaryFunctor<DoubleType, DoubleType,
+                      std::fabs, meta::StringLiteral<'a','b','s'>>,
+// sqrt
+    CMathUnaryFunctor<FloatType, FloatType,
+                      std::sqrt, meta::StringLiteral<'s','q','r','t'>>,
+    CMathUnaryFunctor<DoubleType, DoubleType,
+                      std::sqrt, meta::StringLiteral<'s','q','r','t'>>,
+// exp
+    CMathUnaryFunctor<FloatType, FloatType,
+                      std::exp, meta::StringLiteral<'e','x','p'>>,
+    CMathUnaryFunctor<DoubleType, DoubleType,
+                      std::exp, meta::StringLiteral<'e','x','p'>>,
+// log
+    CMathUnaryFunctor<FloatType, FloatType,
+                      std::log, meta::StringLiteral<'l','o','g'>>,
+    CMathUnaryFunctor<DoubleType, DoubleType,
+                      std::log, meta::StringLiteral<'l','o','g'>>,
+// ceil
+    CMathUnaryFunctor<FloatType, FloatType,
+                      std::ceil, meta::StringLiteral<'c','e','i','l'>>,
+    CMathUnaryFunctor<DoubleType, DoubleType,
+                      std::ceil, meta::StringLiteral<'c','e','i','l'>>,
+// floor
+    CMathUnaryFunctor<FloatType, FloatType,
+                      std::floor, meta::StringLiteral<'f','l','o','o','r'>>,
+    CMathUnaryFunctor<DoubleType, DoubleType,
+                      std::floor, meta::StringLiteral<'f','l','o','o','r'>>,
+// round
+    CMathUnaryFunctor<FloatType, LongType,
+                      CMathRound, meta::StringLiteral<'r','o','u','n','d'>>,
+    CMathUnaryFunctor<DoubleType, LongType,
+                      CMathRound, meta::StringLiteral<'r','o','u','n','d'>>
+>;
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_CMATH_UNARY_FUNCTORS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/CMathUnaryOperations.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/CMathUnaryOperations.hpp b/types/operations/unary_operations/CMathUnaryOperations.hpp
deleted file mode 100644
index 7a372e0..0000000
--- a/types/operations/unary_operations/CMathUnaryOperations.hpp
+++ /dev/null
@@ -1,116 +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_UNARY_OPERATIONS_CMATH_UNARY_OPERATIONS_HPP_
-#define QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_CMATH_UNARY_OPERATIONS_HPP_
-
-#include <cmath>
-#include <string>
-
-#include "types/DoubleType.hpp"
-#include "types/FloatType.hpp"
-#include "types/IntType.hpp"
-#include "types/LongType.hpp"
-#include "types/operations/OperationUtil.hpp"
-#include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
-#include "utility/meta/Common.hpp"
-
-namespace quickstep {
-
-/** \addtogroup Types
- *  @{
- */
-
-template <typename ArgumentT, typename ResultT,
-          typename ResultT::cpptype f(typename ArgumentT::cpptype),
-          typename FunctorNameT>
-struct CMathUnaryFunctorWrapper {
-  struct Implemenation : public UnaryFunctor<ArgumentT, ResultT> {
-    inline typename ResultT::cpptype apply(
-        const typename ArgumentT::cpptype &argument) const {
-      return f(argument);
-    }
-    inline static std::string GetName() {
-      return FunctorNameT::ToString();
-    }
-  };
-
-  typedef Implemenation type;
-};
-
-template <typename ArgumentT, typename ResultT,
-          typename ResultT::cpptype f(typename ArgumentT::cpptype),
-          typename FunctorNameT>
-using CMathUnaryFunctor =
-    typename CMathUnaryFunctorWrapper<ArgumentT, ResultT, f, FunctorNameT>::type;
-
-inline std::int64_t CMathRound(const float arg) {
-  return std::llround(arg);
-}
-inline std::int64_t CMathRound(const double arg) {
-  return std::llround(arg);
-}
-
-using CMathUnaryFunctorPack = FunctorPack<
-// abs
-    CMathUnaryFunctor<IntType, IntType,
-                      std::abs, meta::StringLiteral<'a','b','s'>>,
-    CMathUnaryFunctor<LongType, LongType,
-                      std::abs, meta::StringLiteral<'a','b','s'>>,
-    CMathUnaryFunctor<FloatType, FloatType,
-                      std::fabs, meta::StringLiteral<'a','b','s'>>,
-    CMathUnaryFunctor<DoubleType, DoubleType,
-                      std::fabs, meta::StringLiteral<'a','b','s'>>,
-// sqrt
-    CMathUnaryFunctor<FloatType, FloatType,
-                      std::sqrt, meta::StringLiteral<'s','q','r','t'>>,
-    CMathUnaryFunctor<DoubleType, DoubleType,
-                      std::sqrt, meta::StringLiteral<'s','q','r','t'>>,
-// exp
-    CMathUnaryFunctor<FloatType, FloatType,
-                      std::exp, meta::StringLiteral<'e','x','p'>>,
-    CMathUnaryFunctor<DoubleType, DoubleType,
-                      std::exp, meta::StringLiteral<'e','x','p'>>,
-// log
-    CMathUnaryFunctor<FloatType, FloatType,
-                      std::log, meta::StringLiteral<'l','o','g'>>,
-    CMathUnaryFunctor<DoubleType, DoubleType,
-                      std::log, meta::StringLiteral<'l','o','g'>>,
-// ceil
-    CMathUnaryFunctor<FloatType, FloatType,
-                      std::ceil, meta::StringLiteral<'c','e','i','l'>>,
-    CMathUnaryFunctor<DoubleType, DoubleType,
-                      std::ceil, meta::StringLiteral<'c','e','i','l'>>,
-// floor
-    CMathUnaryFunctor<FloatType, FloatType,
-                      std::floor, meta::StringLiteral<'f','l','o','o','r'>>,
-    CMathUnaryFunctor<DoubleType, DoubleType,
-                      std::floor, meta::StringLiteral<'f','l','o','o','r'>>,
-// round
-    CMathUnaryFunctor<FloatType, LongType,
-                      CMathRound, meta::StringLiteral<'r','o','u','n','d'>>,
-    CMathUnaryFunctor<DoubleType, LongType,
-                      CMathRound, meta::StringLiteral<'r','o','u','n','d'>>
->;
-
-/** @} */
-
-}  // namespace quickstep
-
-#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_CMATH_UNARY_OPERATIONS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/CastFunctorOverloads.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/CastFunctorOverloads.hpp b/types/operations/unary_operations/CastFunctorOverloads.hpp
new file mode 100644
index 0000000..940cab6
--- /dev/null
+++ b/types/operations/unary_operations/CastFunctorOverloads.hpp
@@ -0,0 +1,183 @@
+/**
+ * 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_UNARY_OPERATIONS_CAST_FUNCTOR_OVERLOADS_HPP_
+#define QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_CAST_FUNCTOR_OVERLOADS_HPP_
+
+#include <algorithm>
+#include <cstdint>
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "types/TypeRegistrar.hpp"
+#include "types/TypedValue.hpp"
+#include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
+#include "utility/meta/TypeList.hpp"
+
+namespace quickstep {
+
+/** \addtogroup Types
+ *  @{
+ */
+
+template <typename SourceType, typename TargetType, typename Enable = void>
+struct CastFunctor;
+
+// ----------------------------------------------------------------------------
+// Implementations of numeric to numeric casts.
+
+using NumericTypes = meta::TypeList<BoolType, IntType, LongType, FloatType, DoubleType>;
+using NumericCastOverloads = NumericTypes::cartesian_product<NumericTypes>;
+
+template <typename SourceType, typename TargetType>
+struct CastFunctor<
+    SourceType, TargetType,
+    std::enable_if_t<
+        NumericCastOverloads::contains<meta::TypeList<SourceType, TargetType>>::value>>
+    : public UnaryFunctor<SourceType, TargetType> {
+  inline typename TargetType::cpptype apply(
+      const typename SourceType::cpptype &argument) const {
+    return static_cast<typename TargetType::cpptype>(argument);
+  }
+};
+
+
+// ----------------------------------------------------------------------------
+// Implementations of any type to ascii string casts.
+
+template <typename SourceType>
+struct CastFunctor<SourceType, CharType,
+                   std::enable_if_t<SourceType::kStaticSuperTypeID == SuperTypeID::kNumeric>>
+    : public UnaryFunctor<SourceType, CharType> {
+  explicit CastFunctor(const SourceType &source_type_in,
+                       const CharType &target_type_in)
+      : source_type(source_type_in),
+        max_string_length(target_type_in.getStringLength()) {}
+  inline void apply(const typename SourceType::cpptype &argument, void *result) const {
+    std::string str = source_type.printValueToString(&argument);
+    const std::size_t str_len = str.length();
+    if (str_len < max_string_length) {
+      std::memcpy(result, str.c_str(), str_len);
+      static_cast<char *>(result)[str_len] = 0;
+    } else {
+      std::memcpy(result, str.c_str(), max_string_length);
+    }
+  }
+  const SourceType &source_type;
+  const std::size_t max_string_length;
+};
+
+template <typename SourceType>
+struct CastFunctor<SourceType, VarCharType,
+                   std::enable_if_t<SourceType::kStaticSuperTypeID == SuperTypeID::kNumeric>>
+    : public UnaryFunctor<SourceType, VarCharType> {
+  explicit CastFunctor(const SourceType &source_type_in,
+                       const VarCharType &target_type_in)
+      : source_type(source_type_in),
+        max_string_length(target_type_in.getStringLength()) {}
+  inline TypedValue apply(const typename SourceType::cpptype &argument) const {
+    std::string str = source_type.printValueToString(&argument);
+    const std::size_t len = std::min(str.length(), max_string_length);
+    const std::size_t buf_len = len + 1;
+    char *buf = static_cast<char *>(std::malloc(buf_len));
+    std::memcpy(buf, str.c_str(), len);
+    buf[len] = 0;
+    return TypedValue::CreateWithOwnedData(kVarChar, buf, buf_len);
+  }
+  const SourceType &source_type;
+  const std::size_t max_string_length;
+};
+
+//template <typename SourceType>
+//struct CastFunctor<SourceType, TextType>
+//    : public UnaryFunctor<SourceType, TextType> {
+//  explicit CastFunctor(const SourceType &source_type_in,
+//                       const TextType &target_type_in)
+//      : source_type(source_type_in) {}
+//  inline std::string apply(const typename SourceType::cpptype &argument) const {
+//    return source_type.printValueToString(&argument);
+//  }
+//  const SourceType &source_type;
+//};
+//
+//
+//// ----------------------------------------------------------------------------
+//// Implementations of ascii string to numeric casts.
+//
+//template <typename T>
+//T CastStringToNumericOverload(const char *str);
+//
+//template <>
+//bool CastStringToNumericOverload(const char *str) {
+//  return ToLower(str) == "true";
+//}
+//template <>
+//int CastStringToNumericOverload(const char *str) {
+//  return std::atoi(str);
+//}
+//template <>
+//float CastStringToNumericOverload(const char *str) {
+//  return static_cast<float>(std::atof(str));
+//}
+//template <>
+//std::int64_t CastStringToNumericOverload(const char *str) {
+//  return std::atoll(str);
+//}
+//template <>
+//double CastStringToNumericOverload(const char *str) {
+//  return std::atof(str);
+//}
+//
+//template <typename TargetType>
+//struct CastFunctor<CharType, TargetType,
+//                   std::enable_if_t<NumericTypes::contains<TargetType>::value>>
+//    : public UnaryFunctor<CharType, TargetType> {
+//  explicit CastFunctor(const CharType &source_type_in,
+//                       const TargetType &target_type_in)
+//      : max_string_length(source_type_in.getStringLength()) {}
+//  inline typename TargetType::cpptype apply(const void *argument) const {
+//    const char *str = static_cast<const char*>(argument);
+//    const std::string value(str, strnlen(str, max_string_length));
+//    return CastStringToNumericOverload<typename TargetType::cpptype>(value.c_str());
+//  }
+//  const std::size_t max_string_length;
+//};
+//
+//
+//template <typename TargetType>
+//struct CastFunctor<VarCharType, TargetType,
+//                   std::enable_if_t<NumericTypes::contains<TargetType>::value>>
+//    : public UnaryFunctor<VarCharType, TargetType> {
+//  explicit CastFunctor(const VarCharType &source_type_in,
+//                       const TargetType &target_type_in)
+//      : max_string_length(source_type_in.getStringLength()) {}
+//  inline typename TargetType::cpptype apply(const TypedValue &argument) const {
+//    return CastStringToNumericOverload<typename TargetType::cpptype>(
+//        static_cast<const char*>(argument.getDataPtr()));
+//  }
+//  const std::size_t max_string_length;
+//};
+
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_OPERATIONS_UNARY_OPERATIONS_CAST_FUNCTOR_OVERLOADS_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/CastOperation.cpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/CastOperation.cpp b/types/operations/unary_operations/CastOperation.cpp
index 8e0db55..8f725e2 100644
--- a/types/operations/unary_operations/CastOperation.cpp
+++ b/types/operations/unary_operations/CastOperation.cpp
@@ -29,169 +29,105 @@
 #include "types/CharType.hpp"
 #include "types/DoubleType.hpp"
 #include "types/FloatType.hpp"
+#include "types/GenericValue.hpp"
 #include "types/IntType.hpp"
 #include "types/LongType.hpp"
+#include "types/MetaType.hpp"
 #include "types/Type.hpp"
 #include "types/TypeUtil.hpp"
 #include "types/TypedValue.hpp"
 #include "types/VarCharType.hpp"
+#include "types/operations/unary_operations/CastFunctorOverloads.hpp"
 #include "types/operations/unary_operations/UnaryOperationWrapper.hpp"
 #include "types/port/strnlen.hpp"
 #include "utility/EqualsAnyConstant.hpp"
 #include "utility/StringUtil.hpp"
+#include "utility/meta/Common.hpp"
 
 namespace quickstep {
 
 namespace {
 
-template <typename ArgumentT, typename ResultT>
-struct NumericCastToNumericFunctor
-    : public UnaryFunctor<ArgumentT, ResultT> {
-  inline typename ResultT::cpptype apply(
-      const typename ArgumentT::cpptype &argument) const {
-    return static_cast<typename ResultT::cpptype>(argument);
-  }
-};
-
-template <typename ArgumentT, typename ResultT>
-class CastToAsciiStringFunctor : public UnaryFunctor<ArgumentT, ResultT> {
- public:
-  explicit CastToAsciiStringFunctor(const ArgumentT &argument_type,
-                                    const std::size_t max_string_length)
-      : argument_type_(argument_type),
-        max_string_length_(max_string_length) {}
-
-  inline void apply(const typename ArgumentT::cpptype &argument, void *result) const {
-    std::string str = argument_type_.printValueToString(&argument);
-    const std::size_t str_len = str.length();
-
-    if (str_len < max_string_length_) {
-      std::memcpy(result, str.c_str(), str_len);
-      static_cast<char *>(result)[str_len] = 0;
-    } else {
-      std::memcpy(result, str.c_str(), max_string_length_);
-    }
-  }
-
-  inline TypedValue apply(const typename ArgumentT::cpptype &argument) const {
-    std::string str = argument_type_.printValueToString(&argument);
-    const std::size_t len = std::min(str.length(), max_string_length_);
-    const std::size_t buf_len = len + 1;
-
-    char *buf = static_cast<char *>(std::malloc(buf_len));
-    std::memcpy(buf, str.c_str(), len);
-    buf[len] = 0;
-    return TypedValue::CreateWithOwnedData(kVarChar, buf, buf_len);
-  }
-
- private:
-  const ArgumentT &argument_type_;
-  const std::size_t max_string_length_;
-};
-
-template <typename ResultCppType>
-ResultCppType CastStringToNumericImpl(const char *str);
-
-template <>
-bool CastStringToNumericImpl(const char *str) {
-  const std::string lo_str = ToLower(str);
-  if (lo_str == "true") {
-    return true;
-  } else {
-    return false;
-  }
-}
-template <>
-int CastStringToNumericImpl(const char *str) {
-  return std::atoi(str);
-}
-template <>
-float CastStringToNumericImpl(const char *str) {
-  return static_cast<float>(std::atof(str));
-}
-template <>
-std::int64_t CastStringToNumericImpl(const char *str) {
-  return std::atoll(str);
-}
-template <>
-double CastStringToNumericImpl(const char *str) {
-  return std::atof(str);
+template <typename SourceType, typename TargetType>
+UncheckedUnaryOperator* MakeUncheckedCastOperatorConstructorSpec(
+    const SourceType &source_type,
+    const TargetType &target_type,
+    decltype(new CastFunctor<SourceType, TargetType>()) * = 0) {
+  return new UncheckedUnaryOperatorWrapperCodegen<
+      CastFunctor<SourceType, TargetType>>(
+          source_type, target_type);
 }
 
-template <typename ArgumentT, typename ResultT,
-          typename ResultT::cpptype f(const char*)>
-struct AsciiStringCastToNumericFunctor
-    : public UnaryFunctor<ArgumentT, ResultT> {
-  explicit AsciiStringCastToNumericFunctor(const std::size_t max_string_length)
-      : max_string_length_(max_string_length) {}
-
-  inline typename ResultT::cpptype apply(const TypedValue &argument) const {
-    return f(static_cast<const char*>(argument.getDataPtr()));
-  }
+template <typename SourceType, typename TargetType>
+UncheckedUnaryOperator* MakeUncheckedCastOperatorConstructorSpec(
+    const SourceType &source_type,
+    const TargetType &target_type,
+    decltype(new CastFunctor<SourceType, TargetType>(source_type, target_type)) * = 0) {
+  return new UncheckedUnaryOperatorWrapperCodegen<
+      CastFunctor<SourceType, TargetType>>(
+          source_type, target_type, source_type, target_type);
+}
 
-  inline typename ResultT::cpptype apply(const void *argument) const {
-    const char *str = static_cast<const char*>(argument);
-    const std::string value(str, strnlen(str, max_string_length_));
-    return f(value.c_str());
-  }
+template <typename SourceType, typename TargetType>
+UncheckedUnaryOperator* MakeUncheckedCastOperator(
+    const Type &source_type,
+    const Type &target_type,
+    std::enable_if_t<meta::IsCompleteType<CastFunctor<SourceType, TargetType>>::value> * = 0) {
+  return MakeUncheckedCastOperatorConstructorSpec(
+      static_cast<const SourceType&>(source_type),
+      static_cast<const TargetType&>(target_type));
+}
 
- private:
-  const std::size_t max_string_length_;
-};
+template <typename SourceType, typename TargetType>
+UncheckedUnaryOperator* MakeUncheckedCastOperator(
+    const Type &source_type,
+    const Type &target_type,
+    std::enable_if_t<!meta::IsCompleteType<CastFunctor<SourceType, TargetType>>::value> * = 0) {
+  LOG(FATAL) << "Unsupported cast from type " << source_type.getName()
+             << " to type " << target_type.getName();
+}
 
-template <typename ArgumentT, typename ResultT>
-struct AsciiStringCastToAsciiStringFunctor
-    : public UnaryFunctor<ArgumentT, ResultT> {
-  explicit AsciiStringCastToAsciiStringFunctor(const std::size_t max_string_length)
-      : max_string_length_(max_string_length) {}
+}  // namespace
 
-  inline void apply(const void *argument, void *result) const {
-    std::memcpy(result, argument, max_string_length_);
+const Type* CastOperation::ExtractTargetType(
+    const Type &type,
+    const std::vector<TypedValue> &static_arguments) {
+  if (static_arguments.size() != 1) {
+    return nullptr;
   }
-
-  inline void apply(const TypedValue &argument, void *result) const {
-    std::memcpy(result,
-                argument.getOutOfLineData(),
-                std::min(argument.getDataSize(), max_string_length_));
+  const GenericValue meta_type_value =
+      GenericValue::CreateWithTypedValue(MetaType::InstanceNonNullable(),
+                                         static_arguments.front());
+  if (meta_type_value.isNull() || meta_type_value.getTypeID() != kMetaType) {
+    return nullptr;
   }
+  return meta_type_value.getLiteral<kMetaType>();
+}
 
-  inline TypedValue apply(const void *argument) const {
-    const std::size_t len =
-        strnlen(static_cast<const char*>(argument), max_string_length_);
-
-    char *buf = static_cast<char *>(std::malloc(len+1));
-    std::memcpy(buf, argument, len);
-    buf[len] = 0;
-    return TypedValue::CreateWithOwnedData(kVarChar, buf, len+1);
+bool CastOperation::canApplyTo(
+    const Type &type,
+    const std::vector<TypedValue> &static_arguments,
+    std::string *message) const {
+  const Type *target_type = ExtractTargetType(type, static_arguments);
+  if (target_type == nullptr) {
+    *message = "Invalid target type";
+    return false;
   }
-
-  inline TypedValue apply(const TypedValue &argument) const {
-    const std::size_t len =
-        std::min(argument.getDataSize() - 1, max_string_length_);
-
-    char *buf = static_cast<char *>(std::malloc(len+1));
-    std::memcpy(buf, argument.getDataPtr(), len);
-    buf[len] = 0;
-    return TypedValue::CreateWithOwnedData(kVarChar, buf, len+1);
+  if (!target_type->isCoercibleFrom(type)) {
+    *message = "Unsupported cast from " + type.getName() +
+               " to " + target_type->getName();
+    return false;
   }
+  return true;
+}
 
- private:
-  const std::size_t max_string_length_;
-};
-
-}  // namespace
-
-const re2::RE2 CastOperation::kTypePattern("([a-z]+)(\\(([0-9]+)\\))?");
-
-const std::map<std::string, TypeID> CastOperation::kNameToTypeIDMap = {
-    { "bool",    kBool },
-    { "int",     kInt },
-    { "long",    kLong },
-    { "float",   kFloat },
-    { "double",  kDouble },
-    { "char",    kChar },
-    { "varchar", kVarChar }
-};
+const Type* CastOperation::getResultType(
+    const Type &type,
+    const std::vector<TypedValue> &static_arguments) const {
+  const Type *target_type = ExtractTargetType(type, static_arguments);
+  DCHECK(target_type != nullptr);
+  return target_type;
+}
 
 UncheckedUnaryOperator* CastOperation::makeUncheckedUnaryOperator(
     const Type &type,
@@ -199,100 +135,20 @@ UncheckedUnaryOperator* CastOperation::makeUncheckedUnaryOperator(
   const Type *result_type = getResultType(type, static_arguments);
   DCHECK(result_type != nullptr);
 
-  const TypeID argument_type_id = type.getTypeID();
-  const TypeID result_type_id = result_type->getTypeID();
-
-  if (QUICKSTEP_EQUALS_ANY_CONSTANT(argument_type_id, kBool, kInt, kLong, kFloat, kDouble)) {
-    return InvokeOnTypeID<TypeIDSelectorNumeric>(
-        argument_type_id,
-        [&](auto arg_tid) -> UncheckedUnaryOperator* {  // NOLINT(build/c++11)
-      using ArgumentT = typename TypeIDTrait<decltype(arg_tid)::value>::TypeClass;
-
-      switch (result_type_id) {
-        case kBool:  // Fall through
-        case kInt:
-        case kLong:
-        case kFloat:
-        case kDouble: {
-          return InvokeOnTypeID<TypeIDSelectorNumeric>(
-              result_type_id,
-              [&](auto result_tid) -> UncheckedUnaryOperator* {  // NOLINT(build/c++11)
-            using ResultT = typename TypeIDTrait<decltype(result_tid)::value>::TypeClass;
-
-            return new UncheckedUnaryOperatorWrapperCodegen<
-                NumericCastToNumericFunctor<ArgumentT, ResultT>>(type, *result_type);
-          });
-        }
-        case kChar:  // Fall through
-        case kVarChar: {
-          return InvokeOnTypeID<TypeIDSelector<kChar, kVarChar>>(
-              result_type_id,
-              [&](auto result_tid) -> UncheckedUnaryOperator* {  // NOLINT(build/c++11)
-            using ResultT = typename TypeIDTrait<decltype(result_tid)::value>::TypeClass;
-
-            return new UncheckedUnaryOperatorWrapperCodegen<
-                 CastToAsciiStringFunctor<ArgumentT, ResultT>>(
-                     type, *result_type,
-                     static_cast<const ArgumentT&>(type),
-                     static_cast<const ResultT*>(result_type)->getStringLength());
-          });
-        }
-        default:
-          LOG(FATAL) << "Unexpected result type " << result_type->getName()
-                     << " in CastOperation::makeUncheckedUnaryOperator "
-                     << "for argument type " << type.getName();
-      }
+  const TypeID source_type_id = type.getTypeID();
+  const TypeID target_type_id = result_type->getTypeID();
+
+  return InvokeOnTypeID(
+      source_type_id,
+      [&](auto source) -> UncheckedUnaryOperator* {
+    return InvokeOnTypeID(
+        target_type_id,
+        [&](auto target) -> UncheckedUnaryOperator* {
+      return MakeUncheckedCastOperator<
+          typename TypeIDTrait<decltype(source)::value>::TypeClass,
+          typename TypeIDTrait<decltype(target)::value>::TypeClass>(type, *result_type);
     });
-  } else if (QUICKSTEP_EQUALS_ANY_CONSTANT(argument_type_id, kChar, kVarChar)) {
-    return InvokeOnTypeID<TypeIDSelector<kChar, kVarChar>>(
-        argument_type_id,
-        [&](auto arg_tid) -> UncheckedUnaryOperator* {  // NOLINT(build/c++11)
-      using ArgumentT = typename TypeIDTrait<decltype(arg_tid)::value>::TypeClass;
-
-      switch (result_type_id) {
-        case kBool:  // Fall through
-        case kInt:
-        case kLong:
-        case kFloat:
-        case kDouble: {
-          return InvokeOnTypeID<TypeIDSelectorNumeric>(
-              result_type_id,
-              [&](auto result_tid) -> UncheckedUnaryOperator* {  // NOLINT(build/c++11)
-            using ResultT = typename TypeIDTrait<decltype(result_tid)::value>::TypeClass;
-
-            return new UncheckedUnaryOperatorWrapperCodegen<
-                AsciiStringCastToNumericFunctor<
-                    ArgumentT, ResultT,
-                    CastStringToNumericImpl<typename ResultT::cpptype>>>(
-                        type, *result_type,
-                        static_cast<const ArgumentT&>(type).getStringLength());
-          });
-        }
-        case kChar:  // Fall through
-        case kVarChar: {
-          return InvokeOnTypeID<TypeIDSelector<kChar, kVarChar>>(
-              result_type_id,
-              [&](auto result_tid) -> UncheckedUnaryOperator* {  // NOLINT(build/c++11)
-            using ResultT = typename TypeIDTrait<decltype(result_tid)::value>::TypeClass;
-
-            return new UncheckedUnaryOperatorWrapperCodegen<
-                 AsciiStringCastToAsciiStringFunctor<ArgumentT, ResultT>>(
-                     type, *result_type,
-                     std::min(static_cast<const ArgumentT&>(type).getStringLength(),
-                              static_cast<const ResultT*>(result_type)->getStringLength()));
-          });
-        }
-        default:
-          LOG(FATAL) << "Unexpected result type " << result_type->getName()
-                     << " in CastOperation::makeUncheckedUnaryOperator "
-                     << "for argument type " << type.getName();
-      }
-    });
-  }
-
-  LOG(FATAL) << "Unexpected argument type in "
-             << "CastOperation::makeUncheckedUnaryOperator: "
-             << result_type->getName();
+  });
 }
 
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/CastOperation.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/CastOperation.hpp b/types/operations/unary_operations/CastOperation.hpp
index c0d3357..b8750c0 100644
--- a/types/operations/unary_operations/CastOperation.hpp
+++ b/types/operations/unary_operations/CastOperation.hpp
@@ -64,7 +64,7 @@ class CastOperation : public UnaryOperation {
   std::vector<OperationSignaturePtr> getSignatures() const override {
     const std::vector<TypeID> source_type_ids =
         { kBool, kInt, kLong, kFloat, kDouble, kChar, kVarChar };
-    const std::vector<TypeID> target_type_carrier = { kVarChar };
+    const std::vector<TypeID> target_type_carrier = { kMetaType };
 
     std::vector<OperationSignaturePtr> signatures;
     for (const TypeID source_type_id : source_type_ids) {
@@ -76,68 +76,20 @@ class CastOperation : public UnaryOperation {
 
   bool canApplyTo(const Type &type,
                   const std::vector<TypedValue> &static_arguments,
-                  std::string *message) const override {
-    DCHECK_EQ(1u, static_arguments.size());
-    if (getResultTypeInternal(type, static_arguments.front()) == nullptr) {
-      *message = "Invalid target type for CAST";
-      return false;
-    }
-    return true;
-  }
+                  std::string *message) const override;
 
   const Type* getResultType(
       const Type &type,
-      const std::vector<TypedValue> &static_arguments) const override {
-    DCHECK_EQ(1u, static_arguments.size());
-    const Type *target_type =
-        getResultTypeInternal(type, static_arguments.front());
-    DCHECK(target_type != nullptr);
-    return target_type;
-  }
+      const std::vector<TypedValue> &static_arguments) const override;
 
   UncheckedUnaryOperator* makeUncheckedUnaryOperator(
       const Type &type,
       const std::vector<TypedValue> &static_arguments) const override;
 
  private:
-  static const Type* getResultTypeInternal(const Type &type,
-                                           const TypedValue &type_arg) {
-    DCHECK(type_arg.getTypeID() == kVarChar);
-    const std::string type_str =
-        ToLower(std::string(static_cast<const char*>(type_arg.getOutOfLineData())));
-
-    const re2::StringPiece type_piece(type_str);
-    std::string type_name;
-    std::string length_str;
-    if (!re2::RE2::FullMatch(type_piece,
-                             kTypePattern,
-                             &type_name,
-                             static_cast<void *>(nullptr),
-                             &length_str)) {
-      return nullptr;
-    }
-
-    auto it = kNameToTypeIDMap.find(type_name);
-    if (it == kNameToTypeIDMap.end()) {
-      return nullptr;
-    }
-
-    if (length_str.empty()) {
-      return &TypeFactory::GetType(it->second);
-    } else {
-      TypedValue length_value;
-      if (IntType::InstanceNonNullable().parseTypedValueFromString(length_str, &length_value)) {
-        return &TypeFactory::GetType(
-            it->second,
-            static_cast<std::size_t>(length_value.getLiteral<int>()),
-            type.isNullable());
-      }
-    }
-    return nullptr;
-  }
-
-  static const re2::RE2 kTypePattern;
-  static const std::map<std::string, TypeID> kNameToTypeIDMap;
+  static const Type* ExtractTargetType(
+      const Type &type,
+      const std::vector<TypedValue> &static_arguments);
 
   DISALLOW_COPY_AND_ASSIGN(CastOperation);
 };

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/unary_operations/UnaryOperationWrapper.hpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/UnaryOperationWrapper.hpp b/types/operations/unary_operations/UnaryOperationWrapper.hpp
index 00562a6..78285fa 100644
--- a/types/operations/unary_operations/UnaryOperationWrapper.hpp
+++ b/types/operations/unary_operations/UnaryOperationWrapper.hpp
@@ -33,8 +33,8 @@
 #include "types/TypedValue.hpp"
 #include "types/containers/ColumnVector.hpp"
 #include "types/operations/OperationSignature.hpp"
-#include "types/operations/OperationUtil.hpp"
 #include "types/operations/unary_operations/UnaryOperation.hpp"
+#include "types/operations/utility/OperationSynthesizeUtil.hpp"
 #include "utility/Macros.hpp"
 
 namespace quickstep {
@@ -89,8 +89,8 @@ class UncheckedUnaryOperatorWrapperCodegen : public UncheckedUnaryOperator {
   using ResultType = typename FunctorT::ResultType;
 
   using FuncSpec = typename FunctorSpecializer<FunctorT, SpecArgs...>::type;
-  using ArgumentGen = Codegen<FuncSpec, ArgumentType>;
-  using ResultGen = Codegen<FuncSpec, ResultType>;
+  using ArgumentGen = OperationCodegen<FuncSpec, ArgumentType>;
+  using ResultGen = OperationCodegen<FuncSpec, ResultType>;
 
   template <bool argument_nullable>
   struct Implementation;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/utility/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/operations/utility/CMakeLists.txt b/types/operations/utility/CMakeLists.txt
new file mode 100644
index 0000000..89b1dc6
--- /dev/null
+++ b/types/operations/utility/CMakeLists.txt
@@ -0,0 +1,37 @@
+# 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.
+
+# Declare micro-libs:
+add_library(quickstep_types_operations_utility_CastUtil CastUtil.cpp CastUtil.hpp)
+add_library(quickstep_types_operations_utility_OperationSynthesizeUtil
+            ../../../empty_src.cpp
+            OperationSynthesizeUtil.hpp)
+
+# Link dependencies:
+target_link_libraries(quickstep_types_operations_utility_CastUtil
+                      glog)
+target_link_libraries(quickstep_types_operations_utility_OperationSynthesizeUtil
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_types_Type
+                      quickstep_types_TypedValue
+                      quickstep_types_containers_ColumnVector)
+
+# Module all-in-one library:
+add_library(quickstep_types_operations_utility ../../../empty_src.cpp)
+target_link_libraries(quickstep_types_operations_utility
+                      quickstep_types_operations_utility_CastUtil
+                      quickstep_types_operations_utility_OperationSynthesizeUtil)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/utility/CastUtil.cpp
----------------------------------------------------------------------
diff --git a/types/operations/utility/CastUtil.cpp b/types/operations/utility/CastUtil.cpp
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/98d79448/types/operations/utility/CastUtil.hpp
----------------------------------------------------------------------
diff --git a/types/operations/utility/CastUtil.hpp b/types/operations/utility/CastUtil.hpp
new file mode 100644
index 0000000..e69de29


Mime
View raw message