Java Code Examples for org.apache.kudu.client.KuduTable#newInsert()
The following examples show how to use
org.apache.kudu.client.KuduTable#newInsert() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaEmulationByTableNameConvention.java From presto with Apache License 2.0 | 6 votes |
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(); } }
Example 2
Source File: KuduSink.java From sylph with Apache License 2.0 | 6 votes |
private static Supplier<Operation> getOperationCreater(String mode, KuduTable kuduTable) { //INSERT OR UPSET OR UPDATE OR DELETE switch (mode.toUpperCase()) { case "INSERT": return () -> kuduTable.newInsert(); case "UPSET": return () -> kuduTable.newUpsert(); case "UPDATE": return () -> kuduTable.newUpdate(); case "DELETE": return () -> kuduTable.newDelete(); default: throw new IllegalArgumentException(); } }
Example 3
Source File: AbstractKuduTest.java From syndesis with Apache License 2.0 | 6 votes |
protected void insertRowInTestTable(final String tableName, final String connection) throws KuduException { try (KuduClient client = new KuduClient.KuduClientBuilder(connection).build()) { final KuduTable table = client.openTable(tableName); final Insert insert = table.newInsert(); final PartialRow row = insert.getRow(); row.addInt("id", ThreadLocalRandom.current().nextInt(1, 99)); row.addString("title", "Mr."); row.addString("name", "Samuel"); row.addString("lastname", "Smith"); row.addString("address", "4359 Plainfield Avenue"); client.newSession().apply(insert); } }
Example 4
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 6 votes |
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(); } }
Example 5
Source File: KuduTarget.java From datacollector with Apache License 2.0 | 6 votes |
/** * Return Operation based on the operation code. If the code has a number * that Kudu destination doesn't support, it throws UnsupportedOperationException. * @param table * @param op * @return * @throws UnsupportedOperationException */ protected Operation getOperation(KuduTable table, int op) throws UnsupportedOperationException { Operation operation = null; switch (op) { case OperationType.INSERT_CODE: operation = table.newInsert(); break; case OperationType.UPSERT_CODE: operation = table.newUpsert(); break; case OperationType.UPDATE_CODE: operation = table.newUpdate(); break; case OperationType.DELETE_CODE: operation = table.newDelete(); break; default: LOG.error("Operation {} not supported", op); throw new UnsupportedOperationException(String.format("Unsupported Operation: %s", op)); } return operation; }
Example 6
Source File: KuduMapper.java From flink-learning with Apache License 2.0 | 5 votes |
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(); }
Example 7
Source File: KuduMapper.java From flink-learning with Apache License 2.0 | 5 votes |
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(); }
Example 8
Source File: DafPutKudu.java From daf-kylo with GNU Affero General Public License v3.0 | 4 votes |
@Override protected Insert insertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames) throws IllegalStateException, Exception { Insert insert = kuduTable.newInsert(); this.insert(kuduTable, insert, record, fieldNames); return insert; }
Example 9
Source File: ITestKuduLookupService.java From nifi with Apache License 2.0 | 4 votes |
@Before public void init() throws Exception { testRunner = TestRunners.newTestRunner(SampleProcessor.class); testRunner.setValidateExpressionUsage(false); final String tableName = "table1"; KuduClient client = harness.getClient(); List<ColumnSchema> columns = new ArrayList<>(); columns.add(new ColumnSchema.ColumnSchemaBuilder("string", Type.STRING).key(true).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("binary", Type.BINARY).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("bool", Type.BOOL).build()); columns.add(new ColumnSchema .ColumnSchemaBuilder("decimal", Type.DECIMAL) .typeAttributes(DecimalUtil.typeAttributes(DecimalUtil.MAX_DECIMAL64_PRECISION, 1)) .build() ); columns.add(new ColumnSchema.ColumnSchemaBuilder("double", Type.DOUBLE).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("float", Type.FLOAT).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("int8", Type.INT8).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("int16", Type.INT16).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("int32", Type.INT32).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("int64", Type.INT64).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("unixtime_micros", Type.UNIXTIME_MICROS).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("varchar_3", Type.VARCHAR).typeAttributes( new ColumnTypeAttributes.ColumnTypeAttributesBuilder().length(3).build() ).build()); Schema schema = new Schema(columns); CreateTableOptions opts = new CreateTableOptions().setRangePartitionColumns(Collections.singletonList("string")); client.createTable(tableName, schema, opts); KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); Insert insert = table.newInsert(); PartialRow row = insert.getRow(); row.addString("string", "string1"); row.addBinary("binary", "binary1".getBytes()); row.addBoolean("bool",true); row.addDecimal("decimal", BigDecimal.valueOf(0.1)); row.addDouble("double",0.2); row.addFloat("float",0.3f); row.addByte("int8", (byte) 1); row.addShort("int16", (short) 2); row.addInt("int32",3); row.addLong("int64",4L); row.addTimestamp("unixtime_micros", new Timestamp(nowMillis)); row.addVarchar("varchar_3", "SFO"); session.apply(insert); insert = table.newInsert(); row = insert.getRow(); row.addString("string", "string2"); row.addBinary("binary", "binary2".getBytes()); row.addBoolean("bool",false); row.addDecimal("decimal", BigDecimal.valueOf(0.1)); row.addDouble("double",1.2); row.addFloat("float",1.3f); row.addByte("int8", (byte) 11); row.addShort("int16", (short) 12); row.addInt("int32",13); row.addLong("int64",14L); row.addTimestamp("unixtime_micros", new Timestamp(nowMillis+(1000L * 60 * 60 * 24 * 365))); //+ 1 year row.addVarchar("varchar_3", "SJC"); session.apply(insert); session.close(); kuduLookupService = new KuduLookupService(); testRunner.addControllerService("kuduLookupService", kuduLookupService); testRunner.setProperty(kuduLookupService, KuduLookupService.KUDU_MASTERS, "testLocalHost:7051"); testRunner.setProperty(kuduLookupService, KuduLookupService.KUDU_REPLICA_SELECTION, KuduLookupService.LEADER_ONLY); testRunner.setProperty(kuduLookupService, KuduLookupService.TABLE_NAME, tableName); kuduLookupService.kuduClient = client; }
Example 10
Source File: AbstractKuduProcessor.java From nifi with Apache License 2.0 | 4 votes |
protected Insert insertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames, Boolean ignoreNull, Boolean lowercaseFields) { Insert insert = kuduTable.newInsert(); buildPartialRow(kuduTable.getSchema(), insert.getRow(), record, fieldNames, ignoreNull, lowercaseFields); return insert; }