5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-04 02:21:10 +08:00

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

(Jarek Jarcec Cecho via Abraham Elmahrek)
This commit is contained in:
Abraham Elmahrek 2015-02-05 15:24:23 -08:00
parent 3858e364a9
commit 922e1e6725
2 changed files with 50 additions and 0 deletions

View File

@ -24,6 +24,7 @@
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 @@ public boolean isSupportingScheme() {
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 @@ public void loadClass(String className) {
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);
}
}
}

View File

@ -121,6 +121,10 @@ protected void insertRow(Object ...values) {
provider.insertRow(getTableName(), values);
}
protected void dumpTable() {
provider.dumpTable(getTableName());
}
/**
* Fill link config based on currently active provider.
*