You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by dm...@apache.org on 2016/08/04 20:50:32 UTC
hive git commit: HIVE-14382: Improve the Functionality of Reverse FOR
Statement (Akash Sethi, reviewed by Dmitry Tolpeko)
Repository: hive
Updated Branches:
refs/heads/master 3182378a5 -> 519306439
HIVE-14382: Improve the Functionality of Reverse FOR Statement (Akash Sethi, reviewed by Dmitry Tolpeko)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/51930643
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/51930643
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/51930643
Branch: refs/heads/master
Commit: 51930643971df816ecf1de61b37d2bab5f455849
Parents: 3182378
Author: Dmitry Tolpeko <dm...@gmail.com>
Authored: Thu Aug 4 13:32:49 2016 -0700
Committer: Dmitry Tolpeko <dm...@gmail.com>
Committed: Thu Aug 4 13:32:49 2016 -0700
----------------------------------------------------------------------
.../main/java/org/apache/hive/hplsql/Stmt.java | 39 ++++++++++++++------
hplsql/src/test/queries/local/for_range.sql | 2 +-
2 files changed, 28 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/51930643/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
----------------------------------------------------------------------
diff --git a/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java b/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
index c044616..0fafd59 100644
--- a/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
+++ b/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
@@ -976,24 +976,39 @@ public class Stmt {
int end = evalPop(ctx.expr(1)).intValue();
int step = evalPop(ctx.expr(2), 1L).intValue();
exec.enterScope(Scope.Type.LOOP);
- Var index = new Var(ctx.L_ID().getText(), new Long(start));
+ Var index = setIndex(start, end, ctx);
exec.addVariable(index);
- if (ctx.T_REVERSE() == null) {
for (int i = start; i <= end; i += step) {
visit(ctx.block());
- index.increment(new Long(step));
- }
- } else {
- for (int i = start; i >= end; i -= step) {
- visit(ctx.block());
- index.decrement(new Long(step));
- }
- }
+ updateIndex(step, index, ctx);
+ }
exec.leaveScope();
trace(ctx, "FOR RANGE - LEFT");
return 0;
- }
-
+ }
+
+ /**
+ * To set the Value index for FOR Statement
+ */
+ private Var setIndex(int start, int end, HplsqlParser.For_range_stmtContext ctx) {
+
+ if (ctx.T_REVERSE() == null)
+ return new Var(ctx.L_ID().getText(), new Long(start));
+ else
+ return new Var(ctx.L_ID().getText(), new Long(end));
+ }
+
+ /**
+ * To update the value of index for FOR Statement
+ */
+ private void updateIndex(int step, Var index, HplsqlParser.For_range_stmtContext ctx) {
+
+ if (ctx.T_REVERSE() == null)
+ index.increment(new Long(step));
+ else
+ index.decrement(new Long(step));
+ }
+
/**
* EXEC, EXECUTE and EXECUTE IMMEDIATE statement to execute dynamic SQL or stored procedure
*/
http://git-wip-us.apache.org/repos/asf/hive/blob/51930643/hplsql/src/test/queries/local/for_range.sql
----------------------------------------------------------------------
diff --git a/hplsql/src/test/queries/local/for_range.sql b/hplsql/src/test/queries/local/for_range.sql
index b7af115..7a0057f 100644
--- a/hplsql/src/test/queries/local/for_range.sql
+++ b/hplsql/src/test/queries/local/for_range.sql
@@ -7,7 +7,7 @@ END LOOP;
PRINT i;
-FOR i IN REVERSE 10..1 LOOP
+FOR i IN REVERSE 1..10 LOOP
PRINT i;
END LOOP;