Skip to content

PHOENIX-6486 Phoenix uses inconsistent chronologies internally, breaking pre-Gregorian date handling - #1284

Closed
richardantal wants to merge 1 commit into
apache:masterfrom
richardantal:PHOENIX-6486
Closed

PHOENIX-6486 Phoenix uses inconsistent chronologies internally, breaking pre-Gregorian date handling#1284
richardantal wants to merge 1 commit into
apache:masterfrom
richardantal:PHOENIX-6486

Conversation

@richardantal

Copy link
Copy Markdown
Contributor

No description provided.

@richardantal
richardantal requested a review from stotyAugust 5, 2021 11:27
@stoty

stoty commented Aug 5, 2021

Copy link
Copy Markdown
Contributor

💔 -1 overall

VoteSubsystemRuntimeComment
+0 🆗reexec8m 25sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+1 💚hbaseanti0m 0sPatch does not have any anti-patterns.
+1 💚@author0m 0sThe patch does not contain any @author tags.
-1 ❌test4tests0m 0sThe patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ master Compile Tests _
+1 💚mvninstall22m 34smaster passed
+0hbaserecompile30m 6sHBase recompiled.
+1 💚compile1m 11smaster passed
+1 💚checkstyle1m 10smaster passed
+1 💚javadoc0m 54smaster passed
+0 🆗spotbugs3m 28sphoenix-core in master has 973 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚mvninstall15m 11sthe patch passed
+0hbaserecompile25m 13sHBase recompiled.
+1 💚compile1m 6sthe patch passed
+1 💚javac1m 6sthe patch passed
-1 ❌checkstyle1m 4sphoenix-core: The patch generated 12 new + 269 unchanged - 21 fixed = 281 total (was 290)
+1 💚whitespace0m 0sThe patch has no whitespace issues.
+1 💚javadoc0m 54sthe patch passed
+1 💚spotbugs3m 22sthe patch passed
_ Other Tests _
+1 💚unit118m 55sphoenix-core in the patch passed.
+1 💚asflicense0m 18sThe patch does not generate ASF License warnings.
194m 2s
SubsystemReport/Notes
DockerClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/1/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#1284
Optional Testsdupname asflicense javac javadoc unit spotbugs hbaserebuild hbaseanti checkstyle compile
unameLinux fd16659f3601 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev/phoenix-personality.sh
git revisionmaster / 025a4af
Default JavaPrivate Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
checkstylehttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/1/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt
Test Resultshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/1/testReport/
Max. process+thread count11858 (vs. ulimit of 30000)
modulesC: phoenix-core U: phoenix-core
Console outputhttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/1/console
versionsgit=2.7.4 maven=3.3.9 spotbugs=4.1.3
Powered byApache Yetus 0.12.0 https://yetus.apache.org

This message was automatically generated.

@stotystoty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution of adjusting the time read from DB seems like a kludge to me.
I think that we should do is switch over everything in DateUtil to use the Joda Time, with ISO chronology.
That should take care of keeping the input and output string representations consistent at least.

This is the notes I took:

//TODO
//Switch everything over to Joda Formatter/Parser objects
//Parsing ALWAYS uses the default format string ( why ?)
//Formatting format string is configurable / settable
//Cache formatter objects by Format String / Timezone ?

@richardantal

Copy link
Copy Markdown
ContributorAuthor

I can see the point that it is not the most sophisticated solution to the problem.
When I checked the different type of dates we use in the code I concluded that at the end we return a java.sql.Date in Phoenix resultSet from a long value. The java.sql.Date has the GJChronology so even if until that point we consistently use the ISO chronology it will be changed.

@joshelserjoshelser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I checked the different type of dates we use in the code I concluded that at the end we return a java.sql.Date in Phoenix resultSet from a long value. The java.sql.Date has the GJChronology so even if until that point we consistently use the ISO chronology it will be changed.

If we're still falling back to GJ in what we return back to the user, is this change simply helping us be consistent in what gets written into Phoenix? If this is a less-impactful change than using Jodatime with ISO chronology everywhere, I'm not sure what we are getting/missing with this easier change.

Comment on lines +1972 to +1980
stmt.execute("UPSERT INTO " + tableName + " VALUES(1, TO_DATE('" + date1
+ "'), TO_TIME('" + date1 + "'), TO_TIMESTAMP('" + date1 + "'))");

stmt.execute("UPSERT INTO " + tableName + " VALUES(2, TO_DATE('" + date2
+ "'), TO_TIME('" + date2 + "'), TO_TIMESTAMP('" + date2 + "'))");

String f = " GMT', 'yyyy-MM-dd HH:mm:ss.SSS z', 'UTC";
stmt.execute("UPSERT INTO " + tableName + " VALUES(4, TO_DATE('" + date2 + f
+ "'), TO_TIME('" + date2 + f + "'), TO_TIMESTAMP('" + date2 + f + "'))");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could these be PreparedStatements too?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have test for both PreparedStatements and execute statements as well.

