Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #1821] Add trino ExecuteStatement
<!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html 2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'. 3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'. --> ### _Why are the changes needed?_ <!-- Please clarify why the changes are needed. For instance, 1. If you add a feature, you can talk about the use case of it. 2. If you fix a bug, you can clarify why it is a bug. --> Add trino ExecuteStatement ### _How was this patch tested?_ - [X] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [X] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1830 from hddong/add-operation. Closes #1821 067bde7 [hongdongdong] use flag instead breakable f4d6cbb [hongdongdong] fix 351e2bc [hongdongdong] move context to impl 69d7d9b [hongdongdong] fix wrong func name 9cb757a [hongdongdong] fix a20f2d0 [hongdongdong] fix time unit c5072db [hongdongdong] [KYUUBI #1821] Add trino ExecuteStatement Authored-by: hongdongdong <hongdongdong@cmss.chinamobile.com> Signed-off-by: hongdongdong <hongdongdong@cmss.chinamobile.com>
- Loading branch information
Showing
15 changed files
with
926 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/ExecuteStatement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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.kyuubi.engine.trino.operation | ||
|
||
import java.util.concurrent.RejectedExecutionException | ||
|
||
import org.apache.kyuubi.KyuubiSQLException | ||
import org.apache.kyuubi.Logging | ||
import org.apache.kyuubi.engine.trino.TrinoStatement | ||
import org.apache.kyuubi.operation.ArrayFetchIterator | ||
import org.apache.kyuubi.operation.IterableFetchIterator | ||
import org.apache.kyuubi.operation.OperationState | ||
import org.apache.kyuubi.operation.OperationType | ||
import org.apache.kyuubi.operation.log.OperationLog | ||
import org.apache.kyuubi.session.Session | ||
|
||
class ExecuteStatement( | ||
session: Session, | ||
override val statement: String, | ||
override val shouldRunAsync: Boolean, | ||
incrementalCollect: Boolean) | ||
extends TrinoOperation(OperationType.EXECUTE_STATEMENT, session) with Logging { | ||
|
||
private val operationLog: OperationLog = OperationLog.createOperationLog(session, getHandle) | ||
override def getOperationLog: Option[OperationLog] = Option(operationLog) | ||
|
||
override protected def beforeRun(): Unit = { | ||
OperationLog.setCurrentOperationLog(operationLog) | ||
setState(OperationState.PENDING) | ||
setHasResultSet(true) | ||
} | ||
|
||
override protected def afterRun(): Unit = { | ||
OperationLog.removeCurrentOperationLog() | ||
} | ||
|
||
override protected def runInternal(): Unit = { | ||
val trinoStatement = TrinoStatement(trinoContext, session.sessionManager.getConf, statement) | ||
trino = trinoStatement.getTrinoClient | ||
if (shouldRunAsync) { | ||
val asyncOperation = new Runnable { | ||
override def run(): Unit = { | ||
OperationLog.setCurrentOperationLog(operationLog) | ||
executeStatement(trinoStatement) | ||
} | ||
} | ||
|
||
try { | ||
val trinoSessionManager = session.sessionManager | ||
val backgroundHandle = trinoSessionManager.submitBackgroundOperation(asyncOperation) | ||
setBackgroundHandle(backgroundHandle) | ||
} catch { | ||
case rejected: RejectedExecutionException => | ||
setState(OperationState.ERROR) | ||
val ke = | ||
KyuubiSQLException("Error submitting query in background, query rejected", rejected) | ||
setOperationException(ke) | ||
throw ke | ||
} | ||
} else { | ||
executeStatement(trinoStatement) | ||
} | ||
} | ||
|
||
private def executeStatement(trinoStatement: TrinoStatement): Unit = { | ||
setState(OperationState.RUNNING) | ||
try { | ||
schema = trinoStatement.getColumns | ||
val resultSet = trinoStatement.execute() | ||
iter = | ||
if (incrementalCollect) { | ||
info("Execute in incremental collect mode") | ||
new IterableFetchIterator(resultSet) | ||
} else { | ||
info("Execute in full collect mode") | ||
new ArrayFetchIterator(resultSet.toArray) | ||
} | ||
setState(OperationState.FINISHED) | ||
} catch { | ||
onError(cancel = true) | ||
} | ||
} | ||
} |
Oops, something went wrong.