Skip to content

Commit

Permalink
use ArrayList only
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Kao <[email protected]>
  • Loading branch information
seankao-az committed Nov 12, 2024
1 parent efd2207 commit ce5fea8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class FlintSparkMaterializedViewSuite extends FlintSuite {
metadata.kind shouldBe MV_INDEX_TYPE
metadata.source shouldBe "SELECT 1"
metadata.properties should contain key "sourceTables"
metadata.properties.get("sourceTables").asInstanceOf[Array[String]] should have size 0
metadata.properties
.get("sourceTables")
.asInstanceOf[java.util.ArrayList[String]] should have size 0
metadata.indexedColumns shouldBe Array(
Map("columnName" -> "test_col", "columnType" -> "integer").asJava)
metadata.schema shouldBe Map("test_col" -> Map("type" -> "integer").asJava).asJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class FlintOpenSearchMetadataCacheWriterITSuite extends FlintSparkSuite with Mat
val properties = flintIndexMetadataService.getIndexMetadata(testFlintIndex).properties
properties
.get("sourceTables")
.asInstanceOf[List[String]]
.toArray should contain theSameElementsAs Array(testTable)
.asInstanceOf[java.util.ArrayList[String]] should contain theSameElementsAs Array(
testTable)
}
}

Expand All @@ -181,8 +181,7 @@ class FlintOpenSearchMetadataCacheWriterITSuite extends FlintSparkSuite with Mat
val properties = flintIndexMetadataService.getIndexMetadata(testFlintIndex).properties
properties
.get("sourceTables")
.asInstanceOf[List[String]]
.toArray should contain theSameElementsAs Array(testTable)
.asInstanceOf[java.util.ArrayList[String]] should contain theSameElementsAs Array(testTable)
}

test("write metadata cache with source tables from deserialized metadata") {
Expand Down Expand Up @@ -213,8 +212,9 @@ class FlintOpenSearchMetadataCacheWriterITSuite extends FlintSparkSuite with Mat
val properties = flintIndexMetadataService.getIndexMetadata(testFlintIndex).properties
properties
.get("sourceTables")
.asInstanceOf[List[String]]
.toArray should contain theSameElementsAs Array(testTable, testTable2)
.asInstanceOf[java.util.ArrayList[String]] should contain theSameElementsAs Array(
testTable,
testTable2)
}

test("write metadata cache to index mappings with refresh interval") {
Expand Down

0 comments on commit ce5fea8

Please sign in to comment.