parquet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject parquet-cpp git commit: PARQUET-621: Add flag to indicate if decimalmetadata is set
Date Wed, 18 May 2016 18:02:00 GMT
Repository: parquet-cpp
Updated Branches:
  refs/heads/master 41981d981 -> d45f4dee8


PARQUET-621: Add flag to indicate if decimalmetadata is set

Author: Uwe L. Korn <uwelk@xhochy.com>

Closes #109 from xhochy/parquet-621 and squashes the following commits:

3850a0f [Uwe L. Korn] Add unit test
dc1552f [Uwe L. Korn] Add flag to indicate if decimalmetadata is set


Project: http://git-wip-us.apache.org/repos/asf/parquet-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/parquet-cpp/commit/d45f4dee
Tree: http://git-wip-us.apache.org/repos/asf/parquet-cpp/tree/d45f4dee
Diff: http://git-wip-us.apache.org/repos/asf/parquet-cpp/diff/d45f4dee

Branch: refs/heads/master
Commit: d45f4dee805991ae42dafe870eebbbb4eea4c68d
Parents: 41981d9
Author: Uwe L. Korn <uwelk@xhochy.com>
Authored: Wed May 18 11:00:28 2016 -0700
Committer: Wes McKinney <wesm@apache.org>
Committed: Wed May 18 11:00:28 2016 -0700

----------------------------------------------------------------------
 src/parquet/schema/schema-converter-test.cc | 21 +++++++++++++++++++++
 src/parquet/schema/types.cc                 |  9 +++++++--
 src/parquet/schema/types.h                  |  1 +
 3 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/parquet-cpp/blob/d45f4dee/src/parquet/schema/schema-converter-test.cc
----------------------------------------------------------------------
diff --git a/src/parquet/schema/schema-converter-test.cc b/src/parquet/schema/schema-converter-test.cc
index 0a03dc6..c752919 100644
--- a/src/parquet/schema/schema-converter-test.cc
+++ b/src/parquet/schema/schema-converter-test.cc
@@ -158,6 +158,27 @@ class TestSchemaFlatten : public ::testing::Test {
   std::vector<format::SchemaElement> elements_;
 };
 
+TEST_F(TestSchemaFlatten, DecimalMetadata) {
+  // Checks that DecimalMetadata is only set for DecimalTypes
+  NodePtr node = PrimitiveNode::Make(
+      "decimal", Repetition::REQUIRED, Type::INT64, LogicalType::DECIMAL, -1, 8, 4);
+  NodePtr group =
+      GroupNode::Make("group", Repetition::REPEATED, {node}, LogicalType::LIST);
+  Flatten(reinterpret_cast<GroupNode*>(group.get()));
+  ASSERT_EQ("decimal", elements_[1].name);
+  ASSERT_TRUE(elements_[1].__isset.precision);
+  ASSERT_TRUE(elements_[1].__isset.scale);
+
+  elements_.clear();
+  // Not for integers with no logical type
+  group =
+      GroupNode::Make("group", Repetition::REPEATED, {Int64("int64")}, LogicalType::LIST);
+  Flatten(reinterpret_cast<GroupNode*>(group.get()));
+  ASSERT_EQ("int64", elements_[1].name);
+  ASSERT_FALSE(elements_[0].__isset.precision);
+  ASSERT_FALSE(elements_[0].__isset.scale);
+}
+
 TEST_F(TestSchemaFlatten, NestedExample) {
   SchemaElement elt;
   std::vector<SchemaElement> elements;

http://git-wip-us.apache.org/repos/asf/parquet-cpp/blob/d45f4dee/src/parquet/schema/types.cc
----------------------------------------------------------------------
diff --git a/src/parquet/schema/types.cc b/src/parquet/schema/types.cc
index abb031d..f078f24 100644
--- a/src/parquet/schema/types.cc
+++ b/src/parquet/schema/types.cc
@@ -86,12 +86,14 @@ PrimitiveNode::PrimitiveNode(const std::string& name, Repetition::type
repetitio
       physical_type_(type),
       type_length_(length) {
   std::stringstream ss;
+  decimal_metadata_.isset = false;
   // Check if the physical and logical types match
   // Mapping referred from Apache parquet-mr as on 2016-02-22
   switch (logical_type) {
     case LogicalType::NONE:
       // Logical type not set
       // Clients should be able to read these values
+      decimal_metadata_.isset = true;
       decimal_metadata_.precision = precision;
       decimal_metadata_.scale = scale;
       break;
@@ -123,6 +125,7 @@ PrimitiveNode::PrimitiveNode(const std::string& name, Repetition::type
repetitio
         ss << " cannot be greater than precision " << precision;
         throw ParquetException(ss.str());
       }
+      decimal_metadata_.isset = true;
       decimal_metadata_.precision = precision;
       decimal_metadata_.scale = scale;
       break;
@@ -299,8 +302,10 @@ void PrimitiveNode::ToParquet(void* opaque_element) const {
   element->__set_type(ToThrift(physical_type_));
   // FIXME: SchemaFlattener does this for us: element->__set_field_id(id_);
   element->__set_type_length(type_length_);
-  element->__set_precision(decimal_metadata_.precision);
-  element->__set_scale(decimal_metadata_.scale);
+  if (decimal_metadata_.isset) {
+    element->__set_precision(decimal_metadata_.precision);
+    element->__set_scale(decimal_metadata_.scale);
+  }
 }
 
 }  // namespace schema

http://git-wip-us.apache.org/repos/asf/parquet-cpp/blob/d45f4dee/src/parquet/schema/types.h
----------------------------------------------------------------------
diff --git a/src/parquet/schema/types.h b/src/parquet/schema/types.h
index c9df1b7..d27c073 100644
--- a/src/parquet/schema/types.h
+++ b/src/parquet/schema/types.h
@@ -70,6 +70,7 @@ struct ListEncoding {
 };
 
 struct DecimalMetadata {
+  bool isset;
   int32_t scale;
   int32_t precision;
 };


Mime
View raw message