sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject sqoop git commit: SQOOP-2081: Sqoop2: Provide ability to dump content of testing table to log
Date Thu, 05 Feb 2015 23:24:46 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 3858e364a -> 922e1e672


SQOOP-2081: Sqoop2: Provide ability to dump content of testing table to log

(Jarek Jarcec Cecho via Abraham Elmahrek)


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

Branch: refs/heads/sqoop2
Commit: 922e1e6725cd369d6eb6dcce34fc502684a50b0a
Parents: 3858e36
Author: Abraham Elmahrek <abe@apache.org>
Authored: Thu Feb 5 15:24:23 2015 -0800
Committer: Abraham Elmahrek <abe@apache.org>
Committed: Thu Feb 5 15:24:23 2015 -0800

----------------------------------------------------------------------
 .../sqoop/common/test/db/DatabaseProvider.java  | 46 ++++++++++++++++++++
 .../sqoop/test/testcases/ConnectorTestCase.java |  4 ++
 2 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/922e1e67/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
index be04caa..410aa3c 100644
--- a/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
@@ -24,6 +24,7 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.LinkedList;
@@ -129,6 +130,14 @@ abstract public class DatabaseProvider {
     return false;
   }
 
+  /**
+   * JDBC Driver class name.
+   *
+   * Fully qualified name of the driver class, so that Class.forName() or
+   * similar facility can be used.
+   *
+   * @return
+   */
   public String getJdbcDriver() {
     return null;
   }
@@ -508,4 +517,41 @@ abstract public class DatabaseProvider {
       throw new RuntimeException("Class not found: " + className, e);
     }
   }
+
+  /**
+   * Dump content of given table to log.
+   *
+   * @param tableName Name of the table
+   */
+  public void dumpTable(String tableName) {
+    String query = "SELECT * FROM " + escapeTableName(tableName);
+    List<String> list = new LinkedList<String>();
+    ResultSet rs = null;
+
+    try {
+      rs = executeQuery(query);
+
+      // Header with column names
+      ResultSetMetaData md = rs.getMetaData();
+      for(int i = 0; i < md.getColumnCount(); i++) {
+        list.add(md.getColumnName(i+1));
+      }
+      LOG.info("Dumping table " + tableName);
+      LOG.info("|" + StringUtils.join(list, "|") + "|");
+
+      // Table rows
+      while(rs.next()) {
+        list.clear();
+        for(int i = 0; i < md.getColumnCount(); i++) {
+          list.add(rs.getObject(i+1).toString());
+        }
+        LOG.info("|" + StringUtils.join(list, "|") + "|");
+      }
+
+    } catch (SQLException e) {
+      LOG.info("Ignoring exception: ", e);
+    } finally {
+      closeResultSetWithStatement(rs);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/922e1e67/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java b/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
index 2d28a9a..398a051 100644
--- a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
+++ b/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
@@ -121,6 +121,10 @@ abstract public class ConnectorTestCase extends TomcatTestCase {
     provider.insertRow(getTableName(), values);
   }
 
+  protected void dumpTable() {
+    provider.dumpTable(getTableName());
+  }
+
   /**
    * Fill link config based on currently active provider.
    *


Mime
View raw message