92 lines
1.5 KiB
Go
92 lines
1.5 KiB
Go
package dal
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
type (
|
|
simpleAttribute struct {
|
|
ident string
|
|
source string
|
|
expr string
|
|
primary bool
|
|
t Type
|
|
}
|
|
|
|
simpleRow map[string]any
|
|
)
|
|
|
|
func saToMapping(sa ...simpleAttribute) []AttributeMapping {
|
|
out := make([]AttributeMapping, 0, len(sa))
|
|
for _, a := range sa {
|
|
out = append(out, a)
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
func (sa simpleAttribute) Properties() MapProperties {
|
|
return MapProperties{
|
|
IsPrimary: sa.primary,
|
|
Type: sa.t,
|
|
}
|
|
}
|
|
|
|
func (sa simpleAttribute) Identifier() (ident string) {
|
|
return sa.ident
|
|
}
|
|
|
|
func (sa simpleAttribute) Source() (expr string) {
|
|
if sa.source != "" {
|
|
return sa.source
|
|
}
|
|
|
|
return sa.ident
|
|
}
|
|
|
|
func (sa simpleAttribute) Expression() (expr string) {
|
|
if sa.expr != "" {
|
|
return sa.expr
|
|
}
|
|
|
|
if sa.source != "" {
|
|
return sa.source
|
|
}
|
|
|
|
return sa.ident
|
|
}
|
|
|
|
func bootstrapAggregate(rootTest *testing.T, run func(context.Context, *testing.T, *Aggregate, Buffer)) {
|
|
bootstrapAggregateNoOpt(rootTest, run)
|
|
}
|
|
|
|
func bootstrapAggregateNoOpt(rootTest *testing.T, run func(context.Context, *testing.T, *Aggregate, Buffer)) {
|
|
rootTest.Run("no optimization", func(t *testing.T) {
|
|
ctx := context.Background()
|
|
buff := InMemoryBuffer()
|
|
agg := &Aggregate{}
|
|
|
|
run(ctx, t, agg, buff)
|
|
})
|
|
}
|
|
|
|
func (r simpleRow) CountValues() map[string]uint {
|
|
out := make(map[string]uint)
|
|
|
|
for k := range r {
|
|
out[k]++
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
func (r simpleRow) GetValue(k string, place uint) (any, error) {
|
|
return r[k], nil
|
|
}
|
|
|
|
func (r simpleRow) SetValue(k string, place uint, v any) error {
|
|
r[k] = v
|
|
return nil
|
|
}
|