optimization
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -196,22 +196,17 @@ func getWhereClause(queryText string, columns []string, exactMatch bool) string
|
|||||||
termEscaped = strings.TrimSuffix(termEscaped, "$")
|
termEscaped = strings.TrimSuffix(termEscaped, "$")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_")
|
||||||
|
termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%")
|
||||||
for _, col := range columns {
|
for _, col := range columns {
|
||||||
if exactMatch || (startsWith && endsWith) {
|
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)))
|
orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%s' ESCAPE '\\'", col, strings.ToLower(termEscapedILike)))
|
||||||
|
} 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)))
|
||||||
} else {
|
} else {
|
||||||
// Escape characters for ILIKE
|
orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike)))
|
||||||
termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_")
|
|
||||||
termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%")
|
|
||||||
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)))
|
|
||||||
} else {
|
|
||||||
orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
andClauses = append(andClauses, "("+strings.Join(orClausesForTerm, " OR ")+")")
|
andClauses = append(andClauses, "("+strings.Join(orClausesForTerm, " OR ")+")")
|
||||||
@@ -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, ", "))
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user