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-1628247: Fix Jackson Scala module Compatibility Issue #145

Merged
merged 13 commits into from
Aug 22, 2024

Conversation

sfc-gh-yuwang
Copy link
Contributor

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes #NNNN

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    Replace this with a short description of how your code change solves the related issue.

Pre-review checklist

(For Snowflake employees)

  • This change has passed precommit
  • I have reviewed code coverage report for my PR in (Sonarqube)

}
}

private def scalaToJson(node: Any): String = {
Copy link
Collaborator

@sfc-gh-bli sfc-gh-bli Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's simplify this function

 private def scalaToJson(input: Any): String =
    input match {
      // Scala's None and Python's None are different.
      case null => "null"
      case str: String => s""""$str""""
      case _: Int | _: Short | _: Long | _: Byte | _: Double | _: Float |
        _: Boolean => input.toString
      // only supports String keys
      case map: Map[String, _] => map.map {
        case (key, value) => s"${scalaToJson(key)}:${scalaToJson(value)}"
      }.mkString("{", ",", "}")
      // Seq is the most popular collection type in Scala,
      // It is parent type of all List types.
      case seq: Seq[_] => seq.map(scalaToJson).mkString("[", ",", "]")
      // I am not sure If seq can match Array too, so explicitly match Array here.
      // You can test if it is necessary.
      case arr: Array[_] => scalaToJson(arr.toSeq)
      case _ =>
        throw new UnsupportedOperationException(s"Unsupported Type: ${input.getClass.getName}")
    }

"stringKey" -> "stringValue",
"nestedMap" -> Map("insideKey" -> "stringValue", "insideList" -> Seq(1, 2, 3)),
"nestedList" -> Seq(1, Map("nestedKey" -> "nestedValue"), Array(1, 2, 3)))
val jsonString = Utils.mapToJson(map)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a hard code string comparison here.

assert(jsonString == "<the expected output>"

Otherwise, we don't know if the output of mapToJson is correct.

Copy link
Collaborator

@sfc-gh-bli sfc-gh-bli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sfc-gh-yuwang sfc-gh-yuwang changed the title Fix: SNOW-1628247 Priority Customer: Procedure failed due to version incompatibility between the Jackson Scala module and the Jackson Databind library SNOW-1628247: Fix Jackson Scala module Compatibility Issue Aug 22, 2024
@sfc-gh-yuwang sfc-gh-yuwang merged commit f0c6253 into main Aug 22, 2024
16 checks passed
@sfc-gh-yuwang sfc-gh-yuwang deleted the SNOW-1628247 branch August 22, 2024 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants