Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"io"
"sort"
"strconv"
"strings"
"sync"
"unicode"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions go/vt/sqlparser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -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
}{
Expand Down