Gremlin Syntax to Query Cosmos Db Based on date - database

Could you please guide me on how to write a gremlin query that will return only projects that have started past a specific date?
My first query returns all project vertices within program05:
g.V('program05').has('partitionkey', 'program05').out('hasprojects')
I would like to filter it down to return only projects that have started after '20/19/2018 4:37:12 PM' , a program vertex has a propertt of startDate
I have tried :
g.V('program05').has('partitionkey', 'program05').out('hasprojects').has('startDate').has('startDate',gt, '20/19/2018 4:37:12 PM')
but i get an Error: Unable to resolve symbol 'lt' in the current context. I have tried other opions too with no luck

The predicate logic (javadoc) for strings seems to work based on ASCII values of the string, so your current storage of the date in text format will not work month over month.
I would suggest storing that as epoch seconds and then using the following query to get that data you want.
Assuming you meant the date 2/19/2018 4:37:12 PM
g.V()
.has('partitionkey','program05')
.out('hasprojects')
.has('startDate',P.gt(1519058232))

Related

Can time series settings in Google Data Studio change depending on date format?

I have a table with column "date" in YYYY-MM-DD format HH:MM:SS:MMM (2015-01-27 11:22:03:742). I'm trying to make a time series with the dimension of month/year grouping, to display the total number of records by period.
Settings:
period dimension: date (type: date and time)
period: date (type: year and month)
metric: record count
My time graph doesn't display anything. Can someone help me identify what's going on?
formatDate is the column created with the expression:
PARSE_DATETIME("%Y-%m-%d %H:%M:%S",REGEXP_EXTRACT( create_date,"(.*):[0-9]*"))
Using the date in its standard format, as mentioned at the beginning of the question, the same happens.
When entering dates (original and formatted), both appear with null values.
The milliseconds have to be separated by a . not a :. An option is to import your date a as string/text and add a calculated field, which parse the string in Data Studio:
PARSE_DATETIME("%Y-%m-%d %H:%M:%S",REGEXP_EXTRACT( data_field,"(.*):[0-9]*"))
If the dates are several years in the past, please adjust the Default date range in your graph:
I leave the solution to my problem to the community.
The problem is in the date format. Failed to get Google Data Studio to receive a date with milliseconds. By removing the milliseconds it was possible to work with the dates normally, managing to apply the available functions.
Note: It may be a knowledge limitation, but none of the date formatting functions work if the datetime field contains milliseconds (FORMAT_DATETIME, PARSE_DATETIME,...)

Find Azure Search date without time part

I can't find a way of getting a date from Azure Search using only the date.
The dates in the index are like: "2019-10-15T18:00:00Z","2019-10-22T18:00:00Z","2019-10-29T18:00:00Z"
If I try StartDate/any(s: s eq 2019-10-15T18:00:00Z) I get results
But with StartDate/any(s: s eq 2019-10-15) nothing comes up
I have tried usin the date OData function like so: StartDate/any(s: date(s) eq 2019-10-15) but I get an error 'Function 'date' is not supported'.
Is there any way to get dates without using the time part?
The use of date literals in filters in Azure Search will no longer be supported starting in api-version 2019-05-06-Preview. This was an "accidental feature" that we never intended to support. The reason you don't get any results is because the implicit conversion from Edm.Date to Edm.DateTimeOffset assumes a time of midnight UTC, whereas the dates in your index are 6 PM UTC.
We recommend explicitly providing the time and offset (or Z for UTC) in filters to avoid this problem.
If you want Azure Search to natively support fields and filters of type Edm.Date, please vote for this User Voice suggestion.
Date and time values represented in the OData V4 format: yyyy-MM-ddTHH:mm:ss.fffZ or yyyy-MM-ddTHH:mm:ss.fff[+|-]HH:mm. Precision of DateTimeOffset fields is limited to milliseconds. If you upload DateTimeOffset values with sub-millisecond precision, the value returned will be rounded up to milliseconds.
When you upload DateTimeOffset values with time zone information to your index, Azure Search normalizes these values to UTC.
Refer to supported data types in Azure search.

How to create new date field using CASE in Google Data Studio

I'm creating a dashboard of marketing leads from a Data Source that has two columns of dates in it. One of the columns is historic dates that were imported. One of the columns is all new leads, with accurate dates.
I'm trying to create a new field in Data Studio for use as the Date Range Dimensions. Essentially, if historic date is null, then use new date. If it isn't null, use the historic date.
This is my current code:
CASE
WHEN Historic Date IS NULL THEN Created Date
ELSE Created Date
END
There are no errors thrown when creating the field, but when I set it as the Date Range Dimension, I get this error:
This data source was improperly configured.
Invalid argument type.
Seems that Case function has as output a string which cannot be recognized or configured as a date in google Studio. It can be a bug from Data Studio, but the fact is that I have the same problem and I solve it converting the output of case into a date format.
I have no much time to explain/expose it better, therefore I will put the function that worked for me:
todate(CASE
WHEN Status IN ("X","NMX","MX") THEN Cancel Dt cf
ELSE Confirm Dt cf
END
,'%Y%m%d','%Y%m%d')
Hope it fixes you well you or at least gives you some light/direction on how to solve it.

