Skip to content

Commit

Permalink
Merge branch '5.4.x' into 5.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ncliang committed Sep 1, 2020
2 parents 3fee230 + 37a2b95 commit ff9f621
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,8 @@ protected ColumnConverter columnConverterFor(

// Date is day + month + year
case Types.DATE: {
return rs -> rs.getDate(col, DateTimeUtils.getTimeZoneCalendar(timeZone));
return rs -> rs.getDate(col,
DateTimeUtils.getTimeZoneCalendar(TimeZone.getTimeZone(ZoneOffset.UTC)));
}

// Time is a time of day -- hour, minute, seconds, nanoseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
Expand All @@ -48,18 +50,26 @@
@RunWith(Parameterized.class)
public class JdbcSourceTaskConversionTest extends JdbcSourceTaskTestBase {

@Parameterized.Parameters
public static Object[] mapping() {
return new Object[] { false, true };
@Parameterized.Parameters(name="extendedMapping: {0}, timezone: {1}")
public static Collection<Object[]> mapping() {
return Arrays.asList(new Object[][] {
{false, TimeZone.getTimeZone("UTC")},
{true, TimeZone.getTimeZone("UTC")},
{false, TimeZone.getTimeZone("America/Los_Angeles")},
{true, TimeZone.getTimeZone("Asia/Kolkata")}
});
}

@Parameterized.Parameter
@Parameterized.Parameter(0)
public boolean extendedMapping;

@Parameterized.Parameter(1)
public TimeZone timezone;

@Before
public void setup() throws Exception {
super.setup();
task.start(singleTableConfig(extendedMapping));
task.start(singleTableWithTimezoneConfig(extendedMapping, timezone));
}

@After
Expand Down Expand Up @@ -258,7 +268,7 @@ public void testNullableDate() throws Exception {
@Test
public void testTime() throws Exception {
GregorianCalendar expected = new GregorianCalendar(1970, Calendar.JANUARY, 1, 23, 3, 20);
expected.setTimeZone(TimeZone.getTimeZone("UTC"));
expected.setTimeZone(timezone);
typeConversion("TIME", false, "23:03:20",
Time.builder().build(),
expected.getTime());
Expand All @@ -267,7 +277,7 @@ public void testTime() throws Exception {
@Test
public void testNullableTime() throws Exception {
GregorianCalendar expected = new GregorianCalendar(1970, Calendar.JANUARY, 1, 23, 3, 20);
expected.setTimeZone(TimeZone.getTimeZone("UTC"));
expected.setTimeZone(timezone);
typeConversion("TIME", true, "23:03:20",
Time.builder().optional().build(),
expected.getTime());
Expand All @@ -279,7 +289,7 @@ public void testNullableTime() throws Exception {
@Test
public void testTimestamp() throws Exception {
GregorianCalendar expected = new GregorianCalendar(1977, Calendar.FEBRUARY, 13, 23, 3, 20);
expected.setTimeZone(TimeZone.getTimeZone("UTC"));
expected.setTimeZone(timezone);
typeConversion("TIMESTAMP", false, "1977-02-13 23:03:20",
Timestamp.builder().build(),
expected.getTime());
Expand All @@ -288,7 +298,7 @@ public void testTimestamp() throws Exception {
@Test
public void testNullableTimestamp() throws Exception {
GregorianCalendar expected = new GregorianCalendar(1977, Calendar.FEBRUARY, 13, 23, 3, 20);
expected.setTimeZone(TimeZone.getTimeZone("UTC"));
expected.setTimeZone(timezone);
typeConversion("TIMESTAMP", true, "1977-02-13 23:03:20",
Timestamp.builder().optional().build(),
expected.getTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

import static io.confluent.connect.jdbc.source.JdbcSourceConnectorConfig.NumericMapping;

Expand Down Expand Up @@ -103,6 +104,14 @@ protected Map<String, String> singleTableConfig(boolean completeMapping) {
return props;
}

protected Map<String, String> singleTableWithTimezoneConfig(
boolean completeMapping,
TimeZone tz) {
Map<String, String> props = singleTableConfig(completeMapping);
props.put(JdbcSourceTaskConfig.DB_TIMEZONE_CONFIG, tz.getID());
return props;
}

protected Map<String, String> twoTableConfig() {
Map<String, String> props = new HashMap<>();
props.put(JdbcSourceConnectorConfig.CONNECTION_URL_CONFIG, db.getUrl());
Expand Down

0 comments on commit ff9f621

Please sign in to comment.