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-1374896: return toString result for getObject called on structured types #1945

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sfc-gh-mkubik
Copy link
Contributor

@sfc-gh-mkubik sfc-gh-mkubik commented Oct 29, 2024

SNOW-1374896

Turns out that backward compatibility with JSON structured types may also require support for getObject and getBytes methods.
This PR adds JSON/ARROW compatibility for getObject

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

@sfc-gh-mkubik sfc-gh-mkubik changed the title SNOW-1374896: return toString result for getObject and getBytes called on structured types SNOW-1374896: return toString result for getObject called on structured types Oct 30, 2024
@sfc-gh-pmotacki sfc-gh-pmotacki marked this pull request as ready for review October 30, 2024 09:48
@sfc-gh-pmotacki sfc-gh-pmotacki requested a review from a team as a code owner October 30, 2024 09:48
.collect(
Collectors.toMap(
entry -> entry.get("key").toString(), entry -> entry.get("value")));
return isNull(index) ? null : new StructObject(toString(index), map);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we return null before processing entries?

return entriesList.stream()
.collect(
Collectors.toMap(entry -> entry.get("key").toString(), entry -> entry.get("value")));
Map map =
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's add generics

Map<String, T> resultMap = new HashMap<>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (SQLData.class.isAssignableFrom(type)) {
SQLData instance = (SQLData) SQLDataCreationHelper.create(type);
SQLInput sqlInput =
sfBaseResultSet.createSqlInputForColumn(
entry.getValue(),
object.getClass(),
object.getObject().getClass(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

object.getObject() looks strange - can we rename variable?

} else if (object instanceof StructObject) {
return ((StructObject) object).getStringJson();
} else if (object instanceof SfSqlArray) {
return ((SfSqlArray) object).getJsonString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we decide to have method getStringJson or getJsonString?

@@ -62,6 +62,15 @@ public void testRunAsGetString() throws SQLException {
(resultSet) -> assertGetStringIsCompatible(resultSet, expectedStructureTypeRepresentation));
}

@Test
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we still cannot run tests on Github?

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.

3 participants