Merge pull request #1892 from dolthub/db/schema-infer

fix: infer_schema treat leading zero numbers as strings
This commit is contained in:
Dustin Brown
2021-07-07 13:32:53 -07:00
committed by GitHub
3 changed files with 26 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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},

View File

@@ -45,6 +45,14 @@ CREATE TABLE test (
);
SQL
cat <<DELIM > 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 <<DELIM > other.csv
pk,c1,c2,c3,c4,c5