Skip to content

Commit 0f5dd7c

Browse files
Merge pull request #76 from data-integrations/PLUGIN-1950_log_zero_records-cherrypick
[Cherrypick] [PLUGIN-1950] : Log zero records for Table mode and SQL Statement mode and bump up
2 parents 67b9830 + 1a9d88e commit 0f5dd7c

5 files changed

Lines changed: 16 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<groupId>io.cdap.plugin</groupId>
2222
<artifactId>multi-table-plugins</artifactId>
23-
<version>1.4.1</version>
23+
<version>1.4.2-SNAPSHOT</version>
2424
<packaging>jar</packaging>
2525

2626
<name>Multiple Table Plugins</name>

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

Lines changed: 8 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,8 @@
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);
44+
4145
private final DBTableName tableName;
4246
private final String tableNameField;
4347
private final MultiTableConf dbConf;
@@ -85,6 +89,10 @@ public boolean nextKeyValue() throws IOException {
8589
schema = Schema.recordOf(tableName.getTable(), schemaFields);
8690
}
8791
if (!results.next()) {
92+
if (pos == 0 && DBTableSplit.DEFAULT_CLAUSE.equals(split.getLowerClause())
93+
&& DBTableSplit.DEFAULT_CLAUSE.equals(split.getUpperClause())) {
94+
LOG.info("Source table '{}' has zero records.", tableName.fullTableName());
95+
}
8896
return false;
8997
}
9098

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* A split representing data in a database table.
2727
*/
2828
public class DBTableSplit extends DataDrivenDBInputFormat.DataDrivenDBInputSplit {
29-
private static final String DEFAULT_CLAUSE = "1=1";
29+
public static final String DEFAULT_CLAUSE = "1=1";
3030

3131
private DBTableName tableName;
3232

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ private List<InputSplit> getTableSplits(Connection connection, MultiTableDBConfi
196196
columnName,
197197
conf.getPluginConf().getWhereClause()))) {
198198
results.next();
199+
if (results.getObject(1) == null && results.getObject(2) == null) {
200+
return Collections.singletonList(new DBTableSplit(info.getDbTableName()));
201+
}
199202

200203
// Based on the type of the results, use a different mechanism
201204
// for interpolating split points (i.e., numeric splits, text splits,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public boolean nextKeyValue() throws IOException {
8989
schema = Schema.recordOf(tableName, schemaFields);
9090
}
9191
if (!results.next()) {
92+
if (pos == 0) {
93+
LOG.info("SQL statement '{}' ('{}') has zero records.", split.getId(), split.getSqlStatement());
94+
}
9295
return false;
9396
}
9497

0 commit comments

Comments
 (0)