Skip to content
Merged
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 @@ -358,7 +358,8 @@ public ByteBuffer getRoutingKey() {
if (indices.isEmpty()) {
return null;
} else if (indices.size() == 1) {
return getBytesUnsafe(indices.get(0));
int index = indices.get(0);
return isSet(index) ? getBytesUnsafe(index) : null;
} else {
ByteBuffer[] components = new ByteBuffer[indices.size()];
for (int i = 0; i < components.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,25 @@ private void should_infer_routing_information_when_partition_key_is_bound(String
assertThat(tokenFactory.hash(boundStatement.getRoutingKey())).isEqualTo(expectedToken);
}

@Test
public void should_return_null_routing_information_when_single_partition_key_is_unbound() {
should_return_null_routing_information_when_single_partition_key_is_unbound(
"SELECT a FROM prepared_statement_test WHERE a = ?");
should_return_null_routing_information_when_single_partition_key_is_unbound(
"INSERT INTO prepared_statement_test (a) VALUES (?)");
should_return_null_routing_information_when_single_partition_key_is_unbound(
"UPDATE prepared_statement_test SET b = 1 WHERE a = ?");
should_return_null_routing_information_when_single_partition_key_is_unbound(
"DELETE FROM prepared_statement_test WHERE a = ?");
}

private void should_return_null_routing_information_when_single_partition_key_is_unbound(
String queryString) {
CqlSession session = sessionRule.session();
BoundStatement boundStatement = session.prepare(queryString).bind();
assertThat(boundStatement.getRoutingKey()).isNull();
}

private static Iterable<Row> firstPageOf(CompletionStage<AsyncResultSet> stage) {
return CompletableFutures.getUninterruptibly(stage).currentPage();
}
Expand Down