Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #151

Merged
merged 4 commits into from
May 20, 2024
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
10 changes: 5 additions & 5 deletions quesma/clickhouse/quesma_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (lm *LogManager) ProcessQuery(ctx context.Context, table *Table, query *mod
return nil, err
}

rows, err := executeQuery(ctx, lm, table.Name, query.StringFromColumns(colNames), columns, rowToScan)
rows, err := executeQuery(ctx, lm, query.StringFromColumns(colNames), columns, rowToScan)
if err == nil {
for _, row := range rows {
row.Index = table.Name
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We setup index here, no need to pass table name to inner method.

Expand Down Expand Up @@ -106,7 +106,7 @@ func (lm *LogManager) explainQuery(ctx context.Context, query string, elapsed ti
}
}

func executeQuery(ctx context.Context, lm *LogManager, tableName string, queryAsString string, fields []string, rowToScan []interface{}) ([]model.QueryResultRow, error) {
func executeQuery(ctx context.Context, lm *LogManager, queryAsString string, fields []string, rowToScan []interface{}) ([]model.QueryResultRow, error) {
span := lm.phoneHomeAgent.ClickHouseQueryDuration().Begin()

rows, err := lm.Query(ctx, queryAsString)
Expand All @@ -115,7 +115,7 @@ func executeQuery(ctx context.Context, lm *LogManager, tableName string, queryAs
return nil, fmt.Errorf("clickhouse: query failed. err: %v, query: %v", err, queryAsString)
}

res, err := read(tableName, rows, fields, rowToScan)
res, err := read(rows, fields, rowToScan)
elapsed := span.End(nil)
if err == nil {
if lm.shouldExplainQuery(elapsed) {
Expand All @@ -128,7 +128,7 @@ func executeQuery(ctx context.Context, lm *LogManager, tableName string, queryAs

// 'selectFields' are all values that we return from the query, both columns and non-schema fields,
// like e.g. count(), or toInt8(boolField)
func read(tableName string, rows *sql.Rows, selectFields []string, rowToScan []interface{}) ([]model.QueryResultRow, error) {
func read(rows *sql.Rows, selectFields []string, rowToScan []interface{}) ([]model.QueryResultRow, error) {
rowDb := make([]interface{}, 0, len(rowToScan))
for i := range rowToScan {
rowDb = append(rowDb, &rowToScan[i])
Expand All @@ -139,7 +139,7 @@ func read(tableName string, rows *sql.Rows, selectFields []string, rowToScan []i
if err != nil {
return nil, fmt.Errorf("clickhouse: scan failed: %v", err)
}
resultRow := model.QueryResultRow{Index: tableName, Cols: make([]model.QueryResultCol, len(selectFields))}
resultRow := model.QueryResultRow{Cols: make([]model.QueryResultCol, len(selectFields))}
for i, field := range selectFields {
resultRow.Cols[i] = model.QueryResultCol{ColName: field, Value: rowToScan[i]}
}
Expand Down
2 changes: 1 addition & 1 deletion quesma/clickhouse/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Table struct {
TimestampColumn *string
}

func (t *Table) GetFields() []string {
func (t *Table) GetFulltextFields() []string {
var res = make([]string, 0)
for _, col := range t.Cols {
if col.IsFullTextMatch {
Expand Down
6 changes: 3 additions & 3 deletions quesma/queryparser/query_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (cw *ClickhouseQueryTranslator) parseMultiMatch(queryMap QueryMap) SimpleQu
return newSimpleQuery(NewSimpleStatement("invalid fields type"), false)
}
} else {
fields = cw.Table.GetFields()
fields = cw.Table.GetFulltextFields()
}
if len(fields) == 0 {
return newSimpleQuery(alwaysFalseStatement, true)
Expand Down Expand Up @@ -646,7 +646,7 @@ func (cw *ClickhouseQueryTranslator) parseQueryString(queryMap QueryMap) SimpleQ
if fieldsRaw, ok := queryMap["fields"]; ok {
fields = cw.extractFields(fieldsRaw.([]interface{}))
} else {
fields = cw.Table.GetFields()
fields = cw.Table.GetFulltextFields()
}

query := queryMap["query"].(string) // query: (Required, string)
Expand Down Expand Up @@ -847,7 +847,7 @@ func (cw *ClickhouseQueryTranslator) extractFields(fields []interface{}) []strin
continue
}
if fieldStr == "*" {
return cw.Table.GetFields()
return cw.Table.GetFulltextFields()
}
fieldStr = cw.Table.ResolveField(cw.Ctx, fieldStr)
result = append(result, fieldStr)
Expand Down
2 changes: 2 additions & 0 deletions quesma/quesma/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,15 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, indexPattern strin
}
listQuery := queryTranslator.BuildNRowsQuery(fieldName, simpleQuery, queryInfo.Size)
hitsFallback, err = q.logManager.ProcessQuery(ctx, table, listQuery, nil)
translatedQueryBody = append(translatedQueryBody, []byte("\n"+listQuery.String()+"\n")...)
if err != nil {
logger.ErrorWithCtx(ctx).Msgf("error processing fallback query. Err: %v, query: %+v", err, listQuery)
pushSecondaryInfo(q.quesmaManagementConsole, id, path, body, translatedQueryBody, responseBody, startTime)
return responseBody, err
}
countQuery := queryTranslator.BuildSimpleCountQuery(simpleQuery.Sql.Stmt)
countResult, err := q.logManager.ProcessQuery(ctx, table, countQuery, nil)
translatedQueryBody = append(translatedQueryBody, []byte("\n"+countQuery.String()+"\n")...)
if err != nil {
logger.ErrorWithCtx(ctx).Msgf("error processing count query. Err: %v, query: %+v", err, countQuery)
pushSecondaryInfo(q.quesmaManagementConsole, id, path, body, translatedQueryBody, responseBody, startTime)
Expand Down
Loading