Skip to content

Commit

Permalink
Fix bug with zero-length values in varbinary vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
lidavidm committed Jul 26, 2022
1 parent 0e80e0e commit 52ae3bb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void bind(PreparedStatement statement, int parameterIndex, int rowIndex)
throw new RuntimeException(message);
}
byte[] binaryData = new byte[(int) element.getLength()];
element.getBuf().getBytes(0, binaryData);
element.getBuf().getBytes(element.getOffset(), binaryData);
statement.setBytes(parameterIndex, binaryData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void bind(PreparedStatement statement, int parameterIndex, int rowIndex)
throw new RuntimeException(message);
}
byte[] utf8Bytes = new byte[(int) element.getLength()];
element.getBuf().getBytes(0, utf8Bytes);
element.getBuf().getBytes(element.getOffset(), utf8Bytes);
statement.setString(parameterIndex, new String(utf8Bytes, StandardCharsets.UTF_8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,22 @@ <T, V extends FieldVector> void testSimpleType(ArrowType arrowType, int jdbcType

setNull.accept(vector, 0);
setValue.accept(vector, 1, values.get(2));
root.setRowCount(2);
setValue.accept(vector, 2, values.get(0));
setValue.accept(vector, 3, values.get(2));
setValue.accept(vector, 4, values.get(1));
root.setRowCount(5);

assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isNull();
assertThat(statement.getParamType(1)).isEqualTo(jdbcType);
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(2));
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(0));
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(2));
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(1));
assertThat(binder.next()).isFalse();
}

Expand All @@ -454,11 +463,23 @@ <T, V extends FieldVector> void testSimpleType(ArrowType arrowType, int jdbcType

binder.reset();

setValue.accept(vector, 0, values.get(2));
root.setRowCount(1);
setValue.accept(vector, 0, values.get(0));
setValue.accept(vector, 1, values.get(2));
setValue.accept(vector, 2, values.get(0));
setValue.accept(vector, 3, values.get(2));
setValue.accept(vector, 4, values.get(1));
root.setRowCount(5);

assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(0));
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(2));
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(0));
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(2));
assertThat(binder.next()).isTrue();
assertThat(statement.getParamValue(1)).isEqualTo(values.get(1));
assertThat(binder.next()).isFalse();
}
}
Expand Down

0 comments on commit 52ae3bb

Please sign in to comment.