Skip to content

Commit

Permalink
0000860: Timestamp with timezone doesn't work with timestamp new wins…
Browse files Browse the repository at this point in the history
… conflict resolution

New timestamps were adjusting for the timezone. Existing timestamps were not adjusted for the timezone offset before being compared to the new timestamp.
  • Loading branch information
abrougher committed Oct 25, 2012
1 parent 924b37b commit e6859ab
Showing 1 changed file with 22 additions and 8 deletions.
Expand Up @@ -240,25 +240,39 @@ protected boolean isTimestampNewer(Conflict conflict, DatabaseWriter writer, Csv
DmlStatement stmt = writer.getPlatform().createDmlStatement(DmlType.FROM, table);
Column column = table.getColumnWithName(columnName);
String sql = stmt.getColumnsSql(new Column[] { column });
Timestamp existingTs = writer.getTransaction().queryForObject(sql, Timestamp.class,
objectValues);

Map<String, String> newData = data.toColumnNameValuePairs(table.getColumnNames(),
CsvData.ROW_DATA);
String columnValue = newData.get(columnName);
String loadingStr = newData.get(columnName);

Date loadingTs = null;
Date existingTs = null;
if (column.getMappedTypeCode() == -101) {
int split = columnValue.lastIndexOf(" ");
loadingTs = FormatUtils.parseDate(columnValue.substring(0, split).trim(),
// Get the existingTs with timezone
String existingStr = writer.getTransaction().queryForObject(sql, String.class,
objectValues);
int split = existingStr.lastIndexOf(" ");
existingTs = FormatUtils.parseDate(existingStr.substring(0, split).trim(),
FormatUtils.TIMESTAMP_PATTERNS,
TimeZone.getTimeZone(existingStr.substring(split).trim()));

// Get the loadingTs with timezone
split = loadingStr.lastIndexOf(" ");
loadingTs = FormatUtils.parseDate(loadingStr.substring(0, split).trim(),
FormatUtils.TIMESTAMP_PATTERNS,
TimeZone.getTimeZone(columnValue.substring(split).trim()));
TimeZone.getTimeZone(loadingStr.substring(split).trim()));
} else {
// Get the existingTs
existingTs = writer.getTransaction().queryForObject(sql, Timestamp.class,
objectValues);
// Get the loadingTs
Object[] values = platform.getObjectValues(writer.getBatch().getBinaryEncoding(),
new String[] { columnValue }, new Column[] { column });
new String[] { loadingStr }, new Column[] { column });
if (values[0] instanceof Date) {
loadingTs = (Date) values[0];
} else {
throw new ParseException("Could not parse " + columnName + " with a value of "
+ columnValue + " for purposes of conflict detection");
+ loadingStr + " for purposes of conflict detection");
}
}

Expand Down

0 comments on commit e6859ab

Please sign in to comment.