I have a unitils dataset attempting to enter data into a sybase datetime column, but it errors when I try and run the unit tests.
I cannot find anything online about inserting dates, so I tried declaring it as a String in the same way as the other columns, but I get the error:
org.unitils.core.UnitilsException: Error inserting test data from DbUnit dataset for method etc etc
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:156)
at org.unitils.dbunit.DbUnitModule$DbUnitListener.beforeTestSetUp(DbUnitModule.java:556)
at org.unitils.core.Unitils$UnitilsTestListener.beforeTestSetUp(Unitils.java:273)
at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:151)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.unitils.core.UnitilsException: Error while executing DataSetLoadStrategy
at org.unitils.dbunit.datasetloadstrategy.impl.BaseDataSetLoadStrategy.execute(BaseDataSetLoadStrategy.java:46)
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:230)
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:153)
... 18 more
Caused by: org.dbunit.dataset.datatype.TypeCastException: Error casting value for table 'USER' and column 'SUSPEND_SD'
at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:202)
at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:78)
at org.unitils.dbunit.datasetloadstrategy.impl.CleanInsertLoadStrategy.doExecute(CleanInsertLoadStrategy.java:45)
at org.unitils.dbunit.datasetloadstrategy.impl.BaseDataSetLoadStrategy.execute(BaseDataSetLoadStrategy.java:44)
... 20 more
The only line inserting a date in my dataset is:
<USER ID="4" FULL_NAME="user3" SUSPEND_SD="25/12/2011 00:00" SUSPEND_ED="25/12/2013 00:00" PASSWORD="password3"/>
Can anyone help?
Thanks in advance.
Ok, it turns out it has to be in exactly the format YYYY-MM-DD HH:MM:SS", for example "2011-01-01 02:00:00".
I don't know how unitils works but assuming your dataset is editable why not change the dates to yyyy/mm/dd format.
That java stack mentions casting, and that'll be a failure getting dd/mm/yyyy to datetime I'd think.
Alternatively the middleware probably has some date config means - you can probably tell it dates are British (it might even be regional settings?)
Related
I have some graph data with date type values.
My gremlin query for the date type property is working, but output value is not the date value.
Environment:
Janusgraph 0.3.1
gremlinpython 3.4.3
Below is my example:
Data (JanusGraph): {"ID": "doc_1", "MY_DATE": [Tue Jan 10 00:00:00 KST 1079]}
Query: g.V().has("ID", "doc_1").valueMap("MY_DATE")
Output (gremlinpython): datetime(1079, 1, 16)
The error is 6 days (1079.1.10 -> 1079.1.16).
This mismatch does not occur when the years are above 1600.
Does the timestamp have some serialization/deserialization problems between janusgraph and gremlinpython?
Thanks
There were some issue with Python and dates but I would have them fixed for 3.4.3, which is the version you stated you were using. The issue is described here at TINKERPOP-2264 along with the fix, but basically there were some issues with timezones. From your example data, it looks like you store your date with a timezone (i.e. KST). I'm not completely sure, but I would imagine things would work as expected if the date was stored as UTC.
After some try & search, I found that there are some difference between java Date and python datetime. (Julian vs. Gregorian Calendar)
So I have replaced SimpleDateFormat with JodaTime and got the expected result as below:
Data (Raw): {"ID": "doc_1", "MY_DATE": "1079-1-29"}
Data (JanusGraph): {"ID": "doc_1", "MY_DATE": [Wed Jan 23 00:32:08 KST 1079]}
(I think the JanusGraph uses java Date object internally..)
Query: g.V().has("ID", "doc_1").valueMap("MY_DATE")
Output (gremlinpython): datetime(1079, 1, 29)
Thanks
Using Java 8u222, I've been trying a silly operation and it incurs in an error that I'm not being able to fully understand. The line code:
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[Asia/Qostanay]");
The error:
java.time.format.DateTimeParseException: Text '2011-07-03T02:20:46+06:00[Asia/Qostanay]' could not be parsed, unparsed text found at index 25
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1952)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:582)
Using the same date (although the timezone could be incorrect, the intention is just testing here), I changed the square bracket's value and it works, I mean:
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[Europe/Busingen]);
It works as expected, as well as other values such:
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[Asia/Ulan_Bator]")
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[SystemV/CST6CDT]")
I found some similar questions such as the one below, but not precisely the same usage that I'm trying / facing.
Error java.time.format.DateTimeParseException: could not be parsed, unparsed text found at index 10
Does someone have an understanding of Java Date API to help me out to grasp what I'm doing wrong here?
Thanks.
Asia/Qostanay is a zone which doesn't exist in the JDK8's list of timezones. It was added later.
If you don't care about the location of the timezone then just splice the [...] part of the string off the end before parsing. Knowing that the time is +06:00 is going to sufficient for almost all purposes.
Alternatively, upgrade to a more recent version of Java.
Like in a similar query on this forum I need, but I need it to work in Impala:
In a workaround my colleague and myself attempted the following:
-- combine start date and time into a datetime
-- impala can't handle am/pm so need to look for pm indicator and add 12 hours
-- and then subtract 12 hours if it's 12:xx am or pm
================
t1.appt_time,
hours_add(
to_timestamp(concat(to_date(t1.appt_date),' ',t1.appt_time),'yyyy-MM-dd H:mm'),
12*decode(lower(strright(t1.appt_time,2)),"pm",1,0) -
12*decode(strleft(t1.appt_time,2),'12',1,0)
) as appt_datetime,
t1. ...
=========
Has anybody an easier and more elegant approach ?
Your workaround is valid, Impala does currently support AM/PM formatting for dates. There are a few open issues related
https://issues.apache.org/jira/browse/IMPALA-3381
https://issues.apache.org/jira/browse/IMPALA-5237
https://issues.apache.org/jira/browse/IMPALA-2262
I have a data which have the difference between the start and end time of an event. Now I want to add the difference. the problem is the difference time is in format
difference_time
_______________
00:10:00
00:30:12
01:09:09
00:09:03
01:09:30
01:09:03
00:09:08
01:00:09
09:00:01
But if I do sum(df$difference_time) it throws the error that invalid type of arguement.
I want the result to be something like below format:
51975 seconds.
Any help is appreciated
UPDATE:
I tried period_to_seconds(hms(df$difference_time)) and it works fine
period_to_seconds(hms(df$difference_time))
did the trick.
I am using Splunk 6.2.X along with Django bindings to create a Splunk app.
To get access to the earliest/latest dates from the timerange picker, am using the following in my JS.
mysearchbar.timerange.val()
Am getting back a map where the values are in epoch format:
Object {earliest_time: 1440122400, latest_time: 1440124200}
When I convert them using moment using the following, I get different datetime than expected:
> moment.unix('1440122400').utc().toString()
"Fri Aug 21 2015 02:00:00 GMT+0000"
However, the time does not correspond to the values that have been selected on the time range picker i.e. 08/20/2015 22:00:00.000
Am not sure what the difference is getting caused by? Am sure tht the timezone is not the factor as the time difference is erratically not equivalent to derive using simple timezone add/subtract.
I was wondering if this behaviour can be explained as to how to get the Splunk epoch datetime to UTC would be helpful.
I was able to get rid of the timezone issue by performing the following:
Setting the timezone of the Splunk engine to UTC in props.conf as follows:
TZ = GMT
Setting up the CentOS (the server hosting Splunk) to UTC
Hope this helps anyone else who stumbles upon similar issues.
Thanks.