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

Improve RowMetadata for presence/absence check of columns #56

Closed
mp911de opened this issue Mar 12, 2019 · 4 comments
Closed

Improve RowMetadata for presence/absence check of columns #56

mp911de opened this issue Mar 12, 2019 · 4 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@mp911de
Copy link
Member

mp911de commented Mar 12, 2019

RowMetadata currently exposes getColumnMetadata(…) and getColumnMetadatas(). If a client wants to check if a column is part of the result, then it has to obtain getColumnMetadatas() and iterate over ColumnMetadata.

For a discovery-based client, that does not know the structure of a result, this mapping causes a significant overhead as the client cannot cache a previous metadata object. getColumnMetadata(…) on the other hand, throws an exception of the column at identifier (e.g. name of the column) is absent.

How about introducing a SortedSet<String> getColumnNames() as short-cut? This would solve at least three issues:

  1. Discovery of the number of columns in the row.
  2. Fast retrieval of column names without additional mapping.
  3. Clients can easily call getColumnNames().contains(…) to check whether a column exists.

A nice side effect is that drivers can implement naming rules themselves (e.g. via TreeSet and a Collation) and drivers can cache the result metadata based on vendor-specific rules.

See also spring-projects/spring-data-r2dbc#69 for a use-case.

@nbenjamin
Copy link
Contributor

@mp911de created a PR for this change #58. Please review and let me know if any changes are required

@nebhale
Copy link
Member

nebhale commented Apr 12, 2019

A nice side effect is that drivers can implement naming rules themselves (e.g. via TreeSet and a Collation)

@mp911de Can you please elaborate on this a little?

@mp911de
Copy link
Member Author

mp911de commented Apr 15, 2019

Databases typically implement their own rules how they compare field names (case-sensitive, case-insensitive) and they allow modifiers to (like escape chars) to enforce the former or the latter comparison method. By using an appropriate Comparator, drivers can implement column name equality rules, might resemble functionality of what Spring's LinkedCaseInsensitiveMap does.

@nebhale
Copy link
Member

nebhale commented Apr 15, 2019

Understood. I'm good with this proposal then and am OK merging #58.

nbenjamin added a commit to nbenjamin/r2dbc-spi that referenced this issue Apr 16, 2019
Replace Stream with forEach

replace foreach with for loop

remove unused import
nbenjamin added a commit to nbenjamin/r2dbc-spi that referenced this issue Apr 17, 2019
Replace Stream with forEach

replace foreach with for loop

remove unused import

change to Collection
nbenjamin added a commit to nbenjamin/r2dbc-spi that referenced this issue Apr 25, 2019
Replace Stream with forEach

replace foreach with for loop

remove unused import

change to Collection

Change to LinkedHashSet
nbenjamin added a commit to nbenjamin/r2dbc-spi that referenced this issue Apr 29, 2019
Replace Stream with forEach

replace foreach with for loop

remove unused import

change to Collection

Change to LinkedHashSet

update jave doc
mp911de added a commit that referenced this issue Apr 29, 2019
Slightly tweak Javadoc wording. Update MockRowMetadata.getColumnNames() implementation to reflect case-insensitive lookup.

[#56][#58]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants