Skip to content

Commit 830bef7

Browse files
authored
Merge pull request #27 from gigapi/feat/layers
Multilayer configuration support
2 parents 8b24221 + bd0802e commit 830bef7

4 files changed

Lines changed: 89 additions & 30 deletions

File tree

go.mod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.24.2
44

55
require (
66
github.com/apache/arrow/go/v14 v14.0.2
7-
github.com/gigapi/gigapi-config v0.0.7
7+
github.com/gigapi/gigapi-config v0.0.8
88
github.com/gigapi/gigapi/v2 v2.0.13
9-
github.com/gigapi/metadata v0.0.3
9+
github.com/gigapi/metadata v0.0.4
1010
github.com/marcboeker/go-duckdb/v2 v2.2.0
1111
github.com/spf13/afero v1.12.0
1212
github.com/stretchr/testify v1.10.0
@@ -17,6 +17,7 @@ require (
1717

1818
require (
1919
github.com/apache/arrow-go/v18 v18.1.0 // indirect
20+
github.com/apache/arrow/go/v18 v18.0.0-20240829005432-58415d1fac50 // indirect
2021
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2122
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2223
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
@@ -27,6 +28,8 @@ require (
2728
github.com/duckdb/duckdb-go-bindings/linux-arm64 v0.1.9 // indirect
2829
github.com/duckdb/duckdb-go-bindings/windows-amd64 v0.1.9 // indirect
2930
github.com/fsnotify/fsnotify v1.7.0 // indirect
31+
github.com/go-faster/errors v0.6.1 // indirect
32+
github.com/go-faster/jx v1.1.0 // indirect
3033
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
3134
github.com/goccy/go-json v0.10.5 // indirect
3235
github.com/google/flatbuffers v25.1.24+incompatible // indirect
@@ -47,6 +50,7 @@ require (
4750
github.com/redis/go-redis/v9 v9.8.0 // indirect
4851
github.com/sagikazarmark/locafero v0.4.0 // indirect
4952
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
53+
github.com/segmentio/asm v1.2.0 // indirect
5054
github.com/sourcegraph/conc v0.3.0 // indirect
5155
github.com/spf13/cast v1.6.0 // indirect
5256
github.com/spf13/pflag v1.0.5 // indirect

go.sum

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/apache/arrow-go/v18 v18.1.0 h1:agLwJUiVuwXZdwPYVrlITfx7bndULJ/dggbnLF
44
github.com/apache/arrow-go/v18 v18.1.0/go.mod h1:tigU/sIgKNXaesf5d7Y95jBBKS5KsxTqYBKXFsvKzo0=
55
github.com/apache/arrow/go/v14 v14.0.2 h1:N8OkaJEOfI3mEZt07BIkvo4sC6XDbL+48MBPWO5IONw=
66
github.com/apache/arrow/go/v14 v14.0.2/go.mod h1:u3fgh3EdgN/YQ8cVQRguVW3R+seMybFg8QBQ5LU+eBY=
7+
github.com/apache/arrow/go/v18 v18.0.0-20240829005432-58415d1fac50 h1:3vA3hoM7fM4pJHG1dt0CEMzTwitFvutUrAiIwY+Bp+A=
8+
github.com/apache/arrow/go/v18 v18.0.0-20240829005432-58415d1fac50/go.mod h1:pAdO1xbg0WTJ++tq74I5xKX+yUD7MG0cEI24P+jko10=
79
github.com/apache/thrift v0.21.0 h1:tdPmh/ptjE1IJnhbhrcl2++TauVjy242rkV/UzJChnE=
810
github.com/apache/thrift v0.21.0/go.mod h1:W1H8aR/QRtYNvrPeFXBtobyRkd0/YVhTc6i07XIAgDw=
911
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
@@ -36,12 +38,16 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
3638
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
3739
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
3840
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
39-
github.com/gigapi/gigapi-config v0.0.7 h1:JBygAXojXdTmxhKe2vTSvXoPZU0D7kLWl9+E+PuUQJs=
40-
github.com/gigapi/gigapi-config v0.0.7/go.mod h1:/hD+d1odWyElSP9++ZPLULXthWHXvx0shNypdbZDYA8=
41+
github.com/gigapi/gigapi-config v0.0.8 h1:fyOwS3by+qMlHLthmIgX1gXEchH2PUH2l4x/y9sRyOg=
42+
github.com/gigapi/gigapi-config v0.0.8/go.mod h1:/hD+d1odWyElSP9++ZPLULXthWHXvx0shNypdbZDYA8=
4143
github.com/gigapi/gigapi/v2 v2.0.13 h1:m4w2Sx+AQZl+SPS+5oCtCe7G1888/2nF6m+d1vsiHlQ=
4244
github.com/gigapi/gigapi/v2 v2.0.13/go.mod h1:xoh5uz+EQCK43cI08wMJlyhAZ1368OOPlJjmOr1TGis=
43-
github.com/gigapi/metadata v0.0.3 h1:foO8cD4JT3HbzGUkpEda7jHgiGXpaK74t4x4cSMxO3o=
44-
github.com/gigapi/metadata v0.0.3/go.mod h1:LGFPrq9868U3+4S5DdoL1/aU3Ua0mXsRVblXXzCK1i0=
45+
github.com/gigapi/metadata v0.0.4 h1:kQdreAUyeguIrwSlPukzZ36Y9HlKVhcaBgrg8crK1tY=
46+
github.com/gigapi/metadata v0.0.4/go.mod h1:LGFPrq9868U3+4S5DdoL1/aU3Ua0mXsRVblXXzCK1i0=
47+
github.com/go-faster/errors v0.6.1 h1:nNIPOBkprlKzkThvS/0YaX8Zs9KewLCOSFQS5BU06FI=
48+
github.com/go-faster/errors v0.6.1/go.mod h1:5MGV2/2T9yvlrbhe9pD9LO5Z/2zCSq2T8j+Jpi2LAyY=
49+
github.com/go-faster/jx v1.1.0 h1:ZsW3wD+snOdmTDy9eIVgQdjUpXRRV4rqW8NS3t+20bg=
50+
github.com/go-faster/jx v1.1.0/go.mod h1:vKDNikrKoyUmpzaJ0OkIkRQClNHFX/nF3dnTJZb3skg=
4551
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
4652
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
4753
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@@ -118,6 +124,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
118124
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
119125
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
120126
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
127+
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
128+
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
121129
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
122130
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
123131
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=

querier/queryClient.go

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"fmt"
99
"github.com/gigapi/gigapi-config/config"
10+
"github.com/gigapi/gigapi/v2/merge/shared"
1011
"github.com/gigapi/metadata"
1112
"log"
1213
"os"
@@ -392,14 +393,31 @@ func (q *QueryClient) enumFolderNoMetadata(path string) ([]string, error) {
392393
return res, nil
393394
}
394395

395-
func getIndex(db, measurement string) (metadata.TableIndex, error) {
396+
func getTableIndex(table *shared.Table) (metadata.TableIndex, error) {
397+
layers := make([]metadata.Layer, len(config.Config.Gigapi.Layers))
398+
for i, l := range config.Config.Gigapi.Layers {
399+
layers[i] = metadata.Layer{
400+
URL: l.URL,
401+
Name: l.Name,
402+
Type: l.Type,
403+
TTLSec: int32(l.TTL.Seconds()),
404+
}
405+
}
396406
switch config.Config.Gigapi.Metadata.Type {
397407
case "json":
398-
return metadata.NewJSONIndex(config.Config.Gigapi.Root, db, measurement), nil
408+
return metadata.NewJSONIndex(
409+
config.Config.Gigapi.Root,
410+
table.Database,
411+
table.Name,
412+
layers)
399413
case "redis":
400-
return metadata.NewRedisIndex(config.Config.Gigapi.Metadata.URL, db, measurement)
414+
return metadata.NewRedisIndex(
415+
config.Config.Gigapi.Metadata.URL,
416+
table.Database,
417+
table.Name,
418+
layers)
401419
}
402-
return nil, fmt.Errorf("Unsupported index " + config.Config.Gigapi.Metadata.Type)
420+
return nil, fmt.Errorf("unknown metadata type: %q", config.Config.Gigapi.Metadata.Type)
403421
}
404422

405423
// Find relevant parquet files based on time range
@@ -424,14 +442,21 @@ func (q *QueryClient) FindRelevantFiles(ctx context.Context, dbName, measurement
424442
opts.Before = time.Unix(0, *timeRange.End)
425443
}
426444

427-
idx, err := getIndex(dbName, measurement)
445+
idx, err := getTableIndex(&shared.Table{
446+
Database: dbName,
447+
Name: measurement,
448+
})
428449
if err != nil {
429450
return nil, err
430451
}
431452

432453
ies, err := idx.GetQuerier().Query(opts)
454+
layersMap := make(map[string]string)
455+
for _, l := range config.Config.Gigapi.Layers {
456+
layersMap[l.Name] = strings.TrimPrefix(l.URL, "file://")
457+
}
433458
for _, ie := range ies {
434-
relevantFiles = append(relevantFiles, filepath.Join(config.Config.Gigapi.Root, dbName, measurement, "data", ie.Path))
459+
relevantFiles = append(relevantFiles, filepath.Join(layersMap[ie.Layer], dbName, measurement, "data", ie.Path))
435460
}
436461

437462
if len(relevantFiles) == 0 {
@@ -616,6 +641,25 @@ func (q *QueryClient) getHourDirectoriesInRange(datePath string, startDate, endD
616641
return hourDirs, nil
617642
}
618643

644+
func (c *QueryClient) getDBIndex(ctx context.Context) (metadata.DBIndex, error) {
645+
var layers []metadata.Layer
646+
for _, l := range config.Config.Gigapi.Layers {
647+
layers = append(layers, metadata.Layer{
648+
URL: l.URL,
649+
Name: l.Name,
650+
Type: l.Type,
651+
TTLSec: int32(l.TTL.Seconds()),
652+
})
653+
}
654+
switch config.Config.Gigapi.Metadata.Type {
655+
case "json":
656+
return metadata.NewJSONDBIndex(layers), nil
657+
case "redis":
658+
return metadata.NewRedisDbIndex(config.Config.Gigapi.Metadata.URL)
659+
}
660+
return nil, fmt.Errorf("unsupported metadata type: %s", config.Config.Gigapi.Metadata.Type)
661+
}
662+
619663
// Query executes a query against the database
620664
func (c *QueryClient) Query(ctx context.Context, query, dbName string) ([]map[string]interface{}, error) {
621665
// Ensure we have a context
@@ -633,36 +677,39 @@ func (c *QueryClient) Query(ctx context.Context, query, dbName string) ([]map[st
633677
// Handle special commands
634678
switch upperQuery {
635679
case "SHOW DATABASES":
636-
entries, err := os.ReadDir(c.DataDir)
680+
idx, err := c.getDBIndex(ctx)
681+
if err != nil {
682+
return nil, fmt.Errorf("failed to get DB index: %v", err)
683+
}
684+
entries, err := idx.Databases()
637685
if err != nil {
638686
return nil, fmt.Errorf("failed to read data directory: %v", err)
639687
}
640688

641689
results := make([]map[string]interface{}, 0)
642690
for _, entry := range entries {
643-
if entry.IsDir() {
644-
results = append(results, map[string]interface{}{
645-
"database_name": entry.Name(),
646-
})
647-
}
691+
results = append(results, map[string]interface{}{
692+
"database_name": entry,
693+
})
648694
}
649695
return results, nil
650696

651697
case "SHOW TABLES":
652698
// List directories inside the database folder
653-
dbPath := filepath.Join(c.DataDir, dbName)
654-
entries, err := os.ReadDir(dbPath)
699+
idx, err := c.getDBIndex(ctx)
700+
if err != nil {
701+
return nil, fmt.Errorf("failed to get DB index: %v", err)
702+
}
703+
entries, err := idx.Tables(dbName)
655704
if err != nil {
656705
return nil, fmt.Errorf("failed to read database directory: %v", err)
657706
}
658707

659708
results := make([]map[string]interface{}, 0)
660709
for _, entry := range entries {
661-
if entry.IsDir() {
662-
results = append(results, map[string]interface{}{
663-
"table_name": entry.Name(),
664-
})
665-
}
710+
results = append(results, map[string]interface{}{
711+
"table_name": entry,
712+
})
666713
}
667714
return results, nil
668715
}
@@ -672,13 +719,13 @@ func (c *QueryClient) Query(ctx context.Context, query, dbName string) ([]map[st
672719
if err != nil {
673720
// Fallback: Directly execute the query in DuckDB if ParseQuery fails
674721
// Set DuckDB safety option to disable external access
675-
if _, errSet := c.DB.Exec("SET enable_external_access = false;"); errSet != nil {
676-
return nil, fmt.Errorf("failed to disable external access: %v", errSet)
722+
/*if _, errSet := c.DB.Exec("SET enable_external_access = false;"); errSet != nil {
723+
return nil, fmt.Errorf("failed to disable external access: %v", errSet)
677724
}
678725
if _, errSet := c.DB.Exec("SET lock_configuration = true;"); errSet != nil {
679-
return nil, fmt.Errorf("failed to lock configuration: %v", errSet)
680-
}
681-
726+
return nil, fmt.Errorf("failed to lock configuration: %v", errSet)
727+
}*/
728+
682729
stmt, err2 := c.DB.Prepare(query)
683730
if err2 != nil {
684731
return nil, fmt.Errorf("failed to prepare query: %v", err2)

querier/ui.zip

51.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)