switch (change) { case ADD: alterOptions.addRangePartition(lowerBound, upperBound); break; case DROP:
/** * Add a range partition to the table with an inclusive lower bound and an exclusive upper bound. * * If either row is empty, then that end of the range will be unbounded. If a range column is * missing a value, the logical minimum value for that column type will be used as the default. * * Multiple range partitions may be added as part of a single alter table transaction by calling * this method multiple times. Added range partitions must not overlap with each * other or any existing range partitions (unless the existing range partitions are dropped as * part of the alter transaction first). The lower bound must be less than the upper bound. * * This client will immediately be able to write and scan the new tablets when the alter table * operation returns success, however other existing clients may have to wait for a timeout period * to elapse before the tablets become visible. This period is configured by the master's * 'table_locations_ttl_ms' flag, and defaults to 5 minutes. * * @param lowerBound inclusive lower bound, may be empty but not null * @param upperBound exclusive upper bound, may be empty but not null * @return this instance */ public AlterTableOptions addRangePartition(PartialRow lowerBound, PartialRow upperBound) { return addRangePartition(lowerBound, upperBound, RangePartitionBound.INCLUSIVE_BOUND, RangePartitionBound.EXCLUSIVE_BOUND); }
private void changeRangePartition(SchemaTableName schemaTableName, RangePartition rangePartition, RangePartitionChange change) { try { String rawName = toRawName(schemaTableName); KuduTable table = client.openTable(rawName); Schema schema = table.getSchema(); PartitionDesign design = KuduTableProperties.getPartitionDesign(table); RangePartitionDefinition definition = design.getRange(); if (definition == null) { throw new PrestoException(QUERY_REJECTED, "Table " + schemaTableName + " has no range partition"); } PartialRow lowerBound = KuduTableProperties.toRangeBoundToPartialRow(schema, definition, rangePartition.getLower()); PartialRow upperBound = KuduTableProperties.toRangeBoundToPartialRow(schema, definition, rangePartition.getUpper()); AlterTableOptions alterOptions = new AlterTableOptions(); switch (change) { case ADD: alterOptions.addRangePartition(lowerBound, upperBound); break; case DROP: alterOptions.dropRangePartition(lowerBound, upperBound); break; } client.alterTable(rawName, alterOptions); } catch (PrestoException e) { throw e; } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
switch (change) { case ADD: alterOptions.addRangePartition(lowerBound, upperBound); break; case DROP:
upper = basicSchema.newPartialRow(); lower.addInt("key", 1); alter.addRangePartition(lower, upper); alterClient.alterTable(TABLE_NAME, alter);
client.alterTable(tableName, new AlterTableOptions().addRangePartition( lower, upper, RangePartitionBound.EXCLUSIVE_BOUND, RangePartitionBound.INCLUSIVE_BOUND));
upper.addInt("c0", 100); try { client.alterTable(tableName, new AlterTableOptions().addRangePartition(lower, upper)); fail(); } catch (KuduException e) { upper.addInt("c0", 150); try { client.alterTable(tableName, new AlterTableOptions().addRangePartition(lower, upper)); fail(); } catch (KuduException e) { upper.addInt("c0", 50); try { client.alterTable(tableName, new AlterTableOptions().addRangePartition(lower, upper)); fail(); } catch (KuduException e) { upper.addInt("c0", 300); AlterTableOptions options = new AlterTableOptions(); options.addRangePartition(lower, upper); lower.addInt("c0", -50); upper.addInt("c0", 150); options.addRangePartition(lower, upper); try { client.alterTable(tableName, options); options.addRangePartition(lower, upper); options.dropRangePartition(lower, upper);
client.alterTable(tableName, new AlterTableOptions().addRangePartition(lower, upper)); insertRows(table, 0, 100); assertEquals(100, countRowsInTable(table)); lower.addInt("c0", 50); upper.addInt("c0", 150); options.addRangePartition(lower, upper); client.alterTable(tableName, options); assertEquals(0, countRowsInTable(table)); .addRangePartition(lower, upper)); assertEquals(0, countRowsInTable(table)); insertRows(table, 50, 125); client.alterTable(tableName, new AlterTableOptions().addRangePartition(lower, upper) .renameTable(tableName + "-renamed") .addNullableColumn("c2", Type.INT32));
PartialRow bUpperBound = BASIC_SCHEMA.newPartialRow(); bUpperBound.addInt("key", 400); ato.addRangePartition(bLowerBound, bUpperBound); client.alterTable(tableName, ato);