Java Code Examples for org.apache.cassandra.config.CFMetaData#compile()

The following examples show how to use org.apache.cassandra.config.CFMetaData#compile() . 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: ColumnConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static boolean listAppliesTo(ColumnCondition.CollectionBound bound, List<ByteBuffer> conditionValues, List<ByteBuffer> columnValues)
{
    CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY KEY, b int, c list<int>)", "ks");
    Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
    typeMap.put(ByteBufferUtil.bytes("c"), ListType.getInstance(Int32Type.instance, true));
    CompoundSparseCellNameType.WithCollection nameType = new CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, ColumnToCollectionType.getInstance(typeMap));
    ColumnDefinition definition = new ColumnDefinition(cfm, ByteBufferUtil.bytes("c"), ListType.getInstance(Int32Type.instance, true), 0, ColumnDefinition.Kind.REGULAR);

    List<Cell> cells = new ArrayList<>(columnValues.size());
    if (columnValues != null)
    {
        for (int i = 0; i < columnValues.size(); i++)
        {
            ByteBuffer key = Int32Serializer.instance.serialize(i);
            ByteBuffer value = columnValues.get(i);
            cells.add(new BufferCell(nameType.create(Composites.EMPTY, definition, key), value));
        };
    }

    return bound.listAppliesTo(ListType.getInstance(Int32Type.instance, true), cells == null ? null : cells.iterator(), conditionValues, bound.operator);
}
 
Example 2
Source File: ColumnConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static boolean setAppliesTo(ColumnCondition.CollectionBound bound, Set<ByteBuffer> conditionValues, List<ByteBuffer> columnValues)
{
    CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY KEY, b int, c set<int>)", "ks");
    Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
    typeMap.put(ByteBufferUtil.bytes("c"), SetType.getInstance(Int32Type.instance, true));
    CompoundSparseCellNameType.WithCollection nameType = new CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, ColumnToCollectionType.getInstance(typeMap));
    ColumnDefinition definition = new ColumnDefinition(cfm, ByteBufferUtil.bytes("c"), SetType.getInstance(Int32Type.instance, true), 0, ColumnDefinition.Kind.REGULAR);

    List<Cell> cells = new ArrayList<>(columnValues.size());
    if (columnValues != null)
    {
        for (int i = 0; i < columnValues.size(); i++)
        {
            ByteBuffer key = columnValues.get(i);
            cells.add(new BufferCell(nameType.create(Composites.EMPTY, definition, key), ByteBufferUtil.EMPTY_BYTE_BUFFER));
        };
    }

    return bound.setAppliesTo(SetType.getInstance(Int32Type.instance, true), cells == null ? null : cells.iterator(), conditionValues, bound.operator);
}
 
Example 3
Source File: ColumnConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static boolean mapAppliesTo(ColumnCondition.CollectionBound bound, Map<ByteBuffer, ByteBuffer> conditionValues, Map<ByteBuffer, ByteBuffer> columnValues)
{
    CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY KEY, b map<int, int>)", "ks");
    Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
    typeMap.put(ByteBufferUtil.bytes("b"), MapType.getInstance(Int32Type.instance, Int32Type.instance, true));
    CompoundSparseCellNameType.WithCollection nameType = new CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, ColumnToCollectionType.getInstance(typeMap));
    ColumnDefinition definition = new ColumnDefinition(cfm, ByteBufferUtil.bytes("b"), MapType.getInstance(Int32Type.instance, Int32Type.instance, true), 0, ColumnDefinition.Kind.REGULAR);

    List<Cell> cells = new ArrayList<>(columnValues.size());
    if (columnValues != null)
    {
        for (Map.Entry<ByteBuffer, ByteBuffer> entry : columnValues.entrySet())
            cells.add(new BufferCell(nameType.create(Composites.EMPTY, definition, entry.getKey()), entry.getValue()));
    }

    return bound.mapAppliesTo(MapType.getInstance(Int32Type.instance, Int32Type.instance, true), cells.iterator(), conditionValues, bound.operator);
}
 
Example 4
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void newKsContainsCfWithTrigger() throws Exception
{
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    cfm1.addTriggerDefinition(td);
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.singletonList(cfm1));
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName);
    assertFalse(cfm2.getTriggers().isEmpty());
    assertEquals(1, cfm2.getTriggers().size());
    assertEquals(td, cfm2.getTriggers().get(triggerName));
}
 
Example 5
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void addNewCfWithTriggerToKs() throws Exception
{
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.EMPTY_LIST);
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    cfm1.addTriggerDefinition(td);

    MigrationManager.announceNewColumnFamily(cfm1);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName);
    assertFalse(cfm2.getTriggers().isEmpty());
    assertEquals(1, cfm2.getTriggers().size());
    assertEquals(td, cfm2.getTriggers().get(triggerName));
}
 
Example 6
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void addTriggerToCf() throws Exception
{
    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.singletonList(cfm1));
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName).copy();
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    cfm2.addTriggerDefinition(td);
    MigrationManager.announceColumnFamilyUpdate(cfm2, false);

    CFMetaData cfm3 = Schema.instance.getCFMetaData(ksName, cfName);
    assertFalse(cfm3.getTriggers().isEmpty());
    assertEquals(1, cfm3.getTriggers().size());
    assertEquals(td, cfm3.getTriggers().get(triggerName));
}
 
Example 7
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void removeTriggerFromCf() throws Exception
{
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    cfm1.addTriggerDefinition(td);
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.singletonList(cfm1));
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName).copy();
    cfm2.removeTrigger(triggerName);
    MigrationManager.announceColumnFamilyUpdate(cfm2, false);

    CFMetaData cfm3 = Schema.instance.getCFMetaData(ksName, cfName).copy();
    assertTrue(cfm3.getTriggers().isEmpty());
}
 
Example 8
Source File: CqlBulkRecordWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void addKnownCfs(String keyspace, String cql)
{
    Map<String, CFMetaData> cfs = knownCqlCfs.get(keyspace);
    
    if (cfs == null)
    {
        cfs = new HashMap<>();
        knownCqlCfs.put(keyspace, cfs);
    }
    
    CFMetaData metadata = CFMetaData.compile(cql, keyspace);
    cfs.put(metadata.cfName, metadata);
}
 
Example 9
Source File: CrunchExternalClient.java    From hdfs2cass with Apache License 2.0 5 votes vote down vote up
public void addKnownCfs(String keyspace, String cql) {
  Map<String, CFMetaData> cfs = knownCqlCfs.get(keyspace);

  if (cfs == null) {
    cfs = new HashMap<>();
    knownCqlCfs.put(keyspace, cfs);
  }
  CFMetaData metadata = CFMetaData.compile(cql, keyspace);
  cfs.put(metadata.cfName, metadata);
}