Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PARQUET-2264: Allow scale == precision for DecimalType #198

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

devinrsmith
Copy link
Contributor

The majority of implementations allow for scale == precision.

See apache/arrow-rs#1607 for further motivation.

The majority of implementations allow for scale == precision.

See apache/arrow-rs#1607 for further motivation.
@@ -219,7 +219,7 @@ decimal point, and the precision stores the maximum number of digits supported
in the unscaled value.

If not specified, the scale is 0. Scale must be zero or a positive integer less
than the precision. Precision is required and must be a non-zero positive
than or equal to the precision. Precision is required and must be a non-zero positive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Could you also add the comment to the thrift definition: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift#L253 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@devinrsmith devinrsmith requested a review from wgtmac April 6, 2023 14:23
@mapleFU
Copy link
Member

mapleFU commented Apr 6, 2023

diff --git a/cpp/examples/parquet/parquet_arrow/reader_writer.cc b/cpp/examples/parquet/parquet_arrow/reader_writer.cc
index f5d96ec16..a4c4e5f77 100644
--- a/cpp/examples/parquet/parquet_arrow/reader_writer.cc
+++ b/cpp/examples/parquet/parquet_arrow/reader_writer.cc
@@ -27,10 +27,12 @@
 // To have some input data, we first create an Arrow Table that holds
 // some data.
 std::shared_ptr<arrow::Table> generate_table() {
-  arrow::Int64Builder i64builder;
-  PARQUET_THROW_NOT_OK(i64builder.AppendValues({1, 2, 3, 4, 5}));
-  std::shared_ptr<arrow::Array> i64array;
-  PARQUET_THROW_NOT_OK(i64builder.Finish(&i64array));
+  arrow::Decimal128Builder decimalBuilder(arrow::decimal(15, 15));
+  for (int i = 0; i < 5; ++i) {
+    PARQUET_THROW_NOT_OK(decimalBuilder.Append(arrow::Decimal128()));
+  }
+  std::shared_ptr<arrow::Array> decimalArray;
+  PARQUET_THROW_NOT_OK(decimalBuilder.Finish(&decimalArray));
 
   arrow::StringBuilder strbuilder;
   PARQUET_THROW_NOT_OK(strbuilder.Append("some"));
@@ -42,9 +44,9 @@ std::shared_ptr<arrow::Table> generate_table() {
   PARQUET_THROW_NOT_OK(strbuilder.Finish(&strarray));
 
   std::shared_ptr<arrow::Schema> schema = arrow::schema(
-      {arrow::field("int", arrow::int64()), arrow::field("str", arrow::utf8())});
+      {arrow::field("decimal", arrow::decimal(15, 15)), arrow::field("str", arrow::utf8())});
 
-  return arrow::Table::Make(schema, {i64array, strarray});
+  return arrow::Table::Make(schema, {decimalArray, strarray});
 }
 
 // #1 Write out the data as a Parquet file

I've do an experiment with C++ arrow parquet, and it's able to write decimal with Decimal(15, 15). So I think this patch is ok

Copy link
Member

@wgtmac wgtmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @devinrsmith and @mapleFU !

@wgtmac wgtmac merged commit 60bf83a into apache:master Apr 19, 2023
@devinrsmith devinrsmith deleted the decimal-type-precision-scale branch April 19, 2023 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants