Skip to content

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

Description

@jiminikiz

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!

Activity

  1. stephenplusplus commented on Aug 18, 2015

    @stephenplusplus
    Contributor
  2. pcostell commented on Aug 18, 2015

    @pcostell
    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.

  3. jiminikiz commented on Aug 18, 2015

    @jiminikiz
    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.

  4. pcostell commented on Aug 18, 2015

    @pcostell
    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).

  5. jiminikiz commented on Aug 18, 2015

    @jiminikiz
    Author

    Okay, I get it, thank you.

  6. added a commit that references this issue on Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions