Search in sources :

Example 1 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project stargate-core by tuplejump.

the class CassandraUtils method getOptions.

public static Options getOptions(Properties mapping, ColumnFamilyStore baseCfs, String colName) {
    Map<String, NumericConfig> numericFieldOptions = new HashMap<>();
    Map<String, FieldType> fieldDocValueTypes = new TreeMap<>();
    Map<String, FieldType> collectionFieldDocValueTypes = new TreeMap<>();
    Map<String, FieldType> fieldTypes = new TreeMap<>();
    Map<String, FieldType[]> collectionFieldTypes = new TreeMap<>();
    Map<String, ColumnDefinition> validators = new TreeMap<>();
    Map<String, ColumnDefinition> clusteringKeysIndexed = new LinkedHashMap<>();
    Map<String, ColumnDefinition> partitionKeysIndexed = new LinkedHashMap<>();
    Set<String> indexedColumnNames;
    //getForRow all the fields options.
    indexedColumnNames = new TreeSet<>();
    indexedColumnNames.addAll(mapping.getFields().keySet());
    Set<String> added = new HashSet<>(indexedColumnNames.size());
    List<ColumnDefinition> partitionKeys = baseCfs.metadata.partitionKeyColumns();
    List<ColumnDefinition> clusteringKeys = baseCfs.metadata.clusteringColumns();
    for (ColumnDefinition colDef : partitionKeys) {
        String columnName = colDef.name.toString();
        if (Options.logger.isDebugEnabled()) {
            Options.logger.debug("Partition key name is {} and index is {}", colName, colDef.position());
        }
        validators.put(columnName, colDef);
        if (indexedColumnNames.contains(columnName)) {
            partitionKeysIndexed.put(colName, colDef);
            addPropertiesAndFieldType(mapping, numericFieldOptions, fieldDocValueTypes, collectionFieldDocValueTypes, fieldTypes, collectionFieldTypes, added, colDef, columnName);
        }
    }
    for (ColumnDefinition colDef : clusteringKeys) {
        String columnName = colDef.name.toString();
        if (Options.logger.isDebugEnabled()) {
            Options.logger.debug("Clustering key name is {} and index is {}", colName, colDef.position() + 1);
        }
        validators.put(columnName, colDef);
        if (indexedColumnNames.contains(columnName)) {
            clusteringKeysIndexed.put(columnName, colDef);
            addPropertiesAndFieldType(mapping, numericFieldOptions, fieldDocValueTypes, collectionFieldDocValueTypes, fieldTypes, collectionFieldTypes, added, colDef, columnName);
        }
    }
    for (String columnName : indexedColumnNames) {
        if (added.add(columnName.toLowerCase())) {
            Properties options = mapping.getFields().get(columnName);
            ColumnDefinition colDef = getColumnDefinition(baseCfs, columnName);
            if (colDef != null) {
                validators.put(columnName, colDef);
                addFieldType(columnName, colDef.type, options, numericFieldOptions, fieldDocValueTypes, collectionFieldDocValueTypes, fieldTypes, collectionFieldTypes);
            } else {
                throw new IllegalArgumentException(String.format("Column Definition for %s not found", columnName));
            }
            if (options.getType() == Type.object) {
                mapping.getFields().putAll(options.getFields());
            }
        }
    }
    Set<ColumnDefinition> otherColumns = baseCfs.metadata.regularColumns();
    for (ColumnDefinition colDef : otherColumns) {
        String columnName = UTF8Type.instance.getString(colDef.name.bytes);
        validators.put(columnName, colDef);
    }
    numericFieldOptions.putAll(mapping.getDynamicNumericConfig());
    Analyzer defaultAnalyzer = mapping.getLuceneAnalyzer();
    Analyzer analyzer = new PerFieldAnalyzerWrapper(defaultAnalyzer, mapping.perFieldAnalyzers());
    Map<String, Type> types = new TreeMap<>();
    Set<String> nestedFields = new TreeSet<>();
    for (Map.Entry<String, ColumnDefinition> entry : validators.entrySet()) {
        CQL3Type cql3Type = entry.getValue().type.asCQL3Type();
        AbstractType inner = getValueValidator(cql3Type.getType());
        if (cql3Type.isCollection()) {
            types.put(entry.getKey(), fromAbstractType(inner.asCQL3Type()));
            nestedFields.add(entry.getKey());
        } else {
            types.put(entry.getKey(), fromAbstractType(cql3Type));
        }
    }
    return new Options(mapping, numericFieldOptions, fieldDocValueTypes, collectionFieldDocValueTypes, fieldTypes, collectionFieldTypes, types, nestedFields, clusteringKeysIndexed, partitionKeysIndexed, indexedColumnNames, analyzer, colName);
}
Also used : CQL3Type(org.apache.cassandra.cql3.CQL3Type) Options(com.tuplejump.stargate.lucene.Options) Properties(com.tuplejump.stargate.lucene.Properties) Analyzer(org.apache.lucene.analysis.Analyzer) FieldType(org.apache.lucene.document.FieldType) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition) PerFieldAnalyzerWrapper(org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper) Type(com.tuplejump.stargate.lucene.Type) FieldType(org.apache.lucene.document.FieldType) CQL3Type(org.apache.cassandra.cql3.CQL3Type) NumericConfig(org.apache.lucene.queryparser.flexible.standard.config.NumericConfig)

