Skip to content

Commit

Permalink
Remove relic code (#851)
Browse files Browse the repository at this point in the history
This `Fieldname` thankfully isn't used anywhere anymore.
Can close #10 afterwards.
  • Loading branch information
trzysiek authored Oct 6, 2024
1 parent 54abd78 commit 326278f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 36 deletions.
34 changes: 0 additions & 34 deletions quesma/model/simple_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
// SPDX-License-Identifier: Elastic-2.0
package model

import (
"context"
"quesma/logger"
)

type SimpleQuery struct {
WhereClause Expr
OrderBy []OrderByExpr
CanParse bool
FieldName string
// NeedCountWithLimit > 0 means we need count(*) LIMIT NeedCountWithLimit
// NeedCountWithLimit 0 (WeNeedUnlimitedCount) means we need count(*) (unlimited)
// NeedCountWithLimit -1 (WeDontNeedCount) means we don't need a count(*) query
Expand All @@ -34,10 +28,6 @@ func NewSimpleQuery(whereClause Expr, canParse bool) SimpleQuery {
return SimpleQuery{WhereClause: whereClause, CanParse: canParse}
}

func NewSimpleQueryWithFieldName(whereClause Expr, canParse bool, fieldName string) SimpleQuery {
return SimpleQuery{WhereClause: whereClause, CanParse: canParse, FieldName: fieldName}
}

// LimitForCount returns (limit, true) if we need count(*) with limit,
// (not-important, false) if we don't need count/limit
func (s *SimpleQuery) LimitForCount() (limit int, doWeNeedLimit bool) {
Expand Down Expand Up @@ -69,30 +59,6 @@ func combineStatements(stmtsToCombine []Expr, operator string) Expr {
return nil
}

func CombineWheres(ctx context.Context, where1, where2 SimpleQuery) SimpleQuery {
var combinedWhereClause Expr
if where1.WhereClause != nil && where2.WhereClause != nil {
combinedWhereClause = NewInfixExpr(where1.WhereClause, "AND", where2.WhereClause)
} else if where1.WhereClause != nil {
combinedWhereClause = where1.WhereClause
} else if where2.WhereClause != nil {
combinedWhereClause = where2.WhereClause
}
combined := SimpleQuery{
WhereClause: combinedWhereClause,
CanParse: where1.CanParse && where2.CanParse,
}
if len(where1.FieldName) > 0 && len(where2.FieldName) > 0 && where1.FieldName != where2.FieldName {
logger.WarnWithCtx(ctx).Msgf("combining 2 where clauses with different field names: %s, %s, where queries: %v %v", where1.FieldName, where2.FieldName, where1, where2)
}
if len(where1.FieldName) > 0 {
combined.FieldName = where1.FieldName
} else {
combined.FieldName = where2.FieldName
}
return combined
}

func FilterOutEmptyStatements(stmts []Expr) []Expr {
var nonEmptyStmts []Expr
for _, stmt := range stmts {
Expand Down
2 changes: 1 addition & 1 deletion quesma/queryparser/query_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ func (cw *ClickhouseQueryTranslator) parseRange(queryMap QueryMap) model.SimpleQ
logger.WarnWithCtx(cw.Ctx).Msgf("invalid range operator: %s", op)
}
}
return model.NewSimpleQueryWithFieldName(model.And(stmts), true, field)
return model.NewSimpleQuery(model.And(stmts), true)
}

// unreachable unless something really weird happens
Expand Down
2 changes: 1 addition & 1 deletion quesma/queryparser/query_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestMakeResponseSearchQuery(t *testing.T) {
t.Run(tt.queryType.String(), func(t *testing.T) {
hitQuery := query_util.BuildHitsQuery(
context.Background(), "test", []string{"*"},
&model.SimpleQuery{FieldName: "*"}, model.WeNeedUnlimitedCount,
&model.SimpleQuery{}, model.WeNeedUnlimitedCount,
)
highlighter := NewEmptyHighlighter()
queryType := typical_queries.NewHits(cw.Ctx, cw.Table, &highlighter, hitQuery.SelectCommand.OrderByFieldNames(), true, false, false, []string{cw.Table.Name})
Expand Down

0 comments on commit 326278f

Please sign in to comment.