assertions++;
}
}
assertEquals(assertions, 28);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this dates.size() *7? Not sure if there's a lot of value directly in this assertion either way.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be deleted, I agree it does not add any value anymore. In development I used it to validate if I do the check on every column of every row.

for (int i = 0; i < dates.size(); i++){
assertTrue(rs.next());
for (int j = 0; j < 6; j++){
int expected = Integer.parseInt(dateLists.get(i).get(j));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: IMO, would be more readable to add List<String> dateList = dateList.get(i) outside the inner-loop and make this dateList.get(j).

Date d2 = parseDate(dt2.toString());
long l1 = d1.getTime();
long l2 = d2.getTime();
return (ts + (l1 - l2));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you could include a description as to how/why this math works?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it a bit simpler and added comments in the latest change.

Time d2 = parseTime(dt2.toString());
long l1 = d1.getTime();
long l2 = d2.getTime();
return new Time(ts - (l1 - l2));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An explanation for this one too would be great.

…ing pre-Gregorian date handling
Change-Id: Ie176cc267db7a30585729660271e1636d5a503d6
@richardantal

Copy link
Copy Markdown
ContributorAuthor

If we're still falling back to GJ in what we return back to the user, is this change simply helping us be consistent in what gets written into Phoenix?

Roughly yes, I changed the SimpleDateFormatParser to parse the date in ISO chronology to be more consistent with the ISODateFormatParser (as ISODateFormatParser is used more often). The major change is on the read part where I I simply adjust the long values to be accurate.
We know that for parsing we use ISO chronology and the java.sql.date/time/timestamp output uses GJ so there is going to be a difference on the output. I subtract this difference from the value in order to eliminate it.

@stoty

Copy link
Copy Markdown
Contributor

💔 -1 overall

VoteSubsystemRuntimeComment
+0 🆗reexec5m 38sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+1 💚hbaseanti0m 1sPatch does not have any anti-patterns.
+1 💚@author0m 0sThe patch does not contain any @author tags.
-1 ❌test4tests0m 0sThe patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ master Compile Tests _
+1 💚mvninstall21m 9smaster passed
+0hbaserecompile27m 51sHBase recompiled.
+1 💚compile1m 3smaster passed
+1 💚checkstyle1m 2smaster passed
+1 💚javadoc0m 52smaster passed
+0 🆗spotbugs3m 5sphoenix-core in master has 973 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚mvninstall13m 46sthe patch passed
+0hbaserecompile24m 52sHBase recompiled.
+1 💚compile1m 4sthe patch passed
+1 💚javac1m 4sthe patch passed
-1 ❌checkstyle1m 3sphoenix-core: The patch generated 11 new + 269 unchanged - 21 fixed = 280 total (was 290)
+1 💚whitespace0m 0sThe patch has no whitespace issues.
+1 💚javadoc0m 50sthe patch passed
+1 💚spotbugs3m 17sthe patch passed
_ Other Tests _
-1 ❌unit112m 41sphoenix-core in the patch failed.
+1 💚asflicense0m 47sThe patch does not generate ASF License warnings.
184m 19s
ReasonTests
Failed junit testsphoenix.end2end.PermissionNSEnabledWithCustomAccessControllerIT
SubsystemReport/Notes
DockerClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/2/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#1284
Optional Testsdupname asflicense javac javadoc unit spotbugs hbaserebuild hbaseanti checkstyle compile
unameLinux 8d182695b208 4.15.0-151-generic #157-Ubuntu SMP Fri Jul 9 23:07:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev/phoenix-personality.sh
git revisionmaster / c4d297d
Default JavaPrivate Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
checkstylehttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/2/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt
unithttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/2/artifact/yetus-general-check/output/patch-unit-phoenix-core.txt
Test Resultshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/2/testReport/
Max. process+thread count15364 (vs. ulimit of 30000)
modulesC: phoenix-core U: phoenix-core
Console outputhttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1284/2/console
versionsgit=2.7.4 maven=3.3.9 spotbugs=4.1.3
Powered byApache Yetus 0.12.0 https://yetus.apache.org

This message was automatically generated.

@richardantal

Copy link
Copy Markdown
ContributorAuthor

Closing this PR as this is not a good solution to the problem.
Even if the read getString, GetDate, getObject value seems to be the same we inserted, the underlying long is changed because of the correction. (The "corrected" long value had the same toString value because it was interpreted in a different chronology.)
Inserting a long timestamp and not getting the same back could cause problems and not a good way to handle this issue.
I created an other PR witch uses GJ chronology for parsing. I think that could be a more consistent solution. The java.sql.Date types uses the GJ chronology when we return the resultset, so we could use it for parsing as well.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@richardantal@stoty@joshelser