mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-24 19:48:41 -05:00
Fixed NULLs in pk on table import
This commit is contained in:
committed by
Daylon Wilkins
parent
3ee6b95e98
commit
331a5a6ab5
@@ -29,10 +29,12 @@ DELIM
|
||||
"four":"c3"
|
||||
}
|
||||
JSON
|
||||
|
||||
cat <<DELIM > name-map-data.csv
|
||||
one,two,three,four
|
||||
0,1,2,3
|
||||
DELIM
|
||||
|
||||
cat <<SQL > name-map-sch.sql
|
||||
CREATE TABLE test (
|
||||
pk int not null,
|
||||
@@ -459,6 +461,25 @@ SQL
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "fail on import table creation when defined pk has a NULL value" {
|
||||
cat <<DELIM > null-pk-1.csv
|
||||
pk,v1
|
||||
"a",1
|
||||
,2
|
||||
DELIM
|
||||
cat <<DELIM > null-pk-2.csv
|
||||
pk1,pk2,v1
|
||||
0,0,0
|
||||
1,,1
|
||||
DELIM
|
||||
run dolt table import -c --pk=pk test null-pk-1.csv
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "pk" ]]
|
||||
run dolt table import -c --pk=pk1,pk2 test null-pk-2.csv
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "pk2" ]]
|
||||
}
|
||||
|
||||
@test "table import -c infers types from data" {
|
||||
cat <<DELIM > types.csv
|
||||
pk,str,int,bool,float, date, time, datetime
|
||||
|
||||
@@ -254,6 +254,18 @@ func InferSchema(ctx context.Context, root *doltdb.RootValue, rd table.TableRead
|
||||
pkSet := set.NewStrSet(pks)
|
||||
newCols, _ := schema.MapColCollection(infCols, func(col schema.Column) (schema.Column, error) {
|
||||
col.IsPartOfPK = pkSet.Contains(col.Name)
|
||||
if col.IsPartOfPK {
|
||||
hasNotNull := false
|
||||
for _, constraint := range col.Constraints {
|
||||
if _, ok := constraint.(schema.NotNullConstraint); ok {
|
||||
hasNotNull = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasNotNull {
|
||||
col.Constraints = append(col.Constraints, schema.NotNullConstraint{})
|
||||
}
|
||||
}
|
||||
return col, nil
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user