mirror of
https://github.com/apache/sqoop.git
synced 2025-05-07 07:40:18 +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:
parent
3858e364a9
commit
922e1e6725
@ -24,6 +24,7 @@
|
|||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -129,6 +130,14 @@ public boolean isSupportingScheme() {
|
|||||||
return false;
|
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() {
|
public String getJdbcDriver() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -508,4 +517,41 @@ public void loadClass(String className) {
|
|||||||
throw new RuntimeException("Class not found: " + className, e);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,10 @@ protected void insertRow(Object ...values) {
|
|||||||
provider.insertRow(getTableName(), values);
|
provider.insertRow(getTableName(), values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void dumpTable() {
|
||||||
|
provider.dumpTable(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill link config based on currently active provider.
|
* Fill link config based on currently active provider.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user