Example 2 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project stargate-core by tuplejump.

the class RowIndexSupport method addCell.

private void addCell(Cell cell, ColumnIdentifier cql3ColName, String actualColName, IndexEntryBuilder builder) {
    ColumnDefinition columnDefinition = tableMapper.cfMetaData.getColumnDefinition(cql3ColName);
    if (options.shouldIndex(actualColName)) {
        builder.setCurrentTimestamp(cell.timestamp());
        List<Field> fields = builder.getFieldList();
        addFields(cell, actualColName, columnDefinition, fields);
    }
}
Also used : Field(org.apache.lucene.document.Field) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Example 3 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project stargate-core by tuplejump.

the class TableMapper method getRowWithMetaColumn.

public Row getRowWithMetaColumn(ByteBuffer metaColumnValue) {
    if (isMetaColumn) {
        ColumnFamily cleanColumnFamily = ArrayBackedSortedColumns.factory.create(table.metadata);
        CellNameType cellNameType = table.getComparator();
        boolean hasCollections = cellNameType.hasCollections();
        int prefixSize = cellNameType.size() - (hasCollections ? 2 : 1);
        CBuilder builder = cellNameType.builder();
        for (int i = 0; i < prefixSize; i++) {
            AbstractType<?> type = cellNameType.subtype(i);
            builder.add(Fields.defaultValue(type));
        }
        Composite prefix = builder.build();
        Iterable<ColumnDefinition> cols = table.metadata.regularAndStaticColumns();
        for (ColumnDefinition columnDef : cols) {
            if (columnDef.equals(primaryColumnDefinition)) {
                addColumn(table, cleanColumnFamily, primaryColumnDefinition, prefix, metaColumnValue);
            } else {
                addColumn(table, cleanColumnFamily, columnDef, prefix, Fields.defaultValue(columnDef.type));
            }
        }
        DecoratedKey dk = table.partitioner.decorateKey(defaultPartitionKey);
        return new Row(dk, cleanColumnFamily);
    } else {
        return null;
    }
}
Also used : ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Example 4 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project eiger by wlloyd.

the class SecondaryIndex method buildIndexAsync.

/**
     * Builds the index using the data in the underlying CF, non blocking
     * 
     * 
     * @return A future object which the caller can block on (optional)
     */
public Future<?> buildIndexAsync() {
    // if we're just linking in the index to indexedColumns on an already-built index post-restart, we're done
    boolean allAreBuilt = true;
    for (ColumnDefinition cdef : columnDefs) {
        if (!SystemTable.isIndexBuilt(baseCfs.table.name, getNameForSystemTable(cdef.name))) {
            allAreBuilt = false;
            break;
        }
    }
    if (allAreBuilt)
        return null;
    // build it asynchronously; addIndex gets called by CFS open and schema update, neither of which
    // we want to block for a long period.  (actual build is serialized on CompactionManager.)
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                baseCfs.forceBlockingFlush();
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }
            try {
                buildIndexBlocking();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
    FutureTask<?> f = new FutureTask<Object>(runnable, null);
    new Thread(f, "Creating index: " + getIndexName()).start();
    return f;
}
Also used : IOException(java.io.IOException) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Example 5 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project eiger by wlloyd.

the class SSTableExport method export.

/**
     * Export an SSTable and write the resulting JSON to a PrintStream.
     * 
     * @param ssTableFile the SSTable to export
     * @param outs PrintStream to write the output to
     * @param excludes keys to exclude from export
     *
     * @throws IOException on failure to read/write input/output
     */
public static void export(String ssTableFile, PrintStream outs, String[] excludes) throws IOException {
    Descriptor descriptor = Descriptor.fromFilename(ssTableFile);
    CFMetaData metadata;
    if (descriptor.cfname.contains(".")) {
        // look up index metadata from parent
        int i = descriptor.cfname.indexOf(".");
        String parentName = descriptor.cfname.substring(0, i);
        CFMetaData parent = Schema.instance.getCFMetaData(descriptor.ksname, parentName);
        ColumnDefinition def = parent.getColumnDefinitionForIndex(descriptor.cfname.substring(i + 1));
        metadata = CFMetaData.newIndexMetadata(parent, def, KeysIndex.indexComparator());
    } else {
        metadata = Schema.instance.getCFMetaData(descriptor.ksname, descriptor.cfname);
    }
    export(SSTableReader.open(descriptor, metadata), outs, excludes);
}
Also used : DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) CFMetaData(org.apache.cassandra.config.CFMetaData) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Aggregations

ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)17 ByteBuffer (java.nio.ByteBuffer)5 CFMetaData (org.apache.cassandra.config.CFMetaData)3 IOException (java.io.IOException)2 CellName (org.apache.cassandra.db.composites.CellName)2 Composite (org.apache.cassandra.db.composites.Composite)2 Options (com.tuplejump.stargate.lucene.Options)1 Properties (com.tuplejump.stargate.lucene.Properties)1 Type (com.tuplejump.stargate.lucene.Type)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigurationException (org.apache.cassandra.config.ConfigurationException)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 KSMetaData (org.apache.cassandra.config.KSMetaData)1 CQL3Type (org.apache.cassandra.cql3.CQL3Type)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 CType (org.apache.cassandra.db.composites.CType)1 CellNameType (org.apache.cassandra.db.composites.CellNameType)1 ColumnSlice (org.apache.cassandra.db.filter.ColumnSlice)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1