badalprasadsingh commented on code in PR #2613:
URL: https://github.com/apache/iceberg-go/pull/2613#discussion_r4592254914


##########
table/transaction_test.go:
##########
@@ -1052,6 +1053,133 @@ func (s *SparkIntegrationTestSuite) 
TestOverwriteWithFilter() {
 +-----+---------------+---+`)
 }
 
+func (s *SparkIntegrationTestSuite) TestDynamicPartitionOverwrite() {
+       icebergSchema := iceberg.NewSchema(0,
+               iceberg.NestedField{ID: 1, Name: "id", Type: 
iceberg.PrimitiveTypes.Int32},
+               iceberg.NestedField{ID: 2, Name: "cat", Type: 
iceberg.PrimitiveTypes.String},
+               iceberg.NestedField{ID: 3, Name: "dt", Type: 
iceberg.PrimitiveTypes.Date},
+       )
+
+       // day(dt) makes (b, 2024-01-03) a separate partition from (b, 
2024-01-01),
+       // so the overwrite has to replace by transformed value, not by source 
column.
+       spec := iceberg.NewPartitionSpec(
+               iceberg.PartitionField{SourceIDs: []int{3}, FieldID: 1000, 
Name: "dt_day", Transform: iceberg.DayTransform{}},

Review Comment:
   day() on a DATE is like one partition per date -> like identity. no 
partition holds two dt values: so this passes if the overwrite only removes 
rows whose dt matches a new row. 
   
   better: we can use month(dt), with row 3 on 2024-01-15 and row 6 in February



##########
table/transaction_test.go:
##########
@@ -1052,6 +1053,133 @@ func (s *SparkIntegrationTestSuite) 
TestOverwriteWithFilter() {
 +-----+---------------+---+`)
 }
 
+func (s *SparkIntegrationTestSuite) TestDynamicPartitionOverwrite() {
+       icebergSchema := iceberg.NewSchema(0,
+               iceberg.NestedField{ID: 1, Name: "id", Type: 
iceberg.PrimitiveTypes.Int32},
+               iceberg.NestedField{ID: 2, Name: "cat", Type: 
iceberg.PrimitiveTypes.String},
+               iceberg.NestedField{ID: 3, Name: "dt", Type: 
iceberg.PrimitiveTypes.Date},
+       )
+
+       // day(dt) makes (b, 2024-01-03) a separate partition from (b, 
2024-01-01),
+       // so the overwrite has to replace by transformed value, not by source 
column.
+       spec := iceberg.NewPartitionSpec(
+               iceberg.PartitionField{SourceIDs: []int{3}, FieldID: 1000, 
Name: "dt_day", Transform: iceberg.DayTransform{}},
+               iceberg.PartitionField{SourceIDs: []int{2}, FieldID: 1001, 
Name: "cat", Transform: iceberg.IdentityTransform{}},
+       )
+       tbl, err := s.cat.CreateTable(s.ctx, catalog.ToIdentifier("default", 
"go_test_dynamic_partition_overwrite"), icebergSchema,
+               
catalog.WithProperties(iceberg.Properties{table.PropertyFormatVersion: "2"}),
+               catalog.WithPartitionSpec(&spec),
+       )
+       s.Require().NoError(err)
+
+       arrowSchema, err := table.SchemaToArrowSchema(icebergSchema, nil, true, 
false)
+       s.Require().NoError(err)
+
+       initialTable, err := array.TableFromJSON(memory.DefaultAllocator, 
arrowSchema, []string{
+               `[
+                       {"id": 1, "cat": "a", "dt": "2024-01-01"},
+                       {"id": 2, "cat": "b", "dt": "2024-01-01"},
+                       {"id": 3, "cat": "b", "dt": "2024-01-01"},
+                       {"id": 4, "cat": "c", "dt": "2024-01-02"},
+                       {"id": 5, "cat": null, "dt": "2024-01-01"},
+                       {"id": 6, "cat": "b", "dt": "2024-01-03"}
+               ]`,
+       })
+       s.Require().NoError(err)
+       defer initialTable.Release()
+
+       tx := tbl.NewTransaction()
+       s.Require().NoError(tx.AppendTable(s.ctx, initialTable, 6, nil))
+       tbl, err = tx.Commit(s.ctx)
+       s.Require().NoError(err)
+
+       overwriteTable, err := array.TableFromJSON(memory.DefaultAllocator, 
arrowSchema, []string{
+               `[
+                       {"id": 20, "cat": "b", "dt": "2024-01-01"},
+                       {"id": 50, "cat": null, "dt": "2024-01-01"}
+               ]`,
+       })
+       s.Require().NoError(err)
+       defer overwriteTable.Release()
+
+       tx = tbl.NewTransaction()
+       s.Require().NoError(tx.DynamicPartitionOverwriteTable(s.ctx, 
overwriteTable, 2, nil))

Review Comment:
   right now, here go replaces files which go wrote
   
   can we do a spark insert just before this, then table refresh? this would 
check if go replaces files spark wrote



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