OLD | NEW |
---|---|
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 datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "sort" | 10 "sort" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 // EventuallyConsistent returns true iff this query will be eventually | 58 // EventuallyConsistent returns true iff this query will be eventually |
59 // consistent. This is true when the query is a non-ancestor query, or when it's | 59 // consistent. This is true when the query is a non-ancestor query, or when it's |
60 // an ancestory query with the 'EventualConsistency(true)' option set. | 60 // an ancestory query with the 'EventualConsistency(true)' option set. |
61 func (q *FinalizedQuery) EventuallyConsistent() bool { | 61 func (q *FinalizedQuery) EventuallyConsistent() bool { |
62 return q.eventuallyConsistent | 62 return q.eventuallyConsistent |
63 } | 63 } |
64 | 64 |
65 // Project is the list of fields that this query projects on, or empty if this | 65 // Project is the list of fields that this query projects on, or empty if this |
66 // is not a projection query. | 66 // is not a projection query. |
67 func (q *FinalizedQuery) Project() []string { | 67 func (q *FinalizedQuery) Project() []string { |
68 » if len(q.project) == 0 { | 68 » // For distinct queries with an inequality filter, one must first projec t the |
69 » // inequality field. | |
70 » size := len(q.project) | |
71 » ineqDistinctProject := "" | |
72 » if q.distinct && q.ineqFiltProp != "" { | |
73 » » ineqDistinctProject = q.ineqFiltProp | |
74 » » size++ | |
75 » } | |
76 | |
77 » if size == 0 { | |
69 return nil | 78 return nil |
70 } | 79 } |
71 » ret := make([]string, len(q.project)) | 80 » ret := make([]string, 0, size) |
72 » copy(ret, q.project) | 81 » if ineqDistinctProject != "" { |
82 » » ret = append(ret, ineqDistinctProject) | |
83 » } | |
84 » ret = append(ret, q.project...) | |
iannucci
2016/02/27 00:58:51
ditch this whole thing
| |
73 return ret | 85 return ret |
74 } | 86 } |
75 | 87 |
76 // Distinct returnst true iff this is a distinct projection query. It will never | 88 // Distinct returnst true iff this is a distinct projection query. It will never |
77 // be true for non-projection queries. | 89 // be true for non-projection queries. |
78 func (q *FinalizedQuery) Distinct() bool { | 90 func (q *FinalizedQuery) Distinct() bool { |
79 return q.distinct | 91 return q.distinct |
80 } | 92 } |
81 | 93 |
82 // KeysOnly returns true iff this query will only return keys (as opposed to a | 94 // KeysOnly returns true iff this query will only return keys (as opposed to a |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 if q.ineqFiltProp == "__key__" { | 342 if q.ineqFiltProp == "__key__" { |
331 if q.ineqFiltLowSet && !q.ineqFiltLow.Value().(*Key).Valid(false , aid, ns) { | 343 if q.ineqFiltLowSet && !q.ineqFiltLow.Value().(*Key).Valid(false , aid, ns) { |
332 return ErrInvalidKey | 344 return ErrInvalidKey |
333 } | 345 } |
334 if q.ineqFiltHighSet && !q.ineqFiltHigh.Value().(*Key).Valid(fal se, aid, ns) { | 346 if q.ineqFiltHighSet && !q.ineqFiltHigh.Value().(*Key).Valid(fal se, aid, ns) { |
335 return ErrInvalidKey | 347 return ErrInvalidKey |
336 } | 348 } |
337 } | 349 } |
338 return nil | 350 return nil |
339 } | 351 } |
OLD | NEW |