Search in sources :

Example 6 with KuduScanner

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);
    }
}
Also used : RowResult(org.apache.kudu.client.RowResult) GoraException(org.apache.gora.util.GoraException) KuduScanner(org.apache.kudu.client.KuduScanner) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.kudu.ColumnSchema) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 7 with KuduScanner

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);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) KuduResult(org.apache.gora.kudu.query.KuduResult) KuduScanner(org.apache.kudu.client.KuduScanner) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.kudu.ColumnSchema) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 8 with KuduScanner

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);
    }
}
Also used : RowResult(org.apache.kudu.client.RowResult) GoraException(org.apache.gora.util.GoraException) KuduScanner(org.apache.kudu.client.KuduScanner) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.kudu.ColumnSchema) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 9 with KuduScanner

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);
}
Also used : Delete(org.apache.kudu.client.Delete) KuduScanToken(org.apache.kudu.client.KuduScanToken) KuduSession(org.apache.kudu.client.KuduSession) KuduTable(org.apache.kudu.client.KuduTable) RowResultIterator(org.apache.kudu.client.RowResultIterator) RowResult(org.apache.kudu.client.RowResult) KuduScanner(org.apache.kudu.client.KuduScanner)

Example 10 with KuduScanner

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();
    }
}
Also used : KuduScanner(org.apache.kudu.client.KuduScanner) KuduClient(org.apache.kudu.client.KuduClient) KuduTable(org.apache.kudu.client.KuduTable) KuduPredicate(org.apache.kudu.client.KuduPredicate)

Aggregations

KuduScanner (org.apache.kudu.client.KuduScanner)16 RowResult (org.apache.kudu.client.RowResult)10 ArrayList (java.util.ArrayList)9 RowResultIterator (org.apache.kudu.client.RowResultIterator)8 KuduTable (org.apache.kudu.client.KuduTable)7 ColumnSchema (org.apache.kudu.ColumnSchema)6 KuduException (org.apache.kudu.client.KuduException)6 KuduPredicate (org.apache.kudu.client.KuduPredicate)6 IOException (java.io.IOException)4 GoraException (org.apache.gora.util.GoraException)4 KuduClient (org.apache.kudu.client.KuduClient)4 PartialRow (org.apache.kudu.client.PartialRow)4 KuduSession (org.apache.kudu.client.KuduSession)3 Schema (org.apache.kudu.Schema)2 CreateTableOptions (org.apache.kudu.client.CreateTableOptions)2 Insert (org.apache.kudu.client.Insert)2 ListTablesResponse (org.apache.kudu.client.ListTablesResponse)2 PrestoException (com.facebook.presto.spi.PrestoException)1 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1