diff --git a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/mv/FlintSparkMaterializedView.scala b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/mv/FlintSparkMaterializedView.scala index b8b44ea15..81f996d83 100644 --- a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/mv/FlintSparkMaterializedView.scala +++ b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/mv/FlintSparkMaterializedView.scala @@ -7,8 +7,7 @@ package org.opensearch.flint.spark.mv import java.util.Locale -import scala.collection.JavaConverters.asScalaBufferConverter -import scala.collection.JavaConverters.mapAsJavaMapConverter +import scala.collection.JavaConverters._ import scala.collection.convert.ImplicitConversions.`map AsScala` import org.opensearch.flint.common.metadata.FlintMetadata @@ -66,10 +65,14 @@ case class FlintSparkMaterializedView( }.toArray val schema = generateSchema(outputSchema).asJava + // Convert Scala Array to Java ArrayList for consistency with OpenSearch JSON parsing. + // OpenSearch uses Jackson, which deserializes JSON arrays into ArrayLists. + val sourceTablesProperty = new java.util.ArrayList[String](sourceTables.toSeq.asJava) + metadataBuilder(this) .name(mvName) .source(query) - .addProperty("sourceTables", sourceTables) + .addProperty("sourceTables", sourceTablesProperty) .indexedColumns(indexColumnMaps) .schema(schema) .build() @@ -203,19 +206,16 @@ object FlintSparkMaterializedView extends Logging { */ def getSourceTablesFromMetadata(metadata: FlintMetadata): Array[String] = { logInfo(s"Getting source tables from metadata $metadata") - metadata.properties.get("sourceTables") match { + val sourceTables = metadata.properties.get("sourceTables") + sourceTables match { case list: java.util.ArrayList[_] => - logInfo(s"sourceTables is java.util.ArrayList: [${list.asScala.mkString(", ")}]") + logInfo(s"sourceTables is [${list.asScala.mkString(", ")}]") list.toArray.map(_.toString) - case array: Array[_] => - logInfo(s"sourceTables is Array: [${array.mkString(", ")}]") - array.map(_.toString) case null => logInfo("sourceTables property does not exist") Array.empty[String] case _ => - logInfo( - s"sourceTables is of type: ${metadata.properties.get("sourceTables").getClass.getName}") + logInfo(s"sourceTables has unexpected type: ${sourceTables.getClass.getName}") Array.empty[String] } } diff --git a/integ-test/src/integration/scala/org/opensearch/flint/spark/FlintSparkMaterializedViewITSuite.scala b/integ-test/src/integration/scala/org/opensearch/flint/spark/FlintSparkMaterializedViewITSuite.scala index efc6ff69c..cf0347820 100644 --- a/integ-test/src/integration/scala/org/opensearch/flint/spark/FlintSparkMaterializedViewITSuite.scala +++ b/integ-test/src/integration/scala/org/opensearch/flint/spark/FlintSparkMaterializedViewITSuite.scala @@ -82,7 +82,6 @@ class FlintSparkMaterializedViewITSuite extends FlintSparkSuite { Array(testTable), Map("1" -> "integer")) val metadata = mv.metadata() - metadata.properties.get("sourceTables") shouldBe a[Array[String]] getSourceTablesFromMetadata(metadata) should contain theSameElementsAs Array(testTable) } @@ -103,7 +102,6 @@ class FlintSparkMaterializedViewITSuite extends FlintSparkSuite { | } | } |""".stripMargin) - metadata.properties.get("sourceTables") shouldBe a[java.util.ArrayList[String]] getSourceTablesFromMetadata(metadata) should contain theSameElementsAs Array(testTable) }