-
Notifications
You must be signed in to change notification settings - Fork 66
/
simple.go
70 lines (61 loc) · 1.96 KB
/
simple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"context"
"fmt"
"github.com/apache/arrow/go/v14/arrow"
"github.com/apache/arrow/go/v14/arrow/memory"
"github.com/polarsignals/frostdb"
"github.com/polarsignals/frostdb/query"
"github.com/polarsignals/frostdb/query/logicalplan"
)
// This example demonstrates how to create a simple FrostDB with a dynamic labels column that stores float values.
func main() {
// Create a new column store
columnstore, _ := frostdb.New()
defer columnstore.Close()
// Open up a database in the column store
database, _ := columnstore.DB(context.Background(), "simple_db")
type Simple struct {
Names map[string]string `frostdb:",asc"`
Value int64
}
table, _ := frostdb.NewGenericTable[Simple](
database, "simple_table", memory.DefaultAllocator,
)
// Create values to insert into the database these first rows havel dynamic label names of 'firstname' and 'surname'
frederic := Simple{
Names: map[string]string{
"first_name": "Frederic",
"surname": "Brancz",
},
Value: 100,
}
thor := Simple{
Names: map[string]string{
"first_name": "Thor",
"surname": "Hansen",
},
Value: 99,
}
_ = table.Write(context.Background(), frederic, thor)
// Now we can insert rows that have middle names into our dynamic column
matthias := Simple{
Names: map[string]string{
"first_name": "Matthias",
"middle_name": "Oliver Rainer",
"surname": "Loibl",
},
Value: 101,
}
_ = table.Write(context.Background(), matthias)
// Create a new query engine to retrieve data and print the results
engine := query.NewEngine(memory.DefaultAllocator, database.TableProvider())
_ = engine.ScanTable("simple_table").
Project(logicalplan.DynCol("names")). // We don't know all dynamic columns at query time, but we want all of them to be returned.
Filter(
logicalplan.Col("names.first_name").Eq(logicalplan.Literal("Frederic")),
).Execute(context.Background(), func(ctx context.Context, r arrow.Record) error {
fmt.Println(r)
return nil
})
}