Skip to content

Commit feaff84

Browse files
author
psainics
committed
Log warning when a table has no records to read
When the multi-table source reads from tables that contain zero rows, the lack of output can be confusing to debug. This adds a WARN-level log line with the table name in both DBTableRecordReader and SQLStatementRecordReader so operators can quickly identify empty tables.
1 parent a63622a commit feaff84

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/main/java/io/cdap/plugin/format/DBTableRecordReader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.hadoop.mapreduce.InputSplit;
2525
import org.apache.hadoop.mapreduce.RecordReader;
2626
import org.apache.hadoop.mapreduce.TaskAttemptContext;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729

2830
import java.io.IOException;
2931
import java.sql.Connection;
@@ -38,6 +40,7 @@
3840
* Record reader that reads the entire contents of a database table using JDBC.
3941
*/
4042
public class DBTableRecordReader extends RecordReader<NullWritable, RecordWrapper> {
43+
private static final Logger LOG = LoggerFactory.getLogger(DBTableRecordReader.class);
4144
private final DBTableName tableName;
4245
private final String tableNameField;
4346
private final MultiTableConf dbConf;
@@ -85,6 +88,9 @@ public boolean nextKeyValue() throws IOException {
8588
schema = Schema.recordOf(tableName.getTable(), schemaFields);
8689
}
8790
if (!results.next()) {
91+
if (pos == 0) {
92+
LOG.warn("Table '{}' had no records to read.", tableName.getTable());
93+
}
8894
return false;
8995
}
9096

src/main/java/io/cdap/plugin/format/SQLStatementRecordReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import io.cdap.cdap.api.data.format.StructuredRecord;
2020
import io.cdap.cdap.api.data.schema.Schema;
2121
import io.cdap.plugin.DriverCleanup;
22-
import io.cdap.plugin.format.error.collector.ErrorCollectingMultiSQLStatementInputFormat;
2322
import org.apache.hadoop.io.NullWritable;
2423
import org.apache.hadoop.mapreduce.InputSplit;
2524
import org.apache.hadoop.mapreduce.RecordReader;
@@ -89,6 +88,9 @@ public boolean nextKeyValue() throws IOException {
8988
schema = Schema.recordOf(tableName, schemaFields);
9089
}
9190
if (!results.next()) {
91+
if (pos == 0) {
92+
LOG.warn("Table '{}' had no records to read.", tableName);
93+
}
9294
return false;
9395
}
9496

0 commit comments

Comments
 (0)