Repository: incubator-gobblin
Updated Branches:
  refs/heads/master a48396001 -> 67ace96cc


[GOBBLIN-197] Modify JDBCExtractor to support reading clob columns as strings

Closes #2053 from jenniferzheng/master


Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/67ace96c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/67ace96c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/67ace96c

Branch: refs/heads/master
Commit: 67ace96cc68a7018380f570849363f50cbdf3e97
Parents: a483960
Author: Jennifer Zheng <zheng...@usc.edu>
Authored: Thu Aug 10 21:42:38 2017 -0700
Committer: Abhishek Tiwari <abhishektiwari.bt...@gmail.com>
Committed: Thu Aug 10 21:42:38 2017 -0700

----------------------------------------------------------------------
 .../gobblin/source/jdbc/JdbcExtractor.java       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/67ace96c/gobblin-modules/gobblin-sql/src/main/java/org/apache/gobblin/source/jdbc/JdbcExtractor.java
----------------------------------------------------------------------
diff --git 
a/gobblin-modules/gobblin-sql/src/main/java/org/apache/gobblin/source/jdbc/JdbcExtractor.java
 
b/gobblin-modules/gobblin-sql/src/main/java/org/apache/gobblin/source/jdbc/JdbcExtractor.java
index 94f087c..a6cf8a1 100644
--- 
a/gobblin-modules/gobblin-sql/src/main/java/org/apache/gobblin/source/jdbc/JdbcExtractor.java
+++ 
b/gobblin-modules/gobblin-sql/src/main/java/org/apache/gobblin/source/jdbc/JdbcExtractor.java
@@ -19,6 +19,7 @@ package org.apache.gobblin.source.jdbc;
 
 import java.io.IOException;
 import java.sql.Blob;
+import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -1002,6 +1003,17 @@ public abstract class JdbcExtractor extends 
QueryBasedExtractor<JsonArray, JsonE
     return baString;
   }
 
+  /*
+  * For Clob data, we need to use the substring function to extract the string
+  */
+  private String readClobAsString(Clob logClob) throws SQLException {
+    if (logClob == null) {
+      return StringUtils.EMPTY;
+    }
+    long length = logClob.length();
+    return logClob.getSubString(1, (int) length);
+  }
+
   /**
    * HACK: there is a bug in the MysqlExtractor where tinyint columns are 
always treated as ints.
    * There are MySQL jdbc driver setting (tinyInt1isBit=true and 
transformedBitIsBoolean=false) that
@@ -1028,6 +1040,9 @@ public abstract class JdbcExtractor extends 
QueryBasedExtractor<JsonArray, JsonE
     if (isBlob(resultsetMetadata.getColumnType(i))) {
       return readBlobAsString(resultset.getBlob(i));
     }
+    if (isClob(resultsetMetadata.getColumnType(i))) {
+      return readClobAsString(resultset.getClob(i));
+    }
     if ((resultsetMetadata.getColumnType(i) == Types.BIT
          || resultsetMetadata.getColumnType(i) == Types.BOOLEAN)
         && convertBitToBoolean()) {
@@ -1040,6 +1055,10 @@ public abstract class JdbcExtractor extends 
QueryBasedExtractor<JsonArray, JsonE
     return columnType == Types.LONGVARBINARY || columnType == Types.BINARY;
   }
 
+  private static boolean isClob(int columnType) {
+    return columnType == Types.CLOB;
+  }
+
   protected static Command getCommand(String query, JdbcCommandType 
commandType) {
     return new JdbcCommand().build(Arrays.asList(query), commandType);
   }

Reply via email to