From 116241f1d1e0c58800fca3d6519dd44367de65ca Mon Sep 17 00:00:00 2001 From: Michael Ubell Date: Mon, 29 Oct 2012 16:26:10 -0700 Subject: [PATCH] IMP-497 Insert with limit. --- .../com/cloudera/impala/planner/Planner.java | 9 ++- .../queries/PlannerTest/insert.test | 81 +++++++++++++++++++ .../queries/QueryTest/insert_null.test | 2 +- 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/fe/src/main/java/com/cloudera/impala/planner/Planner.java b/fe/src/main/java/com/cloudera/impala/planner/Planner.java index 2074559f9..eafb77d67 100644 --- a/fe/src/main/java/com/cloudera/impala/planner/Planner.java +++ b/fe/src/main/java/com/cloudera/impala/planner/Planner.java @@ -96,11 +96,16 @@ public class Planner { // single-node execution; we're almost done fragments.add(new PlanFragment(singleNodePlan, DataPartition.UNPARTITIONED)); } else { - // leave the root fragment partitioned if we end up writing to a table; + // leave the root fragment partitioned if we end up writing to a table unless + // there a limit; // otherwise merge everything into a single coordinator fragment, so we can // pass it back to the client + boolean isPartitioned = false; + if (analysisResult.isInsertStmt() && !queryStmt.hasLimitClause()) { + isPartitioned = true; + } createPlanFragments( - singleNodePlan, analysisResult.isInsertStmt(), queryOptions.partition_agg, + singleNodePlan, isPartitioned, queryOptions.partition_agg, fragments); } diff --git a/testdata/workloads/functional-planner/queries/PlannerTest/insert.test b/testdata/workloads/functional-planner/queries/PlannerTest/insert.test index 812fb4be7..33d6f5935 100644 --- a/testdata/workloads/functional-planner/queries/PlannerTest/insert.test +++ b/testdata/workloads/functional-planner/queries/PlannerTest/insert.test @@ -167,3 +167,84 @@ NODE 0: HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=4/100401.txt 0:20179 LOCATIONS: ==== +# insert with limit from paritioned table. +insert into table alltypesnopart +select * +from alltypes limit 10 +---- PLAN +Plan Fragment 0 + UNPARTITIONED + WRITE TO HDFS table=default.alltypesnopart + OVERWRITE=false + SCAN HDFS table=default.alltypes (0) + LIMIT: 10 + TUPLE IDS: 0 +---- DISTRIBUTEDPLAN +Plan Fragment 0 + UNPARTITIONED + WRITE TO HDFS table=default.alltypesnopart + OVERWRITE=false + EXCHANGE (1) + LIMIT: 10 + TUPLE IDS: 0 + +Plan Fragment 1 + RANDOM + STREAM DATA SINK + EXCHANGE ID: 1 + UNPARTITIONED + + SCAN HDFS table=default.alltypes (0) + LIMIT: 10 + TUPLE IDS: 0 +---- SCANRANGELOCATIONS +NODE 0: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=1/090101.txt 0:20433 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=10/091001.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=11/091101.txt 0:20179 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=12/091201.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=2/090201.txt 0:18555 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=3/090301.txt 0:20543 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=4/090401.txt 0:20079 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=5/090501.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=6/090601.txt 0:20179 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=7/090701.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=8/090801.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2009/month=9/090901.txt 0:20179 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=1/100101.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=10/101001.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=11/101101.txt 0:20179 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=12/101201.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=2/100201.txt 0:18835 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=3/100301.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=4/100401.txt 0:20179 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=5/100501.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=6/100601.txt 0:20179 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=7/100701.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=8/100801.txt 0:20853 + LOCATIONS: + HDFS SPLIT hdfs://localhost:20500/test-warehouse/alltypes/year=2010/month=9/100901.txt 0:20179 + LOCATIONS: +==== diff --git a/testdata/workloads/functional-query/queries/QueryTest/insert_null.test b/testdata/workloads/functional-query/queries/QueryTest/insert_null.test index 5aab42964..1a5f8c074 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/insert_null.test +++ b/testdata/workloads/functional-query/queries/QueryTest/insert_null.test @@ -1,5 +1,5 @@ insert overwrite table nullinsert$TABLE -select NULL, "", "NULL", "\\N", NULL from alltypes where id = 0 +select NULL, "", "NULL", "\\N", NULL from alltypes limit 1 ---- SETUP RESET nullinsert$TABLE ---- RESULTS