You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/03/29 12:13:28 UTC

[GitHub] [hive] zeroflag opened a new pull request #2130: HIVE-24383. Add Table type to HPL/SQL (amagyar)

zeroflag opened a new pull request #2130:
URL: https://github.com/apache/hive/pull/2130


   Add table type to hplsql.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] mustafaiman commented on a change in pull request #2130: HIVE-24383. Add Table type to HPL/SQL (amagyar)

Posted by GitBox <gi...@apache.org>.
mustafaiman commented on a change in pull request #2130:
URL: https://github.com/apache/hive/pull/2130#discussion_r607247615



##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Select.java
##########
@@ -87,37 +94,38 @@ public Integer select(HplsqlParser.Select_stmtContext ctx) {
     trace(ctx, "SELECT completed successfully");
     exec.setSqlSuccess();
     try {
-      int into_cnt = getIntoCount(ctx);
-      if (into_cnt > 0) {
-        trace(ctx, "SELECT INTO statement executed");
-        if (query.next()) {
-          for (int i = 0; i < into_cnt; i++) {
-            String into_name = getIntoVariable(ctx, i);
-            Var var = exec.findVariable(into_name);
-            if (var != null) {
-              if (var.type != Var.Type.ROW) {
-                var.setValue(query, i);
-              } else {
-                var.setValues(query);
-              }
-              if (trace) {
-                exec.trace(ctx, var, query.metadata(), i);
-              }
-            } 
-            else {
-              trace(ctx, "Variable not found: " + into_name);
+      int intoCount = getIntoCount(ctx);
+      if (intoCount > 0) {
+        if (isBulkCollect(ctx)) {
+          trace(ctx, "SELECT BULK COLLECT INTO statement executed");
+          long rowIndex = 1;
+          List<Table> tables = exec.intoTables(ctx, intoVariableNames(ctx, intoCount));
+          tables.forEach(Table::removeAll);
+          while (query.next()) {
+            for (int i = 0; i < intoCount; i++) {
+              Table table = tables.get(i);
+              table.populate(query, rowIndex, i);
             }
+            rowIndex++;
+          }
+        } else {
+          trace(ctx, "SELECT INTO statement executed");
+          if (query.next()) {
+            for (int i = 0; i < intoCount; i++) {
+              populateVariable(ctx, query, i);
+            }
+            exec.incRowCount();
+            exec.setSqlSuccess();
+            if (query.next()) {
+              exec.setSqlCode(-1422);

Review comment:
       Can we consolidate known error codes into a class/enum with meaningful variable names? I would like to be able to search for the error code in a known location and understand what is going on when debugging in the future. Similarly we should be able to search within the IDE which code paths can possibly cause a given error code.

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
##########
@@ -961,6 +987,22 @@ public Integer forRange(HplsqlParser.For_range_stmtContext ctx) {
     return 0; 
   }
 
+  public Integer unconditionalLoop(HplsqlParser.Unconditional_loop_stmtContext ctx) {
+    trace(ctx, "UNCONDITIONAL LOOP - ENTERED");
+    String label = exec.labelPop();
+    while (true) {
+      exec.enterScope(Scope.Type.LOOP);
+      visit(ctx.block());
+      exec.leaveScope();
+      if (canContinue(label)) {
+        continue;
+      }
+      break;

Review comment:
       can be simplified
   ```
   if (!canContinue(label)) {
     break;
   }
   ```

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Select.java
##########
@@ -155,7 +162,25 @@ else if (ctx.parent instanceof HplsqlParser.StmtContext) {
     }
     query.close();
     return 0; 
-  }  
+  }
+
+  private void populateVariable(HplsqlParser.Select_stmtContext ctx, QueryResult query, int columnIndex) {
+    String intoName = getIntoVariable(ctx, columnIndex);
+    Var var = exec.findVariable(intoName);
+    if (var != null) {
+      if (var.type == Var.Type.HPL_OBJECT && var.value instanceof Table) {
+        Table table = (Table) var.value;
+        table.populate(query, getIntoTableIndex(ctx, columnIndex), columnIndex);
+      } else if (var.type == Var.Type.ROW) {
+        var.setRowValues(query);
+      } else {
+        var.setValue(query, columnIndex);
+      }
+      exec.trace(ctx, var, query.metadata(), columnIndex);
+    } else {
+      trace(ctx, "Variable not found: " + intoName);

Review comment:
       Seems like we ignore unknown variables. Shouldn't we fail fast when such thing happens?

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Var.java
##########
@@ -26,13 +26,14 @@
 
 import org.apache.hive.hplsql.executor.QueryResult;
 
+

Review comment:
       leftover blank line

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/objects/HplClass.java
##########
@@ -0,0 +1,24 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.hive.hplsql.objects;
+
+public interface HplClass {
+  HplObject instantiate();

Review comment:
       Shouldn't this be newInstance(). We create a new instance of HplClass, we do not instantiate the HplClass.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] kasakrisz merged pull request #2130: HIVE-24383. Add Table type to HPL/SQL (amagyar)

Posted by GitBox <gi...@apache.org>.
kasakrisz merged pull request #2130:
URL: https://github.com/apache/hive/pull/2130


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] zeroflag commented on a change in pull request #2130: HIVE-24383. Add Table type to HPL/SQL (amagyar)

Posted by GitBox <gi...@apache.org>.
zeroflag commented on a change in pull request #2130:
URL: https://github.com/apache/hive/pull/2130#discussion_r608575658



##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
##########
@@ -961,6 +987,22 @@ public Integer forRange(HplsqlParser.For_range_stmtContext ctx) {
     return 0; 
   }
 
+  public Integer unconditionalLoop(HplsqlParser.Unconditional_loop_stmtContext ctx) {
+    trace(ctx, "UNCONDITIONAL LOOP - ENTERED");
+    String label = exec.labelPop();
+    while (true) {
+      exec.enterScope(Scope.Type.LOOP);
+      visit(ctx.block());
+      exec.leaveScope();
+      if (canContinue(label)) {
+        continue;
+      }
+      break;

Review comment:
       Ok.

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Var.java
##########
@@ -26,13 +26,14 @@
 
 import org.apache.hive.hplsql.executor.QueryResult;
 
+

Review comment:
       removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] zeroflag commented on a change in pull request #2130: HIVE-24383. Add Table type to HPL/SQL (amagyar)

Posted by GitBox <gi...@apache.org>.
zeroflag commented on a change in pull request #2130:
URL: https://github.com/apache/hive/pull/2130#discussion_r608575321



##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Select.java
##########
@@ -87,37 +94,38 @@ public Integer select(HplsqlParser.Select_stmtContext ctx) {
     trace(ctx, "SELECT completed successfully");
     exec.setSqlSuccess();
     try {
-      int into_cnt = getIntoCount(ctx);
-      if (into_cnt > 0) {
-        trace(ctx, "SELECT INTO statement executed");
-        if (query.next()) {
-          for (int i = 0; i < into_cnt; i++) {
-            String into_name = getIntoVariable(ctx, i);
-            Var var = exec.findVariable(into_name);
-            if (var != null) {
-              if (var.type != Var.Type.ROW) {
-                var.setValue(query, i);
-              } else {
-                var.setValues(query);
-              }
-              if (trace) {
-                exec.trace(ctx, var, query.metadata(), i);
-              }
-            } 
-            else {
-              trace(ctx, "Variable not found: " + into_name);
+      int intoCount = getIntoCount(ctx);
+      if (intoCount > 0) {
+        if (isBulkCollect(ctx)) {
+          trace(ctx, "SELECT BULK COLLECT INTO statement executed");
+          long rowIndex = 1;
+          List<Table> tables = exec.intoTables(ctx, intoVariableNames(ctx, intoCount));
+          tables.forEach(Table::removeAll);
+          while (query.next()) {
+            for (int i = 0; i < intoCount; i++) {
+              Table table = tables.get(i);
+              table.populate(query, rowIndex, i);
             }
+            rowIndex++;
+          }
+        } else {
+          trace(ctx, "SELECT INTO statement executed");
+          if (query.next()) {
+            for (int i = 0; i < intoCount; i++) {
+              populateVariable(ctx, query, i);
+            }
+            exec.incRowCount();
+            exec.setSqlSuccess();
+            if (query.next()) {
+              exec.setSqlCode(-1422);

Review comment:
       I added a new class for that.

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Select.java
##########
@@ -155,7 +162,25 @@ else if (ctx.parent instanceof HplsqlParser.StmtContext) {
     }
     query.close();
     return 0; 
-  }  
+  }
+
+  private void populateVariable(HplsqlParser.Select_stmtContext ctx, QueryResult query, int columnIndex) {
+    String intoName = getIntoVariable(ctx, columnIndex);
+    Var var = exec.findVariable(intoName);
+    if (var != null) {
+      if (var.type == Var.Type.HPL_OBJECT && var.value instanceof Table) {
+        Table table = (Table) var.value;
+        table.populate(query, getIntoTableIndex(ctx, columnIndex), columnIndex);
+      } else if (var.type == Var.Type.ROW) {
+        var.setRowValues(query);
+      } else {
+        var.setValue(query, columnIndex);
+      }
+      exec.trace(ctx, var, query.metadata(), columnIndex);
+    } else {
+      trace(ctx, "Variable not found: " + intoName);

Review comment:
       I replaced it with an exception.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] zeroflag commented on a change in pull request #2130: HIVE-24383. Add Table type to HPL/SQL (amagyar)

Posted by GitBox <gi...@apache.org>.
zeroflag commented on a change in pull request #2130:
URL: https://github.com/apache/hive/pull/2130#discussion_r608575837



##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/objects/HplClass.java
##########
@@ -0,0 +1,24 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.hive.hplsql.objects;
+
+public interface HplClass {
+  HplObject instantiate();

Review comment:
       That makes more sense. I renamed it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org