-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[POC] Store state and error using QueryMetadataService (#608)
* Store state and error using QueryMetadataService Signed-off-by: Tomoyuki Morita <[email protected]> * Address comments Signed-off-by: Tomoyuki Morita <[email protected]> --------- Signed-off-by: Tomoyuki Morita <[email protected]>
- Loading branch information
Showing
10 changed files
with
145 additions
and
18 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
13 changes: 13 additions & 0 deletions
13
flint-data/src/main/scala/org/opensearch/flint/data/QueryState.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,13 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.data | ||
|
||
object QueryState { | ||
val WAITING = "waiting" | ||
val RUNNING = "running" | ||
val SUCCESS = "success" | ||
val FAILED = "failed" | ||
} |
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
21 changes: 21 additions & 0 deletions
21
spark-sql-application/src/main/scala/org/apache/spark/sql/NoOpQueryMetadataService.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,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.apache.spark.sql | ||
|
||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.sql.flint.config.FlintSparkConf | ||
|
||
/** | ||
* Temporary default implementation for QueryMetadataService. This should be replaced with an | ||
* implementation which write status to OpenSearch index | ||
*/ | ||
class NoOpQueryMetadataService(flintSparkConf: FlintSparkConf) | ||
extends QueryMetadataService | ||
with Logging { | ||
|
||
override def updateQueryState(queryId: String, state: String, error: String): Unit = | ||
logInfo(s"updateQueryState: queryId=${queryId}, state=`${state}`, error=`${error}`") | ||
} |
11 changes: 11 additions & 0 deletions
11
spark-sql-application/src/main/scala/org/apache/spark/sql/QueryMetadataService.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,11 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.apache.spark.sql | ||
|
||
/** Interface for updating query state and error. */ | ||
trait QueryMetadataService { | ||
def updateQueryState(queryId: String, state: String, error: String): Unit | ||
} |
30 changes: 30 additions & 0 deletions
30
spark-sql-application/src/main/scala/org/apache/spark/sql/util/CustomClassLoader.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,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.apache.spark.sql.util | ||
|
||
import org.apache.spark.sql.QueryMetadataService | ||
import org.apache.spark.sql.flint.config.FlintSparkConf | ||
import org.apache.spark.util.Utils | ||
|
||
case class CustomClassLoader(flintSparkConf: FlintSparkConf) { | ||
|
||
def getQueryMetadataService(): QueryMetadataService = { | ||
instantiateClass[QueryMetadataService]( | ||
flintSparkConf.flintOptions().getCustomQueryMetadataService) | ||
} | ||
|
||
private def instantiateClass[T](className: String): T = { | ||
try { | ||
val providerClass = Utils.classForName(className) | ||
val ctor = providerClass.getDeclaredConstructor(classOf[FlintSparkConf]) | ||
ctor.setAccessible(true) | ||
ctor.newInstance(flintSparkConf).asInstanceOf[T] | ||
} catch { | ||
case e: Exception => | ||
throw new RuntimeException(s"Failed to instantiate provider: $className", e) | ||
} | ||
} | ||
} |