From c35ab433709011dcefa9c9b521b86f954a19ae1b Mon Sep 17 00:00:00 2001 From: Chen Dai Date: Tue, 7 Nov 2023 17:00:34 -0800 Subject: [PATCH] Revert emr env changes Signed-off-by: Chen Dai --- .../flint/spark/FlintSparkIndex.scala | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndex.scala b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndex.scala index 8a7ef5b3e..fe5329739 100644 --- a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndex.scala +++ b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndex.scala @@ -90,6 +90,22 @@ object FlintSparkIndex { def flintIndexNamePrefix(fullTableName: String): String = s"flint_${fullTableName.replace(".", "_")}_" + /** + * Populate environment variables to persist in Flint metadata. + * + * @return + * env key value mapping to populate + */ + def populateEnvToMetadata: Map[String, String] = { + // TODO: avoid hardcoding env name below by providing another config + val envNames = Seq("SERVERLESS_EMR_VIRTUAL_CLUSTER_ID", "SERVERLESS_EMR_JOB_ID") + envNames + .flatMap(key => + Option(System.getenv(key)) + .map(value => key -> value)) + .toMap + } + /** * Create Flint metadata builder with common fields. * @@ -104,6 +120,12 @@ object FlintSparkIndex { builder.kind(index.kind) builder.options(index.options.optionsWithDefault.mapValues(_.asInstanceOf[AnyRef]).asJava) + // Index properties + val envs = populateEnvToMetadata + if (envs.nonEmpty) { + builder.addProperty("env", envs.asJava) + } + // Optional index settings val settings = index.options.indexSettings() if (settings.isDefined) {