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

Datastore.select - does it work with column names that have solely integers? #810

Closed
jiminikiz opened this issue Aug 18, 2015 · 5 comments
Closed
Assignees

Comments

@jiminikiz
Copy link

Hey dev team, we have a Datastore table like this:
analytics

As you can see, the column names are integers, i.e. IDs mapping to individual rows within another namespace > path.

Using the code found in this issue, I am able to select a column with a name like date, but not a column with a name like 4820477751066624.

transaction.select(['date']); // this works :)
transaction.select(['date','4820477751066624']); // this does not work :( 

Is it generally assumed that column names are strings with at least one letter as the starting character? Or can there be solely integer column names?

Here is my Datastore response:

{ 
    error: {
        code: 412,
        message: 'no matching index found.' 
    }
}

I have double-triple checked to make sure I run the query using an integer that is definitely a column name for the table pictured above.

Thanks in advance for your help!

@stephenplusplus
Copy link
Contributor

// @pcostell

@pcostell
Copy link
Contributor

Projection queries in Datastore are a little different compared to a traditional SQL projection. In particular, the projection only works if it is being run on an index (in fact, this is why we offer projection queries, so that the query only needs to perform an index scan and not the accompanied entity lookup).

In the case of transaction.select(['date','4820477751066624']);, you would need to have an index on (Date, 4820477751066624) to perform the query. However, given the automatic indexes transaction.select(['4820477751066624']); should work.

@jiminikiz
Copy link
Author

Taking your advice and using GCloud v.0.18, here is the query:

Datastore.query({
    namespace: 'accounts',
    path: [ pathmap[ req.query.metric ] ],
    select: [n],
    filter: {
        "date >=": req.query.ds || m.startOf('month').unix(),
        "date <=": req.query.de || m.endOf('month').unix()
    }
}, function (error, stats) { 
    console.dir(error);
});

Here is the transaction object before it is sent to the Datastore servers:

{ 
    namespace: 'accounts',
    kinds: [ 'analytics' ],
    filters: 
    [ { name: 'date', op: '>=', val: 1438408800 }, { name: 'date', op: '<=', val: 1441087199 } ] ]
    orders: [],
    groupByVal: [],
    selectVal: [ '5666823336886272' ],
    autoPaginateVal: true,
    startVal: null,
    endVal: null,
    limitVal: -1,
    offsetVal: -1,
    ... [fns]
}

And here is the response:

{ 
    error: {
        code: 412,
        message: 'Precondition Failed' 
    }
}

Using the same code I can make a query and select the date column and it works. And yes I have noticed that everything is auto-indexed, so that is why I was hoping we could query by account number.

@pcostell
Copy link
Contributor

You can query by date in this case because it is already part of the index you are using (due to the inequality).

In order to answer this query, you would need an index on (date, 5666823336886272).

@jiminikiz
Copy link
Author

Okay, I get it, thank you.

sofisl pushed a commit that referenced this issue Nov 10, 2022
Source-Link: googleapis/synthtool@d229a12
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:74ab2b3c71ef27e6d8b69b1d0a0c9d31447777b79ac3cd4be82c265b45f37e5e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants