Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.arrow.driver.jdbc.converter.impl;

import java.math.BigDecimal;
import org.apache.arrow.vector.Decimal256Vector;
import org.apache.arrow.vector.DecimalVector;
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.types.pojo.ArrowType;
Expand All @@ -35,6 +36,9 @@ public boolean bindParameter(FieldVector vector, TypedValue typedValue, int inde
if (vector instanceof DecimalVector) {
((DecimalVector) vector).setSafe(index, value);
return true;
} else if (vector instanceof Decimal256Vector) {
((Decimal256Vector) vector).setSafe(index, value);
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.Date;
Expand Down Expand Up @@ -317,29 +318,32 @@ public void testUpdateQueryWithParameters() throws SQLException {
@Test
public void testUpdateQueryWithBatchedParameters() throws SQLException {
String query = "Fake update with batched parameters";
BigDecimal decimal = new BigDecimal("123456789012345678901234567890123456789.01");
Schema parameterSchema =
new Schema(
Arrays.asList(
Field.nullable("", ArrowType.Utf8.INSTANCE),
new Field(
"",
FieldType.nullable(ArrowType.List.INSTANCE),
Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType())))));
Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType()))),
Field.nullable("", new ArrowType.Decimal(76, 2, 256))));
List<List<Object>> expected =
Arrays.asList(
Arrays.asList(new Text("foo"), new Integer[] {1, 2, null}),
Arrays.asList(new Text("bar"), new Integer[] {0, -1, 100000}));
Arrays.asList(new Text("foo"), new Integer[] {1, 2, null}, decimal),
Arrays.asList(new Text("bar"), new Integer[] {0, -1, 100000}, decimal.negate()));

PRODUCER.addUpdateQuery(query, /*updatedRows*/ 42);
PRODUCER.addExpectedParameters(query, parameterSchema, expected);

try (final PreparedStatement stmt = connection.prepareStatement(query)) {
// TODO: make sure this is validated on the server too
stmt.setString(1, "foo");
stmt.setArray(2, connection.createArrayOf("INTEGER", new Integer[] {1, 2, null}));
stmt.setBigDecimal(3, decimal);
stmt.addBatch();
stmt.setString(1, "bar");
stmt.setArray(2, connection.createArrayOf("INTEGER", new Integer[] {0, -1, 100000}));
stmt.setBigDecimal(3, decimal.negate());
stmt.addBatch();
int[] updated = stmt.executeBatch();
assertEquals(42, updated[0]);
Expand Down
Loading