use of org.apache.kudu.client.KuduScanner in project gora by apache.
the class KuduStore method exists.
@Override
public boolean exists(K key) throws GoraException {
try {
ColumnSchema column = table.getSchema().getColumn(kuduMapping.getPrimaryKey().get(0).getName());
ArrayList<KuduPredicate> equalPredicate = new ArrayList<>();
equalPredicate.add(KuduClientUtils.createEqualPredicate(column, key));
KuduScanner build = createScanner(equalPredicate, new ArrayList<>(), 1);
RowResult waitFirstResult = KuduClientUtils.waitFirstResult(build);
build.close();
return waitFirstResult != null;
} catch (Exception e) {
throw new GoraException(e);
}
}
use of org.apache.kudu.client.KuduScanner in project gora by apache.
the class KuduStore method execute.
@Override
public Result<K, T> execute(Query<K, T> query) throws GoraException {
String[] avFields = getFieldsToQuery(query.getFields());
List<String> dbFields = new ArrayList<>();
for (String af : avFields) {
dbFields.add(kuduMapping.getFields().get(af).getName());
}
try {
ColumnSchema column = table.getSchema().getColumn(kuduMapping.getPrimaryKey().get(0).getName());
dbFields.add(kuduMapping.getPrimaryKey().get(0).getName());
List<KuduPredicate> rangePredicates = KuduClientUtils.createRangePredicate(column, query.getStartKey(), query.getEndKey());
rangePredicates.add(KuduPredicate.newIsNotNullPredicate(column));
KuduScanner build = createScanner(rangePredicates, dbFields, query.getLimit());
return new KuduResult<>(this, query, build);
} catch (Exception e) {
throw new GoraException(e);
}
}
use of org.apache.kudu.client.KuduScanner in project gora by apache.
the class KuduStore method get.
@Override
public T get(K key, String[] fields) throws GoraException {
String[] avFields = getFieldsToQuery(fields);
List<String> dbFields = new ArrayList<>();
for (String af : avFields) {
dbFields.add(kuduMapping.getFields().get(af).getName());
}
try {
ColumnSchema column = table.getSchema().getColumn(kuduMapping.getPrimaryKey().get(0).getName());
ArrayList<KuduPredicate> equalPredicate = new ArrayList<>();
equalPredicate.add(KuduClientUtils.createEqualPredicate(column, key));
KuduScanner build = createScanner(equalPredicate, dbFields, 1);
RowResult waitGetOneOrZero = KuduClientUtils.waitFirstResult(build);
T resp = null;
if (waitGetOneOrZero != null) {
resp = newInstance(waitGetOneOrZero, fields);
}
build.close();
return resp;
} catch (Exception ex) {
throw new GoraException(ex);
}
}
use of org.apache.kudu.client.KuduScanner in project apex-malhar by apache.
the class KuduInputOperatorCommons method truncateTable.
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();
// Sleep to allow for scans to complete
Thread.sleep(2000);
}
use of org.apache.kudu.client.KuduScanner in project hive by apache.
the class TestKuduPredicateHandler method scanWithPredicates.
private void scanWithPredicates(List<KuduPredicate> predicates) throws KuduException {
// Scan the table with the predicate to be sure there are no exceptions.
KuduClient client = harness.getClient();
KuduTable table = client.openTable(TABLE_NAME);
KuduScanner.KuduScannerBuilder builder = client.newScannerBuilder(table);
for (KuduPredicate predicate : predicates) {
builder.addPredicate(predicate);
}
KuduScanner scanner = builder.build();
while (scanner.hasMoreRows()) {
scanner.nextRows();
}
}
Aggregations