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
2 changes: 1 addition & 1 deletion server/sqlflowserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *Server) Run(req *pb.Request, stream pb.SQLFlow_RunServer) error {
sqlStatements := strings.Split(req.Sql, ";")
trimedStatements := []string{}
for _, singleSQL := range sqlStatements {
sqlToRun := strings.Trim(singleSQL, "\n")
sqlToRun := strings.TrimSpace(singleSQL)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe \n also need to be trimmed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.TrimSpace can trim \n and space: https://golang.org/pkg/strings/#TrimSpace

if sqlToRun == "" {
continue
}
Expand Down
15 changes: 10 additions & 5 deletions server/sqlflowserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ import (
)

const (
testErrorSQL = "ERROR ..."
testQuerySQL = "SELECT ..."
testExecuteSQL = "INSERT ..."
testExtendedSQL = "SELECT ... TRAIN ..."
testErrorSQL = "ERROR ..."
testQuerySQL = "SELECT ..."
testExecuteSQL = "INSERT ..."
testExtendedSQL = "SELECT ... TRAIN ..."
testExtendedSQLWithSpace = "SELECT ... TRAIN ...; \n\t"
)

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

for _, s := range []string{testQuerySQL, testExecuteSQL, testExtendedSQL} {
testMultipleSQL := fmt.Sprintf("%s; %s", testQuerySQL, testExtendedSQL)

for _, s := range []string{testQuerySQL, testExecuteSQL, testExtendedSQL, testExtendedSQLWithSpace, testMultipleSQL} {
stream, err := c.Run(ctx, &pb.Request{Sql: s})
a.NoError(err)
for {
Expand Down