Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1320314: fix Null handling in Variants #109

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/scala/com/snowflake/snowpark/types/Variant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ class Variant private[snowpark] (
def this(str: String) =
this({
try {
MAPPER.readTree(str)
if (str.toLowerCase().startsWith("null") && str != "null") {
sfc-gh-yuwang marked this conversation as resolved.
Show resolved Hide resolved
JsonNodeFactory.instance.textNode(str)
} else {
MAPPER.readTree(str)
}
} catch {
case _: Exception => JsonNodeFactory.instance.textNode(str)
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/scala/com/snowflake/snowpark_test/DataTypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.snowflake.snowpark_test
import com.snowflake.snowpark.{Row, SNTestBase, TestUtils}
import com.snowflake.snowpark.types._
import com.snowflake.snowpark.functions._
import com.snowflake.snowpark.internal.Utils

import java.sql.{Date, Time, Timestamp}
import java.util.TimeZone
Expand Down Expand Up @@ -588,4 +589,28 @@ class DataTypeSuite extends SNTestBase {
|""".stripMargin)
// scalastyle:on
}

test("Variant containing word null in the text") {
import session.implicits._
var variant = new Variant("null string starts with null")
var df = Seq(variant).toDF("a")
checkAnswer(
df,
Row("\"null string starts with null\"")
)

variant = new Variant("string with null in the middle")
df = Seq(variant).toDF("a")
checkAnswer(
df,
Row("\"string with null in the middle\"")
)

variant = new Variant("string with null in the end null")
df = Seq(variant).toDF("a")
checkAnswer(
df,
Row("\"string with null in the end null\"")
)
}
}
Loading