Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 526e5c1

Browse files
authored
Remove clickhouse.LogManager from ClickhouseQueryTranslator (#1117)
This instance is not really needed, `HandleTermsEnum` was the only place where this has been used. The biggest change is probably `terms_enum.go` and also the `ResolveField(cw.Ctx, fieldStr, cw.Schema)` - it's no longer a method, but function taking Schema as an argument.
1 parent 047ed16 commit 526e5c1

13 files changed

+57
-78
lines changed

quesma/queryparser/aggregation_parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (cw *ClickhouseQueryTranslator) parseFieldField(shouldBeMap any, aggregatio
242242
}
243243
if fieldRaw, ok := Map["field"]; ok {
244244
if field, ok := fieldRaw.(string); ok {
245-
return model.NewColumnRef(cw.ResolveField(cw.Ctx, field)) // model.NewSelectColumnTableField(cw.Table.ResolveField(cw.Ctx, field)) // remove this resolve? we do all transforms after parsing is done?
245+
return model.NewColumnRef(ResolveField(cw.Ctx, field, cw.Schema)) // model.NewSelectColumnTableField(cw.Table.ResolveField(cw.Ctx, field)) // remove this resolve? we do all transforms after parsing is done?
246246
} else {
247247
logger.WarnWithCtx(cw.Ctx).Msgf("field is not a string, but %T, value: %v", fieldRaw, fieldRaw)
248248
}
@@ -322,7 +322,7 @@ func (cw *ClickhouseQueryTranslator) parseFieldFieldMaybeScript(shouldBeMap any,
322322
// maybe "field" field
323323
if fieldRaw, ok := Map["field"]; ok {
324324
if field, ok := fieldRaw.(string); ok {
325-
return model.NewColumnRef(cw.ResolveField(cw.Ctx, field)), true // remove this resolve? we do all transforms after parsing is done?
325+
return model.NewColumnRef(ResolveField(cw.Ctx, field, cw.Schema)), true // remove this resolve? we do all transforms after parsing is done?
326326
} else {
327327
logger.WarnWithCtx(cw.Ctx).Msgf("field is not a string, but %T, value: %v", fieldRaw, fieldRaw)
328328
}

quesma/queryparser/aggregation_parser_new_logic_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/stretchr/testify/assert"
99
"quesma/clickhouse"
1010
"quesma/model"
11-
"quesma/quesma/config"
1211
"quesma/quesma/types"
1312
"quesma/schema"
1413
"quesma/testdata"
@@ -34,7 +33,6 @@ func Test3AggregationParserNewLogic(t *testing.T) {
3433
Name: tableName,
3534
Config: clickhouse.NewDefaultCHConfig(),
3635
}
37-
lm := clickhouse.NewLogManager(util.NewSyncMapWith(tableName, &table), &config.QuesmaConfiguration{})
3836

3937
s := schema.StaticRegistry{
4038
Tables: map[schema.IndexName]schema.Schema{
@@ -54,7 +52,7 @@ func Test3AggregationParserNewLogic(t *testing.T) {
5452
},
5553
},
5654
}
57-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: &table, Ctx: context.Background(), Schema: s.Tables[schema.IndexName(tableName)]}
55+
cw := ClickhouseQueryTranslator{Table: &table, Ctx: context.Background(), Schema: s.Tables[schema.IndexName(tableName)]}
5856

5957
for i, test := range testdata.NewLogicTestCases {
6058
t.Run(test.TestName+"("+strconv.Itoa(i)+")", func(t *testing.T) {

quesma/queryparser/pancake_sql_query_generation_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"quesma/clickhouse"
1111
"quesma/model"
1212
"quesma/model/bucket_aggregations"
13-
"quesma/quesma/config"
1413
"quesma/quesma/types"
1514
"quesma/schema"
1615
"quesma/util"
@@ -38,15 +37,14 @@ func TestPancakeQueryGeneration(t *testing.T) {
3837
Config: clickhouse.NewDefaultCHConfig(),
3938
}
4039

41-
lm := clickhouse.NewLogManager(util.NewSyncMapWith(tableName, &table), &config.QuesmaConfiguration{})
4240
currentSchema := schema.Schema{
4341
Fields: nil,
4442
Aliases: nil,
4543
ExistsInDataSource: false,
4644
DatabaseName: "",
4745
}
4846

49-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: &table, Ctx: context.Background(), Schema: currentSchema}
47+
cw := ClickhouseQueryTranslator{Table: &table, Ctx: context.Background(), Schema: currentSchema}
5048

5149
for i, test := range allAggregationTests() {
5250
t.Run(test.TestName+"("+strconv.Itoa(i)+")", func(t *testing.T) {
@@ -211,11 +209,9 @@ func TestPancakeQueryGeneration_halfpancake(t *testing.T) {
211209
Config: clickhouse.NewDefaultCHConfig(),
212210
}
213211

214-
lm := clickhouse.NewLogManager(util.NewSyncMapWith(tableName, &table), &config.QuesmaConfiguration{})
215-
216212
currentSchema := schema.Schema{}
217213

218-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: &table, Ctx: context.Background(), Schema: currentSchema}
214+
cw := ClickhouseQueryTranslator{Table: &table, Ctx: context.Background(), Schema: currentSchema}
219215

220216
tests := []struct {
221217
name string

quesma/queryparser/query_parser.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"quesma/model/typical_queries"
1717
"quesma/queryparser/lucene"
1818
"quesma/quesma/types"
19+
"quesma/schema"
1920
"quesma/util"
2021
"strconv"
2122
"strings"
@@ -232,7 +233,7 @@ func (cw *ClickhouseQueryTranslator) parseMetadata(queryMap QueryMap) QueryMap {
232233
}
233234

234235
func (cw *ClickhouseQueryTranslator) ParseAutocomplete(indexFilter *QueryMap, fieldName string, prefix *string, caseIns bool) model.SimpleQuery {
235-
fieldName = cw.ResolveField(cw.Ctx, fieldName)
236+
fieldName = ResolveField(cw.Ctx, fieldName, cw.Schema)
236237
canParse := true
237238
stmts := make([]model.Expr, 0)
238239
if indexFilter != nil {
@@ -474,7 +475,7 @@ func (cw *ClickhouseQueryTranslator) parseTerm(queryMap QueryMap) model.SimpleQu
474475
whereClause = model.NewInfixExpr(model.NewLiteral("0"), "=", model.NewLiteral("0 /* "+k+"="+sprint(v)+" */"))
475476
return model.NewSimpleQuery(whereClause, true)
476477
}
477-
fieldName := cw.ResolveField(cw.Ctx, k)
478+
fieldName := ResolveField(cw.Ctx, k, cw.Schema)
478479
whereClause = model.NewInfixExpr(model.NewColumnRef(fieldName), "=", model.NewLiteral(sprint(v)))
479480
return model.NewSimpleQuery(whereClause, true)
480481
}
@@ -540,7 +541,7 @@ func (cw *ClickhouseQueryTranslator) parseMatch(queryMap QueryMap, matchPhrase b
540541
}
541542

542543
for fieldName, v := range queryMap {
543-
fieldName = cw.ResolveField(cw.Ctx, fieldName)
544+
fieldName = ResolveField(cw.Ctx, fieldName, cw.Schema)
544545
// (fieldName, v) = either e.g. ("message", "this is a test")
545546
// or ("message", map["query": "this is a test", ...]). Here we only care about "query" until we find a case where we need more.
546547
vUnNested := v
@@ -640,7 +641,7 @@ func (cw *ClickhouseQueryTranslator) parsePrefix(queryMap QueryMap) model.Simple
640641
}
641642

642643
for fieldName, v := range queryMap {
643-
fieldName = cw.ResolveField(cw.Ctx, fieldName)
644+
fieldName = ResolveField(cw.Ctx, fieldName, cw.Schema)
644645
switch vCasted := v.(type) {
645646
case string:
646647
simpleStat := model.NewInfixExpr(model.NewColumnRef(fieldName), "iLIKE", model.NewLiteral("'"+vCasted+"%'"))
@@ -670,7 +671,7 @@ func (cw *ClickhouseQueryTranslator) parseWildcard(queryMap QueryMap) model.Simp
670671
}
671672

672673
for fieldName, v := range queryMap {
673-
fieldName = cw.ResolveField(cw.Ctx, fieldName)
674+
fieldName = ResolveField(cw.Ctx, fieldName, cw.Schema)
674675
if vAsMap, ok := v.(QueryMap); ok {
675676
if value, ok := vAsMap["value"]; ok {
676677
if valueAsString, ok := value.(string); ok {
@@ -762,9 +763,9 @@ func (cw *ClickhouseQueryTranslator) parseRange(queryMap QueryMap) model.SimpleQ
762763
const dateInSchemaExpected = true
763764

764765
for fieldName, v := range queryMap {
765-
fieldName = cw.ResolveField(cw.Ctx, fieldName)
766+
fieldName = ResolveField(cw.Ctx, fieldName, cw.Schema)
766767

767-
fieldType := cw.Table.GetDateTimeType(cw.Ctx, cw.ResolveField(cw.Ctx, fieldName), dateInSchemaExpected)
768+
fieldType := cw.Table.GetDateTimeType(cw.Ctx, ResolveField(cw.Ctx, fieldName, cw.Schema), dateInSchemaExpected)
768769
stmts := make([]model.Expr, 0)
769770
if _, ok := v.(QueryMap); !ok {
770771
logger.WarnWithCtx(cw.Ctx).Msgf("invalid range type: %T, value: %v", v, v)
@@ -943,7 +944,7 @@ func (cw *ClickhouseQueryTranslator) extractFields(fields []interface{}) []strin
943944
if fieldStr == "*" {
944945
return []string{model.FullTextFieldNamePlaceHolder}
945946
}
946-
fieldStr = cw.ResolveField(cw.Ctx, fieldStr)
947+
fieldStr = ResolveField(cw.Ctx, fieldStr, cw.Schema)
947948
result = append(result, fieldStr)
948949
}
949950
return result
@@ -1044,7 +1045,7 @@ func (cw *ClickhouseQueryTranslator) isItListRequest(queryMap QueryMap) (model.H
10441045
}
10451046
}
10461047

1047-
resolvedField := cw.ResolveField(cw.Ctx, fieldName)
1048+
resolvedField := ResolveField(cw.Ctx, fieldName, cw.Schema)
10481049
if resolvedField == "*" {
10491050
return model.HitsCountInfo{Typ: model.ListAllFields, RequestedFields: []string{"*"}, Size: size}, true
10501051
}
@@ -1093,11 +1094,11 @@ func (cw *ClickhouseQueryTranslator) parseSortFields(sortMaps any) (sortColumns
10931094
// sortMap has only 1 key, so we can just iterate over it
10941095
for k, v := range sortMap {
10951096
// TODO replace cw.Table.GetFieldInfo with schema.Field[]
1096-
if strings.HasPrefix(k, "_") && cw.Table.GetFieldInfo(cw.Ctx, cw.ResolveField(cw.Ctx, k)) == clickhouse.NotExists {
1097+
if strings.HasPrefix(k, "_") && cw.Table.GetFieldInfo(cw.Ctx, ResolveField(cw.Ctx, k, cw.Schema)) == clickhouse.NotExists {
10971098
// we're skipping ELK internal fields, like "_doc", "_id", etc.
10981099
continue
10991100
}
1100-
fieldName := cw.ResolveField(cw.Ctx, k)
1101+
fieldName := ResolveField(cw.Ctx, k, cw.Schema)
11011102
switch v := v.(type) {
11021103
case QueryMap:
11031104
if order, ok := v["order"]; ok {
@@ -1127,7 +1128,7 @@ func (cw *ClickhouseQueryTranslator) parseSortFields(sortMaps any) (sortColumns
11271128
return sortColumns
11281129
case map[string]interface{}:
11291130
for fieldName, fieldValue := range sortMaps {
1130-
if strings.HasPrefix(fieldName, "_") && cw.Table.GetFieldInfo(cw.Ctx, cw.ResolveField(cw.Ctx, fieldName)) == clickhouse.NotExists {
1131+
if strings.HasPrefix(fieldName, "_") && cw.Table.GetFieldInfo(cw.Ctx, ResolveField(cw.Ctx, fieldName, cw.Schema)) == clickhouse.NotExists {
11311132
// TODO Elastic internal fields will need to be supported in the future
11321133
continue
11331134
}
@@ -1144,7 +1145,7 @@ func (cw *ClickhouseQueryTranslator) parseSortFields(sortMaps any) (sortColumns
11441145

11451146
case map[string]string:
11461147
for fieldName, fieldValue := range sortMaps {
1147-
if strings.HasPrefix(fieldName, "_") && cw.Table.GetFieldInfo(cw.Ctx, cw.ResolveField(cw.Ctx, fieldName)) == clickhouse.NotExists {
1148+
if strings.HasPrefix(fieldName, "_") && cw.Table.GetFieldInfo(cw.Ctx, ResolveField(cw.Ctx, fieldName, cw.Schema)) == clickhouse.NotExists {
11481149
// TODO Elastic internal fields will need to be supported in the future
11491150
continue
11501151
}
@@ -1180,11 +1181,9 @@ func createSortColumn(fieldName, ordering string) (model.OrderByExpr, error) {
11801181
// What prevents us from moving it to transformation pipeline now, is that
11811182
// we need to anotate this field somehow in the AST, to be able
11821183
// to distinguish it from other fields
1183-
func (cw *ClickhouseQueryTranslator) ResolveField(ctx context.Context, fieldName string) string {
1184+
func ResolveField(ctx context.Context, fieldName string, schemaInstance schema.Schema) string {
11841185
// Alias resolution should occur *after* the query is parsed, not during the parsing
11851186

1186-
schemaInstance := cw.Schema
1187-
11881187
fieldName = strings.TrimSuffix(fieldName, ".keyword")
11891188
fieldName = strings.TrimSuffix(fieldName, ".text")
11901189

@@ -1221,7 +1220,7 @@ func (cw *ClickhouseQueryTranslator) parseSize(queryMap QueryMap, defaultSize in
12211220
func (cw *ClickhouseQueryTranslator) GetDateTimeTypeFromSelectClause(ctx context.Context, expr model.Expr,
12221221
dateInSchemaExpected bool) clickhouse.DateTimeType {
12231222
if ref, ok := expr.(model.ColumnRef); ok {
1224-
return cw.Table.GetDateTimeType(ctx, cw.ResolveField(ctx, ref.ColumnName), dateInSchemaExpected)
1223+
return cw.Table.GetDateTimeType(ctx, ResolveField(ctx, ref.ColumnName, cw.Schema), dateInSchemaExpected)
12251224
}
12261225
return clickhouse.Invalid
12271226
}

quesma/queryparser/query_parser_range_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"context"
77
"github.com/stretchr/testify/assert"
88
"quesma/clickhouse"
9-
"quesma/quesma/config"
109
"quesma/schema"
11-
"quesma/util"
1210
"testing"
1311
)
1412

@@ -102,8 +100,7 @@ func Test_parseRange(t *testing.T) {
102100
t.Fatal(err)
103101
}
104102
assert.NoError(t, err)
105-
lm := clickhouse.NewLogManager(util.NewSyncMapWith(tableName, table), &config.QuesmaConfiguration{})
106-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: table, Ctx: context.Background(), Schema: s.Tables[schema.IndexName(tableName)]}
103+
cw := ClickhouseQueryTranslator{Table: table, Ctx: context.Background(), Schema: s.Tables[schema.IndexName(tableName)]}
107104

108105
simpleQuery := cw.parseRange(test.rangePartOfQuery)
109106
assert.Equal(t, test.expectedWhere, simpleQuery.WhereClauseAsString())

quesma/queryparser/query_parser_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestQueryParserStringAttrConfig(t *testing.T) {
6161
},
6262
},
6363
}
64-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: table, Ctx: context.Background(), Config: &cfg, Schema: s.Tables[schema.IndexName(tableName)]}
64+
cw := ClickhouseQueryTranslator{Table: table, Ctx: context.Background(), Config: &cfg, Schema: s.Tables[schema.IndexName(tableName)]}
6565

6666
for i, tt := range testdata.TestsSearch {
6767
t.Run(fmt.Sprintf("%s(%d)", tt.Name, i), func(t *testing.T) {
@@ -122,7 +122,7 @@ func TestQueryParserNoFullTextFields(t *testing.T) {
122122
},
123123
},
124124
}
125-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: &table, Ctx: context.Background(), Config: &cfg, Schema: s.Tables[schema.IndexName(tableName)]}
125+
cw := ClickhouseQueryTranslator{Table: &table, Ctx: context.Background(), Config: &cfg, Schema: s.Tables[schema.IndexName(tableName)]}
126126

127127
for i, tt := range testdata.TestsSearchNoFullTextFields {
128128
t.Run(strconv.Itoa(i), func(t *testing.T) {
@@ -185,8 +185,7 @@ func TestQueryParserNoAttrsConfig(t *testing.T) {
185185
},
186186
},
187187
}
188-
lm := clickhouse.NewLogManager(util.NewSyncMapWith(tableName, table), &config.QuesmaConfiguration{})
189-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: table, Ctx: context.Background(), Config: &cfg, Schema: s.Tables["logs-generic-default"]}
188+
cw := ClickhouseQueryTranslator{Table: table, Ctx: context.Background(), Config: &cfg, Schema: s.Tables["logs-generic-default"]}
190189
for _, tt := range testdata.TestsSearchNoAttrs {
191190
t.Run(tt.Name, func(t *testing.T) {
192191
body, parseErr := types.ParseJSON(tt.QueryJson)
@@ -269,8 +268,7 @@ func Test_parseSortFields(t *testing.T) {
269268
ENGINE = Memory`,
270269
clickhouse.NewChTableConfigNoAttrs(),
271270
)
272-
lm := clickhouse.NewLogManager(util.NewSyncMapWith(tableName, table), &config.QuesmaConfiguration{})
273-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: table, Ctx: context.Background()}
271+
cw := ClickhouseQueryTranslator{Table: table, Ctx: context.Background()}
274272
for _, tt := range tests {
275273
t.Run(tt.name, func(t *testing.T) {
276274
assert.Equal(t, tt.sortColumns, cw.parseSortFields(tt.sortMap))
@@ -294,15 +292,14 @@ func TestInvalidQueryRequests(t *testing.T) {
294292
Config: clickhouse.NewDefaultCHConfig(),
295293
}
296294

297-
lm := clickhouse.NewLogManager(util.NewSyncMapWith(tableName, &table), &config.QuesmaConfiguration{})
298295
currentSchema := schema.Schema{
299296
Fields: nil,
300297
Aliases: nil,
301298
ExistsInDataSource: false,
302299
DatabaseName: "",
303300
}
304301

305-
cw := ClickhouseQueryTranslator{ClickhouseLM: lm, Table: &table, Ctx: context.Background(), Schema: currentSchema}
302+
cw := ClickhouseQueryTranslator{Table: &table, Ctx: context.Background(), Schema: currentSchema}
306303

307304
for i, test := range testdata.InvalidAggregationTests {
308305
t.Run(test.TestName+"("+strconv.Itoa(i)+")", func(t *testing.T) {

quesma/queryparser/query_translator.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
type JsonMap = map[string]interface{}
1818

1919
type ClickhouseQueryTranslator struct {
20-
ClickhouseLM *clickhouse.LogManager
21-
2220
Schema schema.Schema
2321
Ctx context.Context
2422

@@ -312,20 +310,3 @@ func (cw *ClickhouseQueryTranslator) BuildCountQuery(whereClause model.Expr, sam
312310
func (cw *ClickhouseQueryTranslator) BuildNRowsQuery(fieldNames []string, query *model.SimpleQuery, limit int) *model.Query {
313311
return query_util.BuildHitsQuery(cw.Ctx, model.SingleTableNamePlaceHolder, fieldNames, query, limit)
314312
}
315-
316-
func (cw *ClickhouseQueryTranslator) BuildAutocompleteQuery(fieldName, tableName string, whereClause model.Expr, limit int) *model.Query {
317-
return &model.Query{
318-
SelectCommand: *model.NewSelectCommand(
319-
[]model.Expr{model.NewColumnRef(fieldName)},
320-
nil,
321-
nil,
322-
model.NewTableRef(tableName),
323-
whereClause,
324-
[]model.Expr{},
325-
limit,
326-
0,
327-
true,
328-
nil,
329-
),
330-
}
331-
}

quesma/queryparser/query_translator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func TestMakeResponseAsyncSearchQuery(t *testing.T) {
437437
// tests MakeSearchResponse, in particular if JSON we return is a proper JSON.
438438
// used to fail before we fixed field quoting.
439439
func TestMakeResponseSearchQueryIsProperJson(t *testing.T) {
440-
cw := ClickhouseQueryTranslator{ClickhouseLM: nil, Table: clickhouse.NewEmptyTable("@"), Ctx: context.Background()}
440+
cw := ClickhouseQueryTranslator{Table: clickhouse.NewEmptyTable("@"), Ctx: context.Background()}
441441
const limit = 1000
442442
queries := []*model.Query{
443443
cw.BuildNRowsQuery([]string{"*"}, &model.SimpleQuery{}, limit),

quesma/quesma/functionality/terms_enum/terms_enum.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ func HandleTermsEnum(ctx context.Context, index string, body types.JSON, lm *cli
3333
return []byte{}, end_user_errors.ErrNoSuchSchema.New(fmt.Errorf("can't load %s schema", resolvedTableName)).Details("Table: %s", resolvedTableName)
3434
}
3535

36-
return handleTermsEnumRequest(ctx, body, &queryparser.ClickhouseQueryTranslator{
37-
ClickhouseLM: lm, Table: lm.FindTable(indices[0]), Ctx: context.Background(), Schema: resolvedSchema,
38-
}, qmc)
36+
return handleTermsEnumRequest(ctx, body, lm, &queryparser.ClickhouseQueryTranslator{Table: lm.FindTable(indices[0]), Ctx: context.Background(), Schema: resolvedSchema}, qmc)
3937
}
4038
}
4139

42-
func handleTermsEnumRequest(ctx context.Context, body types.JSON, qt *queryparser.ClickhouseQueryTranslator,
40+
func handleTermsEnumRequest(ctx context.Context, body types.JSON, lm *clickhouse.LogManager, qt *queryparser.ClickhouseQueryTranslator,
4341
qmc diag.DebugInfoCollector) (result []byte, err error) {
4442
startTime := time.Now()
4543

@@ -60,7 +58,7 @@ func handleTermsEnumRequest(ctx context.Context, body types.JSON, qt *queryparse
6058
logger.ErrorWithCtx(ctx).Msgf("error reading terms enum API request body: field is not present")
6159
return json.Marshal(emptyTermsEnumResponse())
6260
}
63-
field = qt.ResolveField(ctx, field)
61+
field = queryparser.ResolveField(ctx, field, qt.Schema)
6462

6563
size := defaultSize
6664
if sizeRaw, ok := body["size"]; ok {
@@ -93,11 +91,12 @@ func handleTermsEnumRequest(ctx context.Context, body types.JSON, qt *queryparse
9391
}
9492

9593
where := qt.ParseAutocomplete(indexFilter, field, prefixString, caseInsensitive)
96-
selectQuery := qt.BuildAutocompleteQuery(field, qt.Table.Name, where.WhereClause, size)
94+
selectQuery := buildAutocompleteQuery(field, qt.Table.Name, where.WhereClause, size)
9795
dbQueryCtx, cancel := context.WithCancel(ctx)
9896
// TODO this will be used to cancel goroutine that is executing the query
9997
_ = cancel
100-
if rows, _, err2 := qt.ClickhouseLM.ProcessQuery(dbQueryCtx, qt.Table, selectQuery); err2 != nil {
98+
99+
if rows, _, err2 := lm.ProcessQuery(dbQueryCtx, qt.Table, selectQuery); err2 != nil {
101100
logger.Error().Msgf("terms enum failed - error processing SQL query [%s]", err2)
102101
result, err = json.Marshal(emptyTermsEnumResponse())
103102
} else {
@@ -149,3 +148,20 @@ func emptyTermsEnumResponse() *model.TermsEnumResponse {
149148
Terms: nil,
150149
}
151150
}
151+
152+
func buildAutocompleteQuery(fieldName, tableName string, whereClause model.Expr, limit int) *model.Query {
153+
return &model.Query{
154+
SelectCommand: *model.NewSelectCommand(
155+
[]model.Expr{model.NewColumnRef(fieldName)},
156+
nil,
157+
nil,
158+
model.NewTableRef(tableName),
159+
whereClause,
160+
[]model.Expr{},
161+
limit,
162+
0,
163+
true,
164+
nil,
165+
),
166+
}
167+
}

0 commit comments

Comments
 (0)