kgyrtkirk commented on a change in pull request #1633:
URL: https://github.com/apache/hive/pull/1633#discussion_r521910097



##########
File path: ql/pom.xml
##########
@@ -863,6 +863,11 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>org.apache.hive</groupId>
+      <artifactId>hive-hplsql</artifactId>

Review comment:
       I think it would be better to avoid pulling in hplsql under ql - there 
is only a console class and some minor other stuff - I think this could be 
dodged with a few interfaces.

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
##########
@@ -270,6 +271,8 @@
 
   private SparkSession sparkSession;
 
+  private Exec hplsqlInterpreter;

Review comment:
       I don't fully understand why we have this field "here" - we don't even 
use hplsql from ql.
   
   This field is only used from the "service" module

##########
File path: 
service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java
##########
@@ -0,0 +1,149 @@
+/*
+ *
+ *  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.service.cli.operation.hplsql;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hive.hplsql.executor.ColumnMeta;
+import org.apache.hive.hplsql.executor.Metadata;
+import org.apache.hive.hplsql.executor.QueryException;
+import org.apache.hive.hplsql.executor.QueryExecutor;
+import org.apache.hive.hplsql.executor.QueryResult;
+import org.apache.hive.hplsql.executor.RowResult;
+import org.apache.hive.service.cli.ColumnDescriptor;
+import org.apache.hive.service.cli.FetchOrientation;
+import org.apache.hive.service.cli.FetchType;
+import org.apache.hive.service.cli.HiveSQLException;
+import org.apache.hive.service.cli.OperationHandle;
+import org.apache.hive.service.cli.RowSet;
+import org.apache.hive.service.cli.TableSchema;
+import org.apache.hive.service.cli.session.HiveSession;
+
+/**
+ * Executing HiveQL from HPL/SQL directly, without JDBC or Thrift.
+ */
+public class HplSqlQueryExecutor implements QueryExecutor {
+  public static final String QUERY_EXECUTOR = "QUERY_EXECUTOR";
+  public static final String HPLSQL = "HPLSQL";
+  private final HiveSession hiveSession;
+  private long fetchSize;
+
+  public HplSqlQueryExecutor(HiveSession hiveSession) {
+    this.fetchSize = 
hiveSession.getHiveConf().getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_DEFAULT_FETCH_SIZE);
+    this.hiveSession = hiveSession;
+  }
+
+  @Override
+  public QueryResult executeQuery(String sql, ParserRuleContext ctx) {
+    try {
+      Map<String, String> confOverlay = new HashMap<>();
+      confOverlay.put(QUERY_EXECUTOR, HPLSQL);
+      OperationHandle operationHandle = hiveSession.executeStatement(sql, 
confOverlay);
+      return new QueryResult(new OperationRowResult(operationHandle), () -> 
metadata(operationHandle), null);
+    } catch (HiveSQLException e) {
+      return new QueryResult(null, () -> new 
Metadata(Collections.emptyList()), e);
+    }
+  }
+
+  public Metadata metadata(OperationHandle operationHandle) {
+    try {
+      TableSchema meta = hiveSession.getResultSetMetadata(operationHandle);
+      List<ColumnMeta> colMeta = new ArrayList<>();
+      for (int i = 0; i < meta.getSize(); i++) {
+        ColumnDescriptor col = meta.getColumnDescriptorAt(i);
+        colMeta.add(new ColumnMeta(col.getName(), col.getTypeName(), 
col.getType().toJavaSQLType()));
+      }
+      return new Metadata(colMeta);
+    } catch (HiveSQLException e) {
+      throw new QueryException(e);
+    }
+  }
+
+  private class OperationRowResult implements RowResult {
+    private final OperationHandle handle;
+    private RowSet rows;
+    private Iterator<Object[]> iterator;
+    private Object[] current;
+
+    private OperationRowResult(OperationHandle operationHandle) {
+      this.handle = operationHandle;
+    }
+
+    @Override
+    public boolean next() {
+      if (rows == null) {
+        this.rows = fetch();
+        this.iterator = rows.iterator();
+      }
+      if (iterator.hasNext()) {
+        current = iterator.next();
+        return true;
+      } else {
+        current = null;
+        return false;
+      }
+    }
+
+    private RowSet fetch() {
+      try {
+        return hiveSession.fetchResults(
+                handle, FetchOrientation.FETCH_NEXT, fetchSize, 
FetchType.QUERY_OUTPUT);

Review comment:
       I think if I set fetchsize to 1 - and then I try to fetch a resultset of 
10 rows with hplsql; I'll get 1 row back

##########
File path: 
service/src/java/org/apache/hive/service/cli/operation/hplsql/Udf.java
##########
@@ -1,123 +1,125 @@
 /*
- * 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
+ *  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.
  *
- * 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;
+package org.apache.hive.service.cli.operation.hplsql;

Review comment:
       this doesnt look right...
   why are we moviong a UDF into the service package? can't we avoid that?




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to