How to use java `OffsetDateTime` in apache tinkerpop gremlin? - gremlin

The application can be accessed from a different timezone, so I am trying to store date time using class java.time.OffsetDateTime.
startTime: "1996-12-19T16:39:57-08:00",
endTime: "1996-12-19T16:39:57-08:00"
The application/API receives the time in the above format using OffsetDateTime and I am trying to save the same in AWS Neptune using Apache gremlin but I am getting the following error,
org.apache.tinkerpop.gremlin.driver.exception.ResponseException: {"detailedMessage":"Unsupported property value type: java.time.OffsetDateTime","code":"UnsupportedOperationException","requestId":"81e402b0-90ab-4c6d-8839-23542da3437b"}
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:245) ~[gremlin-driver-3.6.1.jar:3.6.1]
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:200) ~[gremlin-driver-3.6.1.jar:3.6.1]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinSaslAuthenticationHandler.channelRead0(Handler.java:126) ~[gremlin-driver-3.6.1.jar:3.6.1]
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinSaslAuthenticationHandler.channelRead0(Handler.java:68) ~[gremlin-driver-3.6.1.jar:3.6.1]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
OffsetDateTime is not supported in Gremlin/Neptune? then how to store, and retrieve in an efficient way from the database?

Amazon Neptune is designed to work with any programming language. As such you cannot store arbitrary Java types/objects into Neptune. You can use the native Date types and they will be converted by the Gremlin GLVs into the appropriate serialization. To store dates you really have two main options.
Store a Date type or use the datetime helper for text queries.
Use Epoch offset integers.
Using real Dates should be slightly more performant (on Neptune).
If you need to store additional TZ information, you will most likely want to store that as an additional property on a node or edge.
More information on Neptune's support for dates when using Gremlin, can be found here.

Related

Submitting time data to wikibase with `wbcreateclaim` results in "invald-snak" error

I am currently trying to populate a wikidata instance via POST requests. For this purpose I use the requests library in Python together with the MediaWiki API.
So far I managed to create claims with different datatypes (like String, Quantity, Wikidata items, Media ...). The general scheme I use is this (with different value strings for each datatype):
import requests
session = requests.Session()
# authenticate and obtain a csrf_token
parameters = {
'action': 'wbcreateclaim',
'format': 'json',
'entity': 'Q1234',
'snaktype': 'value',
'property': 'P12',
'value': '{"time": "+2022-02-19T00:00:00Z", "timezone": 0, "precision": 11, "calendarmodel": "http://www.wikidata.org/entity/Q1985727"}',
'token': csrf_token,
'bot': 1,
}
r = session.post(api_url, data=parameters)
print(r.json())
Every attempt to insert data of type time leads to an invalid-snak error (info: "invalid snak data.").
The following changes did not solve the problem:
submitting the value string as dictionary value (without the single quotes),
putting the numeric values into (double) quotes,
using a local item for the calendarmodel ("http://localhost:8181/entity/Q73"),
adding before and after keys in the dictionary,
omitting timezone, precision, calendarmodel and combinations thereof,
formatting the time string as 2022-02-19,
submitting the request with administrator rights (though the error message does not
suggest a problem with insufficient user rights).
Do you know, what I'm doing wrong here? What must the value field look like?
I am aware of the fact that special libraries or interfaces for exist for these tasks. But I do want to use the Wikidata API directly with the requests library in Python.
Thank you very much for your help!
Installed software versions:
MediaWiki: 1.36.3
PHP: 7.4.27
MariaDB 10.3.32-MariaDB-1:10.3.32+maria~focal
ICU 67.1
It works if the value string is generated from the dictionary via json.dumps().

Which timezone is kafka consumer timestamp using and how to change it?

