public KuduSession newSession() { return client.newSession(); }
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); }
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; }
@Override public void init() throws DBException { this.tableName = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); initClient(); this.session = client.newSession(); if (getProperties().getProperty(SYNC_OPS_OPT) != null && getProperties().getProperty(SYNC_OPS_OPT).equals("false")) { this.session.setFlushMode(KuduSession.FlushMode.AUTO_FLUSH_BACKGROUND); this.session.setMutationBufferSpace( getIntFromProp(getProperties(), BUFFER_NUM_OPS_OPT, BUFFER_NUM_OPS_DEFAULT)); } else { this.session.setFlushMode(KuduSession.FlushMode.AUTO_FLUSH_SYNC); } try { this.kuduTable = client.openTable(tableName); this.schema = kuduTable.getSchema(); } catch (Exception e) { throw new DBException("Could not open a table because of:", e); } }
@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 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); } } }
KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); for (int i = 0; i < rows; i++) {
@Override public KuduSession newSession() { return client.newSession(); }
public KuduSession newSession() { return client.newSession(); }
KuduSession session = kuduClient.newSession(); KuduTable table = null; try
EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz()); KuduSession session = kuduClient.newSession(); KuduTable table = null; try
@Override protected void setup(Context context) throws KuduException { Configuration conf = context.getConfiguration(); CommandLineParser parser = new CommandLineParser(conf); client = parser.getClient(); table = client.openTable(getTableName(conf)); session = client.newSession(); numUpdatesPerMapper = conf.getInt(MAX_LINK_UPDATES_PER_MAPPER, 1); headsCache = new ArrayList<>(numUpdatesPerMapper); }
KuduConnection(Config config, byte[] token) { client = new KuduClient.KuduClientBuilder(config.getString(CONNECTION_CONFIG_NAME)).build(); if (token != null) { client.importAuthenticationCredentials(token); } session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); session.setMutationBufferSpace(10000); session.setIgnoreAllDuplicateRows(KuduUtils.doesInsertIgnoreDuplicates(config)); }
/** * Regression test for KUDU-1402. Calls to session.flush() should return an empty list * instead of null. * @throws Exception */ @Test(timeout = 100000) public void testEmptyFlush() throws Exception { KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); List<OperationResponse> result = session.flush(); assertNotNull(result); assertTrue(result.isEmpty()); }
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()); } }
@Test(timeout = 10000) public void testInsertAutoFlushSyncNonCoveredRange() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); List<Integer> nonCoveredKeys = ImmutableList.of(350, 300, 199, 150, 100, -1, -50); for (int key : nonCoveredKeys) { OperationResponse response = session.apply(createBasicSchemaInsert(table, key)); assertTrue(response.hasRowError()); assertTrue(response.getRowError().getErrorStatus().isNotFound()); } }