Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Jun 7, 2024
1 parent 1fa8c6f commit 91d6740
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class SnowflakeFile {
/**
* Create a new instance of SnowflakeFile. Calls into our C++ layer to construct it.
*
* @param scopedUrl can be scoped URL. Stage file references should use
* the second override to set requireScopedUrl to false.
* @param scopedUrl can be scoped URL. Stage file references should use the second override to set
* requireScopedUrl to false.
* @return A new instance of SnowflakeFile for the given URL.
* @since 1.3.0
*/
Expand Down
30 changes: 16 additions & 14 deletions src/main/scala/com/snowflake/snowpark/types/Variant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,23 @@ class Variant private[snowpark] (
* @since 0.2.0
*/
def this(str: String) =
this({
try {
// `ObjectMapper` only reads the first token from
// the input string but not the whole string.
// For example, It can successfully
// convert "null dummy" to `null` value without reporting error.
if (str.toLowerCase().startsWith("null") && str != "null") {
JsonNodeFactory.instance.textNode(str)
} else {
MAPPER.readTree(str)
this(
{
try {
// `ObjectMapper` only reads the first token from
// the input string but not the whole string.
// For example, It can successfully
// convert "null dummy" to `null` value without reporting error.
if (str.toLowerCase().startsWith("null") && str != "null") {
JsonNodeFactory.instance.textNode(str)
} else {
MAPPER.readTree(str)
}
} catch {
case _: Exception => JsonNodeFactory.instance.textNode(str)
}
} catch {
case _: Exception => JsonNodeFactory.instance.textNode(str)
}
}, VariantTypes.String)
},
VariantTypes.String)

/**
* Creates a Variant from binary value
Expand Down
17 changes: 4 additions & 13 deletions src/test/scala/com/snowflake/snowpark_test/DataTypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -590,27 +590,18 @@ class DataTypeSuite extends SNTestBase {
// scalastyle:on
}

test("Variant containing word null in the text") {
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\"")
)
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\"")
)
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\"")
)
checkAnswer(df, Row("\"string with null in the end null\""))
}
}

0 comments on commit 91d6740

Please sign in to comment.