Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-2829: Fixed PutSQL time unit test. #2082

Closed
wants to merge 2 commits into from

Conversation

ijokarumawak
Copy link
Member

The unit test for DATE type used GMT timezone, that causes an assertion error in timezones such as EST (-5).
We need to use local timezone instead of GMT, as Derby and PutSQL uses local timezone.

The unit test failed before as follows:

  • Unit test code, passed: '2002-02-02 GMT'
  • PutSQL code convertedi it to local: '2002-02-01 EST', and stored as '2002-02-01' in Derby database without timezone info
  • Unit test code SELECT the inserted value, passed a GMT calender, then got epoch timestamp, which was '2002-01-31'

Thank you for submitting a contribution to Apache NiFi.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit 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?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

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.

The unit test for DATE type used GMT timezone, that causes an assertion error in timezones such as EST (-5).
We need to use local timezone instead of GMT, as Derby and PutSQL uses local timezone.

The unit test failed before as follows:
- Unit test code, passed: '2002-02-02 GMT'
- PutSQL code convertedi it to local: '2002-02-01 EST', and stored as '2002-02-01' in Derby database without timezone info
- Unit test code SELECT the inserted value, passed a GMT calender, then got epoch timestamp, which was '2002-01-31'
@ijokarumawak
Copy link
Member Author

@joewitt The test you marked with '@ignore' used GMT, but PutSQL and Derby database (used in unit test) treat date without timezone, i.e. local time. This caused the assertion error.

I've changed the unit test from using GMT to local timezone. Confirmed the test passes with various timezone, including UTC, GMT, JST, PST, EST ... etc.

Thanks for reporting the unit test failure. I believe it works fine now. Would you review this PR?

@yjhyjhyjh0
Copy link
Contributor

yjhyjhyjh0 commented Aug 14, 2017

Thanks for the detail explanation.
Indeed using local time zone is more reasonable.
Didn’t notice the date will be transform into local time zone once with value format.

Just want to point out that I first tried the approach you mentioned (use local time zone) will encounter problem with Time type.
My time zone is UTC+8, which cause time string like “01:01:01” in Time type will become negative long value.
This is reasonable because Time type only consider time without epoch so it will be negative if it’s earlier than “08:00:00”.

However this will not pass the LONG_PATTERN in PutSQL and thus consider a negative long value to be in format "HH:mm:ss.SSS” instead of long.
This will encounter error while parsing for sure : java.text.ParseException: Unparseable date: “-28739000”.

If I try your commit with changing the timeStr to “01:01:01" in testUsingDateTimeValuesWithFormatAttribute will encounter negative long parsing problem which mentioned above.
Don’t know if you will encounter similar problem with negative long value in Time type, too?

I've try your commit together with LONG_PATTERN that also match negative long value ("^-?\d{1,19}$”) today and everything works fine now.
Thanks for any response.

- For timezones such as '+0800', it's possible that a local time e.g. '02:03:04' can be a negative epoch value. This commit changes LONG_PATTERN so that it can accept nevative values.
- Changed time values in unit tests to verify negative epoch values, and avoid using the same digits among different time unit for better readability.
@ijokarumawak
Copy link
Member Author

@yjhyjhyjh0 Thank you very much to point that out. As you mentioned, for timezones ahead of UTC can have negative epoch values time, and we should support those are valid long values.

I've updated PutSQL LONG_PATTERN to accept negative values, and also removed the use of 'GMT' from TestPutSQL completely. It works with various timezones, UTC, GMT, JST, PST and EST. @joewitt Please check when you have time.

@jtstorck
Copy link
Contributor

Reviewing...

@jtstorck
Copy link
Contributor

+1, LGTM. Verified the three cases in the unit test, and tested with a negative long. Merging...

@asfgit asfgit closed this in c6f4421 Sep 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants