Skip to content

losing sort opt #6

@baso4

Description

@baso4

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions