Skip to content

Commit 9afbef3

Browse files
authored
Revert "Filter equality matchers on the dynamo side (#400)"
This reverts commit f486481.
1 parent f486481 commit 9afbef3

File tree

4 files changed

+2
-191
lines changed

4 files changed

+2
-191
lines changed

chunk/aws_storage_client.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,6 @@ func (a awsStorageClient) QueryPages(ctx context.Context, entry IndexEntry, call
240240
}
241241
}
242242

243-
// Filters
244-
if entry.ValueEqual != nil {
245-
input.KeyConditions[valueKey] = &dynamodb.Condition{
246-
AttributeValueList: []*dynamodb.AttributeValue{
247-
{B: entry.ValueEqual},
248-
},
249-
ComparisonOperator: aws.String(dynamodb.ComparisonOperatorEq),
250-
}
251-
}
252-
253243
request := a.queryRequestFn(input)
254244
backoff := minBackoff
255245
for page := request; page != nil; page = page.NextPage() {

chunk/aws_storage_client_test.go

Lines changed: 2 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -101,43 +101,11 @@ func (m *mockDynamoDBClient) queryRequest(input *dynamodb.QueryInput) dynamoDBRe
101101
Items: []map[string]*dynamodb.AttributeValue{},
102102
}
103103

104-
// Required filters
105104
hashValue := *input.KeyConditions[hashKey].AttributeValueList[0].S
106-
107-
// Optional filters
108-
var (
109-
rangeValueFilter []byte
110-
rangeValueFilterType string
111-
valueFilter []byte
112-
valueFilterType *string
113-
)
114-
if c, ok := input.KeyConditions[rangeKey]; ok {
115-
rangeValueFilter = c.AttributeValueList[0].B
116-
rangeValueFilterType = *c.ComparisonOperator
117-
}
118-
if c, ok := input.KeyConditions[valueKey]; ok {
119-
valueFilter = c.AttributeValueList[0].B
120-
valueFilterType = c.ComparisonOperator
121-
}
122-
123-
// Filter by HashValue, RangeValue and Value if it exists
124105
items := m.tables[*input.TableName].items[hashValue]
125-
for _, item := range items {
126-
rangeValue := item[rangeKey].B
127-
if rangeValueFilterType == dynamodb.ComparisonOperatorGe && bytes.Compare(rangeValue, rangeValueFilter) < 0 {
128-
continue
129-
}
130-
if rangeValueFilterType == dynamodb.ComparisonOperatorBeginsWith && !bytes.HasPrefix(rangeValue, rangeValueFilter) {
131-
continue
132-
}
133-
134-
if item[valueKey] != nil {
135-
value := item[valueKey].B
136-
if valueFilter != nil && *valueFilterType == dynamodb.ComparisonOperatorEq && !bytes.Equal(value, valueFilter) {
137-
continue
138-
}
139-
}
140106

107+
// TODO we should also filter by range value
108+
for _, item := range items {
141109
result.Items = append(result.Items, item)
142110
}
143111

@@ -202,136 +170,6 @@ func TestDynamoDBClient(t *testing.T) {
202170
}
203171
}
204172

