本文整理汇总了Java中org.apache.kudu.client.Insert类的典型用法代码示例。如果您正苦于以下问题:Java Insert类的具体用法?Java Insert怎么用?Java Insert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Insert类属于org.apache.kudu.client包,在下文中一共展示了Insert类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: insertTagset
import org.apache.kudu.client.Insert; //导入依赖的package包/类
/**
* Attempts to insert the provided tagset and ID. Returns {@code true} if the
* write was successful, or {@code false} if the write failed due to a tagset
* with the same ID already existing in the table.
*
* @param tagset the tagset to insert
* @param id the ID to insert the tagset with
* @return whether the write succeeded
*/
private Deferred<Boolean> insertTagset(final SerializedTagset tagset, final int id) throws KuduException {
final class InsertTagsetCB implements Callback<Deferred<Boolean>, OperationResponse> {
@Override
public Deferred<Boolean> call(OperationResponse response) {
if (response.hasRowError()) {
if (response.getRowError().getErrorStatus().isAlreadyPresent()) {
LOG.info("Attempted to insert duplicate tagset; id: {}, tagset: {}", id, tagset);
// TODO: Consider adding a backoff with jitter before attempting
// the insert again (if the lookup fails).
return Deferred.fromResult(false);
}
return Deferred.fromError(new RuntimeException(
String.format("Unable to insert tagset; id: %s, tagset: %s, error: %s",
id, tagset, response.getRowError())));
} else {
return Deferred.fromResult(true);
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).toString();
}
}
LOG.debug("Inserting tagset; id: {}, tags: {}", id, tagset);
final AsyncKuduSession session = client.newSession();
try {
// We don't have to handle PleaseThrottleException because we are only
// inserting a single row.
final Insert insert = tagsetsTable.newInsert();
insert.getRow().addInt(Tables.TAGSETS_ID_INDEX, id);
insert.getRow().addBinary(Tables.TAGSETS_TAGSET_INDEX, tagset.getBytes());
return session.apply(insert).addCallbackDeferring(new InsertTagsetCB());
} finally {
session.close();
}
}
开发者ID:danburkert,项目名称:kudu-ts,代码行数:47,代码来源:Tagsets.java
示例2: insertTagset
import org.apache.kudu.client.Insert; //导入依赖的package包/类
/**
* Insert a tagset into the {@code tags} table.
* @param id the tagset ID.
* @param tagset the tagset.
* @return The tagset ID.
*/
public Deferred<Integer> insertTagset(final int id, final SortedMap<String, String> tagset)
throws KuduException {
if (tagset.isEmpty()) { return Deferred.fromResult(id); }
LOG.debug("Inserting tags; tagsetID: {}, tags: {}", id, tagset);
final AsyncKuduSession session = client.newSession();
class InsertTagsetCB implements Callback<Deferred<Integer>, List<OperationResponse>> {
@Override
public Deferred<Integer> call(List<OperationResponse> responses) {
try {
for (OperationResponse response : responses) {
if (response.hasRowError()) {
return Deferred.fromError(new RuntimeException(
String.format("Unable to insert tag: %s", response.getRowError())));
}
}
return Deferred.fromResult(id);
} finally {
session.close();
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("tags", tagset)
.toString();
}
}
if (tagset.size() > 1000) {
session.setMutationBufferSpace(tagset.size());
}
session.setMutationBufferLowWatermark(1.0f);
// buffer all of the tags into the session, and ensure that we don't get
// a PleaseThrottleException. In practice the number of tags should be
// small.
session.setMutationBufferSpace(tagset.size());
session.setMutationBufferLowWatermark(1.0f);
session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
for (Map.Entry<String, String> tag : tagset.entrySet()) {
Insert insert = table.newInsert();
// TODO: check with JD that if the inserts below fail, the error will
// also be returned in the flush call.
insert.getRow().addString(Tables.TAGS_KEY_INDEX, tag.getKey());
insert.getRow().addString(Tables.TAGS_VALUE_INDEX, tag.getValue());
insert.getRow().addInt(Tables.TAGS_TAGSET_ID_INDEX, id);
session.apply(insert);
}
return session.flush().addCallbackDeferring(new InsertTagsetCB());
}
开发者ID:danburkert,项目名称:kudu-ts,代码行数:59,代码来源:Tags.java
示例3: createKuduTable
import org.apache.kudu.client.Insert; //导入依赖的package包/类
public static void createKuduTable(String tableName, int tablets, int replicas, int rows) throws Exception {
try (KuduClient client = new KuduClient.KuduClientBuilder(KUDU_MASTER).build()) {
ListTablesResponse tables = client.getTablesList(tableName);
if (!tables.getTablesList().isEmpty()) {
client.deleteTable(tableName);
}
List<ColumnSchema> columns = new ArrayList<>(5);
columns.add(new ColumnSchema.ColumnSchemaBuilder("key", Type.INT32).key(true).build());
columns.add(new ColumnSchema.ColumnSchemaBuilder("binary", Type.BINARY).nullable(false).build());
columns.add(new ColumnSchema.ColumnSchemaBuilder("boolean", Type.BOOL).nullable(true).build());
columns.add(new ColumnSchema.ColumnSchemaBuilder("float", Type.FLOAT).nullable(false).build());
columns.add(new ColumnSchema.ColumnSchemaBuilder("string", Type.STRING).nullable(true).build());
Schema schema = new Schema(columns);
CreateTableOptions builder = new CreateTableOptions();
builder.setNumReplicas(replicas);
builder.setRangePartitionColumns(Arrays.asList("key"));
for (int i = 1; i < tablets; i++) {
PartialRow splitRow = schema.newPartialRow();
splitRow.addInt("key", i*1000);
builder.addSplitRow(splitRow);
}
client.createTable(tableName, schema, builder);
KuduTable table = client.openTable(tableName);
KuduSession session = client.newSession();
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);
row.addBinary(1, ("Row " + i).getBytes());
row.addBoolean(2, i % 2 == 0);
row.addFloat(3, i + 0.01f);
row.addString(4, ("Row " + i));
session.apply(insert);
}
List<String> projectColumns = new ArrayList<>(1);
projectColumns.add("float");
KuduScanner scanner = client.newScannerBuilder(table)
.setProjectedColumnNames(projectColumns)
.build();
while (scanner.hasMoreRows()) {
RowResultIterator results = scanner.nextRows();
while (results.hasNext()) {
RowResult result = results.next();
System.out.println(result.toStringLongFormat());
}
}
}
}
开发者ID:axbaretto,项目名称:drill,代码行数:59,代码来源:TestKuduConnect.java
示例4: processForInsert
import org.apache.kudu.client.Insert; //导入依赖的package包/类
protected void processForInsert(KuduExecutionContext kuduExecutionContext)
{
Insert thisInsert = kuduTable.newInsert();
performCommonProcessing(thisInsert,kuduExecutionContext);
}
开发者ID:apache,项目名称:apex-malhar,代码行数:6,代码来源:AbstractKuduOutputOperator.java
注:本文中的org.apache.kudu.client.Insert类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论