Skip to content

Commit

Permalink
KUDU-3198: fix encodeRow() when encoding delete operations
Browse files Browse the repository at this point in the history
Before this patch, not all non-key columns are cleared when
encoding delete row operations. If users delele with full row
from a 64 column table, the operation would fail.

Change-Id: I144e1998b99be3e660b7f320c55e4b1c9753a61f
Reviewed-on: http://gerrit.cloudera.org:8080/16571
Reviewed-by: Grant Henke <[email protected]>
Tested-by: Grant Henke <[email protected]>
Reviewed-by: Alexey Serbin <[email protected]>
  • Loading branch information
zhangyifan27 authored and granthenke committed Oct 9, 2020
1 parent 81720a4 commit ea48c9b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ private void encodeRow(PartialRow row, ChangeType type) {
if (type == ChangeType.DELETE) {
columnCount = row.getSchema().getPrimaryKeyColumnCount();
// Clear the bits indicating any non-key fields are set.
columnsBitSet.clear(schema.getPrimaryKeyColumnCount(), columnsBitSet.size() - 1);
columnsBitSet.clear(schema.getPrimaryKeyColumnCount(), columnsBitSet.size());
if (schema.hasNullableColumns()) {
nullsBitSet.clear(schema.getPrimaryKeyColumnCount(), nullsBitSet.size() - 1);
nullsBitSet.clear(schema.getPrimaryKeyColumnCount(), nullsBitSet.size());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import org.junit.Rule;
import org.junit.Test;

import org.apache.kudu.ColumnSchema;
import org.apache.kudu.Schema;
import org.apache.kudu.Type;
import org.apache.kudu.test.ClientTestUtil;
import org.apache.kudu.test.KuduTestHarness;

Expand Down Expand Up @@ -201,6 +203,52 @@ public void testDeleteWithFullRow() throws Exception {
assertEquals(0, countRowsInScan(client.newScannerBuilder(table).build()));
}

/** Regression test for KUDU-3198. Delete with full row from a 64-column table. */
@Test(timeout = 100000)
public void testDeleteWithFullRowFrom64ColumnTable() throws Exception {
ArrayList<ColumnSchema> columns = new ArrayList<>(64);
columns.add(new ColumnSchema.ColumnSchemaBuilder("key", Type.INT32).key(true).build());
for (int i = 1; i < 64; i++) {
columns.add(new ColumnSchema.ColumnSchemaBuilder("column_" + i, Type.STRING)
.nullable(true)
.build());
}
Schema schema = new Schema(columns);

KuduTable table = client.createTable(tableName, schema, getBasicCreateTableOptions());

KuduSession session = client.newSession();
session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);

// Insert 25 rows and then delete them.
List<PartialRow> rows = new ArrayList<>();
for (int i = 0; i < 25; i++) {
Insert insert = table.newInsert();
PartialRow row = insert.getRow();
row.addInt(0, 1);
for (int j = 1; j < 64; j++) {
if (j % 2 == 0) {
row.setNull(j);
} else {
row.addString(j, "val_" + j);
}
}
rows.add(row);
session.apply(insert);
}
session.flush();

for (PartialRow row : rows) {
Delete del = table.newDelete();
del.setRow(row);
session.apply(del);
}
session.flush();

assertEquals(0, session.countPendingErrors());
assertEquals(0, countRowsInScan(client.newScannerBuilder(table).build()));
}

/**
* Regression test for KUDU-1402. Calls to session.flush() should return an empty list
* instead of null.
Expand Down

0 comments on commit ea48c9b

Please sign in to comment.