Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/io/cdap/plugin/format/DBTableRecordReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.sql.Connection;
Expand All @@ -38,6 +40,8 @@
* Record reader that reads the entire contents of a database table using JDBC.
*/
public class DBTableRecordReader extends RecordReader<NullWritable, RecordWrapper> {
private static final Logger LOG = LoggerFactory.getLogger(DBTableRecordReader.class);

private final DBTableName tableName;
private final String tableNameField;
private final MultiTableConf dbConf;
Expand Down Expand Up @@ -85,6 +89,10 @@ public boolean nextKeyValue() throws IOException {
schema = Schema.recordOf(tableName.getTable(), schemaFields);
}
if (!results.next()) {
if (pos == 0 && DBTableSplit.DEFAULT_CLAUSE.equals(split.getLowerClause())
&& DBTableSplit.DEFAULT_CLAUSE.equals(split.getUpperClause())) {
LOG.info("Source table '{}' has zero records.", tableName.fullTableName());
}
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/cdap/plugin/format/DBTableSplit.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* A split representing data in a database table.
*/
public class DBTableSplit extends DataDrivenDBInputFormat.DataDrivenDBInputSplit {
private static final String DEFAULT_CLAUSE = "1=1";
public static final String DEFAULT_CLAUSE = "1=1";

private DBTableName tableName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ private List<InputSplit> getTableSplits(Connection connection, MultiTableDBConfi
columnName,
conf.getPluginConf().getWhereClause()))) {
results.next();
if (results.getObject(1) == null && results.getObject(2) == null) {
return Collections.singletonList(new DBTableSplit(info.getDbTableName()));
}

// Based on the type of the results, use a different mechanism
// for interpolating split points (i.e., numeric splits, text splits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public boolean nextKeyValue() throws IOException {
schema = Schema.recordOf(tableName, schemaFields);
}
if (!results.next()) {
if (pos == 0) {
LOG.info("SQL statement '{}' ('{}') has zero records.", split.getId(), split.getSqlStatement());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Logging the full SQL statement at INFO level can expose sensitive information (such as PII or credentials in the WHERE clause) in the logs. It can also lead to log bloat for very large queries. Consider logging only the statement ID at INFO level and moving the full query to DEBUG level.

          LOG.info("SQL statement '{}' has zero records.", split.getId());
          LOG.debug("SQL statement '{}' ('{}') has zero records.", split.getId(), split.getSqlStatement());

}
return false;
}

Expand Down