-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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 timestamp with timezone mapping in iceberg type converter #23534
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.iceberg; | ||
|
||
import com.facebook.presto.common.type.TimestampType; | ||
import com.facebook.presto.common.type.TimestampWithTimeZoneType; | ||
import com.facebook.presto.common.type.Type; | ||
import com.facebook.presto.testing.MaterializedResult; | ||
import com.facebook.presto.testing.QueryRunner; | ||
import com.facebook.presto.tests.AbstractTestQueryFramework; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.OptionalInt; | ||
|
||
import static com.facebook.presto.hive.HiveCommonSessionProperties.PARQUET_BATCH_READ_OPTIMIZATION_ENABLED; | ||
import static com.facebook.presto.iceberg.IcebergQueryRunner.createIcebergQueryRunner; | ||
import static com.google.common.base.Preconditions.checkState; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class TestIcebergTypes | ||
extends AbstractTestQueryFramework | ||
{ | ||
private QueryRunner batchReaderEnabledQueryRunner; | ||
|
||
@Override | ||
protected QueryRunner createQueryRunner() throws Exception | ||
{ | ||
this.batchReaderEnabledQueryRunner = createIcebergQueryRunner( | ||
ImmutableMap.of(), | ||
ImmutableMap.of(), | ||
ImmutableMap.of(PARQUET_BATCH_READ_OPTIMIZATION_ENABLED, "true"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is no need to refactor the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe there is another way, but adding this to extra properties actually causes the tests to break since it is an unused property there. This sets it as a configuration property, but it needs to be a session property. The session is actually passed to the distributed query runner builder in it's constructor, so we need some way to add properties to that session before building the runner. This is why I decided to make changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh, sorry for the overlooking that |
||
new IcebergConfig().getFileFormat(), | ||
true, | ||
false, | ||
OptionalInt.empty(), | ||
Optional.empty(), | ||
Optional.empty(), | ||
false, | ||
Optional.empty()); | ||
return createIcebergQueryRunner(ImmutableMap.of(), ImmutableMap.of()); | ||
} | ||
|
||
@DataProvider(name = "testTimestampWithTimezone") | ||
public Object[][] createTestTimestampWithTimezoneData() | ||
{ | ||
return new Object[][] { | ||
{getQueryRunner()}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we need a whole separate test for this. Can't we just create a dataProvider which passes in true/false values and lets us construct a valid session in the beginning of the test method? Then you can pass the session to all of the execute/assertQuery methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate on this please? I'm not sure what you are referring to as the separate test. I can have the data provider pass in one true and one false value and add a condition inside the test function itself, is that what you are asking for here? If so what purpose would that serve? Thanks |
||
{getBatchReaderEnabledQueryRunner()} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "testTimestampWithTimezone") | ||
public void testTimestampWithTimezone(QueryRunner runner) | ||
{ | ||
String timestamptz = "TIMESTAMP '1984-12-08 00:10:00 America/Los_Angeles'"; | ||
String timestamp = "TIMESTAMP '1984-12-08 00:10:00'"; | ||
|
||
runner.execute("CREATE TABLE test_timestamptz(a TIMESTAMP WITH TIME ZONE, b TIMESTAMP, c TIMESTAMP WITH TIME ZONE)"); | ||
String row = "(" + timestamptz + ", " + timestamp + ", " + timestamptz + ")"; | ||
for (int i = 0; i < 10; i++) { | ||
runner.execute("INSERT INTO test_timestamptz values " + row); | ||
} | ||
|
||
MaterializedResult initialRows = runner.execute("SELECT * FROM test_timestamptz"); | ||
List<Type> types = initialRows.getTypes(); | ||
|
||
assertTrue(types.get(0) instanceof TimestampWithTimeZoneType); | ||
assertTrue(types.get(1) instanceof TimestampType); | ||
|
||
runner.execute("CREATE TABLE test_timestamptz_partition(a TIMESTAMP WITH TIME ZONE, b TIMESTAMP, c TIMESTAMP WITH TIME ZONE) " + | ||
"WITH (PARTITIONING = ARRAY['b'])"); | ||
runner.execute("INSERT INTO test_timestamptz_partition (a, b, c) SELECT a, b, c FROM test_timestamptz"); | ||
|
||
MaterializedResult partitionRows = runner.execute("SELECT * FROM test_timestamptz"); | ||
List<Type> partitionTypes = partitionRows.getTypes(); | ||
|
||
assertTrue(partitionTypes.get(0) instanceof TimestampWithTimeZoneType); | ||
assertTrue(partitionTypes.get(1) instanceof TimestampType); | ||
|
||
String earlyTimestamptz = "TIMESTAMP '1980-12-08 00:10:00 America/Los_Angeles'"; | ||
runner.execute("CREATE TABLE test_timestamptz_filter(a TIMESTAMP WITH TIME ZONE)"); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
runner.execute("INSERT INTO test_timestamptz_filter VALUES (" + earlyTimestamptz + ")"); | ||
} | ||
for (int i = 0; i < 5; i++) { | ||
runner.execute("INSERT INTO test_timestamptz_filter VALUES (" + timestamptz + ")"); | ||
} | ||
|
||
MaterializedResult lateRows = runner.execute("SELECT a FROM test_timestamptz_filter WHERE a > " + earlyTimestamptz); | ||
assertEquals(lateRows.getMaterializedRows().size(), 5); | ||
|
||
MaterializedResult lateRowsFromEquals = runner.execute("SELECT a FROM test_timestamptz_filter WHERE a = " + timestamptz); | ||
com.facebook.presto.testing.assertions.Assert.assertEquals(lateRows, lateRowsFromEquals); | ||
|
||
MaterializedResult earlyRows = runner.execute("SELECT a FROM test_timestamptz_filter WHERE a < " + timestamptz); | ||
assertEquals(earlyRows.getMaterializedRows().size(), 5); | ||
|
||
MaterializedResult earlyRowsFromEquals = runner.execute("SELECT a FROM test_timestamptz_filter WHERE a = " + earlyTimestamptz); | ||
com.facebook.presto.testing.assertions.Assert.assertEquals(earlyRows, earlyRowsFromEquals); | ||
} | ||
|
||
private QueryRunner getBatchReaderEnabledQueryRunner() | ||
{ | ||
checkState(batchReaderEnabledQueryRunner != null, "batchReaderEnabledQueryRunner not set"); | ||
return batchReaderEnabledQueryRunner; | ||
} | ||
} |
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 think we also need the mapping for the table below (prestodb -> iceberg)?
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.
Actually I'm not sure about this. The below table contains...
I suppose with and without zone just represent
isAdjustedUTC
in this case? Either way it looks like this part is covered. Maybe we should standardize the way we discuss these in the documentation though