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

Fix getNextValue() to increase the number of milliseconds if needed #18588

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

findinpath
Copy link
Contributor

@findinpath findinpath commented Aug 8, 2023

Description

This is a potential correctness issue when using as input

LongTimestampWithTimeZone[epochMillis=1483228799999, picosOfMilli=999000000, timeZoneKey=0]

getNextValue() will return

Optional[LongTimestampWithTimeZone[epochMillis=1483228799998, picosOfMilli=0, timeZoneKey=0]]

even though it should have been returning

Optional[LongTimestampWithTimeZone[epochMillis=1483228800000, picosOfMilli=0, timeZoneKey=0]]

Additional context and related issues

Cherry-picked from #14648

PR contains as well a cherry-pick from #18594 for JUnit5 related changes.

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Iceberg
* Fix partition filter subsuming when dealing with `timestamp with time zone` columns. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Aug 8, 2023
@findinpath findinpath requested a review from findepi August 8, 2023 15:48
@findinpath findinpath added bug Something isn't working no-release-notes This pull request does not require release notes entry labels Aug 8, 2023
@findinpath findinpath self-assigned this Aug 8, 2023
Copy link
Member

@alexjo2144 alexjo2144 left a comment

Choose a reason for hiding this comment

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

Good catch

@martint
Copy link
Member

martint commented Aug 8, 2023

Is there a test that reproduces the issue?

@findinpath
Copy link
Contributor Author

Is there a test that reproduces the issue?

I stumbled over it on BaseIcebergConnectorTest#testYearTransformDate() on #14648

        assertThat(query("SELECT * FROM test_year_transform_timestamptz WHERE d BETWEEN with_timezone(DATE '2015-01-01', 'UTC') AND with_timezone(TIMESTAMP '2016-12-31 23:59:59.999999', 'UTC')"))
                .isFullyPushedDown();

I can add however a test in io.trino.type.TestLongTimestampWithTimeZoneType

@findinpath findinpath force-pushed the findinpath/fix-next-value branch from 2b3dd7c to 138c307 Compare August 8, 2023 16:56
@@ -55,6 +56,7 @@ protected Object getGreaterValue(Object value)
}

@Override
@Test
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we ensure automatically that this doesn't happen?
The method is silently ignored if not annotated with @Test

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn’t be overriding tests like that. If necessary, add new tests specific for the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't follow.
This is pre-existing functionality.

Please add more detail to the comment.
Simply create a new method instead of doing overrides?

Copy link
Member

@martint martint Aug 8, 2023

Choose a reason for hiding this comment

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

I'm just responding to your comment about "ensuring automatically it doesn't happen". Structuring tests that way is not a good practice. It makes it hard to reason about which tests apply where (in some cases, the tests in AbstractXXX apply, in others they are completely overwritten, etc. -- usual arguments about using inheritance for reusing behavior in other contexts). We should fix them separately and not do that going forward.

Copy link
Member

Choose a reason for hiding this comment

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

That is how ATDQ, BCT and other similar "super" test classes are designed to work. We'll need to rethink how to structure those before those can be migrated over safely - since without that it's hard to have re-usable tests which also evolve over time (e.g. testRange is overridden today to throw SkipException but in future once the feature is there the override can be removed).

Copy link
Member

Choose a reason for hiding this comment

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

cc: @ksobolew any ideas to how to get this to work or how to restructure tests to avoid subclassing when using JUnit5?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I can see that the implementations in the base class assert that the relevant properties of the type are Optional.empty(). They could, instead, do some assertions if it's not empty, and use some protected methods to get the expected result. But I'm not sure if that would work with all the types. It's kind of similar to how hasBehavior is used in connector tests...

Copy link
Contributor

Choose a reason for hiding this comment

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

I can see there's already #18594 :)

Copy link
Member

Choose a reason for hiding this comment

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

That is how ATDQ, BCT and other similar "super" test classes are designed to work. We'll need to rethink how to structure those before those can be migrated over safely

I can think of many different, more "pure" approaches.
The whole idea of BCT is impure and we could remove it. Connectors should have tests for features they implement.

Of course, this is straw-man's proposal. While letting us free of test overrides, this would lead to much worse test coverage.

@findinpath findinpath force-pushed the findinpath/fix-next-value branch from 138c307 to 4d6ae7d Compare August 8, 2023 17:04
@@ -16,6 +16,7 @@
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.Type.Range;
import org.junit.jupiter.api.Test;
Copy link
Member

Choose a reason for hiding this comment

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

For me, these all run properly as is if you change the parent class AbstractTestType to use the org.testng.annotations.Test annotation instead of the junit org.junit.jupiter.api.Test annotation.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, but that’s not how junit works — and we’re in the process of replacing testng with junit

Copy link
Member

Choose a reason for hiding this comment

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

We should invest into writing a checker for this for the transition period like we have multiple for TestNG already. It seems very easy to do a migration but not realize multiple tests aren't running anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is a huge landmine. I already stepped on it some time ago and we briefly discussed countermeasures, but nothing came out of it. I suppose we could write an Error Prone check for this (I am surprised that there is no one already).

Copy link
Member

Choose a reason for hiding this comment

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

Requirement to put @Test on overridden test is just junit's "ux bug", or a quirk, and agreed that we definitely need a checker for that. Thanks @ebyhr for reporting #14027.

@findinpath findinpath force-pushed the findinpath/fix-next-value branch 2 times, most recently from e237c0a to 755d5e6 Compare August 11, 2023 04:36
@findinpath findinpath requested a review from martint August 11, 2023 04:37
@findinpath
Copy link
Contributor Author

Rebased on master to re-use the commits from #18594

@findinpath findinpath force-pushed the findinpath/fix-next-value branch from 9224a3a to 7a2bfab Compare August 11, 2023 08:21
@findepi findepi merged commit d2046df into trinodb:master Aug 14, 2023
@github-actions github-actions bot added this to the 424 milestone Aug 14, 2023
@findepi findepi mentioned this pull request Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cla-signed correctness no-release-notes This pull request does not require release notes entry
Development

Successfully merging this pull request may close these issues.

6 participants