Skip to content

Commit bf16376

Browse files
Merge branch 'main' into release-please--branches--main
2 parents 349fb42 + 4f0b312 commit bf16376

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

transformers/tables.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func TransformTables(tables schema.Tables) error {
2626
if err := TransformTables(table.Relations); err != nil {
2727
return err
2828
}
29+
if len(table.PrimaryKeys()) > 0 && len(table.PrimaryKeyComponents()) > 0 {
30+
return fmt.Errorf("primary keys and primary key components cannot both be set for table %q", table.Name)
31+
}
2932
}
3033
return nil
3134
}

transformers/tables_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package transformers
2+
3+
import (
4+
"testing"
5+
6+
"github.com/apache/arrow-go/v18/arrow"
7+
"github.com/cloudquery/plugin-sdk/v4/schema"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestTransformTablesErrorOnPKFieldsAndPKComponentFields(t *testing.T) {
12+
type testStructWithPKComponent struct {
13+
ID int `json:"id"`
14+
Name string `json:"name"`
15+
}
16+
17+
testTable := &schema.Table{
18+
Name: "test",
19+
Transform: TransformWithStruct(testStructWithPKComponent{}, WithPrimaryKeys("id")),
20+
Columns: []schema.Column{
21+
{Name: "name", Type: arrow.BinaryTypes.String, PrimaryKeyComponent: true},
22+
},
23+
}
24+
25+
err := TransformTables([]*schema.Table{testTable})
26+
require.Error(t, err, "primary keys and primary key components cannot both be set for table \"test\"")
27+
}

0 commit comments

Comments
 (0)