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

Unified 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: Convert when building the query, not serializing in general. Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | impl/memory/datastore_query_execution_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore_query.go
diff --git a/impl/memory/datastore_query.go b/impl/memory/datastore_query.go
index 856f4c19bf0c110f29999217dfff28464245c12c..e56e485a0071bb301637b49032af09a59ca45a26 100644
--- a/impl/memory/datastore_query.go
+++ b/impl/memory/datastore_query.go
@@ -9,6 +9,7 @@ import (
"encoding/base64"
"errors"
"fmt"
+ "time"
ds "github.com/luci/gae/service/datastore"
"github.com/luci/gae/service/datastore/serialize"
@@ -102,12 +103,26 @@ func numComponents(fq *ds.FinalizedQuery) int {
return numComponents
}
+// convertQueryProperty converts a ds.Property into a suitable property for
+// query serialization.
+//
+// PTTime fields are serialized into indexes as PTInt, so we need to represent
+// them as PTInt in the serialized query.
iannucci 2015/12/29 19:53:46 could you add another case for all the various byt
dnj 2015/12/29 21:40:47 Sure. AFAICT this only additionally affected blobs
+func convertQueryProperty(p ds.Property) ds.Property {
+ switch p.Type() {
+ case ds.PTTime:
+ return ds.MkProperty(serialize.TimeToInt(p.Value().(time.Time)))
+ default:
+ return p
+ }
+}
+
// GetBinaryBounds gets the binary encoding of the upper and lower bounds of
iannucci 2015/12/29 19:53:46 this bug probably also affects equality comparison
dnj 2015/12/29 21:40:47 yarp, nice catch. Added test case and fix.
// the inequality filter on fq, if any is defined. If a bound does not exist,
// it is nil.
//
// NOTE: if fq specifies a descending sort order for the inequality, the bounds
-// will be inverted, incremented, and fliped.
+// will be inverted, incremented, and flipped.
func GetBinaryBounds(fq *ds.FinalizedQuery) (lower, upper []byte) {
// Pick up the start/end range from the inequalities, if any.
//
@@ -117,7 +132,7 @@ func GetBinaryBounds(fq *ds.FinalizedQuery) (lower, upper []byte) {
if ineqProp := fq.IneqFilterProp(); ineqProp != "" {
_, startOp, startV := fq.IneqFilterLow()
if startOp != "" {
- lower = serialize.ToBytes(startV)
+ lower = serialize.ToBytes(convertQueryProperty(startV))
if startOp == ">" {
lower = increment(lower)
}
@@ -125,7 +140,7 @@ func GetBinaryBounds(fq *ds.FinalizedQuery) (lower, upper []byte) {
_, endOp, endV := fq.IneqFilterHigh()
if endOp != "" {
- upper = serialize.ToBytes(endV)
+ upper = serialize.ToBytes(convertQueryProperty(endV))
if endOp == "<=" {
upper = increment(upper)
}
« no previous file with comments | « no previous file | impl/memory/datastore_query_execution_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698