Skip to content

Commit 098093c

Browse files
authored
fix trim sql (#804)
* fix trim sql * add test with trimed sql
1 parent b17ebca commit 098093c

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

server/sqlflowserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (s *Server) Run(req *pb.Request, stream pb.SQLFlow_RunServer) error {
6262
sqlStatements := strings.Split(req.Sql, ";")
6363
trimedStatements := []string{}
6464
for _, singleSQL := range sqlStatements {
65-
sqlToRun := strings.Trim(singleSQL, "\n")
65+
sqlToRun := strings.TrimSpace(singleSQL)
6666
if sqlToRun == "" {
6767
continue
6868
}

server/sqlflowserver_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ import (
3636
)
3737

3838
const (
39-
testErrorSQL = "ERROR ..."
40-
testQuerySQL = "SELECT ..."
41-
testExecuteSQL = "INSERT ..."
42-
testExtendedSQL = "SELECT ... TRAIN ..."
39+
testErrorSQL = "ERROR ..."
40+
testQuerySQL = "SELECT ..."
41+
testExecuteSQL = "INSERT ..."
42+
testExtendedSQL = "SELECT ... TRAIN ..."
43+
testExtendedSQLWithSpace = "SELECT ... TRAIN ...; \n\t"
4344
)
4445

4546
var testServerAddress string
@@ -67,6 +68,8 @@ func mockRun(sql string, db *sf.DB, modelDir string, session *pb.Session) *sf.Pi
6768
case testExtendedSQL:
6869
wr.Write("log 0")
6970
wr.Write("log 1")
71+
default:
72+
wr.Write(fmt.Errorf("unexcepted SQL: %s", sql))
7073
}
7174
}()
7275
return rd
@@ -123,7 +126,9 @@ func TestSQL(t *testing.T) {
123126
_, err = stream.Recv()
124127
a.Equal(status.Error(codes.Unknown, fmt.Sprintf("run error: %v", testErrorSQL)), err)
125128

126-
for _, s := range []string{testQuerySQL, testExecuteSQL, testExtendedSQL} {
129+
testMultipleSQL := fmt.Sprintf("%s; %s", testQuerySQL, testExtendedSQL)
130+
131+
for _, s := range []string{testQuerySQL, testExecuteSQL, testExtendedSQL, testExtendedSQLWithSpace, testMultipleSQL} {
127132
stream, err := c.Run(ctx, &pb.Request{Sql: s})
128133
a.NoError(err)
129134
for {

0 commit comments

Comments
 (0)