Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is datastore.createQuery.hasAncestor() just work alone without any other query command like order sort or select? #803

Closed
petersunquest opened this issue Aug 17, 2015 · 5 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue.

Comments

@petersunquest
Copy link

Hi,

I use the [email protected] & nodejs 0.12.7.
And use datastore.createQuery get some result.
Every looks great when I do a query with filter + sort + select + limit + order same time.
But I got Error 412 'Precondition Failed' when I add a hasAncestor() for any filter + sort + select + limit. Even I change order for each one when createQuery.
I used hasAncestor() whthout other filter or sort was work fine.
Is the hasAncestor() can only alone, can't use other command as sort or select or filter same time?
Or that is a bug?
I did:
var q = ds.createQuery('table')
.hasAncestor(ds.key({path:['fatherTable','fatherName']}))
.select('time')
.order('-time')
.limit(5)

@stephenplusplus
Copy link
Contributor

Thanks for reporting! I'm not sure in this case, but I bet @pcostell can help.

@stephenplusplus stephenplusplus added type: question Request for information or clarification. Not an issue. api: datastore Issues related to the Datastore API. labels Aug 17, 2015
@pcostell
Copy link
Contributor

In order to use hasAncestor with an order you'll need to build an index. If you try running that query while using the gcd.sh tool, it should recommend the proper index. You can learn more about the index config and gcd tool indexes and the gcd tool in general.

In this particular case, your datastore-indexes.xml file should look something like:

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
  <datastore-index kind="table" ancestor="true">
    <property name="time" direction="desc" />
  </datastore-index>
</datastore-indexes>

@petersunquest
Copy link
Author

Hi Pcostell,

Thank you so much for quickly reply.
I got it.
You are right, I did not ready the indexes.xml file.
The Datastore is so magical, different than SQL. I like that idea to storage data.
ALso thank you Stephenplusplus.
Peter

@petersunquest
Copy link
Author

HI,

I try add a indexes.xml for my project, Because I use the Goole App with Node.js, so It looks hard to add a indexes.xml file to application's dataset directory. Because if you use gcloud command to push to remote. I try add the Index.xml in my local node project's directory like /war/WEB-INF/appengine-generated/datastore-indexes.xml, then push to remote. Finally it looks not working.
So it looks just one way that is use the gcd tool.

  1. Download gcd-v1beta2-rev1-2.1.1.zip
  2. #unzip gcd-v1beta2-rev1-2.1.1.zip <------ use terminal command, if not you will get 'appengine-tools-api.jar not found' ERROR
  3. #gcd.sh create -d my-dataset my-project <---- use gcd command to create local dadastore
  4. Than you can check the directory my-project/WEB-INF/ have some file
  5. Add your index file to that WEB-INF/datastore-indexes.xml
  6. #gcd.sh updateindexes --auth_mode=oauth2 my-project <--- then push local datastore setup to remote project
  7. open Developers console web page. check the indexed at Storage->Cloud Datastore->Indexes. It show a index detail.
    Then all looks fine.
    My problem looks clear.

My question is why let us do so hard work for add a index. (SQL don't need do).
May be make a 'New index' on Developers console's Datastore.Indexes. You can edit or create a new index with webpage, because some case we don't use Python or Java.

I very love use Datastore and need clean up all my SQL idea. I hope it will easy to use and learn.

@pcostell
Copy link
Contributor

@petersunquest sorry it's not super easy right now. We are working to integrate gcd into the gcloud command line tool, which will make this much nicer. In the future we also plan to make index creation available via an API, so you should get the "New Index" option in the developer console.

Unlike SQL, Datastore requires that all queries scale with the size of the result set. Because of this, specific indexes are required to actually run a query. For example, if you were filtering for x = 2, but had no indexes and billions of entities, you would need to scan every single entity looking for entities that match that filter. With Datastore, we require an index on x so that all the results for your query x = 2 exist in a single range scan of the index. Note that if you were running SQL this is still a real concern (which is why you can build indexes), SQL is just willing to issue the expensive (time and cost) query to get your results.

sofisl pushed a commit that referenced this issue Nov 10, 2022
🤖 I have created a release *beep* *boop*
---


## [7.0.1](googleapis/nodejs-translate@v7.0.0...v7.0.1) (2022-08-10)


### Bug Fixes

* **deps:** do not depend on protobufjs ([#802](googleapis/nodejs-translate#802)) ([e8f13e4](googleapis/nodejs-translate@e8f13e4))
* **deps:** update dependency @google-cloud/automl to v3 ([#796](googleapis/nodejs-translate#796)) ([440b1cb](googleapis/nodejs-translate@440b1cb))
* **deps:** update dependency @google-cloud/text-to-speech to v4 ([#797](googleapis/nodejs-translate#797)) ([a210e6e](googleapis/nodejs-translate@a210e6e))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants