elasticsql icon indicating copy to clipboard operation
elasticsql copied to clipboard

losing sort opt

Open baso4 opened this issue 4 years ago • 1 comments

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

}`

baso4 avatar Sep 02 '21 04:09 baso4

the last line return table, buildDSL(querydsl, from, size, string(aggsdsl), []string{}, colArr), nil should be return table, buildDSL(querydsl, from, size, string(aggsdsl), orderByArr , colArr), nil

baso4 avatar Sep 02 '21 04:09 baso4