[
https://issues.apache.org/jira/browse/NIFI-4830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16357847#comment-16357847
]
ASF subversion and git services commented on NIFI-4830:
-------------------------------------------------------
Commit 7d6bbce123a75eb889ee6d2c8b2a0ed786b78cb7 in nifi's branch
refs/heads/master from [~ca9mbu]
[ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=7d6bbce ]
NIFI-4830: Fixed logic errors in BLOB/CLOB processing in JdbcCommon
This closes #2459.
Signed-off-by: Koji Kawamura <[email protected]>
> Blob not being read properly from Database to Avro
> --------------------------------------------------
>
> Key: NIFI-4830
> URL: https://issues.apache.org/jira/browse/NIFI-4830
> Project: Apache NiFi
> Issue Type: Bug
> Reporter: Israel Varea
> Assignee: Matt Burgess
> Priority: Major
>
> When using QueryDatabaseTable or any other component using JdbcCommon.java,
> the Blob column of the database is not fetched correctly to the Avro
> ByteBuffer. Instead of fetching whole file, only first bytes which are
> different to zero are added. Then, the rest of the bytes remain with zero
> value.
> Specifically, this code in JdbcCommon.java should be fixed:
> {code:java}
> if (javaSqlType == BLOB) {
> Blob blob = rs.getBlob(i);
> if (blob != null) {
> long numChars = blob.length();
> byte[] buffer = new byte[(int) numChars];
> InputStream is = blob.getBinaryStream();
> int index = 0;
> int c = is.read();
> while (c > 0) {
> buffer[index++] = (byte) c;
> c = is.read();
> }
> ByteBuffer bb = ByteBuffer.wrap(buffer);
> rec.put(i - 1, bb);
> blob.free();
> } else {
> rec.put(i - 1, null);
> }
> continue;
> }
> {code}
> Notice the while statement.
> The whole block should be replaced for something like
> {code:java}
> if (javaSqlType == BLOB) {
> Blob blob = rs.getBlob(i);
> if (blob != null) {
> long blobLength = blob.length();
>
> byte[] blobAsBytes = blob.getBytes(1,
> (int)blobLength);
> ByteBuffer bb = ByteBuffer.wrap(blobAsBytes);
> rec.put(i - 1, bb);
> blob.free();
> } else {
> rec.put(i - 1, null);
> }
> continue;
> }
> {code}
> This has been tested locally and it works! :)
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)