You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ji...@apache.org on 2017/10/11 18:38:28 UTC

[04/41] incubator-quickstep git commit: Updates to meta type

Updates to meta type


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

Branch: refs/heads/refactor-type
Commit: bef66ad47a6edb69f76f29c56d528a28ba7760b8
Parents: 1e69fb1
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Tue Oct 3 01:52:29 2017 -0500
Committer: Jianqiao Zhu <ji...@cs.wisc.edu>
Committed: Wed Oct 11 13:37:54 2017 -0500

----------------------------------------------------------------------
 types/ArrayType.cpp           | 29 +++++++++++++++
 types/ArrayType.hpp           |  7 +++-
 types/CMakeLists.txt          | 22 ++++++++++--
 types/MetaType.cpp            | 36 -------------------
 types/MetaType.hpp            | 44 +----------------------
 types/MetaTypeLite.cpp        | 52 +++++++++++++++++++++++++++
 types/MetaTypeLite.hpp        | 72 ++++++++++++++++++++++++++++++++++++++
 types/ParameterizedPodLit.hpp |  0
 types/Type.proto              |  4 +++
 types/TypeSynthesizer.hpp     |  8 ++---
 types/TypedValue.cpp          | 15 ++++++--
 11 files changed, 200 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/ArrayType.cpp
----------------------------------------------------------------------
diff --git a/types/ArrayType.cpp b/types/ArrayType.cpp
index c0f3a87..df2b9de 100644
--- a/types/ArrayType.cpp
+++ b/types/ArrayType.cpp
@@ -19,14 +19,43 @@
 
 #include "types/ArrayType.hpp"
 
+#include <cstdlib>
 #include <string>
 
