mirror of https://github.com/apache/nifi.git
NIFI-626: SQL timestamps were being added to Avro schema as string but value was being added as java.sql.Date object, which caused exceptions to be thrown. Now call toString() on the Date object to put to the record.
This commit is contained in:
parent
ae9b40ec6f
commit
ec02e58d3c
|
@ -52,7 +52,21 @@ public class JdbcCommon {
|
|||
while (rs.next()) {
|
||||
for (int i = 1; i <= nrOfColumns; i++) {
|
||||
final Object value = rs.getObject(i);
|
||||
rec.put(i - 1, value);
|
||||
|
||||
// The different types that we support are numbers (int,
|
||||
// long, double, float), as well
|
||||
// as boolean values and Strings. Since Avro doesn't provide
|
||||
// timestamp types, we want to
|
||||
// convert those to Strings. So we will cast anything other
|
||||
// than numbers or booleans to
|
||||
// strings by using to toString() method.
|
||||
if (value == null) {
|
||||
rec.put(i - 1, null);
|
||||
} else if (value instanceof Number || value instanceof Boolean) {
|
||||
rec.put(i - 1, value);
|
||||
} else {
|
||||
rec.put(i - 1, value.toString());
|
||||
}
|
||||
}
|
||||
dataFileWriter.append(rec);
|
||||
nrOfRows += 1;
|
||||
|
|
Loading…
Reference in New Issue