-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow running tests with a connector that supports TIMESTAMP but not …
…DATE For this, `H2QueryRunner` needs to be able to convert a DATE value to TIMESTAMP. It used to be able when `ResultSet.getTimestamp` was used to retrieve the TIMESTAMP value, but this broke when Java Time classes were used to retrieve values from the `ResultSet`.
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
presto-tests/src/test/java/com/facebook/presto/tests/TestH2QueryRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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.tests; | ||
|
||
import com.facebook.presto.testing.MaterializedResult; | ||
import com.google.common.collect.ImmutableList; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import static com.facebook.presto.SessionTestUtils.TEST_SESSION; | ||
import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; | ||
import static com.google.common.base.Preconditions.checkState; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
public class TestH2QueryRunner | ||
{ | ||
private H2QueryRunner h2QueryRunner; | ||
|
||
@BeforeClass | ||
public void init() | ||
{ | ||
h2QueryRunner = new H2QueryRunner(); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
public void close() | ||
{ | ||
h2QueryRunner.close(); | ||
h2QueryRunner = null; | ||
} | ||
|
||
@Test | ||
public void testDateToTimestampCoercion() | ||
{ | ||
// allow running tests with a connector that supports TIMESTAMP but not DATE | ||
|
||
// ordinary date | ||
MaterializedResult rows = h2QueryRunner.execute(TEST_SESSION, "SELECT DATE '2018-01-13'", ImmutableList.of(TIMESTAMP)); | ||
assertEquals(rows.getOnlyValue(), LocalDate.of(2018, 1, 13).atStartOfDay()); | ||
|
||
// date, which midnight was skipped in JVM zone | ||
LocalDate forwardOffsetChangeAtMidnightInJvmZone = LocalDate.of(1986, 1, 1); | ||
checkState(ZoneId.systemDefault().getRules().getValidOffsets(forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()).size() == 0, "This test assumes certain JVM time zone"); | ||
rows = h2QueryRunner.execute(TEST_SESSION, DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(forwardOffsetChangeAtMidnightInJvmZone), ImmutableList.of(TIMESTAMP)); | ||
assertEquals(rows.getOnlyValue(), forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()); | ||
} | ||
} |