Skip to content

SQL: Add BigDecimal support to JDBC #56015

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

Merged
merged 9 commits into from
May 4, 2020

Conversation

bpintea
Copy link
Contributor

@bpintea bpintea commented Apr 30, 2020

This PR implements the JDBC support for BigDecimals. This is limited however, since ES support for this type is limited.
Fetching BigDecimals works with no restrictions, since all ES native and SQL numeric (and boolean) types can be accommodated by a BigDecimal.
Setting a BigDecimal value for a parameter in a prepared statement is limited to what a double can encode.

Closes #43806

bpintea added 2 commits April 29, 2020 22:35
This commit adds support for the getBigDecimal() methods.
A prepared statement will now accept a BigDecimal parameter as a proxy
for a double, if the conversion is lossless.
Comment on lines -24 to -28
index("library", builder -> {
builder.field("name", "Don Quixote");
builder.field("page_count", 1072);
});

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've removed an index involvement mostly due to #56013. Using an index for this test doesn't seem to bring any particular value, but can revert if I'm missing anything.

bpintea added 3 commits April 30, 2020 15:12
- adjust unchanged line to newly enforced line limit
Remove wrongly added chunk.
@bpintea bpintea marked this pull request as ready for review May 4, 2020 11:26
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (:Query Languages/SQL)

@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label May 4, 2020
@bpintea bpintea requested review from costin, matriv and astefan May 4, 2020 11:27
Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -547,7 +550,9 @@ public InputStream getBinaryStream(int columnIndex) throws SQLException {
@Override
@Deprecated
public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
throw new SQLFeatureNotSupportedException("BigDecimal not supported");
BigDecimal bd = getBigDecimal(columnLabel);
Copy link
Member

Choose a reason for hiding this comment

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

Why not delegate to the other getBigDecimal -> return getBigDecimal(column(columnLabel), scale) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, good point! Thanks.

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. Nice enhancements on the ResultSet testing!
Left a couple of comments.

put(Long.class, Types.BIGINT);
put(Float.class, Types.REAL);
put(Double.class, Types.DOUBLE);
// TODO: no half & scaled float testing
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not adding those too?

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 probably should be done indeed, but I was thinking to keep it focused on BigDecimal for now, since adding coverage for half- and scaled- floats would require extending the testing for the rest of the types too.

bpintea and others added 4 commits May 4, 2020 18:01
Remove code duplicate in getBigDecimal(String columnLabel, int scale).
…/qa/jdbc/ResultSetTestCase.java

Co-authored-by: Marios Trivyzas <[email protected]>
Disable the deprecation-API usage failure, since this is used to
implement a deprecated API itself.
Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

@bpintea bpintea merged commit e9a873a into elastic:master May 4, 2020
@bpintea bpintea deleted the enh/jdbc_bigdecimal branch May 4, 2020 19:02
bpintea added a commit that referenced this pull request May 5, 2020
* SQL: Add BigDecimal support to JDBC (#56015)

* Introduce BigDecimal support to JDBC -- fetching

This commit adds support for the getBigDecimal() methods.

* Allow BigDecimal params in double range

A prepared statement will now accept a BigDecimal parameter as a proxy
for a double, if the conversion is lossless.

(cherry picked from commit e9a873a)

* Fix compilation error

Dimond notation with anonymous inner classes not avail in Java8.
@jakelandis jakelandis removed the v8.0.0 label Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL: implement get/setBigDecimal for JDBC
6 participants