From 5585f1aee6c2631325975ff005f675cdb00a03eb Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:06:53 -0800 Subject: [PATCH] Add support for serializing MapType (#929) (#939) (cherry picked from commit 8efe1ec41b19939c72b4f8ef315ea22903778d50) Signed-off-by: Chase Engelbrecht Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../spark/sql/flint/datatype/FlintDataType.scala | 3 +++ .../sql/flint/datatype/FlintDataTypeSuite.scala | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/flint-spark-integration/src/main/scala/org/apache/spark/sql/flint/datatype/FlintDataType.scala b/flint-spark-integration/src/main/scala/org/apache/spark/sql/flint/datatype/FlintDataType.scala index a4b23bd46..5d920a07e 100644 --- a/flint-spark-integration/src/main/scala/org/apache/spark/sql/flint/datatype/FlintDataType.scala +++ b/flint-spark-integration/src/main/scala/org/apache/spark/sql/flint/datatype/FlintDataType.scala @@ -153,6 +153,9 @@ object FlintDataType { // objects case st: StructType => serializeJValue(st) + // Serialize maps as empty objects and let the map entries automap + case mt: MapType => serializeJValue(new StructType()) + // array case ArrayType(elementType, _) => serializeField(elementType, Metadata.empty) diff --git a/flint-spark-integration/src/test/scala/org/apache/spark/sql/flint/datatype/FlintDataTypeSuite.scala b/flint-spark-integration/src/test/scala/org/apache/spark/sql/flint/datatype/FlintDataTypeSuite.scala index 94f4839d6..44e8158d8 100644 --- a/flint-spark-integration/src/test/scala/org/apache/spark/sql/flint/datatype/FlintDataTypeSuite.scala +++ b/flint-spark-integration/src/test/scala/org/apache/spark/sql/flint/datatype/FlintDataTypeSuite.scala @@ -128,6 +128,21 @@ class FlintDataTypeSuite extends FlintSuite with Matchers { |}""".stripMargin) } + test("spark map type serialize") { + val sparkStructType = StructType( + StructField("mapField", MapType(StringType, StringType), true) :: + Nil) + + FlintDataType.serialize(sparkStructType) shouldBe compactJson("""{ + | "properties": { + | "mapField": { + | "properties": { + | } + | } + | } + |}""".stripMargin) + } + test("spark varchar and char type serialize") { val flintDataType = """{ | "properties": {