DRILL-8392: Empty Tables Causes Index Out of Bounds Exception on PDF Reader (#2744)
diff --git a/contrib/format-pdf/src/main/java/org/apache/drill/exec/store/pdf/PdfBatchReader.java b/contrib/format-pdf/src/main/java/org/apache/drill/exec/store/pdf/PdfBatchReader.java
index 26d3a94..05dd3b4 100644
--- a/contrib/format-pdf/src/main/java/org/apache/drill/exec/store/pdf/PdfBatchReader.java
+++ b/contrib/format-pdf/src/main/java/org/apache/drill/exec/store/pdf/PdfBatchReader.java
@@ -218,8 +218,16 @@
if (!Strings.isNullOrEmpty(value)) {
writers.get(rowPosition).load(row.get(rowPosition));
+
+ // If there is not a provided schema, advance the row position index only when values are found
+ if (negotiator.providedSchema() == null) {
+ rowPosition++;
+ }
}
- rowPosition++;
+ // Advance the row position index when there is a provided schema.
+ if (negotiator.providedSchema() != null) {
+ rowPosition++;
+ }
}
metadataReader.writeMetadata();