diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java index 50f86df..953f3ae 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java @@ -145,7 +145,7 @@ public void validateAndMakeEffective() throws SemanticException { } // 2. A Window Spec with no Parition Spec, is Partitioned on a Constant(number 0) - applyContantPartition(wdwSpec); + applyConstantPartition(wdwSpec); // 3. For missing Wdw Frames or for Frames with only a Start Boundary, completely // specify them by the rules in {@link effectiveWindowFrame} @@ -154,8 +154,8 @@ public void validateAndMakeEffective() throws SemanticException { // 4. Validate the effective Window Frames with the rules in {@link validateWindowFrame} validateWindowFrame(wdwSpec); - // 5. If there is no Order, then add the Partition expressions as the Order. - wdwSpec.ensureOrderSpec(); + // 5. Add the Partition expressions as the Order if there is no Order and validate Order spec. + setAndValidateOrderSpec(wdwSpec); } } @@ -196,7 +196,7 @@ private void fillInWindowSpec(String sourceId, WindowSpec dest, ArrayList 1 ) { throw new SemanticException("Range based Window Frame can have only 1 Sort Key"); } + + if (start instanceof ValueBoundarySpec) { + ((ValueBoundarySpec)start).setExpression(order.getExpressions().get(0).getExpression()); + } + if (end instanceof ValueBoundarySpec) { + ((ValueBoundarySpec)end).setExpression(order.getExpressions().get(0).getExpression()); + } } - vbs.setExpression(order.getExpressions().get(0).getExpression()); } } diff --git a/ql/src/test/queries/clientpositive/windowing_windowspec3.q b/ql/src/test/queries/clientpositive/windowing_windowspec3.q new file mode 100644 index 0000000..09a5caf --- /dev/null +++ b/ql/src/test/queries/clientpositive/windowing_windowspec3.q @@ -0,0 +1,21 @@ +-- Test value based windowing spec +drop table over10k; + +create table over10k( + t tinyint, + si smallint, + i int, + b bigint, + f float, + d double, + bo boolean, + s string, + ts timestamp, + dec decimal, + bin binary) + row format delimited + fields terminated by '|'; + +load data local inpath '../../data/files/over10k' into table over10k; + +select ts, f, sum(f) over (partition by ts range between current row and unbounded following) from over10k limit 100; diff --git a/ql/src/test/results/clientpositive/windowing_windowspec3.q.out b/ql/src/test/results/clientpositive/windowing_windowspec3.q.out new file mode 100644 index 0000000..b773535 --- /dev/null +++ b/ql/src/test/results/clientpositive/windowing_windowspec3.q.out @@ -0,0 +1,156 @@ +PREHOOK: query: -- Test value based windowing spec +drop table over10k +PREHOOK: type: DROPTABLE +POSTHOOK: query: -- Test value based windowing spec +drop table over10k +POSTHOOK: type: DROPTABLE +PREHOOK: query: create table over10k( + t tinyint, + si smallint, + i int, + b bigint, + f float, + d double, + bo boolean, + s string, + ts timestamp, + dec decimal, + bin binary) + row format delimited + fields terminated by '|' +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@over10k +POSTHOOK: query: create table over10k( + t tinyint, + si smallint, + i int, + b bigint, + f float, + d double, + bo boolean, + s string, + ts timestamp, + dec decimal, + bin binary) + row format delimited + fields terminated by '|' +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@over10k +PREHOOK: query: load data local inpath '../../data/files/over10k' into table over10k +PREHOOK: type: LOAD +#### A masked pattern was here #### +PREHOOK: Output: default@over10k +POSTHOOK: query: load data local inpath '../../data/files/over10k' into table over10k +POSTHOOK: type: LOAD +#### A masked pattern was here #### +POSTHOOK: Output: default@over10k +PREHOOK: query: select ts, f, sum(f) over (partition by ts range between current row and unbounded following) from over10k limit 100 +PREHOOK: type: QUERY +PREHOOK: Input: default@over10k +#### A masked pattern was here #### +POSTHOOK: query: select ts, f, sum(f) over (partition by ts range between current row and unbounded following) from over10k limit 100 +POSTHOOK: type: QUERY +POSTHOOK: Input: default@over10k +#### A masked pattern was here #### +2013-03-01 09:11:58.70307 54.36 1276.850001335144 +2013-03-01 09:11:58.70307 81.41 1276.850001335144 +2013-03-01 09:11:58.70307 87.43 1276.850001335144 +2013-03-01 09:11:58.70307 14.78 1276.850001335144 +2013-03-01 09:11:58.70307 95.04 1276.850001335144 +2013-03-01 09:11:58.70307 38.61 1276.850001335144 +2013-03-01 09:11:58.70307 73.52 1276.850001335144 +2013-03-01 09:11:58.70307 41.6 1276.850001335144 +2013-03-01 09:11:58.70307 78.58 1276.850001335144 +2013-03-01 09:11:58.70307 38.35 1276.850001335144 +2013-03-01 09:11:58.70307 84.71 1276.850001335144 +2013-03-01 09:11:58.70307 91.36 1276.850001335144 +2013-03-01 09:11:58.70307 40.54 1276.850001335144 +2013-03-01 09:11:58.70307 29.22 1276.850001335144 +2013-03-01 09:11:58.70307 3.17 1276.850001335144 +2013-03-01 09:11:58.70307 39.48 1276.850001335144 +2013-03-01 09:11:58.70307 20.61 1276.850001335144 +2013-03-01 09:11:58.70307 14.54 1276.850001335144 +2013-03-01 09:11:58.70307 92.96 1276.850001335144 +2013-03-01 09:11:58.70307 10.89 1276.850001335144 +2013-03-01 09:11:58.70307 64.96 1276.850001335144 +2013-03-01 09:11:58.70307 17.85 1276.850001335144 +2013-03-01 09:11:58.70307 56.94 1276.850001335144 +2013-03-01 09:11:58.70307 28.69 1276.850001335144 +2013-03-01 09:11:58.70307 46.08 1276.850001335144 +2013-03-01 09:11:58.70307 31.17 1276.850001335144 +2013-03-01 09:11:58.703071 8.86 2368.430002987385 +2013-03-01 09:11:58.703071 46.84 2368.430002987385 +2013-03-01 09:11:58.703071 14.96 2368.430002987385 +2013-03-01 09:11:58.703071 68.62 2368.430002987385 +2013-03-01 09:11:58.703071 63.03 2368.430002987385 +2013-03-01 09:11:58.703071 35.32 2368.430002987385 +2013-03-01 09:11:58.703071 21.01 2368.430002987385 +2013-03-01 09:11:58.703071 44.3 2368.430002987385 +2013-03-01 09:11:58.703071 56.45 2368.430002987385 +2013-03-01 09:11:58.703071 48.89 2368.430002987385 +2013-03-01 09:11:58.703071 10.62 2368.430002987385 +2013-03-01 09:11:58.703071 85.55 2368.430002987385 +2013-03-01 09:11:58.703071 27.23 2368.430002987385 +2013-03-01 09:11:58.703071 61.41 2368.430002987385 +2013-03-01 09:11:58.703071 1.99 2368.430002987385 +2013-03-01 09:11:58.703071 49.64 2368.430002987385 +2013-03-01 09:11:58.703071 64.55 2368.430002987385 +2013-03-01 09:11:58.703071 99.45 2368.430002987385 +2013-03-01 09:11:58.703071 50.28 2368.430002987385 +2013-03-01 09:11:58.703071 0.83 2368.430002987385 +2013-03-01 09:11:58.703071 79.05 2368.430002987385 +2013-03-01 09:11:58.703071 80.43 2368.430002987385 +2013-03-01 09:11:58.703071 54.09 2368.430002987385 +2013-03-01 09:11:58.703071 61.88 2368.430002987385 +2013-03-01 09:11:58.703071 83.98 2368.430002987385 +2013-03-01 09:11:58.703071 42.08 2368.430002987385 +2013-03-01 09:11:58.703071 26.95 2368.430002987385 +2013-03-01 09:11:58.703071 17.58 2368.430002987385 +2013-03-01 09:11:58.703071 56.76 2368.430002987385 +2013-03-01 09:11:58.703071 81.41 2368.430002987385 +2013-03-01 09:11:58.703071 14.7 2368.430002987385 +2013-03-01 09:11:58.703071 37.32 2368.430002987385 +2013-03-01 09:11:58.703071 84.21 2368.430002987385 +2013-03-01 09:11:58.703071 31.84 2368.430002987385 +2013-03-01 09:11:58.703071 29.07 2368.430002987385 +2013-03-01 09:11:58.703071 76.13 2368.430002987385 +2013-03-01 09:11:58.703071 82.85 2368.430002987385 +2013-03-01 09:11:58.703071 19.1 2368.430002987385 +2013-03-01 09:11:58.703071 3.73 2368.430002987385 +2013-03-01 09:11:58.703071 52.09 2368.430002987385 +2013-03-01 09:11:58.703071 87.93 2368.430002987385 +2013-03-01 09:11:58.703071 38.5 2368.430002987385 +2013-03-01 09:11:58.703071 31.94 2368.430002987385 +2013-03-01 09:11:58.703071 88.93 2368.430002987385 +2013-03-01 09:11:58.703071 44.66 2368.430002987385 +2013-03-01 09:11:58.703071 53.26 2368.430002987385 +2013-03-01 09:11:58.703071 12.83 2368.430002987385 +2013-03-01 09:11:58.703071 94.27 2368.430002987385 +2013-03-01 09:11:58.703071 11.32 2368.430002987385 +2013-03-01 09:11:58.703071 29.71 2368.430002987385 +2013-03-01 09:11:58.703072 88.83 1607.950005441904 +2013-03-01 09:11:58.703072 25.13 1607.950005441904 +2013-03-01 09:11:58.703072 80.02 1607.950005441904 +2013-03-01 09:11:58.703072 68.2 1607.950005441904 +2013-03-01 09:11:58.703072 92.33 1607.950005441904 +2013-03-01 09:11:58.703072 25.34 1607.950005441904 +2013-03-01 09:11:58.703072 23.27 1607.950005441904 +2013-03-01 09:11:58.703072 56.7 1607.950005441904 +2013-03-01 09:11:58.703072 52.44 1607.950005441904 +2013-03-01 09:11:58.703072 0.48 1607.950005441904 +2013-03-01 09:11:58.703072 94.04 1607.950005441904 +2013-03-01 09:11:58.703072 99.26 1607.950005441904 +2013-03-01 09:11:58.703072 54.1 1607.950005441904 +2013-03-01 09:11:58.703072 79.46 1607.950005441904 +2013-03-01 09:11:58.703072 37.95 1607.950005441904 +2013-03-01 09:11:58.703072 62.09 1607.950005441904 +2013-03-01 09:11:58.703072 4.48 1607.950005441904 +2013-03-01 09:11:58.703072 30.47 1607.950005441904 +2013-03-01 09:11:58.703072 45.91 1607.950005441904 +2013-03-01 09:11:58.703072 9.0 1607.950005441904 +2013-03-01 09:11:58.703072 88.08 1607.950005441904 +2013-03-01 09:11:58.703072 1.27 1607.950005441904 +2013-03-01 09:11:58.703072 0.79 1607.950005441904 +2013-03-01 09:11:58.703072 71.68 1607.950005441904