GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: adds getValue to ResultSet by thiagotnunes · Pull Request #1073 · googleapis/java-spanner

This repository was archived by the owner on Aug 30, 2026. It is now read-only.

Conversation

@thiagotnunes

@thiagotnunes thiagotnunes commented Apr 19, 2021

Copy link
Copy Markdown
Contributor

Adds the method getValue to the ResultSet. This will return an encapsulated value. It supports all the column types that are provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thiagotnunes added 3 commits April 19, 2021 15:49
@thiagotnunes
feat: adds getValue method to result set
a38c291
Adds a generic getValue method to the result set. It can be used to
retrieve any type from the database.
@thiagotnunes
feat: removes custom int64 and float64 arrays
88e8f35
@thiagotnunes
feat: fixes clirr checks
6a5680c
Clirr does not support java 8 default implementations, so it thinks this
are breaking changes. These in fact are not breaking changes, since we
provide implementations in the interfaces.
@thiagotnunes
thiagotnunes requested review from a team April 19, 2021 06:06
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the googleapis/java-spanner API. label Apr 19, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 19, 2021
thiagotnunes
thiagotnunes commented Apr 19, 2021
View reviewed changes
Comment thread google-cloud-spanner/clirr-ignored-differences.xml
<className>com/google/cloud/spanner/AsyncTransactionManager$CommitTimestampFuture</className>
<method>java.lang.Object get()</method>
</difference>

@thiagotnunes thiagotnunes Apr 19, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Clirr does not support Java 8 features, so it thinks these are breaking changes, where in fact we have provided default implementations for the added interface methods. No need for a major release here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@thiagotnunes
thiagotnunes requested review from olavloite, skuruppu and zoercai April 19, 2021 06:11
olavloite
olavloite reviewed Apr 19, 2021
View reviewed changes
Comment thread google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

thiagotnunes added 2 commits April 19, 2021 16:51
@thiagotnunes
test: fixes GrpcResultSet serialize test
7c2e990
@thiagotnunes
feat: implements getValueInternal in result set
06d2e9c
Adds a less intrusive implementation of getValueInternal for the
AbstractResultSet.
@thiagotnunes

thiagotnunes commented Apr 19, 2021

Copy link
Copy Markdown
Contributor Author

@olavloite got it, thanks for the feedback. I've re-implemented with a less intrusive manner, let me know if that makes sense.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thiagotnunes
thiagotnunes requested a review from olavloite April 19, 2021 09:29
thiagotnunes
thiagotnunes commented Apr 19, 2021
View reviewed changes
Comment thread google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

olavloite
olavloite reviewed Apr 19, 2021
View reviewed changes
Comment thread google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java Outdated
}

