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

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

Merged
merged 7 commits into from
Sep 10, 2024

Conversation

sfc-gh-fgonzalezmendez
Copy link
Collaborator

@sfc-gh-fgonzalezmendez sfc-gh-fgonzalezmendez commented Aug 21, 2024

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:

    • 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)

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

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.

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

@sfc-gh-fgonzalezmendez
Copy link
Collaborator Author

sfc-gh-fgonzalezmendez commented Aug 29, 2024

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].

@sfc-gh-fgonzalezmendez sfc-gh-fgonzalezmendez force-pushed the SIT-2037 branch 2 times, most recently from 5bec589 to c8ebed8 Compare September 4, 2024 21:24
Copy link

@sfc-gh-mvegaalvarez sfc-gh-mvegaalvarez 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-mrojas sfc-gh-mrojas merged commit eed60a4 into main Sep 10, 2024
18 checks passed
@sfc-gh-mrojas sfc-gh-mrojas deleted the SIT-2037 branch September 10, 2024 15:17
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.

5 participants