diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go index 1995f84157b..7299ea4de72 100644 --- a/go/vt/sqlparser/ast.go +++ b/go/vt/sqlparser/ast.go @@ -25,6 +25,7 @@ import ( "fmt" "io" "sort" + "strconv" "strings" "sync" "unicode" @@ -4325,10 +4326,10 @@ type Into struct { Variables Variables Dumpfile string - Outfile string - Charset string - Fields *Fields - Lines *Lines + Outfile string + Charset string + Fields *Fields + Lines *Lines } func (i *Into) Format(buf *TrackedBuffer) { @@ -5166,7 +5167,16 @@ func ExprFromValue(value sqltypes.Value) (Expr, error) { return &NullVal{}, nil case value.IsIntegral(): return NewIntVal(value.ToBytes()), nil - case value.IsFloat() || value.Type() == sqltypes.Decimal: + case value.IsFloat(): + // Ensure that the resulting expression will be parsed back as a float, not a decimal. + // We do this by parsing the float, then reserializing it with exponential notation. + floatValue, err := strconv.ParseFloat(string(value.ToBytes()), 64) + if err != nil { + return nil, err + } + newValue := sqltypes.MakeTrusted(sqltypes.Float64, strconv.AppendFloat(nil, floatValue, 'e', -1, 64)) + return NewFloatVal(newValue.ToBytes()), nil + case value.Type() == sqltypes.Decimal: return NewFloatVal(value.ToBytes()), nil case value.IsQuoted(): return NewStrVal(value.ToBytes()), nil diff --git a/go/vt/sqlparser/ast_test.go b/go/vt/sqlparser/ast_test.go index 5edc447a038..1e77968826a 100644 --- a/go/vt/sqlparser/ast_test.go +++ b/go/vt/sqlparser/ast_test.go @@ -633,7 +633,7 @@ func TestExprFromValue(t *testing.T) { out: NewIntVal([]byte("1")), }, { in: sqltypes.NewFloat64(1.1), - out: NewFloatVal([]byte("1.1")), + out: NewFloatVal([]byte("1.1e+00")), }, { in: sqltypes.MakeTrusted(sqltypes.Decimal, []byte("1.1")), out: NewFloatVal([]byte("1.1")), @@ -887,8 +887,8 @@ func TestSplitStatementToPieces(t *testing.T) { func TestVarScopeForColName(t *testing.T) { testcases := []struct { - colName ColName - expectedName ColName + colName ColName + expectedName ColName expectedScope string expectedSpecifiedScope string }{