Skip to content

Commit 163beaf

Browse files
committed
[CLIENT-1351] Adds Expressions
1 parent 555e1b2 commit 163beaf

24 files changed

+6018
-131
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ os:
33
- linux
44
dist: xenial
55
go:
6-
- "1.12"
76
- "1.13"
87
- "1.14"
98
- "1.15"

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Change History
22

3+
## November 27 2020: v4.0.0
4+
5+
Major feature release. Deprecates `PredExp` filters and replaces them with the far more capable Expressions.
6+
7+
* **New Features**:
8+
9+
- [CLIENT-1361] Replace predicate filters with new Aerospike Expressions.
10+
11+
* **Fixes**
12+
13+
- Allows unmarshalling of bool fields to sub objects in reflection API. (Github #325)
14+
- Fixes an issue where BatchIndexGet commands were not retried in some circumstances.
15+
16+
* **Incompatible changes**:
17+
18+
- Changes the `BitResizeFlagsXXX` enum types to `BitResizeFlags` type. This should not affect any code if the enums were used.
19+
- Changes the `ListSortFlagsXXX` enum types to`ListSortFlags` are now typed. This should not affect any code if the enums were used.
20+
321
## November 9 2020: v3.1.1
422

523
Hotfix release. We recommend upgrading to this version, or cherry-picking the changeset to your vendored version if possible.

bit_resize_flags.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
package aerospike
1616

1717
// BitResizeFlags specifies the bitwise operation flags for resize.
18+
type BitResizeFlags int
1819

1920
const (
2021
// BitResizeFlagsDefault specifies the defalt flag.
21-
BitResizeFlagsDefault = 0
22+
BitResizeFlagsDefault BitResizeFlags = 0
2223

2324
// BitResizeFlagsFromFront Adds/removes bytes from the beginning instead of the end.
24-
BitResizeFlagsFromFront = 1
25+
BitResizeFlagsFromFront BitResizeFlags = 1
2526

2627
// BitResizeFlagsGrowOnly will only allow the byte[] size to increase.
27-
BitResizeFlagsGrowOnly = 2
28+
BitResizeFlagsGrowOnly BitResizeFlags = 2
2829

2930
// BitResizeFlagsShrinkOnly will only allow the byte[] size to decrease.
30-
BitResizeFlagsShrinkOnly = 4
31+
BitResizeFlagsShrinkOnly BitResizeFlags = 4
3132
)

cdt_bitwise.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const (
5858
// byteSize = 4
5959
// resizeFlags = 0
6060
// bin result = [0b00000001, 0b01000010, 0b00000000, 0b00000000]
61-
func BitResizeOp(policy *BitPolicy, binName string, byteSize int, resizeFlags int, ctx ...*CDTContext) *Operation {
61+
func BitResizeOp(policy *BitPolicy, binName string, byteSize int, resizeFlags BitResizeFlags, ctx ...*CDTContext) *Operation {
6262
return &Operation{
6363
opType: _BIT_MODIFY,
6464
ctx: ctx,

cdt_context.go

+49-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
*/
1717
package aerospike
1818

19+
const (
20+
ctxTypeListIndex = 0x10
21+
ctxTypeListRank = 0x11
22+
ctxTypeListValue = 0x13
23+
ctxTypeMapIndex = 0x20
24+
ctxTypeMapRank = 0x21
25+
ctxTypeMapKey = 0x22
26+
ctxTypeMapValue = 0x23
27+
)
28+
1929
// CDTContext defines Nested CDT context. Identifies the location of nested list/map to apply the operation.
2030
// for the current level.
2131
// An array of CTX identifies location of the list/map on multiple
@@ -25,6 +35,36 @@ type CDTContext struct {
2535
value Value
2636
}
2737

38+
func (ctx *CDTContext) pack(cmd BufferEx) (int, error) {
39+
size := 0
40+
sz, err := packAInt64(cmd, int64(ctx.id))
41+
size += sz
42+
if err != nil {
43+
return size, err
44+
}
45+
46+
sz, err = ctx.value.pack(cmd)
47+
size += sz
48+
49+
return size, err
50+
}
51+
52+
// cdtContextList is used in FilterExpression API
53+
type cdtContextList []*CDTContext
54+
55+
func (ctxl cdtContextList) pack(cmd BufferEx) (int, error) {
56+
size := 0
57+
for i := range ctxl {
58+
sz, err := ctxl[i].pack(cmd)
59+
size += sz
60+
if err != nil {
61+
return size, err
62+
}
63+
}
64+
65+
return size, nil
66+
}
67+
2868
// CtxListIndex defines Lookup list by index offset.
2969
// If the index is negative, the resolved index starts backwards from end of list.
3070
// If an index is out of bounds, a parameter error will be returned.
@@ -34,25 +74,25 @@ type CDTContext struct {
3474
// -1: Last item.
3575
// -3: Third to last item.
3676
func CtxListIndex(index int) *CDTContext {
37-
return &CDTContext{0x10, IntegerValue(index)}
77+
return &CDTContext{ctxTypeListIndex, IntegerValue(index)}
3878
}
3979

4080
// CtxListIndexCreate list with given type at index offset, given an order and pad.
4181
func CtxListIndexCreate(index int, order ListOrderType, pad bool) *CDTContext {
42-
return &CDTContext{0x10 | cdtListOrderFlag(order, pad), IntegerValue(index)}
82+
return &CDTContext{ctxTypeListIndex | cdtListOrderFlag(order, pad), IntegerValue(index)}
4383
}
4484

4585
// CtxListRank defines Lookup list by rank.
4686
// 0 = smallest value
4787
// N = Nth smallest value
4888
// -1 = largest value
4989
func CtxListRank(rank int) *CDTContext {
50-
return &CDTContext{0x11, IntegerValue(rank)}
90+
return &CDTContext{ctxTypeListRank, IntegerValue(rank)}
5191
}
5292

5393
// CtxListValue defines Lookup list by value.
5494
func CtxListValue(key Value) *CDTContext {
55-
return &CDTContext{0x13, key}
95+
return &CDTContext{ctxTypeListValue, key}
5696
}
5797

5898
// CtxMapIndex defines Lookup map by index offset.
@@ -64,28 +104,28 @@ func CtxListValue(key Value) *CDTContext {
64104
// -1: Last item.
65105
// -3: Third to last item.
66106
func CtxMapIndex(index int) *CDTContext {
67-
return &CDTContext{0x20, IntegerValue(index)}
107+
return &CDTContext{ctxTypeMapIndex, IntegerValue(index)}
68108
}
69109

70110
// CtxMapRank defines Lookup map by rank.
71111
// 0 = smallest value
72112
// N = Nth smallest value
73113
// -1 = largest value
74114
func CtxMapRank(rank int) *CDTContext {
75-
return &CDTContext{0x21, IntegerValue(rank)}
115+
return &CDTContext{ctxTypeMapRank, IntegerValue(rank)}
76116
}
77117

78118
// CtxMapKey defines Lookup map by key.
79119
func CtxMapKey(key Value) *CDTContext {
80-
return &CDTContext{0x22, key}
120+
return &CDTContext{ctxTypeMapKey, key}
81121
}
82122

83123
// Create map with given type at map key.
84124
func CtxMapKeyCreate(key Value, order mapOrderType) *CDTContext {
85-
return &CDTContext{0x22 | order.flag, key}
125+
return &CDTContext{ctxTypeMapKey | order.flag, key}
86126
}
87127

88128
// CtxMapValue defines Lookup map by value.
89129
func CtxMapValue(key Value) *CDTContext {
90-
return &CDTContext{0x23, key}
130+
return &CDTContext{ctxTypeMapValue, key}
91131
}

cdt_list.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ const (
158158
)
159159

160160
// ListSortFlags detemines sort flags for CDT lists
161-
// type ListSortFlags int
161+
type ListSortFlags int
162162

163163
const (
164164
// ListSortFlagsDefault is the default sort flag for CDT lists, and sort in Ascending order.
165-
ListSortFlagsDefault = 0
165+
ListSortFlagsDefault ListSortFlags = 0
166166
// ListSortFlagsDescending will sort the contents of the list in descending order.
167-
ListSortFlagsDescending = 1
167+
ListSortFlagsDescending ListSortFlags = 1
168168
// ListSortFlagsDropDuplicates will drop duplicate values in the results of the CDT list operation.
169-
ListSortFlagsDropDuplicates = 2
169+
ListSortFlagsDropDuplicates ListSortFlags = 2
170170
)
171171

172172
// ListWriteFlags detemines write flags for CDT lists
@@ -700,7 +700,7 @@ func ListGetRangeFromOp(binName string, index int, ctx ...*CDTContext) *Operatio
700700
// ListSortOp creates list sort operation.
701701
// Server sorts list according to sortFlags.
702702
// Server does not return a result by default.
703-
func ListSortOp(binName string, sortFlags int, ctx ...*CDTContext) *Operation {
703+
func ListSortOp(binName string, sortFlags ListSortFlags, ctx ...*CDTContext) *Operation {
704704
return &Operation{opType: _CDT_MODIFY, ctx: ctx, binName: binName, binValue: ListValue{_CDT_LIST_SORT, IntegerValue(sortFlags)}, encoder: listGenericOpEncoder}
705705
}
706706

0 commit comments

Comments
 (0)