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
[CALCITE-1128] Implement JDBC batch update methods in remote driver #209
Conversation
I've scanned through the PR and it looks OK. |
Thanks for the quick glance @vlsi ! |
int i = 1; | ||
for (TypedValue value : batch) { | ||
// Use the value and then increment | ||
preparedStmt.setObject(i++, value.value); |
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.
Does this ever work for null values?
Proper setNull(index, sqltype, sqltypename)
should be used
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.
Not sure, I just copied what the existing prepared statement logic was doing. Let me write up a quick test.
0fa2d87
to
3635151
Compare
Just pushed two more commits. One gives a better exception in JdbcMeta and the other is a test for setting nulls in JdbcMeta (in the batch and non-batch paths). Thanks against, Vladimir! |
@joshelser, regarding null values, consider the following: Case 2) Consider a statement |
Uhh, wrong user mention there, Vladimir. I'm @joshelser.
But the types of the parameters in the statement are already defined at this point. We're just setting binding a value -- this isn't defining the type of that value.
I really don't follow what you're trying to tell me. Can you phrase your concern by not asking me a question? |
Can you please pin-point where the type is defined? |
My concern is this setObject: https://github.com/apache/calcite/pull/209/files#diff-39e8b3d56f84afa3fbffe40bed7cbbc2R895 does not convey data type properly. Failing to specify data type causes performance degradation for major RDBMS (e.g. Oracle, PostgreSQL). For instance, PostgreSQL cannot efficiently batch statements if data type of a column changes from row to row. |
I thought that the PreparedStatement is going to know when this value can be coerced into whatever the necessary value at runtime is. Maybe I'm assuming too much on what will happen behind the scenes. |
But is this case any different than what is already done in |
That is a typical JDBC user's pitfall. |
.. which is fine if we'll get better performance out of |
That is why I just highlighted the issue here. |
Both apply.
In such a case, "prepared statement" would fail with null argument since database would have no way to pick the proper procedure. That is functional issue. The query would fail with SQLException instead of execution of proper procedure with null argument.
Performance issue: if type of bind value changes over time (e.g. |
I'm not sure how struct/array/SQLData types are supported, if supported at all. |
That's why I sent you a link to the code :). We're doing the same thing in other areas of the code. Thanks for bringing it up. This sounds to me like a limitation of how Avatica is handling types in PreparedStatements. Can you write this up in a JIRA issue? I can try to do it, but I don't want to misrepresent the issues (as I apparently don't fully understand the nitty-gritty details of the problem). If not, I can try copy-pasting what you've already typed up here. I just want to make sure that we don't lose the fact that we should try to address this. |
It might be just fine to add some I just wanted to limit the danger. If it is possible to implement that properly already, it would be better to go that way. At later stages it could be harder to fix the issue due to "backward compatibility", etc, etc. Ok. I think you've got my point. |
Method javadoc needs to use third person throughout. Sorry to be pedantic. |
No worries! I appreciate you looking. I'll give it another pass over before it gets merged (I had grabbed a few yesterday). |
This commit provides an implementation for: * Statement.addBatch(String) * PreparedStatement.addBatch() * PreparedStatement.executeBatch() The implementation is fairly straightforward except for the addition of a new server interface: ProtobufMeta. This is a new interface which the Meta implementation can choose to also implement to provide a "native" implementation on top of Protobuf objects instead of the Avatica POJOs. During the investigations Avatica performance pre-1.7.0, it was found that converting protobufs to POJOs was a very hot code path. This short-circuit helps us avoid extra objects on the heap and computation to create them in what should be a very hot code path for write-workloads.
Created https://issues.apache.org/jira/browse/CALCITE-1164 for the discussion with Vladimir earlier. |
e8bf2b4
to
e83aca0
Compare
This commit provides an implementation for:
The implementation is fairly straightforward except for the addition
of a new server interface: ProtobufMeta. This is a new interface which
the Meta implementation can choose to also implement to provide a "native"
implementation on top of Protobuf objects instead of the Avatica POJOs.
During the investigations Avatica performance pre-1.7.0, it was found
that converting protobufs to POJOs was a very hot code path. This short-circuit
helps us avoid extra objects on the heap and computation to create them
in what should be a very hot code path for write-workloads.