Skip to content

Commit

Permalink
Minor fixes (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakozaur authored May 20, 2024
1 parent 4d0a7c9 commit bc2f642
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
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
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

0 comments on commit bc2f642

Please sign in to comment.