sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-1029: Oracle export using procedures does not work
Date Tue, 21 May 2013 06:10:17 GMT
Updated Branches:
  refs/heads/trunk 0bd1e8935 -> e76ee6eea


SQOOP-1029: Oracle export using procedures does not work

(Venkat Ranganathan via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/e76ee6ee
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/e76ee6ee
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/e76ee6ee

Branch: refs/heads/trunk
Commit: e76ee6eea5aa3afcfe496967a6280540576e9420
Parents: 0bd1e89
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon May 20 23:09:23 2013 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon May 20 23:09:23 2013 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/manager/OracleManager.java    |   48 ++++++++++++++-
 src/java/org/apache/sqoop/manager/SqlManager.java  |   34 ++++++-----
 2 files changed, 65 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/e76ee6ee/src/java/org/apache/sqoop/manager/OracleManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/manager/OracleManager.java b/src/java/org/apache/sqoop/manager/OracleManager.java
index 1999344..edc888e 100644
--- a/src/java/org/apache/sqoop/manager/OracleManager.java
+++ b/src/java/org/apache/sqoop/manager/OracleManager.java
@@ -21,6 +21,7 @@ package org.apache.sqoop.manager;
 import java.io.IOException;
 import java.lang.reflect.Method;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -38,8 +39,10 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.sqoop.util.LoggingUtils;
 
 import com.cloudera.sqoop.SqoopOptions;
 import com.cloudera.sqoop.SqoopOptions.UpdateMode;
@@ -50,7 +53,6 @@ import com.cloudera.sqoop.mapreduce.OracleUpsertOutputFormat;
 import com.cloudera.sqoop.mapreduce.db.OracleDataDrivenDBInputFormat;
 import com.cloudera.sqoop.util.ExportException;
 import com.cloudera.sqoop.util.ImportException;
-import org.apache.sqoop.util.LoggingUtils;
 
 /**
  * Manages connections to Oracle databases.
@@ -708,6 +710,50 @@ public class OracleManager
   }
 
   @Override
+  public String[] getColumnNamesForProcedure(String procedureName) {
+    List<String> ret = new ArrayList<String>();
+    try {
+      DatabaseMetaData metaData = this.getConnection().getMetaData();
+      ResultSet results = metaData.getProcedureColumns(null, null,
+        procedureName, null);
+      if (null == results) {
+        return null;
+      }
+
+      try {
+        while (results.next()) {
+          if (results.getInt("COLUMN_TYPE")
+          != DatabaseMetaData.procedureColumnReturn) {
+            int index = results.getInt("ORDINAL_POSITION");
+            if (index < 0) {
+              continue; // actually the return type
+            }
+            for (int i = ret.size(); i < index; ++i) {
+              ret.add(null);
+            }
+            String name = results.getString("COLUMN_NAME");
+            if (index == ret.size()) {
+              ret.add(name);
+            } else {
+              ret.set(index, name);
+            }
+          }
+        }
+        String[] result = ret.toArray(new String[ret.size()]);
+        LOG.debug("getColumnsNamesForProcedure returns "
+          + StringUtils.join(ret, ","));
+        return result;
+      } finally {
+        results.close();
+        getConnection().commit();
+      }
+    } catch (SQLException e) {
+      LoggingUtils.logAll(LOG, "Error reading procedure metadata: ", e);
+      throw new RuntimeException("Can't fetch column names for procedure.", e);
+    }
+  }
+
+  @Override
   public String[] getColumnNames(String tableName) {
     Connection conn = null;
     PreparedStatement pStmt = null;

http://git-wip-us.apache.org/repos/asf/sqoop/blob/e76ee6ee/src/java/org/apache/sqoop/manager/SqlManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/manager/SqlManager.java b/src/java/org/apache/sqoop/manager/SqlManager.java
index 6952b9e..e96368b 100644
--- a/src/java/org/apache/sqoop/manager/SqlManager.java
+++ b/src/java/org/apache/sqoop/manager/SqlManager.java
@@ -18,20 +18,6 @@
 
 package org.apache.sqoop.manager;
 
-import java.sql.Timestamp;
-
-import com.cloudera.sqoop.SqoopOptions;
-import com.cloudera.sqoop.hbase.HBaseUtil;
-import com.cloudera.sqoop.mapreduce.DataDrivenImportJob;
-import com.cloudera.sqoop.mapreduce.HBaseImportJob;
-import com.cloudera.sqoop.mapreduce.ImportJobBase;
-import com.cloudera.sqoop.mapreduce.JdbcExportJob;
-import com.cloudera.sqoop.mapreduce.JdbcUpdateExportJob;
-import com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat;
-import com.cloudera.sqoop.util.ExportException;
-import com.cloudera.sqoop.util.ImportException;
-import com.cloudera.sqoop.util.ResultSetPrinter;
-
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.sql.Connection;
@@ -40,22 +26,36 @@ import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
-import java.sql.Statement;
 import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.TreeMap;
 import java.util.Properties;
+import java.util.TreeMap;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.sqoop.mapreduce.JdbcCallExportJob;
 import org.apache.sqoop.util.LoggingUtils;
 import org.apache.sqoop.util.SqlTypeMap;
 
+import com.cloudera.sqoop.SqoopOptions;
+import com.cloudera.sqoop.hbase.HBaseUtil;
+import com.cloudera.sqoop.mapreduce.DataDrivenImportJob;
+import com.cloudera.sqoop.mapreduce.HBaseImportJob;
+import com.cloudera.sqoop.mapreduce.ImportJobBase;
+import com.cloudera.sqoop.mapreduce.JdbcExportJob;
+import com.cloudera.sqoop.mapreduce.JdbcUpdateExportJob;
+import com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat;
+import com.cloudera.sqoop.util.ExportException;
+import com.cloudera.sqoop.util.ImportException;
+import com.cloudera.sqoop.util.ResultSetPrinter;
+
 /**
  * ConnManager implementation for generic SQL-compliant database.
  * This is an abstract class; it requires a database-specific
@@ -196,6 +196,8 @@ public abstract class SqlManager
             }
           }
         }
+        LOG.debug("getColumnsNamesForProcedure returns "
+          + StringUtils.join(ret, ","));
         return ret.toArray(new String[ret.size()]);
       } finally {
         results.close();


Mime
View raw message