Skip to content

Commit

Permalink
apacheGH-38627: [Java][FlightRPC] Handle null parameter values (apach…
Browse files Browse the repository at this point in the history
…e#38628)

### Rationale for this change

We want to make sure we correctly handle binding `null` values to JDBC parameters.
We also want better exceptions when handling parameter binding.

### What changes are included in this PR?

- Handle adding null values to parameters if it's a nullable vector, else throw `UnsupportedOperationException`
- For unsupported parameter types or casts, throw `UnsupportedOperationException` instead of `RuntimeException`
* Closes: apache#38627

Authored-by: Diego Fernandez <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
aiguofer authored and JerAguilon committed Nov 8, 2023
1 parent 5c8d434 commit aaa829b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ public interface AvaticaParameterConverter {
*
* @param vector FieldVector that the parameter should be bound to.
* @param typedValue TypedValue to bind as a parameter.
* @param index Vector index that the TypedValue should be bound to.
* @param index Vector index (0-indexed) that the TypedValue should be bound to.
* @return Whether the value was set successfully.
*/
boolean bindParameter(FieldVector vector, TypedValue typedValue, int index);

/**
* Create an AvaticaParameter from the given Field.
*
* @param field Arrow Field to generate an AvaticaParameter from.
*/
AvaticaParameter createParameter(Field field);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public TimestampAvaticaParameterConverter(ArrowType.Timestamp type) {

@Override
public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) {
// FIXME: how should we handle TZ? Do we need to convert the value to the TZ on the vector?
long value = (long) typedValue.toLocal();
if (vector instanceof TimeStampSecVector) {
((TimeStampSecVector) vector).setSafe(index, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ public void bind(List<TypedValue> typedValues, int index) {
*/
private void bind(FieldVector vector, TypedValue typedValue, int index) {
try {
if (!vector.getField().getType().accept(new BinderVisitor(vector, typedValue, index))) {
throw new RuntimeException(
if (typedValue.value == null) {
if (vector.getField().isNullable()) {
vector.setNull(index);
} else {
throw new UnsupportedOperationException("Can't set null on non-nullable parameter");
}
} else if (!vector.getField().getType().accept(new BinderVisitor(vector, typedValue, index))) {
throw new UnsupportedOperationException(
String.format("Binding to vector type %s is not yet supported", vector.getClass()));
}
} catch (ClassCastException e) {
throw new RuntimeException(
throw new UnsupportedOperationException(
String.format("Binding value of type %s is not yet supported for expected Arrow type %s",
typedValue.type, vector.getField().getType()));
}
Expand Down

0 comments on commit aaa829b

Please sign in to comment.