zeroflag commented on a change in pull request #1633:
URL: https://github.com/apache/hive/pull/1633#discussion_r515829841
##########
File path: service-rpc/if/TCLIService.thrift
##########
@@ -515,6 +515,7 @@ struct TSessionHandle {
// The subtype of an OperationHandle.
enum TOperationType {
EXECUTE_STATEMENT,
+ PROCEDURAL_SQL,
Review comment:
Good idea, moved it to the end. No, the existing hplsql tests still use
the old way, most of them are running in offline mode I guess. But the newly
added tests in TestHplSqlViaBeeLine use the new mode.
##########
File path:
service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
##########
@@ -45,6 +62,21 @@ public static ExecuteStatementOperation
newExecuteStatementOperation(HiveSession
throws HiveSQLException {
String cleanStatement = HiveStringUtils.removeComments(statement);
+ if (!HPLSQL.equals(confOverlay.get(QUERY_EXECUTOR)) && hplSqlMode()) {
+ if (SessionState.get().getHplsqlInterpreter() == null) {
Review comment:
Done.
##########
File path:
service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
##########
@@ -36,6 +48,11 @@ public ExecuteStatementOperation(HiveSession parentSession,
String statement,
this.statement = statement;
}
+ public ExecuteStatementOperation(HiveSession parentSession, String
statement, Map<String, String> confOverlay, boolean runInBackground, boolean
generateNewQueryId) {
Review comment:
Removed.
##########
File path:
service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
##########
@@ -45,6 +62,21 @@ public static ExecuteStatementOperation
newExecuteStatementOperation(HiveSession
throws HiveSQLException {
String cleanStatement = HiveStringUtils.removeComments(statement);
+ if (!HPLSQL.equals(confOverlay.get(QUERY_EXECUTOR)) && hplSqlMode()) {
+ if (SessionState.get().getHplsqlInterpreter() == null) {
+ Exec interpreter = new Exec(
+ new Conf(),
+ new BeelineConsole(),
+ ResultListener.NONE,
+ new HplSqlQueryExecutor(parentSession),
+ parentSession.getMetaStoreClient(),
+ new HiveHplSqlSessionState(SessionState.get())
Review comment:
The session state is not available when the operation is running in the
background.
##########
File path:
service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlOperation.java
##########
@@ -0,0 +1,240 @@
+/*
+ *
+ * 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.security.PrivilegedExceptionAction;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.Future;
+import java.util.concurrent.RejectedExecutionException;
+
+import org.apache.hadoop.hive.common.LogUtils;
+import org.apache.hadoop.hive.ql.log.PerfLogger;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.serde2.thrift.Type;
+import org.apache.hadoop.hive.shims.ShimLoader;
+import org.apache.hadoop.hive.shims.Utils;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hive.hplsql.Exec;
+import org.apache.hive.hplsql.ResultListener;
+import org.apache.hive.hplsql.executor.Metadata;
+import org.apache.hive.service.cli.FetchOrientation;
+import org.apache.hive.service.cli.HiveSQLException;
+import org.apache.hive.service.cli.OperationState;
+import org.apache.hive.service.cli.OperationType;
+import org.apache.hive.service.cli.RowSet;
+import org.apache.hive.service.cli.RowSetFactory;
+import org.apache.hive.service.cli.TableSchema;
+import org.apache.hive.service.cli.operation.ExecuteStatementOperation;
+import org.apache.hive.service.cli.session.HiveSession;
+import org.apache.hive.service.server.ThreadWithGarbageCleanup;
+
+public class HplSqlOperation extends ExecuteStatementOperation implements
ResultListener {
+ private final Exec exec;
+ private final boolean runInBackground;
+ private RowSet rowSet;
+ private TableSchema schema;
+
+ public HplSqlOperation(HiveSession parentSession, String statement,
Map<String, String> confOverlay, boolean runInBackground, Exec exec) {
+ super(parentSession, statement, confOverlay, runInBackground, false);
+ this.exec = exec;
+ this.runInBackground = runInBackground;
+ exec.setResultListener(this);
+ }
+
+ @Override
+ protected void runInternal() throws HiveSQLException {
+ setState(OperationState.PENDING);
+ if (!runInBackground) {
+ interpret();
+ } else {
+ Runnable work = new BackgroundWork(getCurrentUGI(),
parentSession.getSessionHive(), SessionState.get());
+ try {
+ // This submit blocks if no background threads are available to run
this operation
+ Future<?> backgroundHandle =
getParentSession().submitBackgroundOperation(work);
+ setBackgroundHandle(backgroundHandle);
+ } catch (RejectedExecutionException rejected) {
+ setState(OperationState.ERROR);
+ throw new HiveSQLException("The background threadpool cannot accept" +
+ " new task for execution, please retry the operation",
rejected);
+ }
+ }
+ }
+
+ private void interpret() throws HiveSQLException {
+ try {
+ OperationState opState = getStatus().getState();
+ // Operation may have been cancelled by another thread
+ if (opState.isTerminal()) {
+ log.info("Not running the query. Operation is already in terminal
state: " + opState
+ + ", perhaps cancelled due to query timeout or by another
thread.");
+ return;
+ }
+ setState(OperationState.RUNNING);
+ int code = exec.run(new String[]{"-e", statement});
+ if (code != 0) {
+ throw new HiveSQLException("HPL/SQL returned " + code);
+ }
+ setState(OperationState.FINISHED);
+ } catch (Throwable e) {
+ if (getStatus().getState().isTerminal()) {
+ log.warn("Ignore exception in terminal state: {}",
getStatus().getState(), e);
Review comment:
I tried it, and it still works this way. The same way is used at other
places in the code.
##########
File path:
service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java
##########
@@ -0,0 +1,148 @@
+/*
+ *
+ * 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 defaultMaxRows =
HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_DEFAULT_FETCH_SIZE.defaultIntVal;
Review comment:
I made it configurable.
##########
File path:
service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
##########
@@ -45,6 +62,21 @@ public static ExecuteStatementOperation
newExecuteStatementOperation(HiveSession
throws HiveSQLException {
String cleanStatement = HiveStringUtils.removeComments(statement);
+ if (!HPLSQL.equals(confOverlay.get(QUERY_EXECUTOR)) && hplSqlMode()) {
+ if (SessionState.get().getHplsqlInterpreter() == null) {
+ Exec interpreter = new Exec(
+ new Conf(),
+ new BeelineConsole(),
+ ResultListener.NONE,
+ new HplSqlQueryExecutor(parentSession),
+ parentSession.getMetaStoreClient(),
+ new HiveHplSqlSessionState(SessionState.get())
Review comment:
Yes, that might be a problem, let me check 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]