You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ha...@apache.org on 2016/05/31 18:19:31 UTC

incubator-quickstep git commit: New type for fixed precision number: Decimal.

Repository: incubator-quickstep
Updated Branches:
  refs/heads/decimal-type [created] 06dce00d4


New type for fixed precision number: Decimal.


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/06dce00d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/06dce00d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/06dce00d

Branch: refs/heads/decimal-type
Commit: 06dce00d46aefa7bdde4e25fcd1dd5468affc88e
Parents: 50b4e55
Author: Hakan Memisoglu <ha...@apache.org>
Authored: Tue May 31 13:14:42 2016 -0500
Committer: Hakan Memisoglu <ha...@apache.org>
Committed: Tue May 31 13:14:42 2016 -0500

----------------------------------------------------------------------
 parser/SqlParser.ypp                            |   2 +-
 types/CMakeLists.txt                            |  16 +++
 types/DecimalLit.hpp                            | 131 +++++++++++++++++++
 types/DecimalType.cpp                           | 115 ++++++++++++++++
 types/DecimalType.hpp                           | 121 +++++++++++++++++
 types/NumericSuperType.hpp                      |   2 +-
 types/NumericTypeUnifier.hpp                    |  46 +++++++
 types/Type.cpp                                  |   3 +
 types/Type.hpp                                  |   3 +
 types/Type.proto                                |   9 +-
 types/TypeFactory.cpp                           |  10 ++
 types/TypeFactory.hpp                           |   1 +
 types/TypeID.cpp                                |   1 +
 types/TypeID.hpp                                |   1 +
 types/TypedValue.cpp                            |  11 ++
 types/TypedValue.hpp                            |  21 +++
 types/TypedValue.proto                          |   7 +-
 .../binary_operations/AddBinaryOperation.cpp    |  10 +-
 .../ArithmeticBinaryOperation.hpp               |  19 +++
 .../ArithmeticBinaryOperators.hpp               | 106 +++++++++++++++
 .../operations/binary_operations/CMakeLists.txt |   2 +
 .../binary_operations/DivideBinaryOperation.cpp |   7 +-
 .../binary_operations/ModuloBinaryOperation.cpp |  13 ++
 .../MultiplyBinaryOperation.cpp                 |  12 +-
 .../SubtractBinaryOperation.cpp                 |   9 +-
 .../operations/comparisons/BasicComparison.cpp  |   4 +-
 .../operations/comparisons/BasicComparison.hpp  |  22 +++-
 types/operations/comparisons/CMakeLists.txt     |   1 +
 .../comparisons/LiteralComparators.hpp          | 127 ++++++++++++++++++
 29 files changed, 812 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/parser/SqlParser.ypp
