Search in sources :

Example 1 with Scanner

use of com.nearinfinity.honeycomb.Scanner in project honeycomb by altamiracorp.

the class HBaseTable method insertTableIndex.

@Override
public void insertTableIndex(final IndexSchema indexSchema) {
    checkNotNull(indexSchema, "The index schema is invalid");
    final Collection<IndexSchema> indices = ImmutableList.of(indexSchema);
    final Scanner scanner = tableScan();
    while (scanner.hasNext()) {
        HBaseOperations.performPut(hTable, mutationFactory.insertIndices(tableId, Row.deserialize(scanner.next()), indices));
    }
    Util.closeQuietly(scanner);
}
Also used : Scanner(com.nearinfinity.honeycomb.Scanner) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 2 with Scanner

use of com.nearinfinity.honeycomb.Scanner in project honeycomb by altamiracorp.

the class HandlerProxy method indexContainsDuplicate.

/**
     * Check whether the index contains a row with the same field values and a
     * distinct UUID.
     *
     * @param indexName
     * @param serializedRow
     * @return True If a duplicate is found, False otherwise
     */
public boolean indexContainsDuplicate(String indexName, byte[] serializedRow) {
    // This method must get its own table because it may be called during
    // a full table scan.
    Verify.isNotNullOrEmpty(indexName);
    checkNotNull(serializedRow);
    Row row = Row.deserialize(serializedRow);
    Table t = store.openTable(tableName);
    TableSchema schema = store.getSchema(tableName);
    IndexSchema indexSchema = schema.getIndexSchema(indexName);
    QueryKey key = new QueryKey(indexName, QueryType.EXACT_KEY, row.getRecords());
    Scanner scanner = t.indexScanExact(key);
    try {
        while (scanner.hasNext()) {
            Row next = Row.deserialize(scanner.next());
            if (!next.getUUID().equals(row.getUUID())) {
                // Special case for inserting nulls
                for (String column : indexSchema.getColumns()) {
                    boolean isNullInRecord = !row.getRecords().containsKey(column);
                    if (isNullInRecord) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    } finally {
        Util.closeQuietly(scanner);
        Util.closeQuietly(t);
    }
}
Also used : Scanner(com.nearinfinity.honeycomb.Scanner) Table(com.nearinfinity.honeycomb.Table) AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Aggregations

Scanner (com.nearinfinity.honeycomb.Scanner)2 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)2 Table (com.nearinfinity.honeycomb.Table)1 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)1 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)1