laskoviymishka commented on code in PR #2688:
URL: https://github.com/apache/iceberg-go/pull/2688#discussion_r4667208267


##########
transforms_test.go:
##########
@@ -388,6 +394,35 @@ func TestPartitionToPath_TimestampTzIdentity(t *testing.T) 
{
        assert.Equal(t, expected, spec.PartitionToPath(record, schema))
 }
 
+func TestPartitionToPath_YearMatchesJava(t *testing.T) {
+       schema := iceberg.NewSchema(0,
+               iceberg.NestedField{ID: 1, Name: "ts", Type: 
iceberg.PrimitiveTypes.Date, Required: true},
+       )
+       spec := iceberg.NewPartitionSpecID(0,
+               iceberg.PartitionField{
+                       SourceIDs: []int{1}, FieldID: 1000,
+                       Transform: iceberg.YearTransform{}, Name: "ts_year",
+               },
+       )
+
+       tests := []struct {
+               name     string
+               year     int32
+               expected string
+       }{
+               {"four digit year", int32(47), "ts_year=2017"},
+               {"year below 1000 is zero padded", int32(-1035), 
"ts_year=0935"},
+               {"year 1 is zero padded", int32(-1969), "ts_year=0001"},
+               {"negative year keeps the sign in the padded width", 
int32(-1971), "ts_year=-001"},
+               {"five digit year is not truncated", int32(10375), 
"ts_year=12345"},
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       assert.Equal(t, tt.expected, 
spec.PartitionToPath(partitionRecord{tt.year}, schema))

Review Comment:
   Should `TestPartitionPathPlanMatchesPartitionToPath` get a year field too? 
The table writers build paths through `partitionPathPlan.format` 
([partition_path.go](https://github.com/apache/iceberg-go/blob/cf6e97acc5037cf7773551cc88baa1ac775931cc/table/partition_path.go#L41-L60)),
 and that test only covers identity, truncate and bucket. The `ToHumanString` 
cases cover it indirectly, so this just keeps the two paths from drifting.



##########
transforms_test.go:
##########
@@ -234,6 +234,12 @@ func TestToHumanStringValues(t *testing.T) {
                {iceberg.HourTransform{}, iceberg.PrimitiveTypes.Int32, 
int32(4645896), "2500-01-01-00"},
                {iceberg.HourTransform{}, iceberg.PrimitiveTypes.Int32, 
int32(-4119936), "1500-01-01-00"},
                {iceberg.YearTransform{}, iceberg.PrimitiveTypes.Int32, 
int32(-1), "1969"},
+               {iceberg.YearTransform{}, iceberg.PrimitiveTypes.Int32, 
int32(0), "1970"},

Review Comment:
   The `int32(0), "1970"` year case is already in this table at line 246, so 
this one can go.
   
   ```suggestion
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to