I'm producing data and comsuming it using Kafka. In the consumer, I print the consumed data using the following code:
consumer = connect_kafka_consumer()
for message in consumer:
print (message)
Here is the output of one line:
ConsumerRecord(topic='states', partition=0, offset=7214, timestamp=1603507387101, timestamp_type=0, key=None, value={'sequence': 1354, 'State': 'WA'}, headers=[], checksum=4012375034, serialized_key_size=-1, serialized_value_size=250, serialized_header_size=-1)
My question is about the timestamp, which I can get using message.timestamp. Which timezone is that? Is default timezone UTC? And how can I tell consumer to change this processing time to another timezone?
Thanks
that is the epoch time, so it is independent of any timezone. You may convert it to human-readable time using any epoch convertor(online here https://www.epochconverter.com/)

Using the current date in a Gatling test

I am trying to load test an application using Gatling, and the application needs the current date to be inserted into the test:
.formParam("dateCreation", "07/01/2015 16:48:04")
If it's hard coded it seems to upset the application being tested.
How can I generate the above string at the time of each request? (It's European format - day/month/year)
Scala isn't my strong point. I'm using Gatling 2.0.3.
Use a modern Java date API, like joda-time, or JDK8's DateTime API.
With either API, you'll have to:
first build a formatter for the desired pattern ("dd/MM/yyyy hh:mm:ss"). Only build this once and for all as those are threadsafe (unlike Java's SimpleDateFormat).
instead of passing a hard coded value, pass a Session function that fetch the current date and format it. It will look like (pseudo code):
val formatter = ???
.formParam("dateCreation", session => formatter.format(now()))
This way, the formatted date will be computed for each execution of this request.

HERE maps - getting road type based on gps coordinates

Is it possible to get the type of road (e.g. motorway, primary, secondary) for given coordinates, using HERE maps RESTful API?
You can use the "getlinkinfo" endpoint of the routing service together with the "linkattributes=all" parameter to get the corresponding functional class value of a certain link:
http://route.st.nlp.nokia.com/routing/6.2/getlinkinfo.xml?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&waypoint=50.05564304861044,8.38889128575724&linkattributes=all
More info about the functional class value:
You can use the "calculateroute" endpoint together with &attributes=LINK_ATTRIBUTE_FC1(*) to get the road type. It returns a json value "ROUTE_TYPES" from 1...6 and each integer depending on the "ISO_COUNTRY_CODE" represents a road type. eg. ISO_COUNTRY_CODE:DEU with ROUTE_TYPES:2 is an Autobahn (motorway).
Different road types and their iso code can be found in the below link.
https://fleet.ls.hereapi.com/1/doc/attributes.html?region=SAM&release=20111&apikey= your api key
Also an example url to is below
https://fleet.ls.hereapi.com/2/calculateroute.json?&apiKey=your_api_key&mode=car&waypoint0=50.10992,8.69030&waypoint1=50.00658,8.29096&attributes=LINK_ATTRIBUTE_FC1(*)
please remember to add your own api key.

How to set local timezone in Sails.js or Express.js

When I create or update record on sails it write this at updateAt:
updatedAt: 2014-07-06T15:00:00.000Z
but I'm in GMT+2 hours (in this season) and update are performed at 16:00.
I have the same problem with all datetime fields declared in my models.
How can I set the right timezone on Sails (or eventually Express) ?
The way I handled the problem after hours of research :
Put
process.env.TZ = 'UTC'; //whatever timezone you want
in config/bootstrap.js
I solved the problem, you should setting the MySql options file to change timezone to UTC
in the config/connections.js
setting at this
devMysqlServer: {
adapter: 'sails-mysql',
host: '127.0.0.1',
user: 'root',
password: '***',
database: '**',
timezone: 'utc'
},
Trying to solve your problem by setting the timezone on your server is a bit short-sighted. What if you move? Or someone in a different country accesses your application? The important thing is that the timestamps in your database have a timezone encoded in them, so that you can translate to the correct time on the front end. That is, if you do:
new Date('2014-07-06T15:00:00.000Z')
in your browser console, you should see it display the correct date and time for wherever you are. Sails automatically encodes this timestamp for you with the default updatedAt and createdAt fields; just make sure you always use a timezone when saving any custom timestamps to the database, and you should be fine!
The best architecture planning here, IMO, is to continue using Sails.js isoDate formatting. When you're user's load your website/app the isoDate will be converted to their client/browser timezone which is usually set at the OS level.
Here's an example you can test this out with. Open a browser console and run new Date().toISOString() and look at the time it sets. It's going to be based of off the spec for isoDate 8601 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString).
Now, change your system time to a different time zone or simply change your hour on the time and save (you shouldn't have to reload if you're using chrome console). Run your command in the console again new Date().toISOString() and you'll get an adjusted time appropriate to the time you just changed.
If you'd like to continue on proving to yourself the time Sails.js is appropriate to use, use Moment.js on an isoDate that is stored in your database (created by waterline ORM) like so moment("2016-02-05T22:36:48.800Z").fromNow() and you'll notice the time is relative to your system time.
I've come to grips with not setting a timezone at the app level (I see why the sails authors did it that way), however I've been having a rough time performing a simple date match query. I'd assume that if you create a record using the default blueprint methods (this one containing an extra datetime field over the defaults), passing in a date, that you'd be able to pass in the same date in a get query and get the same record.
For example, let's say the datetime field is called "specialdate". If I create a new record through the api with "specialdate" equaling "06-09-2014" (ignoring time), I haven't been able to run a find query in which I can pass in "06-09-2014" and get that record back. Greater than queries work fine (if I do a find for a date greater than that). I'm sure it's a timezone offset thing, but haven't been able to come up with a solution.

Resources