Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions quesma/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"quesma/concurrent"
"quesma/end_user_errors"
"quesma/index"
"quesma/logger"
"quesma/persistence"
"quesma/quesma/config"
Expand Down Expand Up @@ -272,7 +271,7 @@ func (lm *LogManager) CheckIfConnectedPaidService(service PaidServiceName) (retu
}

func (lm *LogManager) FindTable(tableName string) (result *Table) {
tableNamePattern := index.TableNamePatternRegexp(tableName)
tableNamePattern := util.TableNamePatternRegexp(tableName)
lm.tableDiscovery.TableDefinitions().
Range(func(name string, table *Table) bool {
if tableNamePattern.MatchString(name) {
Expand Down
27 changes: 0 additions & 27 deletions quesma/index/utils.go

This file was deleted.

37 changes: 0 additions & 37 deletions quesma/index/utils_test.go

This file was deleted.

3 changes: 1 addition & 2 deletions quesma/ingest/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"quesma/common_table"
"quesma/concurrent"
"quesma/end_user_errors"
"quesma/index"
"quesma/jsonprocessor"
"quesma/logger"
"quesma/model"
Expand Down Expand Up @@ -870,7 +869,7 @@ func (ip *IngestProcessor) preprocessJsons(ctx context.Context,
}

func (ip *IngestProcessor) FindTable(tableName string) (result *chLib.Table) {
tableNamePattern := index.TableNamePatternRegexp(tableName)
tableNamePattern := util.TableNamePatternRegexp(tableName)
ip.tableDiscovery.TableDefinitions().
Range(func(name string, table *chLib.Table) bool {
if tableNamePattern.MatchString(name) {
Expand Down
4 changes: 2 additions & 2 deletions quesma/quesma/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"log"
"os"
"quesma/elasticsearch/elasticsearch_field_types"
"quesma/index"
"quesma/network"
"quesma/util"
"strings"
)

Expand Down Expand Up @@ -64,7 +64,7 @@ func (c *QuesmaConfiguration) AliasFields(indexName string) map[string]string {
}

func MatchName(pattern, name string) bool {
return index.TableNamePatternRegexp(pattern).MatchString(name)
return util.TableNamePatternRegexp(pattern).MatchString(name)
}

var k = koanf.New(".")
Expand Down
3 changes: 3 additions & 0 deletions quesma/quesma/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func (p *PathRouter) Register(pattern string, predicate RequestMatcher, handler
}

func (p *PathRouter) Matches(req *Request) (Handler, *table_resolver.Decision) {
if strings.Contains(req.Path, "fligh") {
logger.Debug().Msgf("Matched path: %s", req.Path)
}
handler, decision := p.findHandler(req)
if handler != nil {
routerStatistics.addMatched(req.Path)
Expand Down
19 changes: 19 additions & 0 deletions quesma/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"net/http"
"quesma/logger"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
Expand Down Expand Up @@ -908,3 +909,21 @@ func ExtractUsernameFromBasicAuthHeader(authHeader string) (string, error) {
}
return pair[0], nil
}

func TableNamePatternRegexp(indexPattern string) *regexp.Regexp {
var builder strings.Builder

for _, char := range indexPattern {
switch char {
case '*':
builder.WriteString(".*")
case '[', ']', '\\', '^', '$', '.', '|', '?', '+', '(', ')':
builder.WriteRune('\\')
builder.WriteRune(char)
default:
builder.WriteRune(char)
}
}

return regexp.MustCompile(fmt.Sprintf("^%s$", builder.String()))
}
29 changes: 29 additions & 0 deletions quesma/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package util
import (
"context"
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"reflect"
Expand Down Expand Up @@ -903,3 +904,31 @@ func TestExtractUsernameFromBasicAuthHeader(t *testing.T) {
})
}
}

func TestTableNamePatternRegexp(t *testing.T) {
tests := []struct {
input string
output string
}{
{input: "foo", output: "^foo$"},
{input: "foo*", output: "^foo.*$"},
{input: "foo*bar", output: "^foo.*bar$"},
{input: "foo*bar*", output: "^foo.*bar.*$"},
{input: "foo*b[ar*", output: "^foo.*b\\[ar.*$"},
{input: "foo+bar", output: "^foo\\+bar$"},
{input: "foo|bar", output: "^foo\\|bar$"},
{input: "foo(bar", output: "^foo\\(bar$"},
{input: "foo)bar", output: "^foo\\)bar$"},
{input: "foo^bar", output: "^foo\\^bar$"},
{input: "foo$bar", output: "^foo\\$bar$"},
{input: "foo.bar", output: "^foo\\.bar$"},
{input: "foo\\bar", output: "^foo\\\\bar$"},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s into %s", tt.input, tt.output), func(t *testing.T) {
if got := TableNamePatternRegexp(tt.input); !reflect.DeepEqual(got.String(), tt.output) {
t.Errorf("TableNamePatternRegexp() = %v, want %v", got, tt.output)
}
})
}
}
Loading