METRON-1107 add support for handling epoch dates in seconds or milliseconds #692
Conversation
c26b3d8
to
b4a76d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, aside from the 10 digit assumption and some minor typos.
* | ||
* | ||
* </p> | ||
* @param canidate The Long value to concider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/concider/consider/
for the whole file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:%s/x/y/g
will do the whole file :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't assuming vi, I was assuming more of a sed
-style formatting, plus you only need the g for your canidate typo because it occurs twice on one line. =)
*/ | ||
public static Long ensureEpochMillis(Long canidate) { | ||
int length = (int)Math.floor(Math.log10(canidate) + 1); | ||
return length == 10 ? canidate * 1000 : canidate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should handle inputs of length 1-9 as well.
* Ensures returns the passed value as milliseconds from EPOCH if the value is in seconds. | ||
* This is done by looking at the number of digits. | ||
* If there are 10, then the value is concidered to be in seconds and will by | ||
* muliplited by 1000. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/muliplited/multiplied/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
* @param canidate The Long value to concider | ||
* @return A Long value | ||
*/ | ||
public static Long ensureEpochMillis(Long canidate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/canidate/candidate/g
for this whole file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Assert.assertTrue(meh.longValue() == EpochUtils.ensureEpochMillis(meh).longValue()); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding some tests for < 10 digit epochs.
Object result = run("DAY_OF_YEAR(epoch_seconds)"); | ||
assertEquals(238, result); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding tests for an epoch time at or before Sunday, September 9, 2001 1:46:39 AM.
Also, I did notice a couple of things when poking around that probably fit best into some new JIRAs that I at least wanted to mention here:
|
This is due to our time stuff being java Calendar based. We should have a new jira to convert to the new java.time concepts. Comments from Reviewable |
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/EpochUtils.java, line 41 at r1 (raw file): Previously, JonZeolla (JonZeolla) wrote…
So, the 10/13 rule is pretty standard. If we do this, then we know we are doing seconds->millis for current timestamps. for < 10, we don't know if it is millis or timestamps, at least that is my thinking. adding a 0 up to 13 for those numbers is equally as bad as just leaving them no? Comments from Reviewable |
metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/DateFunctionsTest.java, line 248 at r1 (raw file): Previously, JonZeolla (JonZeolla) wrote…
can I ask why? Comments from Reviewable |
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/EpochUtils.java, line 36 at r1 (raw file): Previously, JonZeolla (JonZeolla) wrote…
one upper Comments from Reviewable |
Because that is 9x
Well, that's partially true. We know that for 1-3 digits it must be seconds, and for 11-13 digits it must be millis. Perhaps we provide an optional field that specifies millis vs seconds with a default to whatever is more common (seconds) and be done with it? Do we have any core assumptions of using milli elsewhere? Of course this will need an update to a lot of tests to either change to seconds or specify milli. As far as attempting to appropriately zero-pad it (which I think is what you mentioned but I could be wrong), I'm probably against that because a small mistake could drastically affect the timestamp. To be explicit - |
I'm going to close this. We need more discussion. |
This PR adds the capability for the Stellar Date functions which take Long times to handle both seconds and milliseconds, so they just handle epoch time.
Testing
run stellar shell and exercise the Stellar date functions using epochconverter.com.
Use both the epoch seconds and millisecond values
In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:
For all changes:
For code changes:
Have you included steps to reproduce the behavior or problem that is being changed or addressed?
Have you included steps or a guide to how the change may be verified and tested manually?
Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:
Have you written or updated unit tests and or integration tests to verify your changes?
If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?
For documentation related changes:
Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via
site-book/target/site/index.html
:Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.