Skip to content

Commit

Permalink
feat: Top level reads from secondary index
Browse files Browse the repository at this point in the history
Supports $eq, $lt, $lte, $gt and $gte queries from the secondary index.
The secondary index can be used for reads, updates and deletes.
  • Loading branch information
garrensmith committed Feb 22, 2023
1 parent 0f5cf52 commit 7a925db
Show file tree
Hide file tree
Showing 13 changed files with 1,422 additions and 84 deletions.
18 changes: 18 additions & 0 deletions internal/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"time"

jsoniter "github.com/json-iterator/go"
"github.com/tigrisdata/tigris/errors"
ulog "github.com/tigrisdata/tigris/util/log"
"github.com/ugorji/go/codec"
Expand Down Expand Up @@ -129,6 +130,23 @@ func (x *TableData) UpdatedToProtoTS() *timestamppb.Timestamp {
return nil
}

func (x *TableData) TimestampsToJSON() ([]byte, error) {
data := map[string]jsoniter.RawMessage{
"_tigris_created_at": nil,
"_tigris_updated_at": nil,
}

if x.CreatedAt != nil {
data["_tigris_created_at"] = jsoniter.RawMessage(x.CreatedAt.ToRFC3339())
}

if x.UpdatedAt != nil {
data["_tigris_updated_at"] = jsoniter.RawMessage(x.CreatedAt.ToRFC3339())
}

return jsoniter.Marshal(data)
}

// Encode is used to encode data to the raw bytes which is used to store in storage as value. The first byte is storing
// the type corresponding to this Data. This is important and used by the decoder later to decode back.
func Encode(data *TableData) ([]byte, error) {
Expand Down
6 changes: 4 additions & 2 deletions query/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (factory *Factory) ParseSelector(k []byte, v []byte, dataType jsonparser.Va

return NewSelector(field, NewEqualityMatcher(val), factory.collation), nil
case jsonparser.Object:
valueMatcher, collation, err := buildValueMatcher(v, field)
valueMatcher, collation, err := buildValueMatcher(v, field, factory.collation)
if err != nil {
return nil, err
}
Expand All @@ -286,7 +286,7 @@ func (factory *Factory) ParseSelector(k []byte, v []byte, dataType jsonparser.Va
// instead of a simple JSON value. Apart from comparison operators, this object can have its own collation, which
// needs to be honored at the field level. Therefore, the caller needs to check if the collation returned by the
// method is not nil and if yes, use this collation..
func buildValueMatcher(input jsoniter.RawMessage, field *schema.QueryableField) (ValueMatcher, *value.Collation, error) {
func buildValueMatcher(input jsoniter.RawMessage, field *schema.QueryableField, factoryCollation *value.Collation) (ValueMatcher, *value.Collation, error) {
if len(input) == 0 {
return nil, nil, errors.InvalidArgument("empty object")
}
Expand All @@ -303,6 +303,8 @@ func buildValueMatcher(input jsoniter.RawMessage, field *schema.QueryableField)
return nil, nil, err
}
collation = value.NewCollationFrom(apiCollation)
} else {
collation = factoryCollation
}

var err error
Expand Down
Loading

0 comments on commit 7a925db

Please sign in to comment.