no more unsigned

This commit is contained in:
James Cor
2022-10-26 11:21:04 -07:00
parent 8748478096
commit 8c24080bca
3 changed files with 13 additions and 37 deletions

View File

@@ -215,32 +215,15 @@ func leastPermissiveNumericType(strVal string, floatThreshold float64) (ti typei
return ti
}
if strings.Contains(strVal, "-") {
i, err := strconv.ParseInt(strVal, 10, 64)
if err != nil {
return typeinfo.UnknownType
}
if i >= math.MinInt32 && i <= math.MaxInt32 {
return typeinfo.Int32Type
} else {
return typeinfo.Int64Type
}
// always parse as signed int
i, err := strconv.ParseInt(strVal, 10, 64)
if err != nil {
return typeinfo.UnknownType
}
if i >= math.MinInt32 && i <= math.MaxInt32 {
return typeinfo.Int32Type
} else {
ui, err := strconv.ParseUint(strVal, 10, 64)
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 {
return typeinfo.Uint64Type
}
return typeinfo.Int64Type
}
}
@@ -283,14 +266,13 @@ func chronoTypes() []typeinfo.TypeInfo {
func numericTypes() []typeinfo.TypeInfo {
// prefer:
// ints over floats
// unsigned over signed
// smaller over larger
return []typeinfo.TypeInfo{
//typeinfo.Uint8Type,
//typeinfo.Uint16Type,
//typeinfo.Uint24Type,
typeinfo.Uint32Type,
typeinfo.Uint64Type,
//typeinfo.Uint32Type,
//typeinfo.Uint64Type,
//typeinfo.Int8Type,
//typeinfo.Int16Type,
@@ -395,12 +377,6 @@ func findCommonNumericType(nums typeInfoSet) typeinfo.TypeInfo {
typeinfo.Int24Type,
typeinfo.Int16Type,
typeinfo.Int8Type,
typeinfo.Uint64Type,
typeinfo.Uint32Type,
typeinfo.Uint24Type,
typeinfo.Uint16Type,
typeinfo.Uint8Type,
}
for _, numType := range mostToLeast {
if setHasType(nums, numType) {

View File

@@ -49,14 +49,14 @@ func TestLeastPermissiveType(t *testing.T) {
{"lower bool", "true", 0.0, typeinfo.BoolType},
{"upper bool", "FALSE", 0.0, typeinfo.BoolType},
{"yes", "yes", 0.0, typeinfo.StringDefaultType},
{"one", "1", 0.0, typeinfo.Uint32Type},
{"one", "1", 0.0, typeinfo.Int32Type},
{"negative one", "-1", 0.0, typeinfo.Int32Type},
{"negative one point 0", "-1.0", 0.0, typeinfo.Float32Type},
{"negative one point 0 with FT of 0.1", "-1.0", 0.1, typeinfo.Int32Type},
{"negative one point one with FT of 0.1", "-1.1", 0.1, typeinfo.Float32Type},
{"negative one point 999 with FT of 1.0", "-1.999", 1.0, typeinfo.Int32Type},
{"zero point zero zero zero zero", "0.0000", 0.0, typeinfo.Float32Type},
{"max int", strconv.FormatUint(math.MaxInt64, 10), 0.0, typeinfo.Uint64Type},
{"max int", strconv.FormatUint(math.MaxInt64, 10), 0.0, typeinfo.Int64Type},
{"bigger than max int", strconv.FormatUint(math.MaxUint64, 10) + "0", 0.0, typeinfo.StringDefaultType},
}

View File

@@ -82,7 +82,7 @@ teardown() {
[[ "$output" =~ "\`string\` varchar(16383)" ]] || false
[[ "$output" =~ "\`boolean\` tinyint" ]] || false
[[ "$output" =~ "\`float\` float" ]] || false
[[ "$output" =~ "\`uint\` int unsigned" ]] || false
[[ "$output" =~ "\`uint\` int" ]] || false
[[ "$output" =~ "\`uuid\` char(36) CHARACTER SET ascii COLLATE ascii_bin" ]] || false
}