@Test
public void testReadNullInArrays() {

@olavloite olavloite Apr 19, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think it would be good to add null values for INT64 and FLOAT64 arrays as well in this test. Arrays of all types can always contain null values, regardless whether the column itself is nullable, and regardless of the array element type.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thiagotnunes thiagotnunes Apr 19, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

These throw a NPE as they do if you use a resultSet.getLongArray(...) or resultSet.getDoubleArray(...). I could test the exception if you feel like we should.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Apr 19, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No, in that case I actually think we should change the implementation. It is logical that resultSet.getDoubleArray(..) throws an NPE. I don't think it is logical that resultSet.getValue("some-float64-array-col") should ever throw an NPE because one of the elements is null, as a Value can hold a null value for an element of an ARRAY<FLOAT64>.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thiagotnunes thiagotnunes Apr 20, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Changed the implementation to support nulls in arrays and added tests for it.

In regards to a single null value as in SELECT column FROM table (where column value is null), when we do a getValue it is currently throwing an exception as if we called a resultSet.getString(...). Do you think we should change this as well?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Apr 20, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, I think we should change that as well now that we have a chance. Value also has an isNull() method, so it would make sense to let resultSet.getValue(...) return a Value instance when the column is null. The user can then check whether the value is actually null by calling Value#isNull().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thiagotnunes thiagotnunes Apr 21, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Awesome, changed the implementation to allow for that. If you could re-review, I'd appreciate it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
olavloite
olavloite approved these changes Apr 19, 2021
View reviewed changes

@olavloite olavloite left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This looks good to me, but I think for completeness it would be good to add null values to the integration tests for all array types. Now the primitive types are missing (Long and Double).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thiagotnunes added 4 commits April 20, 2021 10:42
@thiagotnunes
fix: fixes struct value decoding
3a76dc0
Uses the correct type for decoding structs from the result set
@thiagotnunes
feat: makes the structArray method public
49f3d83
Makes it public the method  to retrieve an array of structs from a Value
@thiagotnunes
test: adds tests for value literals
02a027e
@thiagotnunes
feat: accepts null in arrays for getValue
285b048
thiagotnunes
thiagotnunes commented Apr 20, 2021
View reviewed changes
Comment thread google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java
* @throws IllegalStateException if {@code isNull()} or the value is not of the expected type
*/
abstract List<Struct> getStructArray();
public abstract List<Struct> getStructArray();

@thiagotnunes thiagotnunes Apr 20, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@olavloite I made this method public. It surprising me that this was not public before, since users can SELECT ARRAY(SELECT STRUCT ...) and would not be able to get the results.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

olavloite reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@codecov

codecov Bot commented Apr 20, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #1073 (cab531b) into master (1eeb6aa) will decrease coverage by 0.24%.
The diff coverage is 21.15%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1073      +/-   ##
============================================
- Coverage     85.17%   84.93%   -0.25%     
- Complexity     2719     2727       +8     
============================================
  Files           155      156       +1     
  Lines         14351    14403      +52     
  Branches       1358     1380      +22     
============================================
+ Hits          12224    12233       +9     
- Misses         1558     1603      +45     
+ Partials        569      567       -2     
Impacted Files Coverage Δ Complexity Δ
...va/com/google/cloud/spanner/AbstractResultSet.java 79.13% <0.00%> (-4.32%) 28.00 <0.00> (ø)
...m/google/cloud/spanner/ForwardingStructReader.java 24.27% <0.00%> (-0.99%) 12.00 <0.00> (ø)
...in/java/com/google/cloud/spanner/StructReader.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
.../src/main/java/com/google/cloud/spanner/Value.java 87.81% <ø> (ø) 63.00 <0.00> (ø)
...oud/spanner/connection/DirectExecuteResultSet.java 96.77% <50.00%> (-1.56%) 61.00 <2.00> (+2.00) ⬇️
...ner/connection/ReplaceableForwardingResultSet.java 96.72% <50.00%> (-1.59%) 58.00 <2.00> (+2.00) ⬇️
...com/google/cloud/spanner/AbstractStructReader.java 98.40% <80.00%> (-0.77%) 53.00 <2.00> (+2.00) ⬇️
...main/java/com/google/cloud/spanner/ResultSets.java 97.08% <100.00%> (+0.05%) 5.00 <0.00> (ø)
...src/main/java/com/google/cloud/spanner/Struct.java 88.78% <100.00%> (+0.10%) 28.00 <0.00> (ø)
.../google/cloud/spanner/AbstractLazyInitializer.java 92.85% <0.00%> (-7.15%) 4.00% <0.00%> (-1.00%)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1eeb6aa...cab531b. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thiagotnunes
feat: allows nulls in values from result sets
bab743f
@thiagotnunes
thiagotnunes requested a review from olavloite April 21, 2021 01:43
olavloite
olavloite approved these changes Apr 21, 2021
View reviewed changes
Comment thread google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java Outdated
throw new UnsupportedOperationException("method should be overwritten");
}

/** Returns the value of a non-{@code NULL} column as a {@link Value}. */

@olavloite olavloite Apr 21, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nit: This should be updated to indicate that this method can be called for columns that contain a null value, and what the behavior is when the value is null.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thiagotnunes
docs: fixes java doc for getValue
cab531b
@thiagotnunes
thiagotnunes merged commit 7792c90 into googleapis:master Apr 25, 2021
@thiagotnunes
thiagotnunes deleted the result-set-get-value branch April 25, 2021 03:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@zoercai zoercai Awaiting requested review from zoercai
@skuruppu skuruppu Awaiting requested review from skuruppu
1 more reviewer
@olavloite olavloite olavloite approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: spanner Issues related to the googleapis/java-spanner API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@thiagotnunes @olavloite
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.