Skip to content

Commit

Permalink
Update decimal string format (#407)
Browse files Browse the repository at this point in the history
parquet-cli prints the string format of decimals as
`DECIMAL(precision,scale)`. Update parquet-go's string format to match.
  • Loading branch information
Larry Marburger authored Nov 15, 2022
1 parent 629a510 commit 24e17d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion format/parquet.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ type DecimalType struct {
}

func (t *DecimalType) String() string {
return fmt.Sprintf("DECIMAL(%d,%d)", t.Scale, t.Precision)
// Matching parquet-cli's decimal string format: https://github.com/apache/parquet-mr/blob/d057b39d93014fe40f5067ee4a33621e65c91552/parquet-column/src/test/java/org/apache/parquet/parser/TestParquetParser.java#L249-L265
return fmt.Sprintf("DECIMAL(%d,%d)", t.Precision, t.Scale)
}

// Time units for logical types.
Expand Down
4 changes: 2 additions & 2 deletions print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ func TestPrintSchema(t *testing.T) {
{
node: parquet.Group{"cost": parquet.Decimal(0, 9, parquet.Int32Type)},
print: `message Test {
required int32 cost (DECIMAL(0,9));
required int32 cost (DECIMAL(9,0));
}`,
},

{
node: parquet.Group{"cost": parquet.Decimal(0, 18, parquet.Int64Type)},
print: `message Test {
required int64 cost (DECIMAL(0,18));
required int64 cost (DECIMAL(18,0));
}`,
},

Expand Down

0 comments on commit 24e17d6

Please sign in to comment.