Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(959)

Side by Side Diff: impl/memory/datastore_query_execution_test.go

Issue 1336443003: Implement projection queries correctly. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | impl/memory/datastore_query_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "testing" 9 "testing"
10 "time"
10 11
11 ds "github.com/luci/gae/service/datastore" 12 ds "github.com/luci/gae/service/datastore"
12 "github.com/luci/gae/service/info" 13 "github.com/luci/gae/service/info"
13 . "github.com/luci/luci-go/common/testing/assertions" 14 . "github.com/luci/luci-go/common/testing/assertions"
14 . "github.com/smartystreets/goconvey/convey" 15 . "github.com/smartystreets/goconvey/convey"
15 "golang.org/x/net/context" 16 "golang.org/x/net/context"
16 ) 17 )
17 18
18 type qExpect struct { 19 type qExpect struct {
19 q ds.Query 20 q ds.Query
(...skipping 18 matching lines...) Expand all
38 test []qExStage 39 test []qExStage
39 } 40 }
40 41
41 var stage1Data = []ds.PropertyMap{ 42 var stage1Data = []ds.PropertyMap{
42 pmap("$key", key("Kind", 1), NEXT, 43 pmap("$key", key("Kind", 1), NEXT,
43 "Val", 1, 2, 3, NEXT, 44 "Val", 1, 2, 3, NEXT,
44 "Extra", "hello", 45 "Extra", "hello",
45 ), 46 ),
46 pmap("$key", key("Kind", 2), NEXT, 47 pmap("$key", key("Kind", 2), NEXT,
47 "Val", 6, 8, 7, NEXT, 48 "Val", 6, 8, 7, NEXT,
49 "When", 27, NEXT,
48 "Extra", "zebra", 50 "Extra", "zebra",
49 ), 51 ),
50 pmap("$key", key("Kind", 3), NEXT, 52 pmap("$key", key("Kind", 3), NEXT,
51 "Val", 1, 2, 2, 100, NEXT, 53 "Val", 1, 2, 2, 100, NEXT,
54 "When", 996688461000000, NEXT,
52 "Extra", "waffle", 55 "Extra", "waffle",
53 ), 56 ),
54 pmap("$key", key("Kind", 6), NEXT, 57 pmap("$key", key("Kind", 6), NEXT,
55 "Val", 5, NEXT, 58 "Val", 5, NEXT,
59 "When", time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC), NEXT,
56 "Extra", "waffle", 60 "Extra", "waffle",
57 ), 61 ),
58 pmap("$key", key("Child", "seven", key("Kind", 3)), NEXT, 62 pmap("$key", key("Child", "seven", key("Kind", 3)), NEXT,
59 "Interesting", 28, NEXT, 63 "Interesting", 28, NEXT,
60 "Extra", "hello", 64 "Extra", "hello",
61 ), 65 ),
62 pmap("$key", key("Unique", 1), NEXT, 66 pmap("$key", key("Unique", 1), NEXT,
63 "Derp", 39, 67 "Derp", 39,
64 ), 68 ),
65 } 69 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 get: []ds.PropertyMap{ 221 get: []ds.PropertyMap{
218 pmap("$key", key("Kind", 3), NEX T, 222 pmap("$key", key("Kind", 3), NEX T,
219 "Val", 100), 223 "Val", 100),
220 pmap("$key", key("Kind", 1, key( "Kind", 3)), NEXT, 224 pmap("$key", key("Kind", 1, key( "Kind", 3)), NEXT,
221 "Val", 28), 225 "Val", 28),
222 pmap("$key", key("Kind", 1, key( "Kind", 3)), NEXT, 226 pmap("$key", key("Kind", 1, key( "Kind", 3)), NEXT,
223 "Val", 4), 227 "Val", 4),
224 pmap("$key", key("Kind", 2, key( "Kind", 3)), NEXT, 228 pmap("$key", key("Kind", 2, key( "Kind", 3)), NEXT,
225 "Val", 3), 229 "Val", 3),
226 }}, 230 }},
231
232 // Projecting a complex type (time), gets the in dex type (int64)
233 // instead. Additionally, mixed-types within the same index type are
234 // smooshed together in the result.
235 {q: nq("Kind").Project("When"), get: []ds.Proper tyMap{
236 pmap("$key", key("Kind", 2), NEXT,
237 "When", 27),
238 pmap("$key", key("Kind", 6), NEXT,
239 "When", 946688461000000),
240 pmap("$key", key("Kind", 3), NEXT,
241 "When", 996688461000000),
242 }},
243
244 // Original (complex) types are retained when ge tting the full value.
245 {q: nq("Kind").Order("When"), get: []ds.Property Map{
246 stage1Data[1],
247 stage1Data[3],
248 stage1Data[2],
249 }},
227 }, 250 },
228 251
229 extraFns: []func(context.Context){ 252 extraFns: []func(context.Context){
230 func(c context.Context) { 253 func(c context.Context) {
231 data := ds.Get(c) 254 data := ds.Get(c)
232 curs := ds.Cursor(nil) 255 curs := ds.Cursor(nil)
233 256
234 q := nq("").Filter("__key__ >", key("Kin d", 2)) 257 q := nq("").Filter("__key__ >", key("Kin d", 2))
235 258
236 err := data.Run(q, func(pm ds.PropertyMa p, gc ds.CursorCB) bool { 259 err := data.Run(q, func(pm ds.PropertyMa p, gc ds.CursorCB) bool {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 Convey(fmt.Sprintf("extr aFn %d", j), func() { 373 Convey(fmt.Sprintf("extr aFn %d", j), func() {
351 fn(c) 374 fn(c)
352 }) 375 })
353 } 376 }
354 }) 377 })
355 } 378 }
356 }) 379 })
357 } 380 }
358 }) 381 })
359 } 382 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | impl/memory/datastore_query_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698