Skip to content

Commit

Permalink
Move GetFields from ClickHouseQueryTranslator to Table (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored May 6, 2024
1 parent b5b8499 commit 3fc1f58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
10 changes: 10 additions & 0 deletions quesma/clickhouse/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ type Table struct {
Comment string // this human-readable comment
}

func (t *Table) GetFields() []string {
var res = make([]string, 0)
for _, col := range t.Cols {
if col.IsFullTextMatch {
res = append(res, col.Name)
}
}
return res
}

func (t *Table) createTableOurFieldsString() []string {
rows := make([]string, 0)
if t.Config.hasOthers {
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 @@ -552,7 +552,7 @@ func (cw *ClickhouseQueryTranslator) parseMultiMatch(queryMap QueryMap) SimpleQu
return newSimpleQuery(NewSimpleStatement("invalid fields type"), false)
}
} else {
fields = cw.GetFieldsList()
fields = cw.Table.GetFields()
}
if len(fields) == 0 {
return newSimpleQuery(alwaysFalseStatement, true)
Expand Down Expand Up @@ -670,7 +670,7 @@ func (cw *ClickhouseQueryTranslator) parseQueryString(queryMap QueryMap) SimpleQ
if fieldsRaw, ok := queryMap["fields"]; ok {
fields = cw.extractFields(fieldsRaw.([]interface{}))
} else {
fields = cw.GetFieldsList()
fields = cw.Table.GetFields()
}

query := queryMap["query"].(string) // query: (Required, string)
Expand Down Expand Up @@ -955,7 +955,7 @@ func (cw *ClickhouseQueryTranslator) extractFields(fields []interface{}) []strin
continue
}
if fieldStr == "*" {
return cw.GetFieldsList()
return cw.Table.GetFields()
}
fieldStr = cw.Table.ResolveField(cw.Ctx, fieldStr)
result = append(result, fieldStr)
Expand Down
12 changes: 0 additions & 12 deletions quesma/queryparser/query_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,6 @@ func SearchToAsyncSearchResponse(searchResponse *model.SearchResp, asyncRequestI
return &response
}

// GetFieldsList
// TODO flatten tuples, I think (or just don't support them for now, we don't want them at the moment in production schemas)
func (cw *ClickhouseQueryTranslator) GetFieldsList() []string {
var res []string
for _, col := range cw.Table.Cols {
if col.IsFullTextMatch {
res = append(res, col.Name)
}
}
return res
}

func (cw *ClickhouseQueryTranslator) BuildSelectQuery(fields []string, whereClause string) *model.Query {
return &model.Query{
Fields: fields,
Expand Down

0 comments on commit 3fc1f58

Please sign in to comment.