question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datastore query projection with datetime returns integer

See original GitHub issue

I have datetime type in my projection and it returns me integer value instead of timestamp value. If I remove the datetime type from projection, I get correct type back. Below is sample query -

    Query query = new Query(historical)
            {
                Filter = filter,
                Projection = { stocksymbol, date },
                DistinctOn = { stocksymbol },
                Order = {
                    { stocksymbol, PropertyOrder.Types.Direction.Descending },
                    { date, PropertyOrder.Types.Direction.Descending }
                        }
            };

            var queryResult = await dataStore.RunQueryAsync(query);

queryResult.Entities.Properties[date] return back Integer value.

I read about similar issue here (https://github.com/googleapis/google-cloud-node/issues/1319) and the workaround given is not working for me.

This is my modified code with the workaround but I still get incorrect date:

var result = new DateTime(Convert.ToInt64(x.Properties[date].IntegerValue.ToString(), 10) / 1000)

Any ideas what I am missing or how do i fix this issue?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17

github_iconTop GitHub Comments

1reaction
jskeetcommented, Jan 2, 2019

@Thaina: That would only work with an integer number of seconds or milliseconds (we go down to microseconds) - and isn’t available in the frameworks we target. (So it could be in client code, but not in our libraries.)

0reactions
jskeetcommented, Jan 2, 2019

@Thaina: But DateTimeOffset.FromUnixTimeSeconds doesn’t exist on every platform that we target, so we just can’t use it.

Likewise, TimeSpan.FromMilliseconds isn’t terribly useful when we have a value in microseconds and we don’t want to lose that precision.

I’m entirely comfortable with the implementation we’ve got, and it’s only an implementation detail anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Cloud Datastore date field getting converted ...
Date and time value, returned as part of a projection query, is being converted by the Datastore mode to microsecond integer values.
Read more >
Datastore Queries
The query can return entire entities, projected entities, or just entity keys. A typical query includes the following: An entity kind to which...
Read more >
Projection Queries - Google Cloud Datastore - huihoo
The query returns abridged results with only the specified properties ( name , email , and phone in the example) populated with values;...
Read more >
Queries — google-cloud 0.20.0 documentation - Read the Docs
Create / interact with Google Cloud Datastore queries. ... Limit the number of results returned. offset (integer) – (Optional) Offset used to begin...
Read more >
google.cloud.ndb.model — ndb documentation
"""Model classes for datastore objects and properties for models. ... Iterating over a Query object returns the entities matching the query one at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found