GET v2/entities filtering by dates - fiware-orion

I'm performing an GET /v2/entities query to an exisiting Orion Context Broker and I would like to filter the retrieved entities by TimeInstant attribute, which is in "date" format: 2019-11-14T06:00:23.00Z. I would like to get ONLY those entities which TimeInstant value is > 2019-11-14T06:10:23.00Z. I haven't found examples showing how to deal with attributes different from "int" values.

You have an example for instance in slide 65 of the Orion introductory presentation:
GET /v2/entities?q=TimeInstant>2019-11-14T06:10:23.00Z
Note that in order that query to work, TimeInstant attribute must be of DateTime type (or ISO8601 type, which is an alias). More information on DateTime type in the NGSv2 specification.

Related

Casting a Firebase timestamp to a Date/Time in BigQuery - referencing a computed field again in the same query?

I am not a coder, and very much flying blind, so please excuse the simplicity of this query.
I am streaming Firebase Firestore updates to a BigQuery table using the Firebase extension "Stream collection to BigQuery" which I am then linking as a DataSource in Google Data Studio. This is currently working as intended.
I have 2 questions:
Is there a more efficient way to convert a Firebase timestamp into a BigQuery Date/Time value? The Firebase Timestamp shows in JSON format in the BigQuery table as follows:
{"created_time":{"_seconds":1647554254,"_nanoseconds":234000000}}
My BigQuery SQL code to convert it (which works) is:
DATETIME(TIMESTAMP_SECONDS(CAST(JSON_VALUE(DATA,'$.created_time._seconds') AS int64)),"Africa/Johannesburg") AS createDate
Is there a more efficient way to do this, or is this reasonable?
How do I reference the createDate computed field (above) in another computed field ageDays within this same query? I haven't found it in Google or StackOverflow, either because of poor phrasing or its just too basic a query. I tried using a table alias referencing the createDate computed field (e.g. T.createDate) but no dice. My very ugly workaround was therefore just to reperform the createDate calculation in it's entirety (which feels wrong) in my new computed column ageDays as follows:
DATE_DIFF(current_date("Africa/Johannesburg"),DATETIME(TIMESTAMP_SECONDS(CAST(JSON_VALUE(DATA,'$.created_time._seconds') AS int64)),"Africa/Johannesburg"), DAY) AS ageDays
Would be sincerely grateful for any insights - many thanks.
For your requirement, JSON_EXTRACT can also be used instead of JSON_VALUE. You can use below query to get the expected output.
select
date(timestamp_seconds(cast(json_extract( data , '$.created_time._seconds') as int64))) AS Date_Created
from `project.dataset.timetable`
Output
Table alias cannot be used to reference a field in another column with a SELECT statement as it has limited visibility. Alias can be used with Order By, Group By or Having clauses in a SELECT statement. The best way to get the ageDays is by again computing the whole createDate field.

DynamoDB column with tilde and query using JPA

i have table column with tilde value like below
vendorAndDate - Column name
Chipotle~08-26-2020 - column value
I want to query for month "vendorAndPurchaseDate like '%~08%2020'" and for year ends with 2020 "vendorAndPurchaseDate like '%2020'". I am using Spring Data JPA to query the values. I have not worked on column with tilde values before. Please point me in a right direction or some examples
You cannot.
If vendorAndPurchaseDate is your partition key , you need to pass the whole value.
If vendorAndPurchaseDate is range key , you can only perform
= ,>,<>=,<=,between and begins_with operation along with a partition key
reference : https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html
DynamoDB does not support this type of wildcard query.
Let's consider a more DynamoDB way of handling this type of query. It sounds like you want to support 2 access patterns:
Get Item by month
Get Item by year
You don't describe your Primary Keys (Partition Key/Sort Key), so I'm going to make some assumptions to illustrate one way to address these access patterns.
Your attribute appears to be a composite key, consisting of <vendor>~<date>, where the date is expressed by MM-DD-YYYY. I would recommend storing your date fields in YYYY-MM-DD format, which would allow you to exploit the sort-ability of the date field. An example will make this much clearer. Imagine your table looked like this:
I'm calling your vendorAndDate attribute SK, since I'm using it as a Sort Key in this example. This table structure allows me to implement your two access patterns by executing the following queries (in pseudocode to remain language agnostic):
Access Pattern 1: Fetch all Chipotle records for August 2020
query from MyTable where PK = "Vendors" and SK between Chipotle~2020-08-00 and Chipotle~2020-08-31
Access Pattern 2: Fetch all Chipotle records for 2020
query from MyTable where PK = "Vendors" and SK between Chipotle~2020-01-01 and Chipotle~2020-12-31
Because dates stored in ISO8601 format (e.g. YYYY-MM-DD...) are lexicographically sortable, you can perform range queries in DynamoDB in this way.
Again, I've made some assumptions about your data and access patterns for the purpose of illustrating the technique of using lexicographically sortable timestamps to implement range queries.

How to remove data type from http get service

I have created http get service that is returning collection data as json. But I don't want to show column data type
This is my function code.
const result = doc.find({},{id:1,desc:1,label:1,LocationTree:1,path:1,coordinates:1,_id: 0}).toArray();
return result;
I contacted MongoDB support about this issue when I first started with Stitch. They indicated there is no way to suppress the type returned with numeric and datetime value types.
Your client application must handle the type when processing the JSON response. This is done with dot notation.
Assume your id field is of type Int32.
A typical API call might return an integer or string at result.id. The Stitch HTTP service, however, appends the type to the value, returning it at result.id.$numberInt.
As noted above, type data is included with numeric and datetime values. Booleans, Strings, Objects, and Arrays do not include type data. They can be accessed at result.someBoolean, result.someString, result.someObject, or result.someArray.
I haven't found a full list of types returned by the Stitch HTTP service. For some reason, they do NOT match the BSON Type aliases.

Postgresql jsonb vs datetime

I need to store two dates valid_from, and valid_to.
Is it better to use two datetime fields like valid_from:datetime and valid_to:datatime.
Would be it better to store data in jsonb field validity: {"from": "2001-01-01", "to": "2001-02-02"}
Much more reads than writes to database.
DB: PostgresSQL 9.4
You can use daterange type :
ie :
'[2001-01-01, 2001-02-02]'::daterange means from 2001-01-01 to 2001-02-02
bound inclusive
'(2001-01-01, 2001-02-05)'::daterange means from 2001-01-01
to 2001-02-05 bound exclusive
Also :
Special value like Infinite can be use
lower(anyrange) => lower bound of range
and many other things like overlap operator, see the docs ;-)
Range Type
Use two timestamp columns (there is no datetime type in Postgres).
They can efficiently be indexed and they protect you from invalid timestamp values - nothing prevents you from storing "2019-02-31 28:99:00" in a JSON value.
If you very often need to use those two values to check if another tiemstamp values lies in between, you could also consider a range type that stores both values in a single column.

Get Oracle Timestamp value via orm lite in java

I have the oracle database field value "11-JUL-16 02.51.45.000000000 AM" for field date_updated.
When I retrieve records via orm lite query and iterate over the result set .. I get the data in this format "2016-7-11.2.51. 45. 0" where the java pojo object mapping field is of type String.
Aim is to update these timestamps after processing them. I am not able to covert the date to update(parse error) or retrieve the date as is.
Searched allover but couldn't find an answer. I tried changing the pojo field type to Date/Timestamp(sql) but couldn't get it to work. Any Help would really appreciate ..