public void addColumn(SchemaTableName schemaTableName, ColumnMetadata column) { try { String rawName = schemaEmulation.toRawName(schemaTableName); AlterTableOptions alterOptions = new AlterTableOptions(); Type type = TypeHelper.toKuduClientType(column.getType()); alterOptions.addNullableColumn(column.getName(), type); client.alterTable(rawName, alterOptions); } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
AlterTableOptions alterOptions = new AlterTableOptions(); switch (change) { case ADD: alterOptions.addRangePartition(lowerBound, upperBound); break; case DROP: alterOptions.dropRangePartition(lowerBound, upperBound); break;
public void dropColumn(SchemaTableName schemaTableName, String name) { try { String rawName = schemaEmulation.toRawName(schemaTableName); AlterTableOptions alterOptions = new AlterTableOptions(); alterOptions.dropColumn(name); client.alterTable(rawName, alterOptions); } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
public void renameColumn(SchemaTableName schemaTableName, String oldName, String newName) { try { String rawName = schemaEmulation.toRawName(schemaTableName); AlterTableOptions alterOptions = new AlterTableOptions(); alterOptions.renameColumn(oldName, newName); client.alterTable(rawName, alterOptions); } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
public void renameTable(SchemaTableName schemaTableName, SchemaTableName newSchemaTableName) { try { String rawName = schemaEmulation.toRawName(schemaTableName); String newRawName = schemaEmulation.toRawName(newSchemaTableName); AlterTableOptions alterOptions = new AlterTableOptions(); alterOptions.renameTable(newRawName); client.alterTable(rawName, alterOptions); } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
PartialRow lower = schema.newPartialRow(); PartialRow upper = schema.newPartialRow(); client.alterTable(tableName, new AlterTableOptions().dropRangePartition(lower, upper)); assertEquals(0, countRowsInTable(table)); client.alterTable(tableName, new AlterTableOptions().addRangePartition(lower, upper)); insertRows(table, 0, 100); assertEquals(100, countRowsInTable(table)); AlterTableOptions options = new AlterTableOptions(); options.dropRangePartition(lower, upper); lower.addInt("c0", 50); upper.addInt("c0", 150); options.addRangePartition(lower, upper); client.alterTable(tableName, options); assertEquals(0, countRowsInTable(table)); client.alterTable(tableName, new AlterTableOptions().dropRangePartition(lower, upper) .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)); tableName = tableName + "-renamed"; insertRows(table, 200, 300); options = new AlterTableOptions();
new AlterTableOptions().addColumn("testaddint", Type.INT32, 4)); new AlterTableOptions().renameColumn("testaddint", "newtestaddint")); client.alterTable(tableName, new AlterTableOptions().dropColumn("newtestaddint")); client.alterTable(tableName, new AlterTableOptions().renameTable(newTableName)); client.alterTable(newTableName, new AlterTableOptions().renameTable(tableName)); client.alterTable(tableName, new AlterTableOptions() .addColumn("testaddmulticolnotnull", Type.INT32, 4) .addNullableColumn("testaddmulticolnull", Type.STRING) .addColumn("testaddmulticolTimestampcol", Type.UNIXTIME_MICROS, (System.currentTimeMillis() * 1000))); client.alterTable(nonExistingTableName, new AlterTableOptions()); fail("Shouldn't be able to alter a table that doesn't exist"); } catch (KuduException ex) {
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) { 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); new AlterTableOptions().dropRangePartition(schema.newPartialRow(), schema.newPartialRow())); fail();
alterTableOptions.addNullableColumn(columnInfo.getColumnName(), KuduDBValidationClassMapper.getValidTypeForClass(columnInfo.getType())); updated.set(true); .equals(KuduDBValidationClassMapper.getValidTypeForClass(columnInfo.getType()))) alterTableOptions.dropColumn(columnInfo.getColumnName()); alterTableOptions.addNullableColumn(columnInfo.getColumnName(), KuduDBValidationClassMapper.getValidTypeForClass(columnInfo.getType())); updated.set(true);
assertEquals(100, countRowsInTable(table)); client.alterTable(tableName, new AlterTableOptions() .addColumn("addNonNull", Type.INT32, 100) .addNullableColumn("addNullable", Type.INT32) .addNullableColumn("addNullableDef", Type.INT32, 200));
client.alterTable(testTableName, new AlterTableOptions().dropColumn("a")); try { token.intoScanner(client); new AlterTableOptions().addColumn( new ColumnSchema.ColumnSchemaBuilder("a", Type.STRING).nullable(true).build())); try { new AlterTableOptions().dropColumn("a") .addColumn(new ColumnSchema.ColumnSchemaBuilder("a", Type.INT64) .nullable(true).build())); try { new AlterTableOptions().dropColumn("a") .addColumn(new ColumnSchema.ColumnSchemaBuilder("a", Type.INT64) .nullable(false) .defaultValue(0L).build()));
for (int i = 0; i < 10; i++) { String newName = String.format("foo%d", i); client.alterTable(tableName, new AlterTableOptions() .renameColumn(oldName, newName) .setWait(false));
client.alterTable(tableName, new AlterTableOptions().changeDefault("value", "pizza")); client.alterTable(tableName, new AlterTableOptions().changeDefault("value", "taco")); client.alterTable(tableName, new AlterTableOptions().removeDefault("value")); table.getSchema().getColumn("value").getCompressionAlgorithm()); client.alterTable(tableName, new AlterTableOptions() .changeDesiredBlockSize("value", 8192) .changeEncoding("value", ColumnSchema.Encoding.DICT_ENCODING) .changeCompressionAlgorithm("value", ColumnSchema.CompressionAlgorithm.SNAPPY));
.defaultAdminOperationTimeoutMs(harness.DEFAULT_SLEEP) .build()) { AlterTableOptions alter = new AlterTableOptions(); lower = basicSchema.newPartialRow(); upper = basicSchema.newPartialRow(); lower.addInt("key", 1); alter.addRangePartition(lower, upper); alterClient.alterTable(TABLE_NAME, alter);
@Test public void testAlterModifyColumns() throws Exception { KuduTable table = createTable(ImmutableList.<Pair<Integer,Integer>>of()); insertRows(table, 0, 100); assertEquals(100, countRowsInTable(table)); // Check for expected defaults. ColumnSchema col = table.getSchema().getColumns().get(1); assertEquals(CompressionAlgorithm.DEFAULT_COMPRESSION, col.getCompressionAlgorithm()); assertEquals(Encoding.AUTO_ENCODING, col.getEncoding()); assertEquals(null, col.getDefaultValue()); // Alter the table. client.alterTable(tableName, new AlterTableOptions() .changeCompressionAlgorithm(col.getName(), CompressionAlgorithm.SNAPPY) .changeEncoding(col.getName(), Encoding.RLE) .changeDefault(col.getName(), 0)); // Check for new values. table = client.openTable(tableName); col = table.getSchema().getColumns().get(1); assertEquals(CompressionAlgorithm.SNAPPY, col.getCompressionAlgorithm()); assertEquals(Encoding.RLE, col.getEncoding()); assertEquals(0, col.getDefaultValue()); }
/** * Add a new column that's nullable and has no default value. * @param name name of the new column * @param type type of the new column * @return this instance */ public AlterTableOptions addNullableColumn(String name, Type type) { return addNullableColumn(name, type, null); }
/** * Drop the range partition from the table with the specified inclusive lower bound and exclusive * upper bound. The bounds must match exactly, and may not span multiple range partitions. * * 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 dropped as part of a single alter table transaction by calling * this method multiple times. * * @param lowerBound inclusive lower bound, can be empty but not null * @param upperBound exclusive upper bound, can be empty but not null * @return this instance */ public AlterTableOptions dropRangePartition(PartialRow lowerBound, PartialRow upperBound) { return dropRangePartition(lowerBound, upperBound, RangePartitionBound.INCLUSIVE_BOUND, RangePartitionBound.EXCLUSIVE_BOUND); }
/** * 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); }
/** * Add a new column that's not nullable. * @param name name of the new column * @param type type of the new column * @param defaultVal default value used for the currently existing rows * @return this instance */ public AlterTableOptions addColumn(String name, Type type, Object defaultVal) { return addColumn(new ColumnSchema.ColumnSchemaBuilder(name, type) .defaultValue(defaultVal) .build()); }
@Override public void renameColumn(SchemaTableName schemaTableName, String oldName, String newName) { try { String rawName = toRawName(schemaTableName); AlterTableOptions alterOptions = new AlterTableOptions(); alterOptions.renameColumn(oldName, newName); client.alterTable(rawName, alterOptions); } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }