Skip to content

Commit

Permalink
go fmt code
Browse files Browse the repository at this point in the history
  • Loading branch information
cch123 committed Sep 9, 2021
1 parent 24a7253 commit da3bd33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions select_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func unescapeSql(sql, escapeStr string) string {
strSegments := strings.Split(sql, escapeStr)
for _, segment := range strSegments {
if segment == "" {
resSql += escapeStr // continuous escapeStr, only remove the first one
resSql += escapeStr // continuous escapeStr, only remove the first one
} else {
resSql += segment
}
Expand All @@ -247,7 +247,7 @@ func handleSelectWhereComparisonExpr(expr *sqlparser.Expr, topLevel bool, parent

// unescape rightStr
escapeStr := sqlparser.String(comparisonExpr.Escape)
escapeStr = strings.Trim(escapeStr, "'") // remove quote both sides
escapeStr = strings.Trim(escapeStr, "'") // remove quote both sides
rightStr = unescapeSql(rightStr, escapeStr)
resultStr := ""

Expand Down
12 changes: 6 additions & 6 deletions select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ var selectCaseMap = map[string]string{
"select * from a where id = missing": `{"query" : {"bool" : {"must" : [{"missing":{"field":"id"}}]}},"from" : 0,"size" : 1}`,
"select count(*) from a": `{"query" : {"bool" : {"must": [{"match_all" : {}}]}},"from" : 0,"size" : 0,"aggregations" : {"COUNT(*)":{"value_count":{"field":"_index"}}}}`,
"SELECT online FROM online GROUP BY date_range(field='insert_time' , format='yyyy-MM-dd', '2014-08-18','2014-08-17','now-8d','now-7d','now-6d','now')": `{"query" : {"bool" : {"must": [{"match_all" : {}}]}},"from" : 0,"size" : 0,"aggregations" : {"date_range(field=insert_time,format=yyyy-MM-dd,2014-08-18,2014-08-17,now-8d,now-7d,now-6d,now)":{"date_range":{"field":"insert_time","format":"yyyy-MM-dd","ranges":[{"from":"2014-08-18","to":"2014-08-17"},{"from":"2014-08-17","to":"now-8d"},{"from":"now-8d","to":"now-7d"},{"from":"now-7d","to":"now-6d"},{"from":"now-6d","to":"now"}]}}}}`,
"select count(id), sum(age) from a group by id": `{"query" : {"bool" : {"must": [{"match_all" : {}}]}},"from" : 0,"size" : 0,"aggregations" : {"id":{"aggregations":{"COUNT(id)":{"value_count":{"field":"id"}},"SUM(age)":{"sum":{"field":"age"}}},"terms":{"field":"id","size":200}}}}`,
"select * from a order by `order`.abc": `{"query" : {"bool" : {"must": [{"match_all" : {}}]}},"from" : 0,"size" : 1,"sort" : [{"order.abc": "asc"}]}`,
"select * from aaa where multi_match(query='this is a test', fields=(title,title.origin))": `{"query" : {"multi_match" : {"query" : "this is a test", "fields" : ["title","title.origin"]}},"from" : 0,"size" : 1}`,
"select * from aaa where a= 1 and multi_match(query='this is a test', fields=(title,title.origin))": `{"query" : {"bool" : {"must" : [{"match_phrase" : {"a" : {"query" : "1"}}},{"multi_match" : {"query" : "this is a test", "fields" : ["title","title.origin"]}}]}},"from" : 0,"size" : 1}`,
"select * from aaa where a= 1 and multi_match(query='this is a test', fields=(title,title.origin), type=phrase)": `{"query" : {"bool" : {"must" : [{"match_phrase" : {"a" : {"query" : "1"}}},{"multi_match" : {"query" : "this is a test", "type" : "phrase", "fields" : ["title","title.origin"]}}]}},"from" : 0,"size" : 1}`,
"select count(id), sum(age) from a group by id": `{"query" : {"bool" : {"must": [{"match_all" : {}}]}},"from" : 0,"size" : 0,"aggregations" : {"id":{"aggregations":{"COUNT(id)":{"value_count":{"field":"id"}},"SUM(age)":{"sum":{"field":"age"}}},"terms":{"field":"id","size":200}}}}`,
"select * from a order by `order`.abc": `{"query" : {"bool" : {"must": [{"match_all" : {}}]}},"from" : 0,"size" : 1,"sort" : [{"order.abc": "asc"}]}`,
"select * from aaa where multi_match(query='this is a test', fields=(title,title.origin))": `{"query" : {"multi_match" : {"query" : "this is a test", "fields" : ["title","title.origin"]}},"from" : 0,"size" : 1}`,
"select * from aaa where a= 1 and multi_match(query='this is a test', fields=(title,title.origin))": `{"query" : {"bool" : {"must" : [{"match_phrase" : {"a" : {"query" : "1"}}},{"multi_match" : {"query" : "this is a test", "fields" : ["title","title.origin"]}}]}},"from" : 0,"size" : 1}`,
"select * from aaa where a= 1 and multi_match(query='this is a test', fields=(title,title.origin), type=phrase)": `{"query" : {"bool" : {"must" : [{"match_phrase" : {"a" : {"query" : "1"}}},{"multi_match" : {"query" : "this is a test", "type" : "phrase", "fields" : ["title","title.origin"]}}]}},"from" : 0,"size" : 1}`,
"SELECT `id`, `name` FROM `student` WHERE (`name` LIKE '%aaa!_bbb!!ccc%' ESCAPE '!') ORDER BY `updateTime` DESC LIMIT 10": `{"query" : {"bool" : {"must" : [{"match_phrase" : {"name" : {"query" : "aaa_bbb!ccc"}}}]}},"from" : 0,"size" : 10,"sort" : [{"updateTime": "desc"}]}`,
"SELECT `id`, `name` FROM `student` WHERE (`name` LIKE '%aaa!_bbb!!ccc%') ORDER BY `updateTime` DESC LIMIT 10": `{"query" : {"bool" : {"must" : [{"match_phrase" : {"name" : {"query" : "aaa!_bbb!!ccc"}}}]}},"from" : 0,"size" : 10,"sort" : [{"updateTime": "desc"}]}`,
"SELECT `id`, `name` FROM `student` WHERE (`name` LIKE '%aaa!_bbb!!ccc%') ORDER BY `updateTime` DESC LIMIT 10": `{"query" : {"bool" : {"must" : [{"match_phrase" : {"name" : {"query" : "aaa!_bbb!!ccc"}}}]}},"from" : 0,"size" : 10,"sort" : [{"updateTime": "desc"}]}`,
}

func TestSupported(t *testing.T) {
Expand Down

0 comments on commit da3bd33

Please sign in to comment.