From 98de013b53a763755310a44627d7fb1acf8e935c Mon Sep 17 00:00:00 2001 From: vkorukanti Date: Fri, 31 May 2024 15:33:37 -0700 Subject: [PATCH] [Kernel] Handle long values in `FieldMetadata` parsing --- .../delta/kernel/defaults/internal/types/DataTypeParser.java | 4 ++-- .../kernel/defaults/internal/types/DataTypeParserSuite.scala | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/kernel-defaults/src/main/java/io/delta/kernel/defaults/internal/types/DataTypeParser.java b/kernel/kernel-defaults/src/main/java/io/delta/kernel/defaults/internal/types/DataTypeParser.java index 2813f095b72..ac2d3a1c477 100644 --- a/kernel/kernel-defaults/src/main/java/io/delta/kernel/defaults/internal/types/DataTypeParser.java +++ b/kernel/kernel-defaults/src/main/java/io/delta/kernel/defaults/internal/types/DataTypeParser.java @@ -177,8 +177,8 @@ private static FieldMetadata parseFieldMetadata(JsonNode json) { if (value.isNull()) { builder.putNull(key); - } else if (value.isInt()) { - builder.putLong(key, value.intValue()); + } else if (value.isIntegralNumber()) { // covers both int and long + builder.putLong(key, value.longValue()); } else if (value.isDouble()) { builder.putDouble(key, value.doubleValue()); } else if (value.isBoolean()) { diff --git a/kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/internal/types/DataTypeParserSuite.scala b/kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/internal/types/DataTypeParserSuite.scala index ff56e31e1aa..a7817b55b0b 100644 --- a/kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/internal/types/DataTypeParserSuite.scala +++ b/kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/internal/types/DataTypeParserSuite.scala @@ -146,6 +146,8 @@ class DataTypeParserSuite extends AnyFunSuite { |{ | "null" : null, | "int" : 10, + | "long-1" : -16070400023423400, + | "long-2" : 16070400023423400, | "double" : 2.22, | "boolean" : true, | "string" : "10", @@ -161,6 +163,8 @@ class DataTypeParserSuite extends AnyFunSuite { val expectedFieldMetadataAllTypes = FieldMetadata.builder() .putNull("null") .putLong("int", 10) + .putLong("long-1", -16070400023423400L) + .putLong("long-2", 16070400023423400L) .putDouble("double", 2.22) .putBoolean("boolean", true) .putString("string", "10")