diff --git a/go/libraries/doltcore/env/actions/infer_schema.go b/go/libraries/doltcore/env/actions/infer_schema.go index 4ba6527d24..42f7739204 100644 --- a/go/libraries/doltcore/env/actions/infer_schema.go +++ b/go/libraries/doltcore/env/actions/infer_schema.go @@ -224,6 +224,12 @@ func leastPermissiveNumericType(strVal string, floatThreshold float64) (ti typei if err != nil { return typeinfo.UnknownType } + + // handle leading zero case + if len(strVal) > 1 && strVal[0] == '0' { + return typeinfo.StringDefaultType + } + if ui <= math.MaxUint32 { return typeinfo.Uint32Type } else { diff --git a/go/libraries/doltcore/env/actions/infer_schema_test.go b/go/libraries/doltcore/env/actions/infer_schema_test.go index b38d4b52d0..26031dfd56 100644 --- a/go/libraries/doltcore/env/actions/infer_schema_test.go +++ b/go/libraries/doltcore/env/actions/infer_schema_test.go @@ -80,9 +80,10 @@ func TestLeastPermissiveNumericType(t *testing.T) { {"zero float with floatThreshold of 0.1", "0.0", 0.1, typeinfo.Int32Type}, {"negative float", "-1.3451234", 0.0, typeinfo.Float32Type}, {"double decimal point", "0.00.0", 0.0, typeinfo.UnknownType}, + {"leading zero floats", "05.78", 0.0, typeinfo.Float32Type}, {"zero float with high precision", "0.0000", 0.0, typeinfo.Float32Type}, - {"all zeroes", "0000", 0.0, typeinfo.Uint32Type}, - {"leading zeroes", "01", 0.0, typeinfo.Uint32Type}, + {"all zeroes", "0000", 0.0, typeinfo.StringDefaultType}, + {"leading zeroes", "01", 0.0, typeinfo.StringDefaultType}, {"negative int", "-1234", 0.0, typeinfo.Int32Type}, {"fits in uint64 but not int64", strconv.FormatUint(math.MaxUint64, 10), 0.0, typeinfo.Uint64Type}, {"negative less than math.MinInt64", "-" + strconv.FormatUint(math.MaxUint64, 10), 0.0, typeinfo.UnknownType}, diff --git a/integration-tests/bats/import-create-tables.bats b/integration-tests/bats/import-create-tables.bats index cfe41cd8ce..1f69342339 100755 --- a/integration-tests/bats/import-create-tables.bats +++ b/integration-tests/bats/import-create-tables.bats @@ -45,6 +45,14 @@ CREATE TABLE test ( ); SQL + cat < people.csv +pk,first,last,age,street,city,state,zip,dollar,color,date +1,Oscar,Rodgers,38,Zapib View,Vervutce,OH,03020,$1200.09,RED,11/12/1928 +2,Estella,Cannon,33,Kubta Manor,Tocunuz,OH,04943,$1296.25,YELLOW,03/05/2016 +3,Dora,Stanley,27,Bidohe Boulevard,Siguhazep,CA,53768,$9744.06,WHITE,07/31/1993 +4,Brian,Newman,41,Koef Court,Abemivu,OH,44534,$3808.15,YELLOW,03/29/2064 +DELIM + } teardown() { @@ -99,6 +107,15 @@ teardown() { [ "${#lines[@]}" -eq 6 ] } +@test "import-create-tables: import data from csv and create the table different types" { + run dolt table import -c --pk=pk test people.csv + [ "$status" -eq 0 ] + [[ "$output" =~ "Import completed successfully." ]] || false + run dolt sql -q "select * from test" + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 8 ] +} + @test "import-create-tables: use -f to overwrite data in existing table" { cat < other.csv pk,c1,c2,c3,c4,c5