Dear Community,
I’m exploring DreamFactory features to expose Cassandra tables as RESTful interfaces, everything is good when I do GET calls, but when I do POST calls to put records to cassandra table I have a issue when I include table with TIMESTAMP datatype:
This is the request:
POST: post /ds/_table/{table_name} createDsRecords() - Create one or more records
I put the body with this values to the table api_weather_events:
{
“resource”: [
{“station”: “0057015010”, “sensor”: “0103”, “event_time”: “2017-08-20 23:00:00-0000”, “event_value”: 18.27}
]
}
The curl POST is:
curl -X POST --header ‘Content-Type: application/json’ --header ‘Accept: application/json’ --header ‘X-DreamFactory-Api-Key: 36fda24fe5588fa4285ac6c6c2fdfbdb6b6bc9834699774c9bf777f706d05a88’ --header ‘X-DreamFactory-Session-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJiOTdmMDBhNWU4MWFlZjhkM2EzODJjZGM2ZTI5Njc0NyIsImlzcyI6Imh0dHA6Ly8xNzIuMTYuNTAuNTIvYXBpL3YyL3N5c3RlbS9hZG1pbi9zZXNzaW9uIiwiaWF0IjoxNTEwMzIwNjgxLCJleHAiOjE1MTAzMjQyODEsIm5iZiI6MTUxMDMyMDY4MSwianRpIjoiZ1ZqTmUxR0hYUTVXdGVmWCIsInVzZXJfaWQiOjEsImZvcmV2ZXIiOmZhbHNlfQ.LcSedPzKmw10uWQg5InNfOCUyNBwR0YgItkWvlEiRyc’ -d ‘{
“resource”: [
{“station”: “0057015010”, “sensor”: “0103”, “event_time”: “2017-08-20 23:00:00-0000”, “event_value”: 18.27}
]
}’ ‘http://172.16.50.52/api/v2/ds/_table/api_weather_events’
Which works doing call to API.
But the table show the following data:
cassandra@cqlsh:raw> select * from api_weather_events where station=‘0057015010’;
station | sensor | event_time | event_value
------------±-------±-------------------------------------±------------
0057015010 | 0103 | datetime.datetime(1503, 9, 27, 0, 0) | 18.27
(1 rows)
Failed to format value datetime.datetime(1503, 9, 27, 0, 0) : year=1503 is before 1900; the datetime strftime() methods require year >= 1900
You can see that the data is not stored correctly.
Doing the same operation inside Cqlsh using JSON feature the results data stored are as expected:
cassandra@cqlsh:raw> insert into api_weather_events JSON ‘{“station”: “0057015010”, “sensor”: “0103”, “event_time”: “2017-08-20 23:00:00-0000”, “event_value”: 18.27}’ ;
cassandra@cqlsh:raw> select * from api_weather_events where station=‘0057015010’;
station | sensor | event_time | event_value
------------±-------±-------------------------±------------
0057015010 | 0103 | 2017-08-20 23:00:00+0000 | 18.27
(1 rows)
What I’m doing wrong with datatype in JSON Body for dream factory, maybe can be a bug from DataStax driver.
Any help will be appreciated.
Thanks
Wladimir