Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #1601] Align SparkStatementEvent to KyuubiOperationEvent
<!-- 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. --> Align SparkStatementEvent to KyuubiOperationEvent ### _How was this patch tested?_ - [ ] 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.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1601 from yaooqinn/soe. Closes #1601 090dee8 [Kent Yao] Merge branch 'master' of github.com:apache/incubator-kyuubi into soe a61ce3b [Kent Yao] Align SparkStatementEvent to KyuubiOperationEven efbbdf7 [Kent Yao] Align SparkStatementEvent to KyuubiOperationEven Authored-by: Kent Yao <yao@apache.org> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
- Loading branch information
1 parent
152e394
commit 1b48b18
Showing
14 changed files
with
257 additions
and
150 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
92 changes: 92 additions & 0 deletions
92
...sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/events/SparkOperationEvent.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,92 @@ | ||
/* | ||
* 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.spark.events | ||
|
||
import org.apache.spark.sql.{DataFrame, Encoders} | ||
import org.apache.spark.sql.types.StructType | ||
|
||
import org.apache.kyuubi.Utils | ||
import org.apache.kyuubi.engine.spark.operation.SparkOperation | ||
|
||
/** | ||
* A [[SparkOperationEvent]] used to tracker the lifecycle of an operation at Spark SQL Engine side. | ||
* <ul> | ||
* <li>Operation Basis</li> | ||
* <li>Operation Live Status</li> | ||
* <li>Parent Session Id</li> | ||
* </ul> | ||
* | ||
* @param statementId the unique identifier of a single operation | ||
* @param statement the sql that you execute | ||
* @param shouldRunAsync the flag indicating whether the query runs synchronously or not | ||
* @param state the current operation state | ||
* @param eventTime the time when the event created & logged | ||
* @param createTime the time for changing to the current operation state | ||
* @param startTime the time the query start to time of this operation | ||
* @param completeTime time time the query ends | ||
* @param exception: caught exception if have | ||
* @param sessionId the identifier of the parent session | ||
* @param sessionUser the authenticated client user | ||
* @param queryExecution the query execution of this operation | ||
*/ | ||
case class SparkOperationEvent( | ||
statementId: String, | ||
statement: String, | ||
shouldRunAsync: Boolean, | ||
state: String, | ||
eventTime: Long, | ||
createTime: Long, | ||
startTime: Long, | ||
completeTime: Long, | ||
exception: Option[Throwable], | ||
sessionId: String, | ||
sessionUser: String, | ||
queryExecution: String) extends KyuubiSparkEvent { | ||
|
||
override def schema: StructType = Encoders.product[SparkOperationEvent].schema | ||
override def partitions: Seq[(String, String)] = | ||
("day", Utils.getDateFromTimestamp(createTime)) :: Nil | ||
|
||
def duration: Long = { | ||
if (completeTime == -1L) { | ||
System.currentTimeMillis - createTime | ||
} else { | ||
completeTime - createTime | ||
} | ||
} | ||
} | ||
|
||
object SparkOperationEvent { | ||
def apply(operation: SparkOperation, result: Option[DataFrame] = None): SparkOperationEvent = { | ||
val session = operation.getSession | ||
val status = operation.getStatus | ||
new SparkOperationEvent( | ||
operation.statementId, | ||
operation.statement, | ||
operation.shouldRunAsync, | ||
status.state.name(), | ||
status.lastModified, | ||
status.create, | ||
status.start, | ||
status.completed, | ||
status.exception, | ||
session.handle.identifier.toString, | ||
session.user, | ||
result.map(_.queryExecution.toString).orNull) | ||
} | ||
} |
60 changes: 0 additions & 60 deletions
60
...sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/events/SparkStatementEvent.scala
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.