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-1848734 Prevent string creation on getObject call when not necessary #1989

Conversation

sfc-gh-mkubik
Copy link
Contributor

@sfc-gh-mkubik sfc-gh-mkubik commented Dec 9, 2024

Overview

Commit 1 move StructObjectWrapper from converters to SFArrowResultSet

  • toObject no longer generates string
  • StructObjectWrapper containing both generated string and object are created in SFArrowResultSet.getObject(int columnIndex). Next step is implementing getObject(int columnIndex, Class<T> type) which only calls the converter.toString when type is string

Further commits:

  • Always return StructObjectWrapper in arrow getObject
  • Add sqlInput field to StructObjectWrapper, populate with Json/Arrow SQLInput, keep the object field for Maps/Array(?) use cases
  • Adjust SnowflakeBaseResultSet to make use of StructObjectWrappers

SNOW-1848734

Pre-review self checklist

  • PR branch is updated with all the changes from master branch
  • The code is correctly formatted (run mvn -P check-style validate)
  • New public API is not unnecessary exposed (run mvn verify and inspect target/japicmp/japicmp.html)
  • The pull request name is prefixed with SNOW-XXXX:
  • Code is in compliance with internal logging requirements

External contributors - please answer these questions before submitting a pull request. Thanks!

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

    Issue: #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 modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency or upgrading an existing one
    • I am adding new public/protected component not marked with @SnowflakeJdbcInternalApi (note that public/protected methods/fields in classes marked with this annotation are already internal)
  3. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

@sfc-gh-mkubik sfc-gh-mkubik marked this pull request as ready for review December 9, 2024 17:39
@sfc-gh-mkubik sfc-gh-mkubik requested a review from a team as a code owner December 9, 2024 17:39
…uctured-types-get-object' of github.com:snowflakedb/snowflake-jdbc into SNOW-1848734-prevent-unnecessary-string-creation-in-structured-types-get-object
boolean isStructuredType = resultSetMetaData.isStructuredTypeColumn(columnIndex);
if (obj == null) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a lot of duplicated code lines between getObject(index) and getObject(index, type)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved some part of it to external method

return new StructObjectWrapper(null, null, obj);
}

@SnowflakeJdbcInternalApi
Copy link
Collaborator

Choose a reason for hiding this comment

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

private method does not need the internal annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I'll remove

@@ -113,6 +113,8 @@ public abstract class SFBaseResultSet {

public abstract Object getObject(int columnIndex) throws SFException;

public abstract <T> Object getObject(int columnIndex, Class<T> object) throws SFException;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this API looks strange - the result type should be T, not Object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, in reality this getObject mostly returns StructObjectWrapper which possibly could be generic. I may rename this method since it's used in higher level getObject anyway to better indicate it's purpose

private <T> Map<String, Object> prepareMapWithValues(Object object, Class<T> type)
throws SFException {
if (object instanceof JsonSqlInput) {
private <T> Map<String, Object> prepareMapWithValues(
Copy link
Collaborator

Choose a reason for hiding this comment

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

where are we using type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was already there, in line 1830 to check if it's assignable to SQLData

@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2024
@sfc-gh-dprzybysz sfc-gh-dprzybysz deleted the SNOW-1848734-prevent-unnecessary-string-creation-in-structured-types-get-object branch December 10, 2024 13:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants