/** * Test creating and deleting a table through a KuduClient. */ @Test(timeout = 100000) public void testCreateDeleteTable() throws Exception { // Check that we can create a table. client.createTable(TABLE_NAME, basicSchema, getBasicCreateTableOptions()); assertFalse(client.getTablesList().getTablesList().isEmpty()); assertTrue(client.getTablesList().getTablesList().contains(TABLE_NAME)); // Check that we can delete it. client.deleteTable(TABLE_NAME); assertFalse(client.getTablesList().getTablesList().contains(TABLE_NAME)); // Check that we can re-recreate it, with a different schema. List<ColumnSchema> columns = new ArrayList<>(basicSchema.getColumns()); columns.add(new ColumnSchema.ColumnSchemaBuilder("one more", Type.STRING).build()); Schema newSchema = new Schema(columns); client.createTable(TABLE_NAME, newSchema, getBasicCreateTableOptions()); // Check that we can open a table and see that it has the new schema. KuduTable table = client.openTable(TABLE_NAME); assertEquals(newSchema.getColumnCount(), table.getSchema().getColumnCount()); assertTrue(table.getPartitionSchema().isSimpleRangePartitioning()); // Check that the block size parameter we specified in the schema is respected. assertEquals(4096, newSchema.getColumn("column3_s").getDesiredBlockSize()); assertEquals(ColumnSchema.Encoding.DICT_ENCODING, newSchema.getColumn("column3_s").getEncoding()); assertEquals(ColumnSchema.CompressionAlgorithm.LZ4, newSchema.getColumn("column3_s").getCompressionAlgorithm()); }
table.getSchema().getColumn("value").getDesiredBlockSize()); assertEquals("wrong encoding", ColumnSchema.Encoding.PLAIN_ENCODING, assertEquals("wrong block size post alter", 8192, reopenedTable.getSchema().getColumn("value").getDesiredBlockSize()); assertEquals("wrong encoding post alter", ColumnSchema.Encoding.DICT_ENCODING,
public static Common.ColumnSchemaPB columnToPb(Common.ColumnSchemaPB.Builder schemaBuilder, ColumnSchema column) { schemaBuilder .setName(column.getName()) .setType(column.getType().getDataType(column.getTypeAttributes())) .setIsKey(column.isKey()) .setIsNullable(column.isNullable()) .setCfileBlockSize(column.getDesiredBlockSize()); if (column.getEncoding() != null) { schemaBuilder.setEncoding(column.getEncoding().getInternalPbType()); } if (column.getCompressionAlgorithm() != null) { schemaBuilder.setCompression(column.getCompressionAlgorithm().getInternalPbType()); } if (column.getDefaultValue() != null) { schemaBuilder.setReadDefaultValue(UnsafeByteOperations.unsafeWrap( objectToWireFormat(column, column.getDefaultValue()))); } if(column.getTypeAttributes() != null) { schemaBuilder.setTypeAttributes( columnTypeAttributesToPb(Common.ColumnTypeAttributesPB.newBuilder(), column)); } return schemaBuilder.build(); }