Search between two dates with ISO8601 format

Using angularjs, dynamodb as DB here.
I have a form where user saves some data. I save my "CreateOn" date in my dynamo db as:
DateTime.UtcNow.ToString("o");
//This saves date in DB as:2018-08-21T12:58:08.7823906Z
Storing like this because dynamo db requires dates (string) to stored in ISO8601 format if you want to use between operator to search for date range.
Now I have a search filters on my page which is basically an angular calendar. When the user selects the date in the calendar( start and end date) I want to get the data back based on the selected date. Here I am using moment to pass the calendar selected date to my api call as:
moment(createdOn).toISOString()
Eg: If they select the Today's date in the calendar I pass the selected date
(Tue Aug 21 2018 00:00:00 GMT-0400 (Eastern Daylight Time)) to the above function
The result of passing this date to moment(createdOn).toISOString() is
2018-08-21T04:00:00.000Z
The search condition at dynamo db is:
conditions.Add(new ScanCondition("CreatedOn", ScanOperator.Between, startDate, endDate ));
If the user selects from the calendar the start date as "08-20-2018" (2018-08-20T04:00:00.000Z) and the end date is "08-21-2018"(2018-08-21T04:00:00.000Z), the code all the data created b/w these 2 dates.
Now the issue is if they select same start and end date then the code does not returns any data, I believe because the start and end date is "2018-08-21T04:00:00.000Z" and the time part of this is all 0000 etc.
My question is how can I convert the date from my calendar ie my end date to correctly reflect the the end time which they select. I havent used ISO8601 format before so not sure how can I do so.
Thanks
You don't need moment for this. You can zero out the time using a Date in the following way.
const date = new Date('2018-08-21T12:58:08.7823906Z')
date.setUTCHours(0)
date.setUTCMinutes(0)
date.setUTCSeconds(0)
date.setUTCMilliseconds(0)
Then you can simply use toISOString() to format the date.
date.toISOString()
// returns '2018-08-21T00:00:00.000Z'
If you don't want to zero out the time, and instead want to set some specific time, you can use a similar approach, just substitute the 0 with whatever time you want.
Some other things to note: DynamoDB doesn't require any specific formatting for dates. DynamoDB simply does a string or number comparison depending on what the field is defined as. You could store your dates in DynamoDB as integers or another string format if you feel that would be easier to work with.
Also, I'm not sure how your table is setup but make sure that your "CreateOn" field is the Range key and that you are using Query, not Scan. Using the Scan operation doesn't scale well.

GQL error when formatting datetime query

I'm attempting to format a GQL query that pulls data between two dates. I've referred to several existing StackOverflow threads (GQL SELECT by date for example), and have tried following the formatting shown there, but for some reason when I test my query out it gives me an error.
Here is the query I'm attempting to use:
SELECT * FROM Packets WHERE timestamp > DATETIME(2017,12,23) AND timestamp < DATETIME(2017,12,29) LIMIT 10
It gives this error:
"GQL query error: Encountered "2017" at line 1, column 50. Was expecting one of: <SINGLE_QUOTE_STRING>, <DOUBLE_QUOTE_STRING>"
I've tried enclosing the dates in strings, I've tried using the DATE object, every format I can think of gives me some sort of error. What am I doing wrong?
The error is right, the DATETIME method needs a single string parameter.
According to the GQL reference, to instanciate a DATETIME in a query the format must be 'YYYY-MM-DDThh:mm:ss.SSSSSS+zz:ZZ':
DATETIME DATETIME() represents a timestamp. must be
in the time format specified in RFC 3339 section 5.6. (However, the
second precision is limited to microseconds and leap seconds are
omitted.) This standard format is: YYYY-MM-DDThh:mm:ss.SSSSSS+zz:ZZ
...
Your example working:
SELECT * FROM Packets WHERE timestamp > DATETIME('2013-09-20T09:30:20.00002-08:00') AND timestamp < DATETIME('2013-09-29T09:30:20.00002-08:00') LIMIT 10
You can check the complete article here :
https://cloud.google.com/datastore/docs/reference/gql_reference
Thanks for comment this problem.
With the answers of each one I can do a very easy (but almost impossible in GQL) Query.
Check this out, I hope it will help to someone:
SELECT * FROM Task WHERE recordDate >= DATETIME('2018-09-09T00:00:00.00000-03:00')
AND recordDate <= DATETIME('2018-09-20T23:59:59.99999-03:00')
Where "2018-09-09T00:00:00.00000-03:00" is the full datetime value and
it means:
2018-09-09 -> Date Indicator (YYYY-MM-DD in my case)
T -> Indicator that the next values are Time values
00:00:00.00000 -> Time Indicator (HH:mm:ss:[miliseconds])
-03:00 -> Time Zone indicator (Chile in my case)
I really hope this post will be useful to anyone that have the same trouble with dates using GQL

Resources