Skip to content

Commit 5ea21e3

Browse files
authored
feat: Support skipping PK validation for columns (#2310)
#### Summary So we don't have to insert empty values instead of nulls as a workaround (see cloudquery/cloudquery-private#9411)
1 parent bc9b670 commit 5ea21e3

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

schema/column.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type Column struct {
4949

5050
// If the column type is JSON, this field will have a JSON string that represents the schema of the JSON object.
5151
TypeSchema string `json:"type_schema,omitempty"`
52+
53+
// Some PK columns can be nullable if there are a part of a composite PK, so we want to skip validation for them.
54+
SkipPKValidation bool `json:"skip_pk_validation"`
5255
}
5356

5457
// NewColumnFromArrowField creates a new Column from an arrow.Field

schema/resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ func (r *Resource) Validate() error {
152152
var missingPks []string
153153
var missingPKComponents []string
154154
for i, c := range r.Table.Columns {
155+
if c.SkipPKValidation {
156+
continue
157+
}
155158
switch {
156159
case c.PrimaryKey && !r.data[i].IsValid():
157160
missingPks = append(missingPks, c.Name)

schema/resource_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ func TestResource_Validate(t *testing.T) {
4545
resource: NewResourceData(&Table{Name: "test", Columns: ColumnList{{Name: "col1", Type: arrow.BinaryTypes.String, PrimaryKeyComponent: true}}}, nil, nil),
4646
err: &PKComponentError{MissingPKComponents: []string{"col1"}},
4747
},
48+
{
49+
name: "valid resource with primary key components and skip validation",
50+
resource: NewResourceData(&Table{Name: "test", Columns: ColumnList{
51+
{
52+
Name: "col1", Type: arrow.BinaryTypes.String, PrimaryKeyComponent: true,
53+
},
54+
{
55+
Name: "col2", Type: arrow.BinaryTypes.String, PrimaryKey: true, SkipPKValidation: true,
56+
},
57+
}}, nil, nil),
58+
err: nil,
59+
valueSetter: func(resource *Resource) error {
60+
return resource.Set("col1", "test")
61+
},
62+
},
4863
}
4964
for _, tt := range tests {
5065
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)