org.apache.cassandra.db.ColumnFamilyType Java Examples

The following examples show how to use org.apache.cassandra.db.ColumnFamilyType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectStatementTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Calls the <code>SelectStatement.buildBound</code> with the specified restrictions.
 *
 * @param restrictions the restrictions
 * @return the result from the method call to <code>SelectStatement.buildBound</code>
 * @throws InvalidRequestException if the method call throw an exception
 */
private static List<Composite> executeBuildBound(Restriction[] restrictions,
                                                 Bound bound) throws InvalidRequestException
{
    List<AbstractType<?>> types = new ArrayList<>();

    for (int i = 0, m = restrictions.length; i < m; i++)
        types.add(Int32Type.instance);

    CompoundSparseCellNameType cType = new CompoundSparseCellNameType(types);
    CFMetaData cfMetaData = new CFMetaData("keyspace", "test", ColumnFamilyType.Standard, cType);

    List<ColumnDefinition> columnDefs = new ArrayList<>();
    for (int i = 0, m = restrictions.length; i < m; i++)
    {
        ByteBuffer name = ByteBufferUtil.bytes("clustering_" + i);
        columnDefs.add(ColumnDefinition.clusteringKeyDef(cfMetaData, name, types.get(i), i));
    }

    return SelectStatement.buildBound(bound, columnDefs, restrictions, false, cType, QueryOptions.DEFAULT);
}
 
Example #2
Source File: SSTableRecordReader.java    From hadoop-sstable with Apache License 2.0 6 votes vote down vote up
private static CFMetaData initializeCfMetaData(TaskAttemptContext context) {
    final String cql = context.getConfiguration().get(HadoopSSTableConstants.HADOOP_SSTABLE_CQL);
    Preconditions.checkNotNull(cql, "Cannot proceed without CQL definition.");

    final CreateColumnFamilyStatement statement = getCreateColumnFamilyStatement(cql);

    final String keyspace = context.getConfiguration().get(HadoopSSTableConstants.HADOOP_SSTABLE_KEYSPACE, "default");
    final String columnFamily = context.getConfiguration().get(HadoopSSTableConstants.HADOOP_SSTABLE_COLUMN_FAMILY_NAME, "default");
    final CFMetaData cfMetaData = new CFMetaData(keyspace, columnFamily, ColumnFamilyType.Standard, statement.comparator, null);

    try {
        statement.applyPropertiesTo(cfMetaData);
    } catch (RequestValidationException e) {
        // Cannot proceed if an error occurs
        throw new RuntimeException("Error configuring SSTable reader. Cannot proceed", e);
    }

    return cfMetaData;
}
 
Example #3
Source File: CQLUtil.java    From hadoop-sstable with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a CQL CREATE statement into its CFMetaData object
 *
 * @param cql
 * @return CFMetaData
 * @throws RequestValidationException if CQL is invalid
 */
public static CFMetaData parseCreateStatement(String cql) throws RequestValidationException {
    final CreateColumnFamilyStatement statement =
            (CreateColumnFamilyStatement) QueryProcessor.parseStatement(cql).prepare().statement;

    final CFMetaData cfm =
            new CFMetaData("assess", "kvs_strict", ColumnFamilyType.Standard, statement.comparator, null);

    statement.applyPropertiesTo(cfm);
    return cfm;
}
 
Example #4
Source File: CassandraRunner.java    From staash with Apache License 2.0 5 votes vote down vote up
private List<CFMetaData> extractColumnFamily(RequiresColumnFamily rcf) {
  logger.debug("RequiresColumnFamily  has name: {} for ks: {}", rcf.cfName(), rcf.ksName());
  List<CFMetaData> cfms = new ArrayList<CFMetaData>();
  if ( rcf != null ) {
    try {
      cfms.add(new CFMetaData(rcf.ksName(), rcf.cfName(),
              ColumnFamilyType.Standard, TypeParser.parse(rcf.comparator()), null));

    } catch (Exception ex) {
      throw new RuntimeException("unable to create column family for: " + rcf.cfName(), ex);
    }
  }
  return cfms;
}
 
Example #5
Source File: CreateColumnFamilyStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a CFMetaData instance based on the parameters parsed from this
 * <code>CREATE</code> statement, or defaults where applicable.
 *
 * @param keyspace keyspace to apply this column family to
 * @return a CFMetaData instance corresponding to the values parsed from this statement
 * @throws InvalidRequestException on failure to validate parsed parameters
 */