----------------------------------------------------------------------
diff --git a/parser/SqlParser.ypp b/parser/SqlParser.ypp
index b07c48e..eb2d0cf 100644
--- a/parser/SqlParser.ypp
+++ b/parser/SqlParser.ypp
@@ -730,7 +730,7 @@ data_type:
     $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDatetime));
   }
   | TOKEN_DECIMAL {
-    $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble));
+    $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDecimal));
   }
   | TOKEN_REAL {
     $$ = new quickstep::ParseDataType(quickstep::TypeFactory::GetType(quickstep::kDouble));

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/CMakeLists.txt b/types/CMakeLists.txt
index 0ccdfd7..eb2d4ba 100644
--- a/types/CMakeLists.txt
+++ b/types/CMakeLists.txt
@@ -35,6 +35,8 @@ add_library(quickstep_types_DateOperatorOverloads ../empty_src.cpp DateOperatorO
 add_library(quickstep_types_DatetimeIntervalType DatetimeIntervalType.cpp DatetimeIntervalType.hpp)
 add_library(quickstep_types_DatetimeLit ../empty_src.cpp DatetimeLit.hpp)
 add_library(quickstep_types_DatetimeType DatetimeType.cpp DatetimeType.hpp)
+add_library(quickstep_types_DecimalLit ../empty_src.cpp DecimalLit.hpp)
+add_library(quickstep_types_DecimalType DecimalType.cpp DecimalType.hpp)
 add_library(quickstep_types_DoubleType DoubleType.cpp DoubleType.hpp)
 add_library(quickstep_types_FloatType FloatType.cpp FloatType.hpp)
 add_library(quickstep_types_IntType IntType.cpp IntType.hpp)
@@ -94,6 +96,16 @@ target_link_libraries(quickstep_types_DatetimeType
                       quickstep_types_port_timegm
                       quickstep_utility_CheckSnprintf
                       quickstep_utility_Macros)
+target_link_libraries(quickstep_types_DecimalType
+                      glog
+                      quickstep_types_DecimalLit
+                      quickstep_types_NullCoercibilityCheckMacro
+                      quickstep_types_NumericSuperType
+                      quickstep_types_Type
+                      quickstep_types_TypeID
+                      quickstep_types_TypedValue
+                      quickstep_utility_Macros
+                      quickstep_utility_EqualsAnyConstant)
 target_link_libraries(quickstep_types_DoubleType
                       quickstep_types_NullCoercibilityCheckMacro
                       quickstep_types_NumericSuperType
@@ -158,6 +170,7 @@ target_link_libraries(quickstep_types_TypeFactory
                       quickstep_types_CharType
                       quickstep_types_DatetimeIntervalType
                       quickstep_types_DatetimeType
+                      quickstep_types_DecimalType
                       quickstep_types_DoubleType
                       quickstep_types_FloatType
                       quickstep_types_IntType
@@ -173,6 +186,7 @@ target_link_libraries(quickstep_types_TypedValue
                       farmhash
                       glog
                       quickstep_types_DatetimeLit
+                      quickstep_types_DecimalLit
                       quickstep_types_IntervalLit
                       quickstep_types_TypeID
                       quickstep_types_Type_proto
@@ -213,6 +227,8 @@ target_link_libraries(quickstep_types
                       quickstep_types_DatetimeIntervalType
                       quickstep_types_DatetimeLit
                       quickstep_types_DatetimeType
+                      quickstep_types_DecimalLit
+                      quickstep_types_DecimalType
                       quickstep_types_DoubleType
                       quickstep_types_FloatType
                       quickstep_types_IntType

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/DecimalLit.hpp
----------------------------------------------------------------------
diff --git a/types/DecimalLit.hpp b/types/DecimalLit.hpp
new file mode 100644
index 0000000..a9f3825
--- /dev/null
+++ b/types/DecimalLit.hpp
@@ -0,0 +1,131 @@
+/**
+ *   Copyright 2016, Quickstep Research Group, Computer Sciences Department,
+ *     University of Wisconsin\u2014Madison.
+ *
+ *   Licensed 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_DECIMAL_LIT_HPP_
+#define QUICKSTEP_TYPES_DECIMAL_LIT_HPP_
+
+#include <cstdint>
+#include <cmath>
+
+namespace quickstep {
+
+/** \addtogroup Type
+ *  @{
+ */
+
+/**
+ * @brief A literal representing fixed-precision decimal.
+ **/
+struct DecimalLit {
+  typedef std::int64_t data_type;
+
+  static DecimalLit fromDouble(double value) {
+    return DecimalLit{static_cast<data_type>(value * kMaxFractionInt)};
+  }
+
+  static DecimalLit fromInt(int64_t value) {
+    return DecimalLit{static_cast<data_type>(value * kMaxFractionInt)};
+  }
+
+  data_type data_;
+
+  static constexpr std::uint64_t kPrecisionWidth = 4;
+
+  static constexpr std::int64_t kMaxFractionInt = 10000;
+
+  inline std::uint64_t getFractionalPart() const {
+    return static_cast<std::uint64_t>(static_cast<std::uint64_t>(std::abs(data_)) % kMaxFractionInt);
+  }
+
+  inline std::int64_t getIntegerPart() const {
+    return static_cast<std::int64_t>(data_ / kMaxFractionInt);
+  }
+
+  inline bool operator<(const DecimalLit& other) const {
+    return data_ < other.data_;
+  }
+
+  inline bool operator>(const DecimalLit& other) const {
+    return data_ > other.data_;
+  }
+
+  inline bool operator<=(const DecimalLit& other) const {
+    return data_ <= other.data_;
+  }
+
+  inline bool operator>=(const DecimalLit& other) const {
+    return data_ >= other.data_;
+  }
+
+  inline bool operator==(const DecimalLit& other) const {
+    return data_ == other.data_;
+  }
+
+  inline bool operator!=(const DecimalLit& other) const {
+    return data_ != other.data_;
+  }
+
+  inline DecimalLit operator-() const {
+    return DecimalLit{-data_};
+  }
+
+  inline DecimalLit operator+(const DecimalLit& other) const {
+    return DecimalLit{data_ + other.data_};
+  }
+
+  inline DecimalLit operator-(const DecimalLit& other) const {
+    return DecimalLit{data_ - other.data_};
+  }
+
+  inline DecimalLit operator*(const DecimalLit& other) const {
+    return DecimalLit{(data_ * other.data_) / kMaxFractionInt};
+  }
+
+  inline DecimalLit operator/(const DecimalLit& other) const {
+    return DecimalLit{(data_ * kMaxFractionInt) / other.data_};
+  }
+
+  inline DecimalLit operator%(const DecimalLit& other) const {
+    return DecimalLit{data_ % other.data_};
+  }
+
+  inline DecimalLit& operator+=(const DecimalLit& other) {
+    data_ += other.data_;
+    return *this;
+  }
+
+  inline DecimalLit& operator-=(const DecimalLit& other) {
+    data_ -= other.data_;
+    return *this;
+  }
+
+  inline DecimalLit& operator*=(const DecimalLit& other) {
+    data_ = (data_ * other.data_) / kMaxFractionInt;
+    return *this;
+  }
+
+  inline DecimalLit& operator/=(const DecimalLit& other) {
+    data_ = (data_ * kMaxFractionInt) / other.data_;
+    return *this;
+  }
+};
+
+//** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_DECIMAL_LIT_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/DecimalType.cpp
----------------------------------------------------------------------
diff --git a/types/DecimalType.cpp b/types/DecimalType.cpp
new file mode 100644
index 0000000..db41033
--- /dev/null
+++ b/types/DecimalType.cpp
@@ -0,0 +1,115 @@
+/**
+ *   Copyright 2016, Quickstep Research Group, Computer Sciences Department,
+ *     University of Wisconsin\u2014Madison.
+ *
+ *   Licensed 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/DecimalType.hpp"
+
+#include <cstdint>
+#include <cstdio>
+#include <string>
+#include <sstream>
+
+#include "types/DecimalLit.hpp"
+#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 {
+
+class Type;
+
+const TypeID DecimalType::kStaticTypeID = kDecimal;
+
+bool DecimalType::isSafelyCoercibleFrom(const Type &original_type) const {
+  QUICKSTEP_NULL_COERCIBILITY_CHECK();
+  return QUICKSTEP_EQUALS_ANY_CONSTANT(original_type.getTypeID(),
+                                       kInt, kDecimal);
+}
+
+TypedValue DecimalType::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(DecimalLit::fromInt(original_value.getLiteral<int>()));
+    case kLong:
+      return TypedValue(DecimalLit::fromInt(original_value.getLiteral<std::int64_t>()));
+    case kFloat:
+      return TypedValue(DecimalLit::fromDouble(original_value.getLiteral<float>()));
+    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 DecimalType::printValueToString(const TypedValue &value) const {
+  DCHECK(!value.isNull());
+
+  DecimalLit decimal = value.getLiteral<DecimalLit>();
+  std::stringstream ss;
+  ss << decimal.getIntegerPart() << "."
+     << decimal.getFractionalPart();
+  return ss.str();
+}
+
+void DecimalType::printValueToFile(const TypedValue &value,
+                                   FILE *file,
+                                   const int padding) const {
+  DCHECK(!value.isNull());
+
+  DecimalLit decimal = value.getLiteral<DecimalLit>();
+
+  std::fprintf(file, "%*ld.%0*lu",
+               static_cast<int>(padding -
+                                (DecimalLit::kPrecisionWidth
+                                 + 1 /* Less one space for point. */)),
+               decimal.getIntegerPart(),
+               static_cast<int>(DecimalLit::kPrecisionWidth),
+               decimal.getFractionalPart());
+}
+
+bool DecimalType::parseValueFromString(const std::string &value_string,
+                                       TypedValue *value) const {
+  double parsed_double;
+  int read_chars;
+
+  int matched = std::sscanf(value_string.c_str(),
+                            "%lf%n",
+                            &parsed_double,
+                            &read_chars);
+
+  if (matched != 1 || read_chars != value_string.length())  {
+    return false;
+  }
+
+  *value = TypedValue(DecimalLit::fromDouble(parsed_double));
+  return true;
+}
+
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/DecimalType.hpp
----------------------------------------------------------------------
diff --git a/types/DecimalType.hpp b/types/DecimalType.hpp
new file mode 100644
index 0000000..68a204f
--- /dev/null
+++ b/types/DecimalType.hpp
@@ -0,0 +1,121 @@
+/**
+ *   Copyright 2016, Quickstep Research Group, Computer Sciences Department,
+ *     University of Wisconsin\u2014Madison.
+ *
+ *   Licensed 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_DECIMAL_TYPE_HPP_
+#define QUICKSTEP_TYPES_DECIMAL_TYPE_HPP_
+
+#include <limits>
+#include <string>
+
+#include "types/DecimalLit.hpp"
+#include "types/NumericSuperType.hpp"
+#include "types/TypeID.hpp"
+#include "types/TypedValue.hpp"
+#include "utility/Macros.hpp"
+
+namespace quickstep {
+
+class Type;
+
+/** \addtogroup Types
+ *  @{
+ */
+
+/**
+ * @brief A type representing a fixed-precision number.
+ **/
+class DecimalType : public NumericSuperType<DecimalLit> {
+ 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 DecimalType& InstanceNonNullable() {
+    static DecimalType 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 DecimalType& InstanceNullable() {
+    static DecimalType instance(true);
+    return instance;
+  }
+
+  static const DecimalType& 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;
+
+  void printValueToFile(const TypedValue &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;
+
+  TypedValue makeZeroValue() const override {
+    return TypedValue(DecimalLit::fromInt(0));
+  }
+
+ private:
+  static constexpr int kPrintWidth =
+      std::numeric_limits<DecimalLit::data_type>::digits10
+      + 1   // Decimal point '.'
+      + 1;  // Minus sign '-'
+
+  explicit DecimalType(const bool nullable)
+       : NumericSuperType<DecimalLit>(kDecimal, nullable) {
+  }
+
+  DISALLOW_COPY_AND_ASSIGN(DecimalType);
+};
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_DECIMAL_TYPE_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/NumericSuperType.hpp
----------------------------------------------------------------------
diff --git a/types/NumericSuperType.hpp b/types/NumericSuperType.hpp
index ec487e7..ac4183b 100644
--- a/types/NumericSuperType.hpp
+++ b/types/NumericSuperType.hpp
@@ -51,7 +51,7 @@ class NumericSuperType : public Type {
   }
 
   TypedValue makeZeroValue() const override {
-    return TypedValue(static_cast<CppType>(0));
+    return TypedValue(CppType());
   }
 
  protected:

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/NumericTypeUnifier.hpp
----------------------------------------------------------------------
diff --git a/types/NumericTypeUnifier.hpp b/types/NumericTypeUnifier.hpp
index 6ea8510..c2fb949 100644
--- a/types/NumericTypeUnifier.hpp
+++ b/types/NumericTypeUnifier.hpp
@@ -19,6 +19,7 @@
 
 namespace quickstep {
 
+class DecimalType;
 class DoubleType;
 class FloatType;
 class IntType;
@@ -76,6 +77,11 @@ struct NumericTypeUnifier<IntType, DoubleType> {
 };
 
 template<>
+struct NumericTypeUnifier<IntType, DecimalType> {
+  typedef DecimalType type;
+};
+
+template<>
 struct NumericTypeUnifier<LongType, IntType> {
   typedef LongType type;
 };
@@ -96,6 +102,11 @@ struct NumericTypeUnifier<LongType, DoubleType> {
 };
 
 template<>
+struct NumericTypeUnifier<LongType, DecimalType> {
+  typedef DecimalType type;
+};
+
+template<>
 struct NumericTypeUnifier<FloatType, IntType> {
   typedef FloatType type;
 };
@@ -116,6 +127,11 @@ struct NumericTypeUnifier<FloatType, DoubleType> {
 };
 
 template<>
+struct NumericTypeUnifier<FloatType, DecimalType> {
+  typedef DecimalType type;
+};
+
+template<>
 struct NumericTypeUnifier<DoubleType, IntType> {
   typedef DoubleType type;
 };
@@ -135,6 +151,36 @@ struct NumericTypeUnifier<DoubleType, DoubleType> {
   typedef DoubleType type;
 };
 
+template<>
+struct NumericTypeUnifier<DoubleType, DecimalType> {
+  typedef DecimalType type;
+};
+
+template<>
+struct NumericTypeUnifier<DecimalType, IntType> {
+  typedef DecimalType type;
+};
+
+template<>
+struct NumericTypeUnifier<DecimalType, LongType> {
+  typedef DecimalType type;
+};
+
+template<>
+struct NumericTypeUnifier<DecimalType, FloatType> {
+  typedef DecimalType type;
+};
+
+template<>
+struct NumericTypeUnifier<DecimalType, DoubleType> {
+  typedef DecimalType type;
+};
+
+template<>
+struct NumericTypeUnifier<DecimalType, DecimalType> {
+  typedef DecimalType type;
+};
+
 }  // namespace quickstep
 
 #endif  // QUICKSTEP_TYPES_NUMERIC_TYPE_UNIFIER_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/Type.cpp
----------------------------------------------------------------------
diff --git a/types/Type.cpp b/types/Type.cpp
index 8981bc2..4f199f1 100644
--- a/types/Type.cpp
+++ b/types/Type.cpp
@@ -41,6 +41,9 @@ serialization::Type Type::getProto() const {
     case kDouble:
       proto.set_type_id(serialization::Type::DOUBLE);
       break;
+    case kDecimal:
+      proto.set_type_id(serialization::Type::DECIMAL);
+      break;
     case kDatetime:
       proto.set_type_id(serialization::Type::DATETIME);
       break;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/Type.hpp
----------------------------------------------------------------------
diff --git a/types/Type.hpp b/types/Type.hpp
index fc6f4e2..33f38aa 100644
--- a/types/Type.hpp
+++ b/types/Type.hpp
@@ -34,6 +34,7 @@ namespace quickstep {
 
 struct DatetimeIntervalLit;
 struct DatetimeLit;
+struct DecimalLit;
 struct YearMonthIntervalLit;
 
 /** \addtogroup Types
@@ -370,6 +371,8 @@ class Type {
         return TypedValue(*static_cast<const float*>(value_ptr));
       case kDouble:
         return TypedValue(*static_cast<const double*>(value_ptr));
+      case kDecimal:
+        return TypedValue(*static_cast<const DecimalLit*>(value_ptr));
       case kDatetime:
         return TypedValue(*static_cast<const DatetimeLit*>(value_ptr));
       case kDatetimeInterval:

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/Type.proto
----------------------------------------------------------------------
diff --git a/types/Type.proto b/types/Type.proto
index dbf248e..337d962 100644
--- a/types/Type.proto
+++ b/types/Type.proto
@@ -25,10 +25,11 @@ message Type {
     DOUBLE = 3;
     CHAR = 4;
     VAR_CHAR = 5;
-    DATETIME = 6;
-    DATETIME_INTERVAL = 7;
-    YEAR_MONTH_INTERVAL = 8;
-    NULL_TYPE = 9;
+    DECIMAL = 6;
+    DATETIME = 7;
+    DATETIME_INTERVAL = 8;
+    YEAR_MONTH_INTERVAL = 9;
+    NULL_TYPE = 10;
   }
 
   required TypeID type_id = 1;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/TypeFactory.cpp
----------------------------------------------------------------------
diff --git a/types/TypeFactory.cpp b/types/TypeFactory.cpp
index a8f2961..e0b52d8 100644
--- a/types/TypeFactory.cpp
+++ b/types/TypeFactory.cpp
@@ -22,6 +22,7 @@
 #include "types/CharType.hpp"
 #include "types/DatetimeIntervalType.hpp"
 #include "types/DatetimeType.hpp"
+#include "types/DecimalType.hpp"
 #include "types/DoubleType.hpp"
 #include "types/FloatType.hpp"
 #include "types/IntType.hpp"
@@ -49,6 +50,8 @@ const Type& TypeFactory::GetType(const TypeID id,
       return FloatType::Instance(nullable);
     case kDouble:
       return DoubleType::Instance(nullable);
+    case kDecimal:
+      return DecimalType::Instance(nullable);
     case kDatetime:
       return DatetimeType::Instance(nullable);
     case kDatetimeInterval:
@@ -90,6 +93,7 @@ bool TypeFactory::ProtoIsValid(const serialization::Type &proto) {
     case serialization::Type::LONG:
     case serialization::Type::FLOAT:
     case serialization::Type::DOUBLE:
+    case serialization::Type::DECIMAL:
     case serialization::Type::DATETIME:
     case serialization::Type::DATETIME_INTERVAL:
     case serialization::Type::YEAR_MONTH_INTERVAL:
@@ -119,6 +123,8 @@ const Type& TypeFactory::ReconstructFromProto(const serialization::Type &proto)
       return FloatType::Instance(proto.nullable());
     case serialization::Type::DOUBLE:
       return DoubleType::Instance(proto.nullable());
+    case serialization::Type::DECIMAL:
+      return DecimalType::Instance(proto.nullable());
     case serialization::Type::DATETIME:
       return DatetimeType::Instance(proto.nullable());
     case serialization::Type::DATETIME_INTERVAL:
@@ -155,6 +161,8 @@ const Type* TypeFactory::GetUnifyingType(const Type &first, const Type &second)
       if (((first.getTypeID() == kLong) && (second.getTypeID() == kFloat))
             || ((first.getTypeID() == kFloat) && (second.getTypeID() == kLong))) {
         unifier = &(DoubleType::Instance(true));
+      } else if (first.getTypeID() == kDecimal || second.getTypeID() == kDecimal) {
+        unifier = &(DecimalType::Instance(true));
       }
     }
   } else {
@@ -163,6 +171,8 @@ const Type* TypeFactory::GetUnifyingType(const Type &first, const Type &second)
       if (((first.getTypeID() == kLong) && (second.getTypeID() == kFloat))
             || ((first.getTypeID() == kFloat) && (second.getTypeID() == kLong))) {
         unifier = &(DoubleType::Instance(false));
+      } else if (first.getTypeID() == kDecimal || second.getTypeID() == kDecimal) {
+        unifier = &(DecimalType::Instance(false));
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/TypeFactory.hpp
----------------------------------------------------------------------
diff --git a/types/TypeFactory.hpp b/types/TypeFactory.hpp
index ed9be5e..029d2bb 100644
--- a/types/TypeFactory.hpp
+++ b/types/TypeFactory.hpp
@@ -52,6 +52,7 @@ class TypeFactory {
       case kLong:
       case kFloat:
       case kDouble:
+      case kDecimal:
       case kDatetime:
       case kDatetimeInterval:
       case kYearMonthInterval:

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/TypeID.cpp
----------------------------------------------------------------------
diff --git a/types/TypeID.cpp b/types/TypeID.cpp
index 1aeea04..901b232 100644
--- a/types/TypeID.cpp
+++ b/types/TypeID.cpp
@@ -26,6 +26,7 @@ const char *kTypeNames[] = {
   "Double",
   "Char",
   "VarChar",
+  "Decimal",
   "Datetime",
   "DatetimeInterval",
   "YearMonthInterval",

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/TypeID.hpp
----------------------------------------------------------------------
diff --git a/types/TypeID.hpp b/types/TypeID.hpp
index 23d32da..ab52b96 100644
--- a/types/TypeID.hpp
+++ b/types/TypeID.hpp
@@ -34,6 +34,7 @@ enum TypeID {
   kDouble,
   kChar,
   kVarChar,
+  kDecimal,
   kDatetime,
   kDatetimeInterval,
   kYearMonthInterval,

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/TypedValue.cpp
----------------------------------------------------------------------
diff --git a/types/TypedValue.cpp b/types/TypedValue.cpp
index bc1ebd9..e964400 100644
--- a/types/TypedValue.cpp
+++ b/types/TypedValue.cpp
@@ -49,6 +49,7 @@ bool TypedValue::isPlausibleInstanceOf(const TypeSignature type) const {
     case kLong:
     case kFloat:
     case kDouble:
+    case kDecimal:
     case kDatetime:
     case kDatetimeInterval:
     case kYearMonthInterval:
@@ -104,6 +105,12 @@ serialization::TypedValue TypedValue::getProto() const {
         proto.set_double_value(getLiteral<double>());
       }
       break;
+    case kDecimal:
+      proto.set_type_id(serialization::Type::DECIMAL);
+      if (!isNull()) {
+        proto.set_decimal_value(value_union_.decimal_value.data_);
+      }
+      break;
     case kDatetime:
       proto.set_type_id(serialization::Type::DATETIME);
       if (!isNull()) {
@@ -171,6 +178,10 @@ TypedValue TypedValue::ReconstructFromProto(const serialization::TypedValue &pro
       return proto.has_double_value() ?
           TypedValue(static_cast<double>(proto.double_value())) :
           TypedValue(kDouble);
+    case serialization::Type::DECIMAL:
+      return proto.has_decimal_value() ?
+          TypedValue(DecimalLit{proto.decimal_value()}) :
+          TypedValue(kDecimal);
     case serialization::Type::DATETIME:
       if (proto.has_datetime_value()) {
         DatetimeLit datetime;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/TypedValue.hpp
----------------------------------------------------------------------
diff --git a/types/TypedValue.hpp b/types/TypedValue.hpp
index 6e22111..06d69ad 100644
--- a/types/TypedValue.hpp
+++ b/types/TypedValue.hpp
@@ -25,6 +25,7 @@
 #include <functional>
 
 #include "types/DatetimeLit.hpp"
+#include "types/DecimalLit.hpp"
 #include "types/IntervalLit.hpp"
 #include "types/TypeID.hpp"
 #include "types/TypedValue.pb.h"
@@ -126,6 +127,11 @@ class TypedValue {
     value_union_.double_value = literal_double == 0 ? 0 : literal_double;
   }
 
+  explicit TypedValue(const DecimalLit literal_decimal)
+      : value_info_(static_cast<std::uint64_t>(kDecimal)) {
+    value_union_.decimal_value = literal_decimal;
+  }
+
   /**
    * @brief Constructor for a literal value of DatetimeType.
    **/
@@ -276,6 +282,7 @@ class TypedValue {
       case kLong:
       case kFloat:
       case kDouble:
+      case kDecimal:
       case kDatetime:
       case kDatetimeInterval:
       case kYearMonthInterval:
@@ -307,6 +314,7 @@ class TypedValue {
         return sizeof(value_union_.int_value) <= sizeof(std::size_t);
       case kLong:
       case kDouble:
+      case kDecimal:
       case kDatetime:
       case kDatetimeInterval:
       case kYearMonthInterval:
@@ -384,6 +392,7 @@ class TypedValue {
         return sizeof(int);
       case kLong:
       case kDouble:
+      case kDecimal:
       case kDatetime:
       case kDatetimeInterval:
       case kYearMonthInterval:
@@ -469,6 +478,7 @@ class TypedValue {
                    || getTypeID() == kLong
                    || getTypeID() == kFloat
                    || getTypeID() == kDouble
+                   || getTypeID() == kDecimal
                    || getTypeID() == kDatetime
                    || getTypeID() == kDatetimeInterval
                    || getTypeID() == kYearMonthInterval));
@@ -564,6 +574,7 @@ class TypedValue {
       case kLong:
       case kFloat:
       case kDouble:
+      case kDecimal:
       case kDatetime:
       case kDatetimeInterval:
       case kYearMonthInterval:
@@ -659,6 +670,7 @@ class TypedValue {
       case kLong:
       case kFloat:
       case kDouble:
+      case kDecimal:
       case kDatetime:
       case kDatetimeInterval:
       case kYearMonthInterval:
@@ -778,6 +790,7 @@ class TypedValue {
     float float_value;
     double double_value;
     const void* out_of_line_data;
+    DecimalLit decimal_value;
     DatetimeLit datetime_value;
     DatetimeIntervalLit datetime_interval_value;
     YearMonthIntervalLit year_month_interval_value;
@@ -804,6 +817,7 @@ class TypedValue {
 
   static_assert(sizeof(ValueUnion) == sizeof(std::int64_t)
                     && sizeof(ValueUnion) == sizeof(double)
+                    && sizeof(ValueUnion) == sizeof(DecimalLit)
                     && sizeof(ValueUnion) == sizeof(DatetimeLit)
                     && sizeof(ValueUnion) == sizeof(DatetimeIntervalLit)
                     && sizeof(ValueUnion) == sizeof(YearMonthIntervalLit),
@@ -853,6 +867,13 @@ inline double TypedValue::getLiteral<double>() const {
 }
 
 template <>
+inline DecimalLit TypedValue::getLiteral<DecimalLit>() const {
+  DCHECK_EQ(kDecimal, getTypeID());
+  DCHECK(!isNull());
+  return value_union_.decimal_value;
+}
+
+template <>
 inline DatetimeLit TypedValue::getLiteral<DatetimeLit>() const {
   DCHECK_EQ(kDatetime, getTypeID());
   DCHECK(!isNull());

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/TypedValue.proto
----------------------------------------------------------------------
diff --git a/types/TypedValue.proto b/types/TypedValue.proto
index 78a38cb..a2b52f3 100644
--- a/types/TypedValue.proto
+++ b/types/TypedValue.proto
@@ -28,7 +28,8 @@ message TypedValue {
   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 int64 decimal_value = 7;
+  optional int64 datetime_value = 8;
+  optional int64 datetime_interval_value = 9;
+  optional int64 year_month_interval_value = 10;
 }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/AddBinaryOperation.cpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/AddBinaryOperation.cpp b/types/operations/binary_operations/AddBinaryOperation.cpp
index 6e6e839..18118d0 100644
--- a/types/operations/binary_operations/AddBinaryOperation.cpp
+++ b/types/operations/binary_operations/AddBinaryOperation.cpp
@@ -44,7 +44,8 @@ bool AddBinaryOperation::canApplyToTypes(const Type &left, const Type &right) co
     case kInt:  // Fall through.
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       return (right.getSuperTypeID() == Type::kNumeric);
     }
     case kDatetime: {
@@ -229,12 +230,14 @@ TypedValue AddBinaryOperation::applyToChecked(const TypedValue &left,
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       switch (right_type.getTypeID()) {
         case kInt:
         case kLong:
         case kFloat:
         case kDouble:
+        case kDecimal:
           return applyToCheckedNumericHelper<AddFunctor>(left, left_type,
                                                          right, right_type);
         default:
@@ -304,7 +307,8 @@ UncheckedBinaryOperator* AddBinaryOperation::makeUncheckedBinaryOperatorForTypes
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       if (right.getSuperTypeID() == Type::kNumeric) {
         return makeNumericBinaryOperatorOuterHelper<AddArithmeticUncheckedBinaryOperator>(left, right);
       }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/ArithmeticBinaryOperation.hpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/ArithmeticBinaryOperation.hpp b/types/operations/binary_operations/ArithmeticBinaryOperation.hpp
index 3cad289..931c805 100644
--- a/types/operations/binary_operations/ArithmeticBinaryOperation.hpp
+++ b/types/operations/binary_operations/ArithmeticBinaryOperation.hpp
@@ -22,6 +22,7 @@
 
 #include <string>
 
+#include "types/DecimalType.hpp"
 #include "types/DoubleType.hpp"
 #include "types/FloatType.hpp"
 #include "types/IntType.hpp"
@@ -309,6 +310,14 @@ UncheckedBinaryOperator* ArithmeticBinaryOperation::makeNumericBinaryOperatorOut
         return makeNumericBinaryOperatorInnerHelper<OperatorType, DoubleType, false>(
             left, right);
       }
+    case kDecimal:
+      if (left.isNullable()) {
+        return makeNumericBinaryOperatorInnerHelper<OperatorType, DecimalType,
+                                                    true>(left, right);
+      } else {
+        return makeNumericBinaryOperatorInnerHelper<OperatorType, DecimalType,
+                                                    false>(left, right);
+      }
     default:
       throw OperationInapplicableToType(getName(), 2, left.getName().c_str(), right.getName().c_str());
   }
@@ -362,6 +371,16 @@ UncheckedBinaryOperator* ArithmeticBinaryOperation::makeNumericBinaryOperatorInn
                                 typename LeftType::cpptype, left_nullable,
                                 typename DoubleType::cpptype, false>();
       }
+    case kDecimal:
+      if (right.isNullable()) {
+        return new OperatorType<typename NumericTypeUnifier<LeftType, DecimalType>::type,
+                                typename LeftType::cpptype, left_nullable,
+                                typename DecimalType::cpptype, true>();
+      } else {
+        return new OperatorType<typename NumericTypeUnifier<LeftType, DecimalType>::type,
+                                typename LeftType::cpptype, left_nullable,
+                                typename DecimalType::cpptype, false>();
+      }
     default:
       throw OperationInapplicableToType(getName(), 2, left.getName().c_str(), right.getName().c_str());
   }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/ArithmeticBinaryOperators.hpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/ArithmeticBinaryOperators.hpp b/types/operations/binary_operations/ArithmeticBinaryOperators.hpp
index e5e1493..9b9c3c9 100644
--- a/types/operations/binary_operations/ArithmeticBinaryOperators.hpp
+++ b/types/operations/binary_operations/ArithmeticBinaryOperators.hpp
@@ -35,6 +35,7 @@
 #include "storage/ValueAccessorUtil.hpp"
 #endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
 
+#include "types/DecimalLit.hpp"
 #include "types/TypedValue.hpp"
 #include "types/containers/ColumnVector.hpp"
 #include "types/operations/binary_operations/BinaryOperation.hpp"
@@ -75,6 +76,27 @@ struct AddFunctor<float, std::int64_t> {
   }
 };
 
+template <>
+struct AddFunctor<DecimalLit, DecimalLit> {
+  inline DecimalLit operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left + right;
+  }
+};
+
+template <typename RightArgument>
+struct AddFunctor<DecimalLit, RightArgument> {
+  inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left + DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument>
+struct AddFunctor<LeftArgument, DecimalLit> {
+  inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) + right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct SubtractFunctor {
   inline auto operator() (const LeftArgument &left, const RightArgument &right) const -> decltype(left - right) {
     return left - right;
@@ -98,6 +120,27 @@ struct SubtractFunctor<float, std::int64_t> {
   }
 };
 
+template <>
+struct SubtractFunctor<DecimalLit, DecimalLit> {
+  inline DecimalLit operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left - right;
+  }
+};
+
+template <typename RightArgument>
+struct SubtractFunctor<DecimalLit, RightArgument> {
+  inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left - DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument>
+struct SubtractFunctor<LeftArgument, DecimalLit> {
+  inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) - right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct MultiplyFunctor {
   inline auto operator() (const LeftArgument &left, const RightArgument &right) const -> decltype(left * right) {
     return left * right;
@@ -121,6 +164,27 @@ struct MultiplyFunctor<float, std::int64_t> {
   }
 };
 
+template <>
+struct MultiplyFunctor<DecimalLit, DecimalLit> {
+  inline DecimalLit operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left / right;
+  }
+};
+
+template <typename RightArgument>
+struct MultiplyFunctor<DecimalLit, RightArgument> {
+  inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left * DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument>
+struct MultiplyFunctor<LeftArgument, DecimalLit> {
+  inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) * right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct DivideFunctor {
   inline auto operator() (const LeftArgument &left, const RightArgument &right) const -> decltype(left / right) {
     return left / right;
@@ -144,6 +208,27 @@ struct DivideFunctor<float, std::int64_t> {
   }
 };
 
+template <>
+struct DivideFunctor<DecimalLit, DecimalLit> {
+  inline DecimalLit operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left / right;
+  }
+};
+
+template <typename RightArgument>
+struct DivideFunctor<DecimalLit, RightArgument> {
+  inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left / DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument>
+struct DivideFunctor<LeftArgument, DecimalLit> {
+  inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) / right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct IntegerModuloFunctor {
   inline auto operator() (const LeftArgument &left, const RightArgument &right) const -> decltype(left % right) {
     return left % right;
@@ -162,6 +247,27 @@ template <typename LeftArgument, typename RightArgument> struct FloatModuloFunct
   }
 };
 
+template <>
+struct FloatModuloFunctor<DecimalLit, DecimalLit> {
+  inline DecimalLit operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left % right;
+  }
+};
+
+template <typename RightArgument>
+struct FloatModuloFunctor<DecimalLit, RightArgument> {
+  inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left % DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument>
+struct FloatModuloFunctor<LeftArgument, DecimalLit> {
+  inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) % right;
+  }
+};
+
 template <template <typename LeftCppType, typename RightCppType> class OpFunctor,
           typename ResultType,
           typename LeftCppType, bool left_nullable,

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/CMakeLists.txt b/types/operations/binary_operations/CMakeLists.txt
index 63db377..d503688 100644
--- a/types/operations/binary_operations/CMakeLists.txt
+++ b/types/operations/binary_operations/CMakeLists.txt
@@ -68,6 +68,7 @@ target_link_libraries(quickstep_types_operations_binaryoperations_AddBinaryOpera
                       quickstep_utility_Macros)
 target_link_libraries(quickstep_types_operations_binaryoperations_ArithmeticBinaryOperation
                       glog
+                      quickstep_types_DecimalType
                       quickstep_types_DoubleType
                       quickstep_types_FloatType
                       quickstep_types_IntType
@@ -87,6 +88,7 @@ target_link_libraries(quickstep_types_operations_binaryoperations_ArithmeticBina
                       quickstep_storage_StorageBlockInfo
                       quickstep_storage_ValueAccessor
                       quickstep_storage_ValueAccessorUtil
+                      quickstep_types_DecimalLit
                       quickstep_types_TypedValue
                       quickstep_types_containers_ColumnVector
                       quickstep_types_operations_binaryoperations_BinaryOperation

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/DivideBinaryOperation.cpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/DivideBinaryOperation.cpp b/types/operations/binary_operations/DivideBinaryOperation.cpp
index 23cbb99..2eb902c 100644
--- a/types/operations/binary_operations/DivideBinaryOperation.cpp
+++ b/types/operations/binary_operations/DivideBinaryOperation.cpp
@@ -47,6 +47,7 @@ bool DivideBinaryOperation::canApplyToTypes(const Type &left, const Type &right)
     case kLong:
     case kFloat:
     case kDouble:
+    case kDecimal:
     case kDatetimeInterval:
     case kYearMonthInterval: {
       return (right.getSuperTypeID() == Type::kNumeric);
@@ -238,7 +239,8 @@ TypedValue DivideBinaryOperation::applyToChecked(const TypedValue &left,
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       if (right_type.getSuperTypeID() == Type::kNumeric) {
         return applyToCheckedNumericHelper<DivideFunctor>(left, left_type,
                                                           right, right_type);
@@ -321,7 +323,8 @@ UncheckedBinaryOperator* DivideBinaryOperation::makeUncheckedBinaryOperatorForTy
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       if (right.getSuperTypeID() == Type::kNumeric) {
         return makeNumericBinaryOperatorOuterHelper<DivideArithmeticUncheckedBinaryOperator>(left, right);
       }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/ModuloBinaryOperation.cpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/ModuloBinaryOperation.cpp b/types/operations/binary_operations/ModuloBinaryOperation.cpp
index 9af5470..18144f2 100644
--- a/types/operations/binary_operations/ModuloBinaryOperation.cpp
+++ b/types/operations/binary_operations/ModuloBinaryOperation.cpp
@@ -223,6 +223,13 @@ TypedValue ModuloBinaryOperation::applyToChecked(const TypedValue &left,
       }
       break;
     }
+    case kDecimal: {
+      if (right_type.getSuperTypeID() == Type::kNumeric) {
+        return applyToCheckedNumericHelper<FloatModuloFunctor>(left, left_type,
+                                                                 right, right_type);
+      }
+      break;
+    }
     default:
       break;
   }
@@ -248,6 +255,12 @@ UncheckedBinaryOperator* ModuloBinaryOperation::makeUncheckedBinaryOperatorForTy
       }
       break;
     }
+    case kDecimal: {
+      if (right.getSuperTypeID() == Type::kNumeric) {
+        return makeNumericBinaryOperatorOuterHelper<FloatModuloArithmeticUncheckedBinaryOperator>(left, right);
+      }
+      break;
+    }
     default:
       break;
   }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/MultiplyBinaryOperation.cpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/MultiplyBinaryOperation.cpp b/types/operations/binary_operations/MultiplyBinaryOperation.cpp
index 970953d..dd342c5 100644
--- a/types/operations/binary_operations/MultiplyBinaryOperation.cpp
+++ b/types/operations/binary_operations/MultiplyBinaryOperation.cpp
@@ -51,6 +51,9 @@ bool MultiplyBinaryOperation::canApplyToTypes(const Type &left, const Type &righ
               right.getTypeID() == kDatetimeInterval   ||
               right.getTypeID() == kYearMonthInterval);
     }
+    case kDecimal: {
+      return (right.getSuperTypeID() == Type::kNumeric);
+    }
     case kDatetimeInterval:
     case kYearMonthInterval: {
       return (right.getSuperTypeID() == Type::kNumeric);
@@ -217,7 +220,8 @@ TypedValue MultiplyBinaryOperation::applyToChecked(const TypedValue &left,
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       if (right_type.getSuperTypeID() == Type::kNumeric) {
         return applyToCheckedNumericHelper<MultiplyFunctor>(left, left_type,
                                                             right, right_type);
@@ -311,6 +315,12 @@ UncheckedBinaryOperator* MultiplyBinaryOperation::makeUncheckedBinaryOperatorFor
       }
       break;
     }
+    case kDecimal: {
+      if (right.getSuperTypeID() == Type::kNumeric) {
+        return makeNumericBinaryOperatorOuterHelper<MultiplyArithmeticUncheckedBinaryOperator>(left, right);
+      }
+      break;
+    }
     case kDatetimeInterval: {
       switch (right.getTypeID()) {
         case kInt: {

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/binary_operations/SubtractBinaryOperation.cpp
----------------------------------------------------------------------
diff --git a/types/operations/binary_operations/SubtractBinaryOperation.cpp b/types/operations/binary_operations/SubtractBinaryOperation.cpp
index e410488..3464599 100644
--- a/types/operations/binary_operations/SubtractBinaryOperation.cpp
+++ b/types/operations/binary_operations/SubtractBinaryOperation.cpp
@@ -44,7 +44,8 @@ bool SubtractBinaryOperation::canApplyToTypes(const Type &left, const Type &righ
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       return (right.getSuperTypeID() == Type::kNumeric);
     }
     case kDatetime: {
@@ -287,7 +288,8 @@ TypedValue SubtractBinaryOperation::applyToChecked(const TypedValue &left,
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       if (right_type.getSuperTypeID() == Type::kNumeric) {
         return applyToCheckedNumericHelper<SubtractFunctor>(left, left_type,
                                                             right, right_type);
@@ -352,7 +354,8 @@ UncheckedBinaryOperator* SubtractBinaryOperation::makeUncheckedBinaryOperatorFor
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       if (right.getSuperTypeID() == Type::kNumeric) {
         return makeNumericBinaryOperatorOuterHelper<SubtractArithmeticUncheckedBinaryOperator>(left, right);
       }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/comparisons/BasicComparison.cpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/BasicComparison.cpp b/types/operations/comparisons/BasicComparison.cpp
index 21b92ca..e705646 100644
--- a/types/operations/comparisons/BasicComparison.cpp
+++ b/types/operations/comparisons/BasicComparison.cpp
@@ -38,12 +38,14 @@ bool BasicComparison::canCompareTypes(const Type &left, const Type &right) const
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       switch (right.getTypeID()) {
         case kInt:
         case kLong:
         case kFloat:
         case kDouble:
+        case kDecimal:
           return true;
         default:
           return false;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/comparisons/BasicComparison.hpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/BasicComparison.hpp b/types/operations/comparisons/BasicComparison.hpp
index 9741c32..7f2aad9 100644
--- a/types/operations/comparisons/BasicComparison.hpp
+++ b/types/operations/comparisons/BasicComparison.hpp
@@ -23,6 +23,7 @@
 #include <string>
 
 #include "types/DatetimeLit.hpp"
+#include "types/DecimalLit.hpp"
 #include "types/IntervalLit.hpp"
 #include "types/Type.hpp"
 #include "types/TypeErrors.hpp"
@@ -147,12 +148,14 @@ bool BasicComparison::compareTypedValuesCheckedHelper(const TypedValue &left,
     case kInt:
     case kLong:
     case kFloat:
-    case kDouble: {
+    case kDouble:
+    case kDecimal: {
       switch (right_type.getTypeID()) {
         case kInt:
         case kLong:
         case kFloat:
         case kDouble:
+        case kDecimal:
           break;
         default: {
           LOG(FATAL) << "Comparison " << getName() << " can not be applied to types "
@@ -252,6 +255,11 @@ bool BasicComparison::compareTypedValuesCheckedHelper(const TypedValue &left,
       return comparison_functor(left_coerced.getLiteral<double>(),
                                 right_coerced.getLiteral<double>());
     }
+    case kDecimal: {
+      ComparisonFunctor<DecimalLit> comparison_functor;
+      return comparison_functor(left_coerced.getLiteral<DecimalLit>(),
+                                right_coerced.getLiteral<DecimalLit>());
+    }
     default: {
       LOG(FATAL) << "Comparison " << getName() << " can not be applied to types "
                  << left_type.getName() << " and " << right_type.getName();
@@ -310,6 +318,12 @@ UncheckedComparator* BasicComparison::makeNumericComparatorOuterHelper(
       } else {
         return makeNumericComparatorInnerHelper<ComparatorType, double, false>(left, right);
       }
+    case kDecimal:
+      if (left.isNullable()) {
+        return makeNumericComparatorInnerHelper<ComparatorType, DecimalLit, true>(left, right);
+      } else {
+        return makeNumericComparatorInnerHelper<ComparatorType, DecimalLit, false>(left, right);
+      }
     default:
       throw OperationInapplicableToType(getName(), 2, left.getName().c_str(), right.getName().c_str());
   }
@@ -347,6 +361,12 @@ UncheckedComparator* BasicComparison::makeNumericComparatorInnerHelper(
       } else {
         return new ComparatorType<LeftCppType, left_type_nullable, double, false>();
       }
+    case kDecimal:
+      if (right.isNullable()) {
+        return new ComparatorType<LeftCppType, left_type_nullable, DecimalLit, true>();
+      } else {
+        return new ComparatorType<LeftCppType, left_type_nullable, DecimalLit, false>();
+      }
     default:
       throw OperationInapplicableToType(getName(), 2, left.getName().c_str(), right.getName().c_str());
   }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/comparisons/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/CMakeLists.txt b/types/operations/comparisons/CMakeLists.txt
index d2dfecf..266d1a2 100644
--- a/types/operations/comparisons/CMakeLists.txt
+++ b/types/operations/comparisons/CMakeLists.txt
@@ -65,6 +65,7 @@ target_link_libraries(quickstep_types_operations_comparisons_AsciiStringComparat
 target_link_libraries(quickstep_types_operations_comparisons_BasicComparison
                       glog
                       quickstep_types_DatetimeLit
+                      quickstep_types_DecimalLit
                       quickstep_types_IntervalLit
                       quickstep_types_Type
                       quickstep_types_TypeErrors

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06dce00d/types/operations/comparisons/LiteralComparators.hpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/LiteralComparators.hpp b/types/operations/comparisons/LiteralComparators.hpp
index 3bf6b00..c5ea1e0 100644
--- a/types/operations/comparisons/LiteralComparators.hpp
+++ b/types/operations/comparisons/LiteralComparators.hpp
@@ -45,6 +45,27 @@ template <typename LeftArgument, typename RightArgument> struct EqualFunctor
   }
 };
 
+template <> struct EqualFunctor<DecimalLit, DecimalLit>
+    : public std::binary_function<DecimalLit, DecimalLit, bool> {
+  inline bool operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left == right;
+  }
+};
+
+template <typename RightArgument> struct EqualFunctor<DecimalLit, RightArgument>
+    : public std::binary_function<DecimalLit, RightArgument, bool> {
+  inline bool operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left == DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument> struct EqualFunctor<LeftArgument, DecimalLit>
+    : public std::binary_function<LeftArgument, DecimalLit, bool> {
+  inline bool operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) == right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct NotEqualFunctor
     : public std::binary_function<LeftArgument, RightArgument, bool> {
   inline bool operator() (const LeftArgument &left, const RightArgument &right) const {
@@ -52,6 +73,27 @@ template <typename LeftArgument, typename RightArgument> struct NotEqualFunctor
   }
 };
 
+template <> struct NotEqualFunctor<DecimalLit, DecimalLit>
+    : public std::binary_function<DecimalLit, DecimalLit, bool> {
+  inline bool operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left != right;
+  }
+};
+
+template <typename RightArgument> struct NotEqualFunctor<DecimalLit, RightArgument>
+    : public std::binary_function<DecimalLit, RightArgument, bool> {
+  inline bool operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left != DecimalLit::fromDouble(right);
+  }
+};
+
+template <typename LeftArgument> struct NotEqualFunctor<LeftArgument, DecimalLit>
+    : public std::binary_function<LeftArgument, DecimalLit, bool> {
+  inline bool operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(left) != right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct LessFunctor
     : public std::binary_function<LeftArgument, RightArgument, bool> {
   inline bool operator() (const LeftArgument &left, const RightArgument &right) const {
@@ -59,6 +101,27 @@ template <typename LeftArgument, typename RightArgument> struct LessFunctor
   }
 };
 
+template <> struct LessFunctor<DecimalLit, DecimalLit>
+    : public std::binary_function<DecimalLit, DecimalLit, bool> {
+  inline bool operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left < right;
+  }
+};
+
+template <typename RightArgument> struct LessFunctor<DecimalLit, RightArgument>
+    : public std::binary_function<DecimalLit, RightArgument, bool> {
+  inline bool operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left < DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument> struct LessFunctor<LeftArgument, DecimalLit>
+    : public std::binary_function<LeftArgument, DecimalLit, bool> {
+  inline bool operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) < right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct LessOrEqualFunctor
     : public std::binary_function<LeftArgument, RightArgument, bool> {
   inline bool operator() (const LeftArgument &left, const RightArgument &right) const {
@@ -66,6 +129,27 @@ template <typename LeftArgument, typename RightArgument> struct LessOrEqualFunct
   }
 };
 
+template <> struct LessOrEqualFunctor<DecimalLit, DecimalLit>
+    : public std::binary_function<DecimalLit, DecimalLit, bool> {
+  inline bool operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left <= right;
+  }
+};
+
+template <typename RightArgument> struct LessOrEqualFunctor<DecimalLit, RightArgument>
+    : public std::binary_function<DecimalLit, RightArgument, bool> {
+  inline bool operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left <= DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument> struct LessOrEqualFunctor<LeftArgument, DecimalLit>
+    : public std::binary_function<LeftArgument, DecimalLit, bool> {
+  inline bool operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) <= right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct GreaterFunctor
     : public std::binary_function<LeftArgument, RightArgument, bool> {
   inline bool operator() (const LeftArgument &left, const RightArgument &right) const {
@@ -73,6 +157,27 @@ template <typename LeftArgument, typename RightArgument> struct GreaterFunctor
   }
 };
 
+template <> struct GreaterFunctor<DecimalLit, DecimalLit>
+    : public std::binary_function<DecimalLit, DecimalLit, bool> {
+  inline bool operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left > right;
+  }
+};
+
+template <typename RightArgument> struct GreaterFunctor<DecimalLit, RightArgument>
+    : public std::binary_function<DecimalLit, RightArgument, bool> {
+  inline bool operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left > DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument> struct GreaterFunctor<LeftArgument, DecimalLit>
+    : public std::binary_function<LeftArgument, DecimalLit, bool> {
+  inline bool operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) > right;
+  }
+};
+
 template <typename LeftArgument, typename RightArgument> struct GreaterOrEqualFunctor
     : public std::binary_function<LeftArgument, RightArgument, bool> {
   inline bool operator() (const LeftArgument &left, const RightArgument &right) const {
@@ -80,6 +185,28 @@ template <typename LeftArgument, typename RightArgument> struct GreaterOrEqualFu
   }
 };
 
+template <> struct GreaterOrEqualFunctor<DecimalLit, DecimalLit>
+    : public std::binary_function<DecimalLit, DecimalLit, bool> {
+  inline bool operator() (const DecimalLit &left, const DecimalLit &right) const {
+    return left >= right;
+  }
+};
+
+template <typename RightArgument> struct GreaterOrEqualFunctor<DecimalLit, RightArgument>
+    : public std::binary_function<DecimalLit, RightArgument, bool> {
+  inline bool operator() (const DecimalLit &left, const RightArgument &right) const {
+    return left >= DecimalLit::fromDouble(static_cast<double>(right));
+  }
+};
+
+template <typename LeftArgument> struct GreaterOrEqualFunctor<LeftArgument, DecimalLit>
+    : public std::binary_function<LeftArgument, DecimalLit, bool> {
+  inline bool operator() (const LeftArgument &left, const DecimalLit &right) const {
+    return DecimalLit::fromDouble(static_cast<double>(left)) >= right;
+  }
+};
+
+
 template <template <typename LeftArgument, typename RightArgument> class ComparisonFunctor,
           typename LeftCppType, bool left_nullable,
           typename RightCppType, bool right_nullable>