private void closeSession() { try { session.close(); } catch (KuduException e) { throw new RuntimeException(e); } } }
@Override public void cleanup() throws DBException { try { this.session.close(); } catch (Exception e) { throw new DBException("Couldn't cleanup the session", e); } }
private void flushKuduSession(final KuduSession kuduSession, boolean close, final List<RowError> rowErrors) throws KuduException { final List<OperationResponse> responses = close ? kuduSession.close() : kuduSession.flush(); if (kuduSession.getFlushMode() == SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND) { rowErrors.addAll(Arrays.asList(kuduSession.getPendingErrors().getRowErrors())); } else { responses.stream() .filter(OperationResponse::hasRowError) .map(OperationResponse::getRowError) .forEach(rowErrors::add); } }
@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(); } }
@Override public void deleteRows(Block rowIds) { Schema schema = table.getSchema(); KuduSession session = clientSession.newSession(); session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND); try { try { for (int i = 0; i < rowIds.getPositionCount(); i++) { int len = rowIds.getSliceLength(i); Slice slice = rowIds.getSlice(i, 0, len); PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes()); Delete delete = table.newDelete(); RowHelper.copyPrimaryKey(schema, row, delete.getRow()); session.apply(delete); } } finally { session.close(); } } catch (KuduException e) { throw new RuntimeException(e); } }
@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); } } }
session.close();
private void closeSession() { try { session.close(); } catch (KuduException e) { throw new RuntimeException(e); } } }
private void closeSession() { try { session.close(); } catch (KuduException e) { throw new RuntimeException(e); } } }
session.close();
@Override protected void cleanup(Context context) throws KuduException { session.close(); client.shutdown(); }
@Override protected void cleanup(Context context) throws KuduException { session.close(); client.shutdown(); } }
@Override public void close() throws Exception { kuduSession.close(); kuduClient.close(); }
void close() throws KuduException { session.close(); client.close(); }
@Override public void deleteRows(Block rowIds) { Schema schema = table.getSchema(); KuduSession session = clientSession.newSession(); session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND); try { try { for (int i = 0; i < rowIds.getPositionCount(); i++) { int len = rowIds.getSliceLength(i); Slice slice = rowIds.getSlice(i, 0, len); PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes()); Delete delete = table.newDelete(); RowHelper.copyPrimaryKey(schema, row, delete.getRow()); session.apply(delete); } } finally { session.close(); } } catch (KuduException e) { throw new RuntimeException(e); } }
private void insertRows(KuduTable table, Set<Row> rows) throws KuduException { KuduSession session = client.newSession(); try { for (Row row : rows) { Insert insert = table.newInsert(); PartialRow insertRow = insert.getRow(); row.fillPartialRow(insertRow); session.apply(insert); } } finally { session.close(); } }
/** * Load a table of default schema with the specified number of records, in ascending key order. */ public static void loadDefaultTable(KuduClient client, String tableName, int numRows) throws KuduException { KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); for (int i = 0; i < numRows; i++) { Insert insert = createBasicSchemaInsert(table, i); session.apply(insert); } session.flush(); session.close(); }
@Override public void run() { try { KuduTable table = localClient.openTable(TABLE_NAME); KuduSession session = localClient.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); for (int i = 0; i < 100; i++) { Insert insert = createBasicSchemaInsert(table, id * 100 + i); session.apply(insert); } session.close(); } catch (Exception e) { fail("insert thread should not throw exception: " + e); } } });
public boolean writeRow(KuduRow row, Consistency consistency, WriteMode writeMode) throws Exception { final Operation operation = KuduMapper.toOperation(table, writeMode, row); if (Consistency.EVENTUAL.equals(consistency)) { AsyncKuduSession session = client.newSession(); session.apply(operation); session.flush(); return session.close().addCallback(new ResponseCallback()).join(); } else { KuduSession session = client.syncClient().newSession(); session.apply(operation); session.flush(); return processResponse(session.close()); } }