public CFMetaData getCFMetaData(String keyspace, List<ByteBuffer> variables) throws InvalidRequestException
{
    validate(variables);

    try
    {
        boolean isDense = columns.isEmpty();
        CFMetaData newCFMD = new CFMetaData(keyspace,
                                            name,
                                            ColumnFamilyType.Standard,
                                            CellNames.fromAbstractType(cfProps.getComparator(), isDense));

        if (CFMetaData.DEFAULT_COMPRESSOR != null && cfProps.compressionParameters.isEmpty())
            cfProps.compressionParameters.put(CompressionParameters.SSTABLE_COMPRESSION, CFMetaData.DEFAULT_COMPRESSOR);
        int maxCompactionThreshold = getPropertyInt(CFPropDefs.KW_MAXCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD);
        int minCompactionThreshold = getPropertyInt(CFPropDefs.KW_MINCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD);
        if (minCompactionThreshold <= 0 || maxCompactionThreshold <= 0)
            throw new ConfigurationException("Disabling compaction by setting compaction thresholds to 0 has been deprecated, set the compaction option 'enabled' to false instead.");

        newCFMD.isDense(isDense)
               .addAllColumnDefinitions(getColumns(newCFMD))
               .comment(cfProps.getProperty(CFPropDefs.KW_COMMENT))
               .readRepairChance(getPropertyDouble(CFPropDefs.KW_READREPAIRCHANCE, CFMetaData.DEFAULT_READ_REPAIR_CHANCE))
               .dcLocalReadRepairChance(getPropertyDouble(CFPropDefs.KW_DCLOCALREADREPAIRCHANCE, CFMetaData.DEFAULT_DCLOCAL_READ_REPAIR_CHANCE))
               .gcGraceSeconds(getPropertyInt(CFPropDefs.KW_GCGRACESECONDS, CFMetaData.DEFAULT_GC_GRACE_SECONDS))
               .defaultValidator(cfProps.getValidator())
               .minCompactionThreshold(minCompactionThreshold)
               .maxCompactionThreshold(maxCompactionThreshold)
               .keyValidator(TypeParser.parse(CFPropDefs.comparators.get(getKeyType())))
               .compactionStrategyClass(cfProps.compactionStrategyClass)
               .compactionStrategyOptions(cfProps.compactionStrategyOptions)
               .compressionParameters(CompressionParameters.create(cfProps.compressionParameters))
               .caching(CachingOptions.fromString(getPropertyString(CFPropDefs.KW_CACHING, CFMetaData.DEFAULT_CACHING_STRATEGY.toString())))
               .speculativeRetry(CFMetaData.SpeculativeRetry.fromString(getPropertyString(CFPropDefs.KW_SPECULATIVE_RETRY, CFMetaData.DEFAULT_SPECULATIVE_RETRY.toString())))
               .bloomFilterFpChance(getPropertyDouble(CFPropDefs.KW_BF_FP_CHANCE, null))
               .memtableFlushPeriod(getPropertyInt(CFPropDefs.KW_MEMTABLE_FLUSH_PERIOD, 0))
               .defaultTimeToLive(getPropertyInt(CFPropDefs.KW_DEFAULT_TIME_TO_LIVE, CFMetaData.DEFAULT_DEFAULT_TIME_TO_LIVE));

        // CQL2 can have null keyAliases
        if (keyAlias != null)
            newCFMD.addColumnDefinition(ColumnDefinition.partitionKeyDef(newCFMD, keyAlias, newCFMD.getKeyValidator(), null));

        return newCFMD.rebuild();
    }
    catch (ConfigurationException | SyntaxException e)
    {
        throw new InvalidRequestException(e.toString());
    }
}
 
Example #6
Source File: CountTombstones.java    From cassandra-opstools with Apache License 2.0 4 votes vote down vote up
private static void run(Descriptor desc, CommandLine cmd, PrintStream out) throws IOException {
  // Since we don't have a schema, make one up!
  CFMetaData cfm = new CFMetaData(desc.ksname, desc.cfname, ColumnFamilyType.Standard,
                                  UTF8Type.instance, UTF8Type.instance);

  SSTableReader reader = SSTableReader.open(desc, cfm);
  SSTableScanner scanner = reader.getScanner();

  long totalTombstones = 0, totalColumns = 0;
  if (cmd.hasOption("l")) {
    out.printf(desc.baseFilename() + "\n");
    out.printf("rowkey #tombstones (#columns)\n");
  }
  while (scanner.hasNext()) {
    SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();

    int tombstonesCount = 0, columnsCount = 0;
    while (row.hasNext())
    {
      OnDiskAtom column = row.next();
      long now = System.currentTimeMillis();
      if (column instanceof Column && ((Column) column).isMarkedForDelete(now)) {
        tombstonesCount++;
      }
      columnsCount++;
    }
    totalTombstones += tombstonesCount;
    totalColumns += columnsCount;

    if (tombstonesCount > 0) {
      String key;
      try {
        key = UTF8Type.instance.getString(row.getKey().key);
      } catch (RuntimeException e) {
        key = BytesType.instance.getString(row.getKey().key);
      }
      out.printf("%s %d (%d)%n", key, tombstonesCount, columnsCount);
    }

  }

  if (cmd.hasOption("l")) {
    out.printf("#total_tombstones (#total_columns)\n");
  }
  out.printf("%d (%d)%n", totalTombstones, totalColumns);

  scanner.close();
}