@Override public void startRecord() throws IOException { insert = table.newInsert(); setUp(insert.getRow()); }
protected Insert insertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames) throws IllegalStateException, Exception { Insert insert = kuduTable.newInsert(); this.buildPartialRow(kuduTable.getSchema(), insert.getRow(), record, fieldNames); return insert; }
@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; }
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(); } }
session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); for (int i = 0; i < rows; i++) { Insert insert = table.newInsert(); PartialRow row = insert.getRow(); row.addInt(0, i);
throw new KunderaException("Cannot open table : " + entityMetadata.getTableName(), e); Operation operation = isUpdate ? table.newUpdate() : table.newInsert(); PartialRow row = operation.getRow(); populatePartialRow(row, entityMetadata, entity);
protected void processForInsert(KuduExecutionContext kuduExecutionContext) { Insert thisInsert = kuduTable.newInsert(); performCommonProcessing(thisInsert,kuduExecutionContext); }
public static Operation toOperation(KuduTable table, KuduConnector.WriteMode writeMode) { switch (writeMode) { case INSERT: return table.newInsert(); case UPDATE: return table.newUpdate(); case UPSERT: return table.newUpsert(); } return table.newUpsert(); }
private void insertDefaultRow(KuduTable table, KuduSession session, int key) throws Exception { Insert insert = table.newInsert(); PartialRow row = insert.getRow(); row.addInt("key", key); // Omit value. session.apply(insert); }
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(); } }
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 void createAndFillSchemasTable() throws KuduException { List<String> existingSchemaNames = listSchemaNamesFromTablets(); ColumnSchema tenantColumnSchema = new ColumnSchema.ColumnSchemaBuilder("tenant", Type.STRING) .key(true).build(); ColumnSchema schemaColumnSchema = new ColumnSchema.ColumnSchemaBuilder("schema", Type.STRING) .key(true).build(); Schema schema = new Schema(ImmutableList.of(tenantColumnSchema, schemaColumnSchema)); CreateTableOptions options = new CreateTableOptions(); options.setNumReplicas(1); // TODO config options.addHashPartitions(ImmutableList.of(tenantColumnSchema.getName()), 2); KuduTable schemasTable = client.createTable(rawSchemasTableName, schema, options); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); try { for (String schemaName : existingSchemaNames) { Insert insert = schemasTable.newInsert(); fillSchemaRow(insert.getRow(), schemaName); session.apply(insert); } } finally { session.close(); } }
private Insert createInsertWithNull(int key) { Insert insert = table.newInsert(); PartialRow row = insert.getRow(); row.addInt(0, key); row.addInt(1, 2); row.addInt(2, 3); row.setNull(3); row.addBoolean(4, false); return insert; }
/** * Insert rows into the provided table. The table's columns must be ints, and * must have a primary key in the first column. * @param table the table * @param start the inclusive start key * @param end the exclusive end key */ private void insertRows(KuduTable table, int start, int end) throws KuduException { KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); for (int i = start; i < end; i++) { Insert insert = table.newInsert(); for (int idx = 0; idx < table.getSchema().getColumnCount(); idx++) { insert.getRow().addInt(idx, i); } session.apply(insert); } session.flush(); RowError[] rowErrors = session.getPendingErrors().getRowErrors(); assertEquals(String.format("row errors: %s", Arrays.toString(rowErrors)), 0, rowErrors.length); }
@Test public void testShortPredicates() throws Exception { Schema schema = createTableSchema(Type.INT16); client.createTable("short-table", schema, new CreateTableOptions().setRangePartitionColumns( ImmutableList.<String>of())); KuduTable table = client.openTable("short-table"); NavigableSet<Long> values = createIntegerValues(Type.INT16); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); long i = 0; for (long value : values) { Insert insert = table.newInsert(); insert.getRow().addLong("key", i++); insert.getRow().addShort("value", (short) value); session.apply(insert); } Insert nullInsert = table.newInsert(); nullInsert.getRow().addLong("key", i++); nullInsert.getRow().setNull("value"); session.apply(nullInsert); session.flush(); checkIntPredicates(table, values, createIntegerTestValues(Type.INT16)); }
@Test public void testLongPredicates() throws Exception { Schema schema = createTableSchema(Type.INT64); client.createTable("long-table", schema, new CreateTableOptions().setRangePartitionColumns( ImmutableList.<String>of())); KuduTable table = client.openTable("long-table"); NavigableSet<Long> values = createIntegerValues(Type.INT64); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); long i = 0; for (long value : values) { Insert insert = table.newInsert(); insert.getRow().addLong("key", i++); insert.getRow().addLong("value", value); session.apply(insert); } Insert nullInsert = table.newInsert(); nullInsert.getRow().addLong("key", i++); nullInsert.getRow().setNull("value"); session.apply(nullInsert); session.flush(); checkIntPredicates(table, values, createIntegerTestValues(Type.INT64)); }
@Test public void testTimestampPredicate() throws Exception { Schema schema = createTableSchema(Type.INT64); client.createTable("timestamp-table", schema, createTableOptions()); KuduTable table = client.openTable("timestamp-table"); NavigableSet<Long> values = createIntegerValues(Type.INT64); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); long i = 0; for (long value : values) { Insert insert = table.newInsert(); insert.getRow().addLong("key", i++); insert.getRow().addLong("value", value); session.apply(insert); } Insert nullInsert = table.newInsert(); nullInsert.getRow().addLong("key", i++); nullInsert.getRow().setNull("value"); session.apply(nullInsert); session.flush(); checkIntPredicates(table, values, createIntegerTestValues(Type.INT64)); }
@Test public void testIntPredicates() throws Exception { Schema schema = createTableSchema(Type.INT32); client.createTable("int-table", schema, createTableOptions()); KuduTable table = client.openTable("int-table"); NavigableSet<Long> values = createIntegerValues(Type.INT32); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); long i = 0; for (long value : values) { Insert insert = table.newInsert(); insert.getRow().addLong("key", i++); insert.getRow().addInt("value", (int) value); session.apply(insert); } Insert nullInsert = table.newInsert(); nullInsert.getRow().addLong("key", i++); nullInsert.getRow().setNull("value"); session.apply(nullInsert); session.flush(); checkIntPredicates(table, values, createIntegerTestValues(Type.INT32)); }
@Test public void testBytePredicates() throws Exception { Schema schema = createTableSchema(Type.INT8); client.createTable("byte-table", schema, createTableOptions()); KuduTable table = client.openTable("byte-table"); NavigableSet<Long> values = createIntegerValues(Type.INT8); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); long i = 0; for (long value : values) { Insert insert = table.newInsert(); insert.getRow().addLong("key", i++); insert.getRow().addByte("value", (byte) value); session.apply(insert); } Insert nullInsert = table.newInsert(); nullInsert.getRow().addLong("key", i++); nullInsert.getRow().setNull("value"); session.apply(nullInsert); session.flush(); checkIntPredicates(table, values, createIntegerTestValues(Type.INT8)); }
@Test(timeout = 100000) public void testCreateTableWithConcurrentInsert() throws Exception { KuduTable table = client.createTable( TABLE_NAME, createManyStringsSchema(), getBasicCreateTableOptions().setWait(false)); // Insert a row. // // It's very likely that the tablets are still being created, but the client // should transparently retry the insert (and associated master lookup) // until the operation succeeds. Insert insert = table.newInsert(); insert.getRow().addString("key", "key_0"); insert.getRow().addString("c1", "c1_0"); insert.getRow().addString("c2", "c2_0"); KuduSession session = client.newSession(); OperationResponse resp = session.apply(insert); assertFalse(resp.hasRowError()); // This won't do anything useful (i.e. if the insert succeeds, we know the // table has been created), but it's here for additional code coverage. assertTrue(client.isCreateTableDone(TABLE_NAME)); }