snowflakedb / snowpark-java-scala

Snowflake Snowpark Java & Scala API
Apache License 2.0
18 stars 20 forks source link

SIT-2037 Add support for `com.snowflake.snowpark.Row.getAs` function #148

Closed sfc-gh-fgonzalezmendez closed 2 days ago

sfc-gh-fgonzalezmendez commented 3 weeks ago

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 SIT-2037

  2. Fill out the following pre-review checklist:

    • [X] 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.

    It adds a new function to the Row class that returns the value at the specified column index and casts it to the desired type.

Pre-review checklist

(For Snowflake employees)

sfc-gh-fgonzalezmendez commented 2 weeks ago

I see this PR missed structured types and timestamp types, what is the plan to support them?

@sfc-gh-bli Can you explain in more detail which scenarios are not covered yet with this implementation, please?

For example, calling the function row.getAs[Timestamp](0) will have the same behaviour as calling the function row.getTimestamp(0). Inside, those two functions will just call get(index).asInstanceOf[T]

val schema = StructType(StructField("c1", TimestampType))
val data = Seq(Row(new Timestamp(System.currentTimeMillis())))
val row = session.createDataFrame(data, schema).collect()(0)
row.getAs[Timestamp](0) == row.getTimestamp(0) // true

Regarding the structured types, I think it is similar to the above scenario. Those types will fall in the default case: get(index).asInstanceOf[T].