serramatutu commented on code in PR #558:
URL: https://github.com/apache/arrow-go/pull/558#discussion_r3066918730


##########
arrow/extensions/timestamp_with_offset_test.go:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package extensions_test
+
+import (
+       "bytes"
+       "fmt"
+       "testing"
+       "time"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       "github.com/apache/arrow-go/v18/arrow/extensions"
+       "github.com/apache/arrow-go/v18/arrow/ipc"
+       "github.com/apache/arrow-go/v18/arrow/memory"
+       "github.com/apache/arrow-go/v18/internal/json"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+var testTimeUnit = arrow.Microsecond
+
+var testDate0 = time.Date(2025, 01, 01, 00, 00, 00, 00, 
time.FixedZone("UTC+00:00", 0))
+
+var testZone1 = time.FixedZone("UTC-08:30", -8*60*60 -30*60)
+var testDate1 = testDate0.In(testZone1)
+
+var testZone2 = time.FixedZone("UTC+11:00", +11*60*60)
+var testDate2 = testDate0.In(testZone2)
+
+func dict(index arrow.DataType) arrow.DataType {
+       return &arrow.DictionaryType{
+               IndexType: index,
+               ValueType: arrow.PrimitiveTypes.Int16,
+               Ordered: false,
+       }
+}
+
+func ree(runEnds arrow.DataType) arrow.DataType {
+       v := arrow.RunEndEncodedOf(runEnds, arrow.PrimitiveTypes.Int16)
+       v.ValueNullable = false
+       return v
+}
+
+// All tests use this in a for loop to make sure everything works for every 
possible
+// encoding of offsets (primitive, dictionary, run-end)
+var allAllowedOffsetTypes = []arrow.DataType{
+       // primitive offsetType
+       arrow.PrimitiveTypes.Int16,
+
+       // dict-encoded offsetType
+       dict(arrow.PrimitiveTypes.Uint8),
+       dict(arrow.PrimitiveTypes.Uint16),
+       dict(arrow.PrimitiveTypes.Uint32),
+       dict(arrow.PrimitiveTypes.Uint64),
+       dict(arrow.PrimitiveTypes.Int8),
+       dict(arrow.PrimitiveTypes.Int16),
+       dict(arrow.PrimitiveTypes.Int32),
+       dict(arrow.PrimitiveTypes.Int64),
+
+       // run-end encoded offsetType
+       ree(arrow.PrimitiveTypes.Int16),
+       ree(arrow.PrimitiveTypes.Int32),
+       ree(arrow.PrimitiveTypes.Int64),
+}
+
+func TestTimestampWithOffsetTypePrimitiveBasics(t *testing.T) {
+       typ := extensions.NewTimestampWithOffsetType(testTimeUnit)
+
+       assert.Equal(t, "arrow.timestamp_with_offset", typ.ExtensionName())
+       assert.True(t, typ.ExtensionEquals(typ))
+
+       assert.True(t, arrow.TypeEqual(typ, typ))
+       assert.True(t, arrow.TypeEqual(
+               arrow.StructOf(
+                       arrow.Field{
+                               Name: "timestamp",
+                               Type: &arrow.TimestampType{
+                                       Unit:     testTimeUnit,
+                                       TimeZone: "UTC",
+                               },
+                               Nullable: false,
+                       },
+                       arrow.Field{
+                               Name:     "offset_minutes",
+                               Type:     arrow.PrimitiveTypes.Int16,
+                               Nullable: false,
+                       },
+               ),
+               typ.StorageType()))
+
+       assert.Equal(t, "extension<arrow.timestamp_with_offset>", typ.String())
+}
+
+func assertDictBasics[I extensions.DictIndexType](t *testing.T, indexType I) {
+       typ := 
extensions.NewTimestampWithOffsetTypeDictionaryEncoded(testTimeUnit, indexType)
+
+       assert.Equal(t, "arrow.timestamp_with_offset", typ.ExtensionName())
+       assert.True(t, typ.ExtensionEquals(typ))
+
+       assert.True(t, arrow.TypeEqual(typ, typ))
+       assert.True(t, arrow.TypeEqual(
+               arrow.StructOf(
+                       arrow.Field{
+                               Name: "timestamp",
+                               Type: &arrow.TimestampType{
+                                       Unit:     testTimeUnit,
+                                       TimeZone: "UTC",
+                               },
+                               Nullable: false,
+                       },
+                       arrow.Field{
+                               Name: "offset_minutes",
+                               Type: dict(arrow.DataType(indexType)),
+                               Nullable: false,
+                       },
+               ),
+               typ.StorageType()))
+
+       assert.Equal(t, "extension<arrow.timestamp_with_offset>", typ.String())
+}
+
+func TestTimestampWithOffsetTypeDictionaryEncodedBasics(t *testing.T) {
+       assertDictBasics(t, &arrow.Uint8Type{})
+       assertDictBasics(t, &arrow.Uint16Type{})
+       assertDictBasics(t, &arrow.Uint32Type{})
+       assertDictBasics(t, &arrow.Uint64Type{})
+       assertDictBasics(t, &arrow.Int8Type{})
+       assertDictBasics(t, &arrow.Int16Type{})
+       assertDictBasics(t, &arrow.Int32Type{})
+       assertDictBasics(t, &arrow.Int64Type{})
+}
+
+func assertReeBasics[E extensions.TimestampWithOffsetRunEndsType](t 
*testing.T, runEndsType E) {
+       typ := extensions.NewTimestampWithOffsetTypeRunEndEncoded(testTimeUnit, 
runEndsType)
+
+       assert.Equal(t, "arrow.timestamp_with_offset", typ.ExtensionName())
+       assert.True(t, typ.ExtensionEquals(typ))
+
+       assert.True(t, arrow.TypeEqual(typ, typ))
+       assert.True(t, arrow.TypeEqual(
+               arrow.StructOf(
+                       arrow.Field{
+                               Name: "timestamp",
+                               Type: &arrow.TimestampType{
+                                       Unit:     testTimeUnit,
+                                       TimeZone: "UTC",
+                               },
+                               Nullable: false,
+                       },
+                       arrow.Field{
+                               Name: "offset_minutes",
+                               Type: ree(arrow.DataType(runEndsType)),
+                               Nullable: false,
+                       },
+               ),
+               typ.StorageType()))
+
+       assert.Equal(t, "extension<arrow.timestamp_with_offset>", typ.String())
+}
+
+func TestTimestampWithOffsetTypeRunEndEncodedBasics(t *testing.T) {
+       assertReeBasics(t, &arrow.Int16Type{})
+       assertReeBasics(t, &arrow.Int32Type{})
+       assertReeBasics(t, &arrow.Int64Type{})
+}
+
+func TestTimestampWithOffsetEquals(t *testing.T) {
+       // Completely different types are not equal
+       assert.False(t, 
extensions.NewTimestampWithOffsetType(arrow.Nanosecond).ExtensionEquals(extensions.NewBool8Type()))
+
+       // Different time units are not equal
+       // assert.False(t, 
extensions.NewTimestampWithOffsetType(arrow.Nanosecond).ExtensionEquals(extensions.NewTimestampWithOffsetType(arrow.Microsecond)))
+       // assert.False(t, 
extensions.NewTimestampWithOffsetType(arrow.Nanosecond).ExtensionEquals(extensions.NewTimestampWithOffsetType(arrow.Second)))
+       // assert.False(t, 
extensions.NewTimestampWithOffsetType(arrow.Microsecond).ExtensionEquals(extensions.NewTimestampWithOffsetType(arrow.Second)))
+       //
+       // // Different underlying storage type is not equal
+       // assert.False(t, 
extensions.NewTimestampWithOffsetType(arrow.Microsecond).ExtensionEquals(extensions.NewTimestampWithOffsetTypeDictionaryEncoded(arrow.Microsecond,
 &arrow.Int16Type{})))
+       // assert.False(t, 
extensions.NewTimestampWithOffsetType(arrow.Microsecond).ExtensionEquals(extensions.NewTimestampWithOffsetTypeRunEndEncoded(arrow.Microsecond,
 &arrow.Int16Type{})))
+       // assert.False(t, 
extensions.NewTimestampWithOffsetTypeDictionaryEncoded(arrow.Microsecond, 
&arrow.Int16Type{}).ExtensionEquals(extensions.NewTimestampWithOffsetTypeRunEndEncoded(arrow.Microsecond,
 &arrow.Int16Type{})))
+       //
+       // // Dict-encoding key type is not equal

Review Comment:
   I was dumb. Fixed 
https://github.com/apache/arrow-go/pull/558/changes/02498067c12dfd04265234e715f8c8da34d22fbc



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to