[
https://issues.apache.org/jira/browse/NIFI-9064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17401647#comment-17401647
]
ZhangCheng edited comment on NIFI-9064 at 8/19/21, 1:13 PM:
------------------------------------------------------------
Maybe I can fix this by making some change at DataTypeUtils.toTimestamp, sth
like
```
if ("oracle.sql.TIMESTAMP".equals(value.getClass().getName())) {
......
}
```
was (Author: ku_cheng):
Maybe I can fix this by making some change at DataTypeUtils.toTimestamp, sth
like
```
if ("oracle.sql.TIMESTAMP".equals(value.getClass().getName())) {
String orcValue = value.toString();
String orcFormat = "yyyy-MM-dd HH:mm:ss.SSS";
DateFormat dateFormat = getDateFormat(orcFormat);
if (orcValue.length() > orcFormat.length()) {
orcValue = orcValue.substring(0, orcValue.indexOf(".") + 4);
}
if (orcValue.length() < orcFormat.length()) {
int supplement = orcFormat.length() - orcValue.length();
while (supplement > 0) {
orcValue += '0';
supplement -- ;
}
}
try {
final java.util.Date utilDate = dateFormat.parse(orcValue);
return new Timestamp(utilDate.getTime());
} catch (ParseException e) {
throw new IllegalTypeConversionException("Could not convert
value [" + value
+ "] of Oracle DB to Timestamp for field " + fieldName
+ " because the value is not in the expected date format: "
+ orcFormat);
}
}
```
> ExecuteSQLRecord support Oracle timestamp when `Use Avro Logical Types` is
> true
> --------------------------------------------------------------------------------
>
> Key: NIFI-9064
> URL: https://issues.apache.org/jira/browse/NIFI-9064
> Project: Apache NiFi
> Issue Type: Bug
> Components: Extensions
> Affects Versions: 1.14.0
> Reporter: ZhangCheng
> Assignee: ZhangCheng
> Priority: Major
> Fix For: 1.15.0
>
>
> When the source db is Oracle, and the table has `timestamp` column, using
> `ExecuteSQLRecord`(the same as `QueryDatabaseTableRecord`) and set `Use Avro
> Logical Types` true, we will get sth like this:
> ```
> Caused by: java.io.IOException:
> org.apache.nifi.serialization.record.util.IllegalTypeConversionException:
> Cannot convert value [2021-08-19 10:58:50.000001] of type class
> oracle.sql.TIMESTAMP to Timestamp for field TS
> at
> org.apache.nifi.processors.standard.sql.RecordSqlWriter.writeResultSet(RecordSqlWriter.java:88)
> at
> org.apache.nifi.processors.standard.AbstractExecuteSQL.lambda$onTrigger$1(AbstractExecuteSQL.java:302)
> ... 14 common frames omitted
> ```
--
This message was sent by Atlassian Jira
(v8.3.4#803005)