本文整理汇总了Java中org.apache.kudu.client.KuduSession类的典型用法代码示例。如果您正苦于以下问题:Java KuduSession类的具体用法?Java KuduSession怎么用?Java KuduSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KuduSession类属于org.apache.kudu.client包,在下文中一共展示了KuduSession类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openKuduSession
import org.apache.kudu.client.KuduSession; //导入依赖的package包/类
private KuduSession openKuduSession(List<ConfigIssue> issues) {
KuduSession session = kuduClient.newSession();
try {
session.setExternalConsistencyMode(ExternalConsistencyMode.valueOf(configBean.consistencyMode.name()));
} catch (IllegalArgumentException ex) {
issues.add(
getContext().createConfigIssue(
Groups.KUDU.name(),
KuduConfigBean.CONF_PREFIX + CONSISTENCY_MODE,
Errors.KUDU_02
)
);
}
session.setMutationBufferSpace(configBean.mutationBufferSpace);
session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
return session;
}
示例2: truncateTable
import org.apache.kudu.client.KuduSession; //导入依赖的package包/类
public void truncateTable() throws Exception
{
AbstractKuduPartitionScanner<UnitTestTablePojo,InputOperatorControlTuple> scannerForDeletingRows =
unitTestStepwiseScanInputOperator.getScanner();
List<KuduScanToken> scansForAllTablets = unitTestStepwiseScanInputOperator
.getPartitioner().getKuduScanTokensForSelectAllColumns();
ApexKuduConnection aCurrentConnection = scannerForDeletingRows.getConnectionPoolForThreads().get(0);
KuduSession aSessionForDeletes = aCurrentConnection.getKuduClient().newSession();
KuduTable currentTable = aCurrentConnection.getKuduTable();
for ( KuduScanToken aTabletScanToken : scansForAllTablets) {
KuduScanner aScanner = aTabletScanToken.intoScanner(aCurrentConnection.getKuduClient());
while ( aScanner.hasMoreRows()) {
RowResultIterator itrForRows = aScanner.nextRows();
while ( itrForRows.hasNext()) {
RowResult aRow = itrForRows.next();
int intRowKey = aRow.getInt("introwkey");
String stringRowKey = aRow.getString("stringrowkey");
long timestampRowKey = aRow.getLong("timestamprowkey");
Delete aDeleteOp = currentTable.newDelete();
aDeleteOp.getRow().addInt("introwkey",intRowKey);
aDeleteOp.getRow().addString("stringrowkey", stringRowKey);
aDeleteOp.getRow().addLong("timestamprowkey",timestampRowKey);
aSessionForDeletes.apply(aDeleteOp);
}
}
}
aSessionForDeletes.close();
Thread.sleep(2000); // Sleep to allow for scans to complete
}
示例3: addTestDataRows
import org.apache.kudu.client.KuduSession; //导入依赖的package包/类
public void addTestDataRows(int numRowsInEachPartition) throws Exception
{
int intRowKeyStepsize = Integer.MAX_VALUE / SPLIT_COUNT_FOR_INT_ROW_KEY;
int splitBoundaryForIntRowKey = intRowKeyStepsize;
int[] inputrowkeyPartitionEntries = new int[SPLIT_COUNT_FOR_INT_ROW_KEY + 1];
// setting the int keys that will fall in the range of all partitions
for ( int i = 0; i < SPLIT_COUNT_FOR_INT_ROW_KEY; i++) {
inputrowkeyPartitionEntries[i] = splitBoundaryForIntRowKey + 3; // 3 to fall into the partition next to boundary
splitBoundaryForIntRowKey += intRowKeyStepsize;
}
inputrowkeyPartitionEntries[SPLIT_COUNT_FOR_INT_ROW_KEY] = splitBoundaryForIntRowKey + 3;
AbstractKuduPartitionScanner<UnitTestTablePojo,InputOperatorControlTuple> scannerForAddingRows =
unitTestStepwiseScanInputOperator.getScanner();
ApexKuduConnection aCurrentConnection = scannerForAddingRows.getConnectionPoolForThreads().get(0);
KuduSession aSessionForInserts = aCurrentConnection.getKuduClient().newSession();
KuduTable currentTable = aCurrentConnection.getKuduTable();
long seedValueForTimestampRowKey = 0L; // constant to allow for data landing on first partition for unit tests
for ( int i = 0; i <= SPLIT_COUNT_FOR_INT_ROW_KEY; i++) { // range key iterator
int intRowKeyBaseValue = inputrowkeyPartitionEntries[i] + i;
for ( int k = 0; k < 2; k++) { // hash key iterator . The table defines two hash partitions
long timestampRowKeyValue = seedValueForTimestampRowKey + k; // to avoid spilling to another tablet
String stringRowKeyValue = "" + timestampRowKeyValue + k; // to avoid spilling to another tablet randomly
for ( int y = 0; y < numRowsInEachPartition; y++) {
Upsert aNewRow = currentTable.newUpsert();
PartialRow rowValue = aNewRow.getRow();
// Start assigning row keys below the current split boundary.
rowValue.addInt("introwkey",intRowKeyBaseValue - y - 1);
rowValue.addString("stringrowkey",stringRowKeyValue);
rowValue.addLong("timestamprowkey",timestampRowKeyValue);
rowValue.addLong("longdata",(seedValueForTimestampRowKey + y));
rowValue.addString("stringdata", ("" + seedValueForTimestampRowKey + y));
OperationResponse response = aSessionForInserts.apply(aNewRow);
}
}
}
List<OperationResponse> insertResponse = aSessionForInserts.flush();
aSessionForInserts.close();
Thread.sleep(2000); // Sleep to allow for scans to complete
}
示例4: buildMockWiring
import org.apache.kudu.client.KuduSession; //导入依赖的package包/类
public ApexKuduConnection buildMockWiring(AbstractKuduInputOperator abstractKuduInputOperator,
int numScanTokens) throws Exception
{
ApexKuduConnection mockedConnectionHandle = PowerMockito.mock(ApexKuduConnection.class);
ApexKuduConnection.ApexKuduConnectionBuilder mockedConnectionHandleBuilder = PowerMockito.mock(
ApexKuduConnection.ApexKuduConnectionBuilder.class);
KuduClient mockedClient = PowerMockito.mock(KuduClient.class);
KuduSession mockedKuduSession = PowerMockito.mock(KuduSession.class);
KuduTable mockedKuduTable = PowerMockito.mock(KuduTable.class);
KuduScanToken.KuduScanTokenBuilder mockedScanTokenBuilder = PowerMockito.mock(
KuduScanToken.KuduScanTokenBuilder.class);
List<KuduScanToken> mockedScanTokens = new ArrayList<>();
int scanTokensToBuild = numScanTokens;
for (int i = 0; i < scanTokensToBuild; i++) {
mockedScanTokens.add(PowerMockito.mock(KuduScanToken.class));
}
PowerMockito.mockStatic(KryoCloneUtils.class);
when(KryoCloneUtils.cloneObject(abstractKuduInputOperator)).thenReturn(abstractKuduInputOperator);
//wire the mocks
when(abstractKuduInputOperator.getApexKuduConnectionInfo()).thenReturn(mockedConnectionHandleBuilder);
when(mockedConnectionHandle.getKuduClient()).thenReturn(mockedClient);
when(mockedClient.newSession()).thenReturn(mockedKuduSession);
when(mockedConnectionHandle.getKuduTable()).thenReturn(mockedKuduTable);
when(mockedConnectionHandle.getKuduSession()).thenReturn(mockedKuduSession);
when(mockedConnectionHandle.getBuilderForThisConnection()).thenReturn(mockedConnectionHandleBuilder);
when(mockedClient.openTable(tableName)).thenReturn(mockedKuduTable);
when(mockedConnectionHandleBuilder.build()).thenReturn(mockedConnectionHandle);
when(mockedKuduTable.getSchema()).thenReturn(schemaForUnitTests);
when(mockedClient.newScanTokenBuilder(mockedKuduTable)).thenReturn(mockedScanTokenBuilder);
when(mockedScanTokenBuilder.build()).thenReturn(mockedScanTokens);
return mockedConnectionHandle;
}
示例5: createKuduTable
import org.apache.kudu.client.KuduSession; //导入依赖的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());
}
}
}
}
示例6: getKuduSession
import org.apache.kudu.client.KuduSession; //导入依赖的package包/类
public KuduSession getKuduSession()
{
return kuduSession;
}
示例7: setKuduSession
import org.apache.kudu.client.KuduSession; //导入依赖的package包/类
public void setKuduSession(KuduSession kuduSession)
{
this.kuduSession = kuduSession;
}