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

Commit 79d2543

Browse files
authored
Remove 0=0 /* _index = table_name /* from generated SQL (#1303)
Noticed it at the customer #1199 Before, for my test request we generated `WHERE 0=0 /* _index=\'Quesma\' */` Now we generate `WHERE true`, which is IMO a style improvement. (I've grepped a lot and I'm pretty sure it's the only place in code where we generate this `0=0` thing) Ideally I'd write a simple transformation to remove unnecessary `true` from the `WHERE`, but that's more work and I propose to do it in another PR, not very urgently. (Actually I'll make Claude 3.7 do it, it should manage, shouldn't it?)
1 parent 8554320 commit 79d2543

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

quesma/parsers/elastic_query_dsl/query_parser.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,8 @@ func (cw *ClickhouseQueryTranslator) parseTerm(queryMap QueryMap) model.SimpleQu
490490
if len(queryMap) == 1 {
491491
for k, v := range queryMap {
492492
if k == "_index" { // index is a table name, already taken from URI and moved to FROM clause
493-
logger.Warn().Msgf("term %s=%v in query body, ignoring in result SQL", k, v)
494-
whereClause = model.NewInfixExpr(model.NewLiteral("0"), "=", model.NewLiteral("0 /* "+k+"="+sprint(v)+" */"))
495-
return model.NewSimpleQuery(whereClause, true)
493+
logger.WarnWithCtx(cw.Ctx).Msgf("term %s=%v in query body, ignoring in result SQL", k, v)
494+
return model.NewSimpleQuery(model.TrueExpr, true)
496495
}
497496
fieldName := ResolveField(cw.Ctx, k, cw.Schema)
498497
whereClause = model.NewInfixExpr(model.NewColumnRef(fieldName), "=", model.NewLiteral(sprint(v)))

quesma/testdata/requests.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,23 @@ Men\\'s Clothing \\\\ %' LIMIT 10`},
25042504
},
25052505
[]string{},
25062506
},
2507+
{ // [48]
2508+
"_index term",
2509+
`{
2510+
"query": { /*one comment */
2511+
"bool": {
2512+
"must": {
2513+
"term": { "_index": "Quesma" }
2514+
}
2515+
}
2516+
},
2517+
"track_total_hits": false
2518+
}`,
2519+
[]string{"true"},
2520+
model.ListAllFields,
2521+
[]string{`SELECT "message" FROM ` + TableName + " WHERE true"},
2522+
[]string{},
2523+
},
25072524
}
25082525

25092526
var TestSearchRuntimeMappings = []SearchTestCase{

0 commit comments

Comments
 (0)