-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
github.com/farmerx/elasticsql/elasticsql.go
`
// handleParseSelect parse sql select
func handleParseSelect(selectStmt *sqlparser.Select) (table string, dsl string, err error) {
// 获取from
if table, err = getFromTable(selectStmt); err != nil {
return ,
, err
}
from, size := getFromAndSize(selectStmt)
// 解析where
querydsl := ``
if selectStmt.Where != nil {
if querydsl, err = handleSelectWhere(&selectStmt.Where.Expr, true); err != nil {
return ``, ``, err
}
}
if querydsl == `` {
querydsl = `{"bool" : {"must": [{"match_all" : {}}]}}`
}
colArr, aggsdsl, err := handleSelectGroupBy(selectStmt, size)
if err != nil {
return ``, ``, err
}
var orderByArr []string
if aggsdsl != nil {
from, size = "0", "0"
} else {
// Handle order by
// when executating aggregations, order by is useless
for _, orderByExpr := range selectStmt.OrderBy {
orderByStr := fmt.Sprintf(`{"%v": "%v"}`, sqlparser.String(orderByExpr.Expr), orderByExpr.Direction)
orderByArr = append(orderByArr, orderByStr)
}
}
return table, buildDSL(querydsl, from, size, string(aggsdsl), []string{}, colArr), nil
}`
Metadata
Metadata
Assignees
Labels
No labels