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

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

Issue 1550903002: impl/memory: Fix time serialization encoding. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Support PTBytes type, found the "ForIndex" method. Created 4 years, 11 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
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 "bytes" 8 "bytes"
9 "encoding/base64" 9 "encoding/base64"
10 "errors" 10 "errors"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 numComponents += v.Len() 100 numComponents += v.Len()
101 } 101 }
102 return numComponents 102 return numComponents
103 } 103 }
104 104
105 // GetBinaryBounds gets the binary encoding of the upper and lower bounds of 105 // GetBinaryBounds gets the binary encoding of the upper and lower bounds of
106 // the inequality filter on fq, if any is defined. If a bound does not exist, 106 // the inequality filter on fq, if any is defined. If a bound does not exist,
107 // it is nil. 107 // it is nil.
108 // 108 //
109 // NOTE: if fq specifies a descending sort order for the inequality, the bounds 109 // NOTE: if fq specifies a descending sort order for the inequality, the bounds
110 // will be inverted, incremented, and fliped. 110 // will be inverted, incremented, and flipped.
111 func GetBinaryBounds(fq *ds.FinalizedQuery) (lower, upper []byte) { 111 func GetBinaryBounds(fq *ds.FinalizedQuery) (lower, upper []byte) {
112 // Pick up the start/end range from the inequalities, if any. 112 // Pick up the start/end range from the inequalities, if any.
113 // 113 //
114 // start and end in the reducedQuery are normalized so that `start >= 114 // start and end in the reducedQuery are normalized so that `start >=
115 // X < end`. Because of that, we need to tweak the inequality filters 115 // X < end`. Because of that, we need to tweak the inequality filters
116 // contained in the query if they use the > or <= operators. 116 // contained in the query if they use the > or <= operators.
117 if ineqProp := fq.IneqFilterProp(); ineqProp != "" { 117 if ineqProp := fq.IneqFilterProp(); ineqProp != "" {
118 _, startOp, startV := fq.IneqFilterLow() 118 _, startOp, startV := fq.IneqFilterLow()
119 if startOp != "" { 119 if startOp != "" {
120 » » » lower = serialize.ToBytes(startV) 120 » » » lower = serialize.ToBytes(startV.ForIndex())
121 if startOp == ">" { 121 if startOp == ">" {
122 lower = increment(lower) 122 lower = increment(lower)
123 } 123 }
124 } 124 }
125 125
126 _, endOp, endV := fq.IneqFilterHigh() 126 _, endOp, endV := fq.IneqFilterHigh()
127 if endOp != "" { 127 if endOp != "" {
128 » » » upper = serialize.ToBytes(endV) 128 » » » upper = serialize.ToBytes(endV.ForIndex())
129 if endOp == "<=" { 129 if endOp == "<=" {
130 upper = increment(upper) 130 upper = increment(upper)
131 } 131 }
132 } 132 }
133 133
134 // The inequality is specified in natural (ascending) order in t he query's 134 // The inequality is specified in natural (ascending) order in t he query's
135 // Filter syntax, but the order information may indicate to use a descending 135 // Filter syntax, but the order information may indicate to use a descending
136 // index column for it. If that's the case, then we must invert, swap and 136 // index column for it. If that's the case, then we must invert, swap and
137 // increment the inequality endpoints. 137 // increment the inequality endpoints.
138 // 138 //
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ns: ns, 173 ns: ns,
174 kind: fq.Kind(), 174 kind: fq.Kind(),
175 suffixFormat: fq.Orders(), 175 suffixFormat: fq.Orders(),
176 } 176 }
177 177
178 eqFilts := fq.EqFilters() 178 eqFilts := fq.EqFilters()
179 ret.eqFilters = make(map[string]stringset.Set, len(eqFilts)) 179 ret.eqFilters = make(map[string]stringset.Set, len(eqFilts))
180 for prop, vals := range eqFilts { 180 for prop, vals := range eqFilts {
181 sVals := stringset.New(len(vals)) 181 sVals := stringset.New(len(vals))
182 for _, v := range vals { 182 for _, v := range vals {
183 » » » sVals.Add(string(serialize.ToBytes(v))) 183 » » » sVals.Add(string(serialize.ToBytes(v.ForIndex())))
184 } 184 }
185 ret.eqFilters[prop] = sVals 185 ret.eqFilters[prop] = sVals
186 } 186 }
187 187
188 startD, endD := GetBinaryBounds(fq) 188 startD, endD := GetBinaryBounds(fq)
189 189
190 // Now we check the start and end cursors. 190 // Now we check the start and end cursors.
191 // 191 //
192 // Cursors are composed of a list of IndexColumns at the beginning, foll owed 192 // Cursors are composed of a list of IndexColumns at the beginning, foll owed
193 // by the raw bytes to use for the suffix. The cursor is only valid if a ll of 193 // by the raw bytes to use for the suffix. The cursor is only valid if a ll of
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // and the new value has overflowed this representation. 270 // and the new value has overflowed this representation.
271 // 271 //
272 // Fortunately, the first byte of a serialized index column entr y is a 272 // Fortunately, the first byte of a serialized index column entr y is a
273 // PropertyType byte, and the only valid values that we'll be in crementing 273 // PropertyType byte, and the only valid values that we'll be in crementing
274 // are never equal to 0xFF, since they have the high bit set (so either they're 274 // are never equal to 0xFF, since they have the high bit set (so either they're
275 // 0x8*, or 0x7*, depending on if it's inverted). 275 // 0x8*, or 0x7*, depending on if it's inverted).
276 impossible(fmt.Errorf("incrementing %v would require more sigfig s", bstr)) 276 impossible(fmt.Errorf("incrementing %v would require more sigfig s", bstr))
277 } 277 }
278 return ret 278 return ret
279 } 279 }
OLDNEW
« no previous file with comments | « no previous file | impl/memory/datastore_query_execution_test.go » ('j') | service/datastore/serialize/serialize.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698