Example usage for org.apache.cassandra.db.rows Cell value

List of usage examples for org.apache.cassandra.db.rows Cell value

Introduction

In this page you can find the example usage for org.apache.cassandra.db.rows Cell value.

Prototype

public abstract ByteBuffer value();

Source Link

Document

The cell value.

Usage

From source file:com.stratio.cassandra.lucene.column.ColumnsMapper.java

License:Apache License

private void addColumns(Columns columns, Cell cell) {
    if (cell != null) {
        ColumnDefinition columnDefinition = cell.column();
        String name = columnDefinition.name.toString();
        AbstractType<?> type = cell.column().type;
        ByteBuffer value = cell.value();
        ColumnBuilder builder = Column.builder(name);
        if (type.isCollection() && !type.isFrozenCollection()) {
            CollectionType<?> collectionType = (CollectionType<?>) type;
            switch (collectionType.kind) {
            case SET: {
                type = collectionType.nameComparator();
                value = cell.path().get(0);
                addColumns(columns, builder, type, value);
                break;
            }/*from w  w w .  j  a v a2s .  c  om*/
            case LIST: {
                type = collectionType.valueComparator();
                addColumns(columns, builder, type, value);
                break;
            }
            case MAP: {
                type = collectionType.valueComparator();
                ByteBuffer keyValue = cell.path().get(0);
                AbstractType<?> keyType = collectionType.nameComparator();
                String nameSuffix = keyType.compose(keyValue).toString();
                addColumns(columns, builder.withMapName(nameSuffix), type, value);
                break;
            }
            default: {
                throw new IndexException("Unknown collection type %s", collectionType.kind);
            }
            }
        } else {
            addColumns(columns, Column.builder(name), type, value);
        }
    }
}

From source file:io.puntanegra.fhir.index.FhirIndexIndexer.java

License:Apache License

@SuppressWarnings("unused")
private boolean insertInIndex(final String indexResourceType, Row row) {
    // only index in the correct lucene index.
    // this code checks if the resourceType is the same as the index.
    // TODO: externalizar resource_type

    for (Cell cell : row.cells()) {
        String columnname = cell.column().name.toString();
        if ("resource_type".equals(columnname)) {
            String resourceType = ByteBufferUtils.toString(cell.value(), UTF8Type.instance);

            if (indexResourceType.equals(resourceType)) {
                return true;
            }/*from   ww w . ja  v a 2  s  .  c o  m*/
            return false;
        }
    }
    return false;
}

From source file:io.puntanegra.fhir.index.FhirIndexService.java

License:Apache License

/**
 * Creates a Lucene {@link Document} to index a FHIR {@link IBaseResource}.
 * //  w  w  w .ja  v  a  2s. co  m
 * @param key,
 *            the key of the row inserted.
 * @param row,
 *            the row inserted.
 * @return the Lucene {@link Document} to be inserted in the index.
 */
public Optional<Document> document(DecoratedKey key, Row row) {
    Document document = new Document();

    Cell cell = row.getCell(this.indexOptions.targetColumn);
    ByteBuffer value = cell.value();
    if (cell != null && !ByteBufferUtils.isEmpty(value)) {
        String json = ByteBufferUtils.toString(value, UTF8Type.instance);
        fhirMapper.addFields(document, json);
    }

    if (document.getFields().isEmpty()) {
        return Optional.empty();
    } else {
        Clustering clustering = row.clustering();
        tokenMapper.addFields(document, key);
        partitionMapper.addFields(document, key);
        keyMapper.addFields(document, key, clustering);
        return Optional.of(document);
    }
}