@@ -322,6 +322,39 @@ var (
322322 },
323323 },
324324 }
325+
326+ expectedTableWithSkipPKValidation = schema.Table {
327+ Name : "test_pk_struct" ,
328+ Columns : schema.ColumnList {
329+ {
330+ Name : "parent" ,
331+ Type : arrow .BinaryTypes .String ,
332+ SkipPKValidation : true ,
333+ },
334+ {
335+ Name : "name" ,
336+ Type : arrow .BinaryTypes .String ,
337+ },
338+ {
339+ Name : "version" ,
340+ Type : arrow .PrimitiveTypes .Int64 ,
341+ },
342+ },
343+ }
344+
345+ expectedTestTableNonEmbeddedStructWithSkipPKValidation = schema.Table {
346+ Name : "test_struct" ,
347+ Columns : schema.ColumnList {
348+ schema.Column {Name : "int_col" , Type : arrow .PrimitiveTypes .Int64 },
349+ schema.Column {Name : "test_struct" , Type : types .ExtensionTypes .JSON },
350+ schema.Column {
351+ Name : "non_embedded_embedded_string" ,
352+ Type : arrow .BinaryTypes .String ,
353+ SkipPKValidation : true ,
354+ },
355+ schema.Column {Name : "non_embedded_int_col" , Type : arrow .PrimitiveTypes .Int64 },
356+ },
357+ }
325358)
326359
327360func TestTableFromGoStruct (t * testing.T ) {
@@ -476,6 +509,38 @@ func TestTableFromGoStruct(t *testing.T) {
476509 },
477510 want : expectedTestTableStructNonNullableFields ,
478511 },
512+ {
513+ name : "Should configure skip PK validation when option is set" ,
514+ args : args {
515+ testStruct : testPKStruct {},
516+ options : []StructTransformerOption {
517+ WithSkipPrimaryKeyValidation ("Parent" ),
518+ },
519+ },
520+ want : expectedTableWithSkipPKValidation ,
521+ },
522+ {
523+ name : "Should return an error when a skip PK validation field is not found" ,
524+ args : args {
525+ testStruct : testPKStruct {},
526+ options : []StructTransformerOption {
527+ WithSkipPrimaryKeyValidation ("Parent" , "InvalidColumn" ),
528+ },
529+ },
530+ want : expectedTableWithSkipPKValidation ,
531+ wantErr : true ,
532+ },
533+ {
534+ name : "Should configure skip PK validation for unwrapped struct fields" ,
535+ args : args {
536+ testStruct : testStructWithNonEmbeddedStruct {},
537+ options : []StructTransformerOption {
538+ WithUnwrapStructFields ("NonEmbedded" ),
539+ WithSkipPrimaryKeyValidation ("NonEmbedded.EmbeddedString" ),
540+ },
541+ },
542+ want : expectedTestTableNonEmbeddedStructWithSkipPKValidation ,
543+ },
479544 }
480545
481546 for _ , tt := range tests {
@@ -512,6 +577,19 @@ func TestTableFromGoStruct(t *testing.T) {
512577 if diff := cmp .Diff (table .PrimaryKeys (), tt .want .PrimaryKeys ()); diff != "" {
513578 t .Fatalf ("table does not match expected. diff (-got, +want): %v" , diff )
514579 }
580+
581+ // Check SkipPKValidation field for columns that have it set in expected
582+ for _ , wantCol := range tt .want .Columns {
583+ if wantCol .SkipPKValidation {
584+ gotCol := table .Column (wantCol .Name )
585+ if gotCol == nil {
586+ t .Fatalf ("column %q not found" , wantCol .Name )
587+ }
588+ if ! gotCol .SkipPKValidation {
589+ t .Fatalf ("column %q expected SkipPKValidation=true, got false" , wantCol .Name )
590+ }
591+ }
592+ }
515593 })
516594 }
517595}
0 commit comments