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

Unified Diff: service/datastore/query.go

Issue 1309803004: Add transaction buffer filter. (Closed) Base URL: https://github.com/luci/gae.git@add_query_support
Patch Set: Fix builtin+ancestor+multi-eq+multiIterator bug, add more txnBuf test 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 side-by-side diff with in-line comments
Download patch
« service/datastore/key.go ('K') | « service/datastore/key.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/query.go
diff --git a/service/datastore/query.go b/service/datastore/query.go
index 74ed2f0ec293a21df613bd7a672091dd7a8f4977..7416c3b30212a7a4db4f299ea58bb89ac33a8920 100644
--- a/service/datastore/query.go
+++ b/service/datastore/query.go
@@ -470,14 +470,25 @@ func (q *Query) Finalize() (*FinalizedQuery, error) {
return q.finalized, q.err
}
+ ancSlice, hasAncestor := q.eqFilts["__ancestor__"]
+ ancestor := (*Key)(nil)
+ if hasAncestor {
Vadim Sh. 2015/09/28 18:52:56 nit: ancestor := (*Key)(nil) if slice, ok := q.eqF
iannucci 2015/09/29 03:21:37 Nope, you're right. nil ancestor means no ancestor
+ ancestor = ancSlice[0].Value().(*Key)
+ }
+
err := func() error {
+
if q.kind == "" { // kindless query checks
if q.ineqFiltProp != "" && q.ineqFiltProp != "__key__" {
return fmt.Errorf(
"kindless queries can only filter on __key__, got %q", q.ineqFiltProp)
}
- if len(q.eqFilts) > 0 {
- return fmt.Errorf("kindless queries not have any equality filters")
+ allowedEqs := 0
+ if hasAncestor {
+ allowedEqs = 1
+ }
+ if len(q.eqFilts) > allowedEqs {
+ return fmt.Errorf("kindless queries may not have any equality filters")
}
for _, o := range q.order {
if o.Property != "__key__" || o.Descending {
@@ -503,6 +514,28 @@ func (q *Query) Finalize() (*FinalizedQuery, error) {
return ErrNullQuery
}
}
+ if q.ineqFiltProp == "__key__" {
+ if q.ineqFiltLowSet {
+ if q.ineqFiltLow.Type() != PTKey {
+ return fmt.Errorf(
+ "inequality filters on __key__ must use *ds.Key values")
+ }
+ if hasAncestor && !q.ineqFiltLow.Value().(*Key).HasAncestor(ancestor) {
+ return fmt.Errorf(
+ "inequality filters on __key__ must be descendants of the __ancestor__")
+ }
+ }
+ if q.ineqFiltHighSet {
+ if q.ineqFiltHigh.Type() != PTKey {
+ return fmt.Errorf(
+ "inequality filters on __key__ must use *ds.Key values")
+ }
+ if hasAncestor && !q.ineqFiltHigh.Value().(*Key).HasAncestor(ancestor) {
+ return fmt.Errorf(
+ "inequality filters on __key__ must be descendants of the __ancestor__")
+ }
+ }
+ }
}
err := error(nil)
@@ -527,7 +560,7 @@ func (q *Query) Finalize() (*FinalizedQuery, error) {
kind: q.kind,
keysOnly: q.keysOnly,
- eventuallyConsistent: q.eventualConsistency || q.eqFilts["__ancestor__"] == nil,
+ eventuallyConsistent: q.eventualConsistency || !hasAncestor,
limit: q.limit,
offset: q.offset,
start: q.start,
« service/datastore/key.go ('K') | « service/datastore/key.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698