optimization

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2025-09-25 17:30:33 +02:00
parent 3cb63ec240
commit a1a6689feb

View File

@@ -196,16 +196,12 @@ func getWhereClause(queryText string, columns []string, exactMatch bool) string
termEscaped = strings.TrimSuffix(termEscaped, "$")
}
termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_")
termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%")
for _, col := range columns {
if exactMatch || (startsWith && endsWith) {
termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_")
termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%")
orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%s' ESCAPE '\\'", col, strings.ToLower(termEscapedILike)))
} else {
// Escape characters for ILIKE
termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_")
termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%")
if startsWith {
} else if startsWith {
orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike)))
} else if endsWith {
orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s' ESCAPE '\\'", col, strings.ToLower(termEscapedILike)))
@@ -213,7 +209,6 @@ func getWhereClause(queryText string, columns []string, exactMatch bool) string
orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike)))
}
}
}
andClauses = append(andClauses, "("+strings.Join(orClausesForTerm, " OR ")+")")
}
return strings.Join(andClauses, " AND ")
@@ -226,11 +221,3 @@ func getFromClause(s *server.Server) string {
}
return fmt.Sprintf("read_parquet([%s], union_by_name=true, filename=true)", strings.Join(parquets, ", "))
}
func castAllColumns(cols []string) []string {
casted := make([]string, len(cols))
for i, col := range cols {
casted[i] = fmt.Sprintf("cast(%s as text)", col)
}
return casted
}