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

Fix findColumn and get*(String label) methods. #185

Merged
merged 2 commits into from
Dec 20, 2023
Merged

Conversation

goomrw
Copy link
Contributor

@goomrw goomrw commented Dec 19, 2023

The ResultSet findColumn methods (BQForwardOnlyResultSet.findColumn, BQScrollableResultSet.findColumn, and BQResultSet.findColumn) called BQResultSetMetadata.getCatalogName to determine the name of each column instead of BQResultSetMetadata.getColumnLabel.

This was wrong because getCatalogName always returns the BigQuery project ID, not the column name.

This bug in turn broke the get methods that are implemented in terms of findColumn, e.g. getString(String).

This change fixes findColumn and adds tests for methods that use it with some caveats:

  • BQResultSet has its findColumn fixed but it's not tested. That's because it's unused, even by its tests, which request a TYPE_SCROLL_INSENSITIVE result set and thus get a BQScrollableResultSet.

  • BQScrollableResultSet only accepts dates and times that can be parsed as longs, which disagrees with the more widely used BQForwardOnlyResultSet. Its date and time accessors are uncovered.

  • getBigDecimal is excluded because it calls BigDecimal.setScale without a rounding mode, which no longer works in modern Java. A separate change can fix this.

Copy link
Contributor

@tanclary tanclary left a comment

Choose a reason for hiding this comment

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

Left some questions and suggestions 👍

The ResultSet `findColumn` methods (`BQForwardOnlyResultSet.findColumn`,
`BQScrollableResultSet.findColumn`, and `BQResultSet.findColumn`) called
`BQResultSetMetadata.getCatalogName` to determine the name of each column
instead of `BQResultSetMetadata.getColumnLabel`.

This was wrong because `getCatalogName` always returns the BigQuery project ID,
not the column name.

This bug in turn broke the get methods that are implemented in terms of
`findColumn`, e.g. `getString(String)`.

This change fixes `findColumn` and adds tests for methods that use it with some
caveats:

- `BQResultSet` has its findColumn fixed but it's not tested. That's because
it's unused, even by its tests, which request a `TYPE_SCROLL_INSENSITIVE`
result set and thus get a `BQScrollableResultSet`.

- `BQScrollableResultSet` only accepts dates and times that can be parsed as
longs, which disagrees with the more widely used `BQForwardOnlyResultSet`.
Its date and time accessors are uncovered.

- `getBigDecimal` is excluded because it calls `BigDecimal.setScale`
without a rounding mode, which no longer works in modern Java. A
separate change can fix this.
Copy link
Contributor

@fzakaria fzakaria left a comment

Choose a reason for hiding this comment

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

Added nit about optional but otherwise solid change,.

@goomrw goomrw merged commit 94614a9 into main Dec 20, 2023
2 checks passed
@tanclary
Copy link
Contributor

If we do much more work in this repo it might be a good idea to adopt some practices like:

  • having a way of tracking issues or easily correlating a Github PR to a b/ (ideally bidirectional)
  • squashing PR commits down to a single one so the commit history is more readable/helpful.

These are some things Calcite does that I think work to its advantage, what do you think @goomrw @fzakaria ?

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