From 91d4193053ae2fc8e1707213d8d5fe78a9b2d2f8 Mon Sep 17 00:00:00 2001 From: Hsuan-Yi Chu Date: Thu, 12 Nov 2015 15:01:10 -0800 Subject: [PATCH] DRILL-4083: ScanPrel's CPU cost should not be zero even if column count is zero --- .../apache/drill/exec/hive/TestHiveStorage.java | 15 +++++++++++++++ .../drill/exec/planner/physical/ScanPrel.java | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java index 1112e8c0b4c..9d784fe11dc 100644 --- a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java +++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java @@ -36,6 +36,21 @@ public static void setupOptions() throws Exception { test(String.format("alter session set `%s` = true", PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY)); } + + @Test // DRILL-4083 + public void testNativeScanWhenNoColumnIsRead() throws Exception { + try { + test(String.format("alter session set `%s` = true", ExecConstants.HIVE_OPTIMIZE_SCAN_WITH_NATIVE_READERS)); + + String query = "SELECT count(*) FROM hive.readtest_parquet"; + testPhysicalPlan(query, "hive-drill-native-parquet-scan"); + } finally { + test(String.format("alter session set `%s` = %s", + ExecConstants.HIVE_OPTIMIZE_SCAN_WITH_NATIVE_READERS, + ExecConstants.HIVE_OPTIMIZE_SCAN_WITH_NATIVE_READERS_VALIDATOR.getDefault().bool_val ? "true" : "false")); + } + } + @Test public void hiveReadWithDb() throws Exception { test("select * from hive.kv"); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java index f69ee4c009f..b100d903f05 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java @@ -118,8 +118,9 @@ public RelOptCost computeSelfCost(final RelOptPlanner planner) { // double rowCount = RelMetadataQuery.getRowCount(this); double rowCount = stats.getRecordCount(); - - double cpuCost = rowCount * columnCount; // for now, assume cpu cost is proportional to row count. + // As DRILL-4083 points out, when columnCount == 0, cpuCost becomes zero, + // which makes the costs of HiveScan and HiveDrillNativeParquetScan the same + double cpuCost = rowCount * Math.max(columnCount, 1); // For now, assume cpu cost is proportional to row count. // If a positive value for CPU cost is given multiply the default CPU cost by given CPU cost. if (stats.getCpuCost() > 0) {