205-
func TestDynamoDBClientQueryPages(t *testing.T) {
206-
dynamoDB := newMockDynamoDB(0, 0)
207-
client := awsStorageClient{
208-
DynamoDB: dynamoDB,
209-
queryRequestFn: dynamoDB.queryRequest,
210-
}
211-
212-
entries := []IndexEntry{
213-
{
214-
TableName: "table",
215-
HashValue: "foo",
216-
RangeValue: []byte("bar:1"),
217-
Value: []byte("10"),
218-
},
219-
{
220-
TableName: "table",
221-
HashValue: "foo",
222-
RangeValue: []byte("bar:2"),
223-
Value: []byte("20"),
224-
},
225-
{
226-
TableName: "table",
227-
HashValue: "foo",
228-
RangeValue: []byte("bar:3"),
229-
Value: []byte("30"),
230-
},
231-
{
232-
TableName: "table",
233-
HashValue: "foo",
234-
RangeValue: []byte("baz:1"),
235-
Value: []byte("10"),
236-
},
237-
{
238-
TableName: "table",
239-
HashValue: "foo",
240-
RangeValue: []byte("baz:2"),
241-
Value: []byte("20"),
242-
},
243-
{
244-
TableName: "table",
245-
HashValue: "flip",
246-
RangeValue: []byte("bar:1"),
247-
Value: []byte("abc"),
248-
},
249-
{
250-
TableName: "table",
251-
HashValue: "flip",
252-
RangeValue: []byte("bar:2"),
253-
Value: []byte("abc"),
254-
},
255-
{
256-
TableName: "table",
257-
HashValue: "flip",
258-
RangeValue: []byte("bar:3"),
259-
Value: []byte("abc"),
260-
},
261-
}
262-
263-
tests := []struct {
264-
name string
265-
entry IndexEntry
266-
want []IndexEntry
267-
}{
268-
{
269-
"check HashValue only",
270-
IndexEntry{
271-
TableName: "table",
272-
HashValue: "flip",
273-
},
274-
[]IndexEntry{entries[5], entries[6], entries[7]},
275-
},
276-
{
277-
"check RangeValueStart",
278-
IndexEntry{
279-
TableName: "table",
280-
HashValue: "foo",
281-
RangeValueStart: []byte("bar:2"),
282-
},
283-
[]IndexEntry{entries[1], entries[2], entries[3], entries[4]},
284-
},
285-
{
286-
"check RangeValuePrefix",
287-
IndexEntry{
288-
TableName: "table",
289-
HashValue: "foo",
290-
RangeValuePrefix: []byte("baz:"),
291-
},
292-
[]IndexEntry{entries[3], entries[4]},
293-
},
294-
{
295-
"check ValueEqual",
296-
IndexEntry{
297-
TableName: "table",
298-
HashValue: "foo",
299-
RangeValuePrefix: []byte("bar"),
300-
ValueEqual: []byte("20"),
301-
},
302-
[]IndexEntry{entries[1]},
303-
},
304-
}
305-
306-
batch := client.NewWriteBatch()
307-
for _, entry := range entries {
308-
batch.Add(entry.TableName, entry.HashValue, entry.RangeValue, entry.Value)
309-
}
310-
dynamoDB.createTable("table")
311-
312-
err := client.BatchWrite(context.Background(), batch)
313-
require.NoError(t, err)
314-
315-
for _, tt := range tests {
316-
t.Run(tt.name, func(t *testing.T) {
317-
var have []IndexEntry
318-
err := client.QueryPages(context.Background(), tt.entry, func(read ReadBatch, lastPage bool) bool {
319-
for i := 0; i < read.Len(); i++ {
320-
have = append(have, IndexEntry{
321-
TableName: tt.entry.TableName,
322-
HashValue: tt.entry.HashValue,
323-
RangeValue: read.RangeValue(i),
324-
Value: read.Value(i),
325-
})
326-
}
327-
return !lastPage
328-
})
329-
require.NoError(t, err)
330-
require.Equal(t, tt.want, have)
331-
})
332-
}
333-
}
334-
335173
func TestAWSConfigFromURL(t *testing.T) {
336174
for _, tc := range []struct {
337175
url string

chunk/inmemory_storage_client.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,6 @@ func (m *MockStorage) QueryPages(_ context.Context, entry IndexEntry, callback f
193193
log.Debugf("Lookup %s/* (%d)", entry.HashValue, len(items))
194194
}
195195

196-
// Filters
197-
if entry.ValueEqual != nil {
198-
log.Debugf("Filter Value EQ = %s", entry.ValueEqual)
199-
200-
filtered := make([]mockItem, 0)
201-
for _, v := range items {
202-
if bytes.Equal(v.value, entry.ValueEqual) {
203-
filtered = append(filtered, v)
204-
}
205-
}
206-
items = filtered
207-
}
208-
209196
result := mockReadBatch{}
210197
for _, item := range items {
211198
result = append(result, item)

chunk/schema.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ type IndexEntry struct {
5252
// - If neither is set, must read all keys for that row.
5353
RangeValuePrefix []byte
5454
RangeValueStart []byte
55-
56-
// Filters for querying
57-
ValueEqual []byte
5855
}
5956

6057
// v1Schema was:
@@ -413,7 +410,6 @@ func (v6Entries) GetReadMetricLabelValueEntries(from, _ uint32, tableName, hashK
413410
TableName: tableName,
414411
HashValue: hashKey + ":" + string(labelName),
415412
RangeValueStart: buildRangeKey(encodedFromBytes),
416-
ValueEqual: []byte(labelValue),
417413
},
418414
}, nil
419415
}

0 commit comments

Comments
 (0)