Skip to content

Commit 1e9befd

Browse files
dvjyothsnasohami
authored andcommitted
DRILL-7166: Count query with wildcard should skip reading of metadata summary file
1 parent bf07127 commit 1e9befd

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/ConvertCountToDirectScanRule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,14 @@ public void onMatch(RelOptRuleCall call) {
138138

139139
// Rule is applicable only if the statistics for row count and null count are available from the metadata,
140140
FormatSelection formatSelection = (FormatSelection) selection;
141-
Pair<Boolean, Metadata_V4.MetadataSummary> status = checkMetadataForScanStats(settings, drillTable, formatSelection);
142141

142+
// Rule cannot be applied if the selection had wildcard since the totalrowcount cannot be read from the parent directory
143+
if (formatSelection.getSelection().hadWildcard()) {
144+
logger.debug("Rule does not apply when there is a wild card since the COUNT could not be determined from metadata.");
145+
return;
146+
}
147+
148+
Pair<Boolean, Metadata_V4.MetadataSummary> status = checkMetadataForScanStats(settings, drillTable, formatSelection);
143149
if (!status.getLeft()) {
144150
logger.debug("Rule does not apply since MetadataSummary metadata was not found.");
145151
return;

exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/TestConvertCountToDirectScan.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,40 @@ public void testCountsWithMetadataCacheSummaryAndDirPruning() throws Exception {
238238
test("drop table if exists %s", tableName);
239239
}
240240
}
241+
242+
@Test
243+
public void testCountsWithWildCard() throws Exception {
244+
test("use dfs.tmp");
245+
String tableName = "parquet_table_counts";
246+
247+
try {
248+
for (int i = 0; i < 10; i++) {
249+
test(String.format("create table `%s/12/%s` as select * from cp.`tpch/nation.parquet`", tableName, i));
250+
}
251+
test(String.format("create table `%s/2` as select * from cp.`tpch/nation.parquet`", tableName));
252+
test(String.format("create table `%s/2/11` as select * from cp.`tpch/nation.parquet`", tableName));
253+
test(String.format("create table `%s/2/12` as select * from cp.`tpch/nation.parquet`", tableName));
254+
255+
test("refresh table metadata %s", tableName);
256+
257+
String sql = String.format("select\n" +
258+
"count(*) as star_count\n" +
259+
"from `%s/1*`", tableName);
260+
261+
String usedMetaSummaryPattern = "usedMetadataSummaryFile = false";
262+
String recordReaderPattern = "DynamicPojoRecordReader";
263+
264+
testPlanMatchingPatterns(sql, new String[]{usedMetaSummaryPattern, recordReaderPattern});
265+
266+
testBuilder()
267+
.sqlQuery(sql)
268+
.unOrdered()
269+
.baselineColumns("star_count")
270+
.baselineValues(250L)
271+
.go();
272+
273+
} finally {
274+
test("drop table if exists %s", tableName);
275+
}
276+
}
241277
}

0 commit comments

Comments
 (0)