You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@parquet.apache.org by "mapleFU (via GitHub)" <gi...@apache.org> on 2023/04/06 16:03:00 UTC

[GitHub] [parquet-format] mapleFU commented on pull request #198: PARQUET-2264: Allow scale == precision for DecimalType

mapleFU commented on PR #198:
URL: https://github.com/apache/parquet-format/pull/198#issuecomment-1499297787

   ```
   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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org