@Override public void writeField() throws IOException { reader.read(holder); byte[] bytes = new byte[holder.end - holder.start]; holder.buffer.getBytes(holder.start, bytes); row.addString(fieldId, new String(bytes)); } }
@Override public Status insert(String table, String key, Map<String, ByteIterator> values) { Insert insert = this.kuduTable.newInsert(); PartialRow row = insert.getRow(); row.addString(KEY, key); for (int i = 1; i < schema.getColumnCount(); i++) { row.addStringUtf8(i, values.get(schema.getColumnByIndex(i).getName()).toArray()); } apply(insert); return Status.OK; }
@Override public void writeField() throws IOException { if (!reader.isSet()) { return; } reader.read(holder); byte[] bytes = new byte[holder.end - holder.start]; holder.buffer.getBytes(holder.start, bytes); row.addString(fieldId, new String(bytes)); } }
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { Update update = this.kuduTable.newUpdate(); PartialRow row = update.getRow(); row.addString(KEY, key); for (int i = 1; i < schema.getColumnCount(); i++) { String columnName = schema.getColumnByIndex(i).getName(); ByteIterator b = values.get(columnName); if (b != null) { row.addStringUtf8(columnName, b.toArray()); } } apply(update); return Status.OK; }
@Override public Status delete(String table, String key) { Delete delete = this.kuduTable.newDelete(); PartialRow row = delete.getRow(); row.addString(KEY, key); apply(delete); return Status.OK; }
row.addString(destChannel, type.getSlice(block, position).toStringUtf8());
@Override public CompletableFuture<?> appendPage(Page page) { for (int position = 0; position < page.getPositionCount(); position++) { Upsert upsert = table.newUpsert(); PartialRow row = upsert.getRow(); int start = 0; if (generateUUID) { String id = String.format("%s-%08x", uuid, nextSubId++); row.addString(0, id); start = 1; } for (int channel = 0; channel < page.getChannelCount(); channel++) { appendColumn(row, page, position, channel, channel + start); } try { session.apply(upsert); } catch (KuduException e) { throw new RuntimeException(e); } } return NOT_BLOCKED; }
@Override public void createSchema(KuduClient client, String schemaName) { if (DEFAULT_SCHEMA.equals(schemaName)) { throw new SchemaAlreadyExistsException(schemaName); } else { try { KuduTable schemasTable = getSchemasTable(client); KuduSession session = client.newSession(); try { Upsert upsert = schemasTable.newUpsert(); upsert.getRow().addString(0, schemaName); session.apply(upsert); } finally { session.close(); } } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } } }
private void createAndFillSchemasTable(KuduClient client) throws KuduException { List<String> existingSchemaNames = listSchemaNamesFromTablets(client); ColumnSchema schemaColumnSchema = new ColumnSchema.ColumnSchemaBuilder("schema", Type.STRING) .key(true).build(); Schema schema = new Schema(ImmutableList.of(schemaColumnSchema)); CreateTableOptions options = new CreateTableOptions(); options.addHashPartitions(ImmutableList.of(schemaColumnSchema.getName()), 2); KuduTable schemasTable = client.createTable(rawSchemasTableName, schema, options); KuduSession session = client.newSession(); try { session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); for (String schemaName : existingSchemaNames) { Insert insert = schemasTable.newInsert(); insert.getRow().addString(0, schemaName); session.apply(insert); } } finally { session.close(); } }
case STRING: if (obj instanceof String) { partialRow.addString(idx, (String) obj);
@Override public void dropSchema(KuduClient client, String schemaName) { if (DEFAULT_SCHEMA.equals(schemaName)) { throw new PrestoException(GENERIC_USER_ERROR, "Deleting default schema not allowed."); } else { try { String prefix = getPrefixForTablesOfSchema(schemaName); for (String name : client.getTablesList(prefix).getTablesList()) { client.deleteTable(name); } KuduTable schemasTable = getSchemasTable(client); KuduSession session = client.newSession(); try { Delete delete = schemasTable.newDelete(); delete.getRow().addString(0, schemaName); session.apply(delete); } finally { session.close(); } } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } } }
break; case STRING: row.addString(colIdx, record.getAsString(colName)); break; case DECIMAL32:
row.addBoolean(2, i % 2 == 0); row.addFloat(3, i + 0.01f); row.addString(4, ("Row " + i)); session.apply(insert);
break; case STRING: row.addString(jpaColumnName, (String) value); break; case UNIXTIME_MICROS:
@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); }
@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); }
public static Insert createBasicSchemaInsert(KuduTable table, int key) { Insert insert = table.newInsert(); PartialRow row = insert.getRow(); row.addInt(0, key); row.addInt(1, 2); row.addInt(2, 3); row.addString(3, "a string"); row.addBoolean(4, true); return insert; }
private Upsert createUpsert(KuduTable table, int key, int secondVal, boolean hasNull) { Upsert upsert = table.newUpsert(); PartialRow row = upsert.getRow(); row.addInt(0, key); row.addInt(1, secondVal); row.addInt(2, 3); if (hasNull) { row.setNull(3); } else { row.addString(3, "a string"); } row.addBoolean(4, true); return upsert; } }