Skip to content

Commit

Permalink
Merge pull request #58 from openziti/mem-store
Browse files Browse the repository at this point in the history
Implement querying collections of in memory objects. Fixes #57
  • Loading branch information
plorenz authored Dec 4, 2023
2 parents e5122b4 + 2f6a818 commit a05a3e7
Show file tree
Hide file tree
Showing 7 changed files with 1,054 additions and 22 deletions.
9 changes: 9 additions & 0 deletions ast/node_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ func (node *SortByNode) IsConst() bool {
return false
}

func NewSortFieldNode(symbol string, isAscending bool) SortField {
return &SortFieldNode{
symbol: &UntypedSymbolNode{
symbol: symbol,
},
isAscending: isAscending,
}
}

type SortFieldNode struct {
symbol SymbolNode
isAscending bool
Expand Down
23 changes: 1 addition & 22 deletions boltz/store_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package boltz

import (
"fmt"
"github.com/michaelquigley/pfxlog"
"strings"

Expand Down Expand Up @@ -325,30 +324,10 @@ func (store *BaseStore[E]) NewScanner(sort []ast.SortField) Scanner {
return &sortingScanner{store: store}
}

type sortFieldImpl struct {
name string
isAsc bool
}

func (sortField *sortFieldImpl) Symbol() string {
return sortField.name
}

func (sortField *sortFieldImpl) IsAscending() bool {
return sortField.isAsc
}

func (sortField *sortFieldImpl) String() string {
if sortField.isAsc {
return sortField.name
}
return fmt.Sprintf("%v DESC", sortField.name)
}

func (store *BaseStore[E]) newRowComparator(sort []ast.SortField) (RowComparator, error) {
// always have id as last sort element. this way if other sorts come out equal, we still
// can order on something, instead of having duplicates which causes rows to get discarded
sort = append(sort, &sortFieldImpl{name: "id", isAsc: true})
sort = append(sort, ast.NewSortFieldNode("id", true))

var symbolsComparators []symbolComparator
for _, sortField := range sort {
Expand Down
99 changes: 99 additions & 0 deletions objectz/object_cursor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
Copyright NetFoundry, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package objectz

import (
"github.com/openziti/storage/ast"
"time"
)

type ObjectCursor[T any] struct {
store *ObjectStore[T]
current T
}

func (self *ObjectCursor[T]) GetSymbolType(name string) (ast.NodeType, bool) {
symbol, found := self.store.symbols[name]
if !found {
return 0, false
}
return symbol.GetType(), true
}

func (self *ObjectCursor[T]) GetSetSymbolTypes(name string) ast.SymbolTypes {
return nil
}

func (self *ObjectCursor[T]) IsSet(name string) (bool, bool) {
_, found := self.store.symbols[name]
return false, found
}

func (self *ObjectCursor[T]) eval(name string) any {
symbol := self.store.symbols[name]
result := symbol.Eval(self.current)
return result
}

func (self *ObjectCursor[T]) EvalBool(name string) *bool {
if val, ok := self.eval(name).(*bool); ok {
return val
}
return nil
}

func (self *ObjectCursor[T]) EvalString(name string) *string {
if val, ok := self.eval(name).(*string); ok {
return val
}
return nil
}

func (self *ObjectCursor[T]) EvalInt64(name string) *int64 {
if val, ok := self.eval(name).(*int64); ok {
return val
}
return nil
}

func (self *ObjectCursor[T]) EvalFloat64(name string) *float64 {
if val, ok := self.eval(name).(*float64); ok {
return val
}
return nil
}

func (self *ObjectCursor[T]) EvalDatetime(name string) *time.Time {
if val, ok := self.eval(name).(*time.Time); ok {
return val
}
return nil
}

func (self *ObjectCursor[T]) IsNil(name string) bool {
return nil == self.eval(name)
}

func (self *ObjectCursor[T]) OpenSetCursor(name string) ast.SetCursor {
//TODO implement me
panic("implement me")
}

func (self *ObjectCursor[T]) OpenSetCursorForQuery(name string, query ast.Query) ast.SetCursor {
//TODO implement me
panic("implement me")
}
Loading

0 comments on commit a05a3e7

Please sign in to comment.