Skip to content

Commit

Permalink
Add support for inline scalar arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Jan 19, 2022
1 parent 7fd117d commit 7f8abd4
Show file tree
Hide file tree
Showing 11 changed files with 1,176 additions and 6 deletions.
4 changes: 4 additions & 0 deletions db/base/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ const (
FieldKind_None FieldKind = iota
FieldKind_DocKey
FieldKind_BOOL
FieldKind_BOOL_ARRAY
FieldKind_INT
FieldKind_INT_ARRAY
FieldKind_FLOAT
FieldKind_FLOAT_ARRAY
FieldKind_DECIMNAL
FieldKind_DATE
FieldKind_TIMESTAMP
FieldKind_STRING
FieldKind_STRING_ARRAY
FieldKind_BYTES
FieldKind_OBJECT // Embedded object within the type
FieldKind_OBJECT_ARRAY // Array of embedded objects
Expand Down
70 changes: 70 additions & 0 deletions db/collection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,63 @@ func validateFieldSchema(val interface{}, field base.FieldDescription) (interfac
switch field.Kind {
case base.FieldKind_DocKey, base.FieldKind_STRING:
cval, ok = val.(string)
case base.FieldKind_STRING_ARRAY:
if val == nil {
ok = true
cval = nil
break
}
untypedCollection := val.([]interface{})
stringArray := make([]string, len(untypedCollection))
for i, value := range untypedCollection {
if value == nil {
stringArray[i] = ""
continue
}
stringArray[i], ok = value.(string)
if !ok {
return nil, fmt.Errorf("Failed to cast value: %v of type: %T to string", value, value)
}
}
ok = true
cval = stringArray
case base.FieldKind_BOOL:
cval, ok = val.(bool)
case base.FieldKind_BOOL_ARRAY:
if val == nil {
ok = true
cval = nil
break
}
untypedCollection := val.([]interface{})
boolArray := make([]bool, len(untypedCollection))
for i, value := range untypedCollection {
boolArray[i], ok = value.(bool)
if !ok {
return nil, fmt.Errorf("Failed to cast value: %v of type: %T to bool", value, value)
}
}
ok = true
cval = boolArray
case base.FieldKind_FLOAT, base.FieldKind_DECIMNAL:
cval, ok = val.(float64)
case base.FieldKind_FLOAT_ARRAY:
if val == nil {
ok = true
cval = nil
break
}
untypedCollection := val.([]interface{})
floatArray := make([]float64, len(untypedCollection))
for i, value := range untypedCollection {
floatArray[i], ok = value.(float64)
if !ok {
return nil, fmt.Errorf("Failed to cast value: %v of type: %T to float64", value, value)
}
}
ok = true
cval = floatArray

case base.FieldKind_DATE:
var sval string
sval, ok = val.(string)
Expand All @@ -451,6 +504,23 @@ func validateFieldSchema(val interface{}, field base.FieldDescription) (interfac
return nil, ErrInvalidMergeValueType
}
cval = int64(fval)
case base.FieldKind_INT_ARRAY:
if val == nil {
ok = true
cval = nil
break
}
untypedCollection := val.([]interface{})
intArray := make([]int64, len(untypedCollection))
for i, value := range untypedCollection {
valueAsFloat, castOk := value.(float64)
if !castOk {
return nil, fmt.Errorf("Failed to cast value: %v of type: %T to float64", value, value)
}
intArray[i] = int64(valueAsFloat)
}
ok = true
cval = intArray
case base.FieldKind_OBJECT, base.FieldKind_OBJECT_ARRAY,
base.FieldKind_FOREIGN_OBJECT, base.FieldKind_FOREIGN_OBJECT_ARRAY:
err = errors.New("Merge doesn't support sub types yet")
Expand Down
3 changes: 2 additions & 1 deletion db/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ func (df *DocumentFetcher) processKV(kv *core.KeyValue) error {
// secondary index is provided, we need to extract the indexed/implicit fields
// from the KV pair.
df.doc.Properties[fieldDesc] = &document.EncProperty{
Raw: kv.Value,
Desc: fieldDesc,
Raw: kv.Value,
}
// @todo: Extract Index implicit/stored keys
return nil
Expand Down
Loading

0 comments on commit 7f8abd4

Please sign in to comment.