Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/src/main/java/org/apache/hop/core/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,18 @@ public String getMessage() {
public static final String HOP_LENIENT_STRING_TO_NUMBER_CONVERSION =
"HOP_LENIENT_STRING_TO_NUMBER_CONVERSION";

/*
* Restore the flag HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE dropped from upstream ValueMetaBase during
* the 1.2.0 -> 2.x migration. See DLPX-87054.
*/
/** Systemwide flag to ignore timezone while writing date/timestamp value to the database. */
@Variable(
value = "N",
description =
"System wide flag to ignore timezone while writing date/timestamp value to the database. Needed for Teradata, whose JDBC driver assigns a different SQL type to timestamp parameters bound via the Calendar-aware PreparedStatement overload, which breaks batch inserts mixing null and non-null rows for the same column.")
public static final String HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE =
"HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE";

/**
* You can use this variable to speed up hostname lookup. Hostname lookup is performed by Hop so
* that it is capable of logging the server on which a workflow or pipeline is executed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public class ValueMetaBase implements IValueMeta {
protected boolean dateFormatLenient;
protected boolean lenientStringToNumber;
protected boolean emptyStringAndNullAreDifferent;
protected boolean ignoreTimezone;
Comment thread
srusia-delphix marked this conversation as resolved.

@JsonIgnore protected SimpleDateFormat dateFormat;
@JsonIgnore protected boolean dateFormatChanged;
Expand Down Expand Up @@ -335,6 +336,9 @@ public ValueMetaBase(
this.emptyStringAndNullAreDifferent =
convertStringToBoolean(
Const.NVL(System.getProperty(Const.HOP_EMPTY_STRING_DIFFERS_FROM_NULL, "N"), "N"));
this.ignoreTimezone =
convertStringToBoolean(
Const.NVL(System.getProperty(Const.HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE, "N"), "N"));

this.comparator = comparator;
determineSingleByteEncoding();
Expand Down Expand Up @@ -481,6 +485,7 @@ && getPrecision() == that.getPrecision()
&& dateFormatLenient == that.dateFormatLenient
&& lenientStringToNumber == that.lenientStringToNumber
&& emptyStringAndNullAreDifferent == that.emptyStringAndNullAreDifferent
&& ignoreTimezone == that.ignoreTimezone
&& Objects.equals(name, that.name)
&& Objects.equals(conversionMask, that.conversionMask)
&& Objects.equals(stringEncoding, that.stringEncoding)
Expand Down Expand Up @@ -522,7 +527,8 @@ public int hashCode() {
dateFormatTimeZone,
dateFormatLenient,
lenientStringToNumber,
emptyStringAndNullAreDifferent);
emptyStringAndNullAreDifferent,
ignoreTimezone);
result = 31 * result + Arrays.hashCode(index);
return result;
}
Expand Down Expand Up @@ -5851,7 +5857,7 @@ public void setPreparedStatementValue(
// is not yet implemented
preparedStatement.setDate(index, ddate);
} else {
if (this.getDateFormatTimeZone() == null) {
if (ignoreTimezone || this.getDateFormatTimeZone() == null) {
preparedStatement.setDate(index, ddate);
} else {
preparedStatement.setDate(
Expand All @@ -5868,7 +5874,7 @@ public void setPreparedStatementValue(
// is not yet implemented
preparedStatement.setTimestamp(index, timestamp);
} else {
if (this.getDateFormatTimeZone() == null) {
if (ignoreTimezone || this.getDateFormatTimeZone() == null) {
preparedStatement.setTimestamp(index, timestamp);
} else {
preparedStatement.setTimestamp(
Expand All @@ -5884,7 +5890,7 @@ public void setPreparedStatementValue(
// is not yet implemented
preparedStatement.setTimestamp(index, sdate);
} else {
if (this.getDateFormatTimeZone() == null) {
if (ignoreTimezone || this.getDateFormatTimeZone() == null) {
Comment thread
srusia-delphix marked this conversation as resolved.
preparedStatement.setTimestamp(index, sdate);
} else {
preparedStatement.setTimestamp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -30,13 +31,15 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import org.apache.hop.core.Const;
import org.apache.hop.core.database.BaseDatabaseMeta;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.database.IDatabase;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.RowMeta;
import org.apache.hop.junit.rules.RestoreHopEnvironment;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
Expand All @@ -61,6 +64,11 @@ public void setUp() {
ts = new Timestamp(System.currentTimeMillis());
}

@After
public void tearDown() {
System.clearProperty(Const.HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE);
}

@Test
public void testXMLParsingWithNoDataFormatLocale() throws IOException {
IValueMeta r1 = new ValueMetaString("value");
Expand Down Expand Up @@ -99,4 +107,27 @@ public void testConvertedTimestampRegular() throws Exception {

verify(ps).setTimestamp(eq(1), any(Timestamp.class), any(Calendar.class));
}

@Test
public void testTimestampWithIgnoreTimezoneSkipsCalendarOverload() throws Exception {
System.setProperty(Const.HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE, "Y");

ValueMetaBase valueMeta = new ValueMetaDate("");
valueMeta.setPreparedStatementValue(dbMeta, ps, 1, ts);

verify(ps).setTimestamp(eq(1), any(Timestamp.class));
verify(ps, never()).setTimestamp(eq(1), any(Timestamp.class), any(Calendar.class));
}

@Test
public void testDateWithIgnoreTimezoneSkipsCalendarOverload() throws Exception {
System.setProperty(Const.HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE, "Y");

ValueMetaBase valueMeta = new ValueMetaDate("");
valueMeta.setPrecision(1);
valueMeta.setPreparedStatementValue(dbMeta, ps, 1, date);

verify(ps).setDate(eq(1), any(java.sql.Date.class));
verify(ps, never()).setDate(eq(1), any(java.sql.Date.class), any(Calendar.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ protected void before() throws Throwable {
System.clearProperty(Const.HOP_DEFAULT_DATE_FORMAT);
System.clearProperty(Const.HOP_DEFAULT_TIMESTAMP_FORMAT);
System.clearProperty(Const.HOP_EMPTY_STRING_DIFFERS_FROM_NULL);
System.clearProperty(Const.HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE);
Comment thread
srusia-delphix marked this conversation as resolved.

defaultInit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void beforeAll(ExtensionContext context) throws Exception {
System.clearProperty(Const.HOP_DEFAULT_DATE_FORMAT);
System.clearProperty(Const.HOP_DEFAULT_TIMESTAMP_FORMAT);
System.clearProperty(Const.HOP_EMPTY_STRING_DIFFERS_FROM_NULL);
System.clearProperty(Const.HOP_COMPATIBILITY_DB_IGNORE_TIMEZONE);

try {
defaultInit();
Expand Down
Loading