public static PartialRow decodeRangePartitionKey(Schema schema, PartitionSchema partitionSchema, byte[] key) { return KeyEncoder.decodeRangePartitionKey(schema, partitionSchema, key); } }
private KuduTable getSchemasTable(KuduClient client) throws KuduException { if (rawSchemasTable == null) { rawSchemasTable = client.openTable(rawSchemasTableName); } return rawSchemasTable; }
public static byte[] encodeRangePartitionKey(PartialRow row, PartitionSchema.RangeSchema rangeSchema) { return KeyEncoder.encodeRangePartitionKey(row, rangeSchema); }
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(); } }
protected KuduSession getKuduSession(final KuduClient client) { final KuduSession kuduSession = client.newSession(); kuduSession.setMutationBufferSpace(batchSize); kuduSession.setFlushMode(flushMode); if (operationType == OperationType.INSERT_IGNORE) { kuduSession.setIgnoreAllDuplicateRows(true); } return kuduSession; }
public KuduRecordWriterImpl(OperatorContext context, KuduClient client, String name) { this.client = client; this.name = name; this.context = context; session = client.newSession(); session.setFlushMode(FlushMode.MANUAL_FLUSH); }
private PartialRow buildPrimaryKey() { Schema schema = table.getSchema(); PartialRow row = new PartialRow(schema); RowHelper.copyPrimaryKey(schema, currentRow, row); return row; } }
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 KuduSession newSession() { return client.newSession(); }
private List<String> internalListTables(String prefix) { try { if (prefix.isEmpty()) { return client.getTablesList().getTablesList(); } else { return client.getTablesList(prefix).getTablesList(); } } 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); } }
public Schema getTableSchema(KuduTableHandle tableHandle) { KuduTable table = tableHandle.getTable(this); return table.getSchema(); }
private void closeSession() { try { session.close(); } catch (KuduException e) { throw new RuntimeException(e); } } }
public static double getDouble(Type type, RowResult row, int field) { if (type == DoubleType.DOUBLE) { return row.getDouble(field); } else { throw new IllegalStateException("getDouble not implemented for " + type); } }
public static boolean getBoolean(Type type, RowResult row, int field) { if (type == BooleanType.BOOLEAN) { return row.getBoolean(field); } else { throw new IllegalStateException("getBoolean not implemented for " + type); } }
@Override public boolean isNull(int field) { int mappedField = mapping(field); return mappedField >= 0 && currentRow.isNull(mappedField); }
public static PartialRow decodePrimaryKey(Schema schema, byte[] key) { return KeyEncoder.decodePrimaryKey(schema, key); }
public static byte[] encodePrimaryKey(PartialRow row) { return KeyEncoder.encodePrimaryKey(row); }