This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new f9d8edda36 GH-36698: [Go][Parquet] Add a TimestampLogicalType creation
function … (#36699)
f9d8edda36 is described below
commit f9d8edda36acbd83a552a34392d0df926646d849
Author: Mark Wolfe <[email protected]>
AuthorDate: Fri Jul 21 00:40:33 2023 +1000
GH-36698: [Go][Parquet] Add a TimestampLogicalType creation function …
(#36699)
…with more options
This change introduces a more flexible creation function for
TimestampLogicalType which will enable changes to all the flags provided by
this type, but without requiring a lot of parameters.
Following on from other great examples in arrow it uses the functional
options pattern.
### Rationale for this change
Add a `TimestampLogicalType` creation function with more options, in
particular an option to set `fromConverted` as I can't see another way to set
this private struct property after creation.
### What changes are included in this PR?
This change introduces a more flexible creation function for
`TimestampLogicalType` which will enable changes to all the flags provided by
this type, but without requiring a lot of parameters.
### Are these changes tested?
Yes I have updated one of the existing tests.
### Are there any user-facing changes?
* Closes: #36698
Authored-by: Mark Wolfe <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
---
go/parquet/schema/logical_types.go | 49 +++++++++++++++++++++++++++++++++
go/parquet/schema/logical_types_test.go | 1 +
2 files changed, 50 insertions(+)
diff --git a/go/parquet/schema/logical_types.go
b/go/parquet/schema/logical_types.go
index ade6e750ad..4075edc1e9 100644
--- a/go/parquet/schema/logical_types.go
+++ b/go/parquet/schema/logical_types.go
@@ -616,6 +616,55 @@ func NewTimestampLogicalTypeForce(isAdjustedToUTC bool,
unit TimeUnitType) Logic
}
}
+// TimestampOpt options used with New Timestamp Logical Type
+type TimestampOpt func(*TimestampLogicalType)
+
+// WithTSIsAdjustedToUTC sets the IsAdjustedToUTC field of the timestamp type.
+func WithTSIsAdjustedToUTC() TimestampOpt {
+ return func(t *TimestampLogicalType) {
+ t.typ.IsAdjustedToUTC = true
+ }
+}
+
+// WithTSTimeUnitType sets the time unit for the timestamp type
+func WithTSTimeUnitType(unit TimeUnitType) TimestampOpt {
+ return func(t *TimestampLogicalType) {
+ t.typ.Unit = createTimeUnit(unit)
+ }
+}
+
+// WithTSForceConverted enable force converted mode
+func WithTSForceConverted() TimestampOpt {
+ return func(t *TimestampLogicalType) {
+ t.forceConverted = true
+ }
+}
+
+// WithTSFromConverted enable the timestamp logical type to be
+// constructed from a converted type.
+func WithTSFromConverted() TimestampOpt {
+ return func(t *TimestampLogicalType) {
+ t.fromConverted = true
+ }
+}
+
+// NewTimestampLogicalTypeWithOpts creates a new TimestampLogicalType with the
provided options.
+//
+// TimestampType Unit defaults to milliseconds (TimeUnitMillis)
+func NewTimestampLogicalTypeWithOpts(opts ...TimestampOpt) LogicalType {
+ ts := &TimestampLogicalType{
+ typ: &format.TimestampType{
+ Unit: createTimeUnit(TimeUnitMillis), // default to
milliseconds
+ },
+ }
+
+ for _, o := range opts {
+ o(ts)
+ }
+
+ return ts
+}
+
// TimestampLogicalType represents an int64 number that can be decoded
// into a year, month, day, hour, minute, second, and subsecond
type TimestampLogicalType struct {
diff --git a/go/parquet/schema/logical_types_test.go
b/go/parquet/schema/logical_types_test.go
index 540899d79a..117157f95e 100644
--- a/go/parquet/schema/logical_types_test.go
+++ b/go/parquet/schema/logical_types_test.go
@@ -93,6 +93,7 @@ func TestConvertedTypeCompatibility(t *testing.T) {
{"time_micro", schema.NewTimeLogicalType(true /* adjutedToUTC
*/, schema.TimeUnitMicros), schema.ConvertedTypes.TimeMicros},
{"timestamp_milli", schema.NewTimestampLogicalType(true /*
adjutedToUTC */, schema.TimeUnitMillis), schema.ConvertedTypes.TimestampMillis},
{"timestamp_micro", schema.NewTimestampLogicalType(true /*
adjutedToUTC */, schema.TimeUnitMicros), schema.ConvertedTypes.TimestampMicros},
+ {"timestamp_milli_opts",
schema.NewTimestampLogicalTypeWithOpts(schema.WithTSIsAdjustedToUTC(),
schema.WithTSTimeUnitType(schema.TimeUnitMillis)),
schema.ConvertedTypes.TimestampMillis},
{"uint8", schema.NewIntLogicalType(8 /* bitWidth */, false /*
signed */), schema.ConvertedTypes.Uint8},
{"uint16", schema.NewIntLogicalType(16 /* bitWidth */, false /*
signed */), schema.ConvertedTypes.Uint16},
{"uint32", schema.NewIntLogicalType(32 /* bitWidth */, false /*
signed */), schema.ConvertedTypes.Uint32},