+#include "types/Type.pb.h"
 #include "types/TypeID.hpp"
 
 #include "glog/logging.h"
 
 namespace quickstep {
 
+TypedValue ArrayType::marshallValue(const UntypedLiteral *value) const {
+  const ArrayLiteral &array = *static_cast<const ArrayLiteral*>(value);
+  serialization::ArrayLiteral proto;
+  for (const auto &element : array) {
+    // TODO(refactor-type): Improve performance.
+    TypedValue value = element_type_.marshallValue(element);
+    proto.add_data(value.getDataPtr(), value.getDataSize());
+  }
+  const std::size_t data_size = proto.ByteSize();
+  void *data = std::malloc(data_size);
+  proto.SerializeToArray(data, data_size);
+  return TypedValue::CreateWithOwnedData(kArray, data, data_size);
+}
+
+UntypedLiteral* ArrayType::unmarshallValue(const void *data,
+                                           const std::size_t data_size) const {
+  std::unique_ptr<ArrayLiteral> array = std::make_unique<ArrayLiteral>();
+  serialization::ArrayLiteral proto;
+  proto.ParseFromArray(data, data_size);
+  for (int i = 0; i < proto.data_size(); ++i) {
+    const std::string &element_data = proto.data(i);
+    array->emplace_back(
+        element_type_.unmarshallValue(element_data.c_str(), element_data.size()));
+  }
+  return array.release();
+}
+
 std::string ArrayType::printValueToString(const UntypedLiteral *value) const {
   DCHECK(value != nullptr);
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/ArrayType.hpp
----------------------------------------------------------------------
diff --git a/types/ArrayType.hpp b/types/ArrayType.hpp
index fe81c3e..a48cfa3 100644
--- a/types/ArrayType.hpp
+++ b/types/ArrayType.hpp
@@ -44,6 +44,11 @@ class ArrayType : public TypeSynthesizer<kArray> {
     return 16;
   }
 
+  TypedValue marshallValue(const UntypedLiteral *value) const override;
+
+  UntypedLiteral* unmarshallValue(const void *data,
+                                  const std::size_t length) const override;
+
   std::string printValueToString(const UntypedLiteral *value) const override;
 
   bool parseTypedValueFromString(const std::string &value_string,
@@ -63,7 +68,7 @@ class ArrayType : public TypeSynthesizer<kArray> {
     DCHECK_EQ(1u, parameters.size());
     const GenericValue &value = parameters.front();
     DCHECK(value.getType().getTypeID() == kMetaType);
-    return *static_cast<const Type*>(value.getValue());
+    return **static_cast<const MetaTypeLiteral*>(value.getValue());
   }
 
   const Type &element_type_;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/CMakeLists.txt b/types/CMakeLists.txt
index 07f9d97..69ac906 100644
--- a/types/CMakeLists.txt
+++ b/types/CMakeLists.txt
@@ -49,13 +49,13 @@ add_library(quickstep_types_IntervalLit ../empty_src.cpp IntervalLit.hpp)
 add_library(quickstep_types_IntervalParser IntervalParser.cpp IntervalParser.hpp)
 add_library(quickstep_types_LongType LongType.cpp LongType.hpp)
 add_library(quickstep_types_MetaType MetaType.cpp MetaType.hpp)
+add_library(quickstep_types_MetaTypeLite MetaTypeLite.cpp MetaTypeLite.hpp)
 add_library(quickstep_types_NullCoercibilityCheckMacro ../empty_src.cpp NullCoercibilityCheckMacro.hpp)
 add_library(quickstep_types_NullLit ../empty_src.cpp NullLit.hpp)
 add_library(quickstep_types_NullType ../empty_src.cpp NullType.hpp)
 add_library(quickstep_types_NumericSuperType ../empty_src.cpp NumericSuperType.hpp)
 add_library(quickstep_types_NumericTypeSafeCoercibility ../empty_src.cpp NumericTypeSafeCoercibility.hpp)
 add_library(quickstep_types_NumericTypeUnifier ../empty_src.cpp NumericTypeUnifier.hpp)
-add_library(quickstep_types_ParameterizedPodLit ../empty_src.cpp ParameterizedPodLit.hpp)
 add_library(quickstep_types_Type Type.cpp Type.hpp)
 add_library(quickstep_types_TypeErrors ../empty_src.cpp TypeErrors.hpp)
 add_library(quickstep_types_TypeFactory TypeFactory.cpp TypeFactory.hpp)
@@ -71,6 +71,12 @@ add_library(quickstep_types_VarCharType VarCharType.cpp VarCharType.hpp)
 add_library(quickstep_types_YearMonthIntervalType YearMonthIntervalType.cpp YearMonthIntervalType.hpp)
 
 # Link dependencies:
+target_link_libraries(quickstep_types_ArrayType
+                      quickstep_types_Type
+                      quickstep_types_TypeID
+                      quickstep_types_TypeSynthesizer
+                      quickstep_types_Type_proto
+                      quickstep_utility_Macros)
 target_link_libraries(quickstep_types_AsciiStringSuperType
                       quickstep_types_Type
                       quickstep_types_TypeID
@@ -158,6 +164,13 @@ target_link_libraries(quickstep_types_LongType
                       quickstep_types_TypeID
                       quickstep_types_TypedValue
                       quickstep_utility_Macros)
+target_link_libraries(quickstep_types_MetaType
+                      quickstep_types_MetaTypeLite)
+target_link_libraries(quickstep_types_MetaTypeLite
+                      quickstep_types_Type
+                      quickstep_types_TypeID
+                      quickstep_types_TypeSynthesizer
+                      quickstep_utility_Macros)
 target_link_libraries(quickstep_types_NullType
                       glog
                       quickstep_types_Type
@@ -205,12 +218,16 @@ target_link_libraries(quickstep_types_TypeRegistrar
                       quickstep_types_TypeIDSelectors
                       quickstep_utility_meta_Common)
 target_link_libraries(quickstep_types_TypeSynthesizer
+                      quickstep_types_GenericValue
                       quickstep_types_Type
                       quickstep_types_TypeID
                       quickstep_types_TypeRegistrar
+                      quickstep_types_TypedValue
                       quickstep_types_Type_proto
+                      quickstep_utility_HashPair
                       quickstep_utility_Macros
-                      quickstep_utility_PtrMap)
+                      quickstep_utility_PtrMap
+                      quickstep_utility_meta_Common)
 target_link_libraries(quickstep_types_TypeUtil
                       quickstep_types_BoolType
                       quickstep_types_CharType
@@ -221,6 +238,7 @@ target_link_libraries(quickstep_types_TypeUtil
                       quickstep_types_FloatType
                       quickstep_types_IntType
                       quickstep_types_LongType
+                      quickstep_types_MetaTypeLite
                       quickstep_types_NullType
                       quickstep_types_Type
                       quickstep_types_TypeID

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/MetaType.cpp
----------------------------------------------------------------------
diff --git a/types/MetaType.cpp b/types/MetaType.cpp
index 01fc3a0..e69de29 100644
--- a/types/MetaType.cpp
+++ b/types/MetaType.cpp
@@ -1,36 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- **/
-
-#include "types/MetaType.hpp"
-
-#include <string>
-
-#include "types/TypeID.hpp"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-std::string MetaType::printValueToString(const UntypedLiteral *value) const {
-  DCHECK(value != nullptr);
-
-  return castValueToLiteral(value)->getName();
-}
-
-}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/MetaType.hpp
----------------------------------------------------------------------
diff --git a/types/MetaType.hpp b/types/MetaType.hpp
index c046771..6edd270 100644
--- a/types/MetaType.hpp
+++ b/types/MetaType.hpp
@@ -20,48 +20,6 @@
 #ifndef QUICKSTEP_TYPES_META_TYPE_HPP_
 #define QUICKSTEP_TYPES_META_TYPE_HPP_
 
-#include <cstddef>
-#include <string>
-
-#include "types/Type.hpp"
-#include "types/TypeID.hpp"
-#include "types/TypeSynthesizer.hpp"
-#include "utility/Macros.hpp"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-class TypedValue;
-
-/** \addtogroup Types
- *  @{
- */
-
-class MetaType : public TypeSynthesizer<kMetaType> {
- public:
-  int getPrintWidth() const override {
-    return 16;
-  }
-
-  std::string printValueToString(const UntypedLiteral *value) const override;
-
-  bool parseTypedValueFromString(const std::string &value_string,
-                                 TypedValue *value) const override {
-    return false;
-  }
-
- private:
-  MetaType(const bool nullable)
-      : TypeSynthesizer<kMetaType>(nullable, sizeof(TypeID), 0x100) {
-    // TODO(refactor-type): Possibly infinite maximum size.
-  }
-
-  QUICKSTEP_SYNTHESIZE_TYPE(MetaType);
-};
-
-/** @} */
-
-}  // namespace quickstep
+#include "types/MetaTypeLite.hpp"
 
 #endif  // QUICKSTEP_TYPES_META_TYPE_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/MetaTypeLite.cpp
----------------------------------------------------------------------
diff --git a/types/MetaTypeLite.cpp b/types/MetaTypeLite.cpp
new file mode 100644
index 0000000..8022534
--- /dev/null
+++ b/types/MetaTypeLite.cpp
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ **/
+
+#include "types/MetaType.hpp"
+
+#include <string>
+
+#include "types/TypeID.hpp"
+
+#include "glog/logging.h"
+
+namespace quickstep {
+
+TypedValue MetaType::marshallValue(const UntypedLiteral *value) const {
+  const Type *type = castValueToLiteral(value);
+  serialization::Type proto = type->getProto();
+  const std::size_t data_size = proto.ByteSize();
+  void *data = std::malloc(data_size);
+  proto.SerializeToArray(data, data_size);
+  return TypedValue::CreateWithOwnedData(kMetaType, data, data_size);
+}
+
+//UntypedLiteral* MetaType::unmarshallValue(const void *data,
+//                                          const std::size_t data_size) const {
+//  serialization::Type proto;
+//  proto.ParseFromArray(data, data_size);
+//  return
+//}
+
+std::string MetaType::printValueToString(const UntypedLiteral *value) const {
+  DCHECK(value != nullptr);
+
+  return castValueToLiteral(value)->getName();
+}
+
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/MetaTypeLite.hpp
----------------------------------------------------------------------
diff --git a/types/MetaTypeLite.hpp b/types/MetaTypeLite.hpp
new file mode 100644
index 0000000..776fe03
--- /dev/null
+++ b/types/MetaTypeLite.hpp
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ **/
+
+#ifndef QUICKSTEP_TYPES_META_TYPE_LITE_HPP_
+#define QUICKSTEP_TYPES_META_TYPE_LITE_HPP_
+
+#include <cstddef>
+#include <string>
+
+#include "types/Type.hpp"
+#include "types/TypeID.hpp"
+#include "types/TypeSynthesizer.hpp"
+#include "utility/Macros.hpp"
+
+#include "glog/logging.h"
+
+namespace quickstep {
+
+class TypedValue;
+
+/** \addtogroup Types
+ *  @{
+ */
+
+class MetaType : public TypeSynthesizer<kMetaType> {
+ public:
+  int getPrintWidth() const override {
+    return 16;
+  }
+
+  TypedValue marshallValue(const UntypedLiteral *value) const override;
+
+  UntypedLiteral* unmarshallValue(const void *data,
+                                  const std::size_t length) const override;
+
+  std::string printValueToString(const UntypedLiteral *value) const override;
+
+  bool parseTypedValueFromString(const std::string &value_string,
+                                 TypedValue *value) const override {
+    return false;
+  }
+
+ private:
+  MetaType(const bool nullable)
+      : TypeSynthesizer<kMetaType>(nullable, sizeof(TypeID), 0x100) {
+    // TODO(refactor-type): Possibly infinite maximum size.
+  }
+
+  QUICKSTEP_SYNTHESIZE_TYPE(MetaType);
+};
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_TYPES_META_TYPE_LITE_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/ParameterizedPodLit.hpp
----------------------------------------------------------------------
diff --git a/types/ParameterizedPodLit.hpp b/types/ParameterizedPodLit.hpp
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/Type.proto
----------------------------------------------------------------------
diff --git a/types/Type.proto b/types/Type.proto
index e449ee6..8092953 100644
--- a/types/Type.proto
+++ b/types/Type.proto
@@ -34,3 +34,7 @@ message GenericValue {
   required Type type = 1;
   optional bytes data = 2;
 }
+
+message ArrayLiteral {
+  repeated bytes data = 1;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/TypeSynthesizer.hpp
----------------------------------------------------------------------
diff --git a/types/TypeSynthesizer.hpp b/types/TypeSynthesizer.hpp
index cebbd6b..29267f8 100644
--- a/types/TypeSynthesizer.hpp
+++ b/types/TypeSynthesizer.hpp
@@ -114,9 +114,7 @@ class TypeSynthesizePolicy<
   }
 
   TypedValue marshallValue(const UntypedLiteral *value) const override {
-    TypedValue ret = makeValue(value, sizeof(cpptype));
-    ret.ensureNotReference();
-    return ret;
+    return makeValue(value, sizeof(cpptype)).ensureNotReference();
   }
 
   UntypedLiteral* unmarshallValue(const void *data,
@@ -340,7 +338,9 @@ class TypeSynthesizePolicy<
   bool checkValuesEqual(const UntypedLiteral *lhs,
                         const UntypedLiteral *rhs,
                         const Type &rhs_type) const override {
-    LOG(FATAL) << "Not implemented";
+    // LOG(FATAL) << "Not implemented";
+    // TODO.
+    return false;
   }
 
   UntypedLiteral* cloneValue(const UntypedLiteral *value) const override {

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bef66ad4/types/TypedValue.cpp
----------------------------------------------------------------------
diff --git a/types/TypedValue.cpp b/types/TypedValue.cpp
index ad1eb0f..79e80a3 100644
--- a/types/TypedValue.cpp
+++ b/types/TypedValue.cpp
@@ -147,8 +147,12 @@ serialization::TypedValue TypedValue::getProto() const {
       DCHECK(isNull());
       break;
     default:
-      FATAL_ERROR("Unrecognized TypeID in TypedValue::getProto");
-  }
+//      FATAL_ERROR("Unrecognized TypeID in TypedValue::getProto");
+      if (!isNull()) {
+        proto.set_out_of_line_data(static_cast<const char*>(getOutOfLineData()), getDataSize());
+      }
+      break;
+}
 
   return proto;
 }
@@ -231,7 +235,12 @@ TypedValue TypedValue::ReconstructFromProto(const serialization::TypedValue &pro
     case kNullType:
       return TypedValue(kNullType);
     default:
-      FATAL_ERROR("Unrecognized TypeID in TypedValue::ReconstructFromProto");
+//      FATAL_ERROR("Unrecognized TypeID in TypedValue::ReconstructFromProto");
+      return proto.has_out_of_line_data() ?
+          TypedValue(type_id,
+                     static_cast<const void*>(proto.out_of_line_data().c_str()),
+                     proto.out_of_line_data().size()).ensureNotReference() :
+          TypedValue(type_id);
   }
 }