PartialRow splitRow = schema.newPartialRow(); splitRow.addInt("key", i*1000); builder.addSplitRow(splitRow);
public static CreateTableOptions getCreateTableOptions(Schema schema, int numReplicas, int rangePartitions, int hashPartitions) { Preconditions.checkArgument(rangePartitions > 0); Preconditions.checkArgument(hashPartitions > 0); CreateTableOptions options = new CreateTableOptions().setNumReplicas(numReplicas); if (rangePartitions > 1) { options.setRangePartitionColumns(ImmutableList.of(COLUMN_KEY_ONE)); BigInteger min = BigInteger.valueOf(Long.MIN_VALUE); BigInteger max = BigInteger.valueOf(Long.MAX_VALUE); BigInteger step = max.multiply(BigInteger.valueOf(2)) .divide(BigInteger.valueOf(rangePartitions)); PartialRow splitRow = schema.newPartialRow(); for (int i = 1; i < rangePartitions; i++) { long key = min.add(step.multiply(BigInteger.valueOf(i))).longValue(); splitRow.addLong(COLUMN_KEY_ONE_IDX, key); options.addSplitRow(splitRow); } } else { options.setRangePartitionColumns(Collections.<String>emptyList()); } if (hashPartitions > 1) { options.addHashPartitions(ImmutableList.of(COLUMN_KEY_ONE), hashPartitions); } return options; }
@Test(timeout = 100000) public void testSimplePartitionedTable() throws Exception { Schema schema = createSchema(); CreateTableOptions tableBuilder = new CreateTableOptions().setRangePartitionColumns(ImmutableList.of("a", "b", "c")); PartialRow split = schema.newPartialRow(); split.addString("c", "3"); tableBuilder.addSplitRow(split); split = schema.newPartialRow(); split.addString("c", "3"); split.addString("b", "3"); tableBuilder.addSplitRow(split); testPartitionSchema(tableBuilder); }
@Test(timeout = 100000) public void testHashBucketedAndRangePartitionedTable() throws Exception { Schema schema = createSchema(); CreateTableOptions tableBuilder = new CreateTableOptions(); tableBuilder.addHashPartitions(ImmutableList.of("a"), 3); tableBuilder.addHashPartitions(ImmutableList.of("b", "c"), 3, 42); tableBuilder.setRangePartitionColumns(ImmutableList.of("c", "b")); PartialRow split = schema.newPartialRow(); split.addString("c", "3"); tableBuilder.addSplitRow(split); split = schema.newPartialRow(); split.addString("c", "3"); split.addString("b", "3"); tableBuilder.addSplitRow(split); testPartitionSchema(tableBuilder); }
@Test(timeout = 100000) public void testNonDefaultRangePartitionedTable() throws Exception { Schema schema = createSchema(); CreateTableOptions tableBuilder = new CreateTableOptions(); tableBuilder.setRangePartitionColumns(ImmutableList.of("c", "b")); PartialRow split = schema.newPartialRow(); split.addString("c", "3"); tableBuilder.addSplitRow(split); split = schema.newPartialRow(); split.addString("c", "3"); split.addString("b", "3"); tableBuilder.addSplitRow(split); testPartitionSchema(tableBuilder); }
private KuduTable createTableWithSplitsAndTest(String tableNamePrefix, int splitsCount) throws Exception { String newTableName = tableNamePrefix + "-" + splitsCount; CreateTableOptions builder = getBasicCreateTableOptions(); if (splitsCount != 0) { for (int i = 1; i <= splitsCount; i++) { PartialRow row = BASIC_SCHEMA.newPartialRow(); row.addInt(0, i); builder.addSplitRow(row); } } KuduTable table = client.createTable(newTableName, BASIC_SCHEMA, builder); List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP); assertEquals(splitsCount + 1, tablets.size()); assertEquals(splitsCount + 1, table.asyncGetTabletsLocations(DEFAULT_SLEEP).join().size()); for (LocatedTablet tablet : tablets) { assertEquals(3, tablet.getReplicas().size()); } return table; }
createOptions.addSplitRow(splitRow);
split.addByte("b", (byte) 0); split.addByte("c", (byte) 0); tableBuilder.addSplitRow(split); split.addByte("a", (byte) 10); split.addByte("b", (byte) 10); split.addByte("c", (byte) 10); tableBuilder.addSplitRow(split);
/** * Creates table options with non-covering range partitioning for a table with * the basic schema. Range partition key ranges fall between the following values: * * [ 0, 50) * [ 50, 100) * [200, 300) */ public static CreateTableOptions getBasicTableOptionsWithNonCoveredRange() { Schema schema = getBasicSchema(); CreateTableOptions option = new CreateTableOptions(); option.setRangePartitionColumns(ImmutableList.of("key")); PartialRow aLowerBound = schema.newPartialRow(); aLowerBound.addInt("key", 0); PartialRow aUpperBound = schema.newPartialRow(); aUpperBound.addInt("key", 100); option.addRangePartition(aLowerBound, aUpperBound); PartialRow bLowerBound = schema.newPartialRow(); bLowerBound.addInt("key", 200); PartialRow bUpperBound = schema.newPartialRow(); bUpperBound.addInt("key", 300); option.addRangePartition(bLowerBound, bUpperBound); PartialRow split = schema.newPartialRow(); split.addInt("key", 50); option.addSplitRow(split); return option; }
split.addByte("a", (byte) 0); split.addByte("b", (byte) 0); tableBuilder.addSplitRow(split);
/** * Regression test for KUDU-1226. Calls to session.flush() concurrent with AUTO_FLUSH_BACKGROUND * can end up giving ConvertBatchToListOfResponsesCB a list with nulls if a tablet was already * flushed. Only happens with multiple tablets. */ @Test(timeout = 10000) public void testConcurrentFlushes() throws Exception { CreateTableOptions builder = getBasicCreateTableOptions(); int numTablets = 4; int numRowsPerTablet = 100; // Create a 4 tablets table split on 1000, 2000, and 3000. for (int i = 1; i < numTablets; i++) { PartialRow split = basicSchema.newPartialRow(); split.addInt(0, i * numRowsPerTablet); builder.addSplitRow(split); } KuduTable table = client.createTable(tableName, basicSchema, builder); // Configure the session to background flush as often as it can (every 1ms). KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); session.setFlushInterval(1); // Fill each tablet in parallel 1 by 1 then flush. Without the fix this would quickly get an // NPE. for (int i = 0; i < numRowsPerTablet; i++) { for (int j = 0; j < numTablets; j++) { session.apply(createInsert(table, i + (numRowsPerTablet * j))); } session.flush(); } }
createOptions.addSplitRow(split);
public static KuduTable createFourTabletsTableWithNineRows(AsyncKuduClient client, String tableName, final long timeoutMs) throws Exception { final int[] KEYS = new int[] { 10, 20, 30 }; final Schema basicSchema = getBasicSchema(); CreateTableOptions builder = getBasicCreateTableOptions(); for (int i : KEYS) { PartialRow splitRow = basicSchema.newPartialRow(); splitRow.addInt(0, i); builder.addSplitRow(splitRow); } KuduTable table = client.syncClient().createTable(tableName, basicSchema, builder); AsyncKuduSession session = client.newSession(); // create a table with on empty tablet and 3 tablets of 3 rows each for (int key1 : KEYS) { for (int key2 = 1; key2 <= 3; key2++) { Insert insert = table.newInsert(); PartialRow row = insert.getRow(); row.addInt(0, key1 + key2); row.addInt(1, key1); row.addInt(2, key2); row.addString(3, "a string"); row.addBoolean(4, true); session.apply(insert).join(timeoutMs); } } session.close().join(timeoutMs); return table; }
tableBuilder.addSplitRow(split);
splitRow.addString("key1", "" + i); splitRow.addString("key2", ""); builder.addSplitRow(splitRow);
split.addByte("c", (byte) 0); split.addString("b", "m"); tableBuilder.addSplitRow(split); split.addByte("c", (byte) 10); split.addString("b", "r"); tableBuilder.addSplitRow(split);