Search in sources :

Example 36 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class SSTableLoaderTest method testLoadingSSTable.

@Test
public void testLoadingSSTable() throws Exception {
    File dataDir = new File(tmpdir.getAbsolutePath() + File.separator + KEYSPACE1 + File.separator + CF_STANDARD1);
    assert dataDir.mkdirs();
    TableMetadata metadata = Schema.instance.getTableMetadata(KEYSPACE1, CF_STANDARD1);
    String schema = "CREATE TABLE %s.%s (key ascii, name ascii, val ascii, val1 ascii, PRIMARY KEY (key, name))";
    String query = "INSERT INTO %s.%s (key, name, val) VALUES (?, ?, ?)";
    try (CQLSSTableWriter writer = CQLSSTableWriter.builder().inDirectory(dataDir).forTable(String.format(schema, KEYSPACE1, CF_STANDARD1)).using(String.format(query, KEYSPACE1, CF_STANDARD1)).build()) {
        writer.addRow("key1", "col1", "100");
    }
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1);
    // wait for sstables to be on disk else we won't be able to stream them
    cfs.forceBlockingFlush();
    final CountDownLatch latch = new CountDownLatch(1);
    SSTableLoader loader = new SSTableLoader(dataDir, new TestClient(), new OutputHandler.SystemOutput(false, false));
    loader.stream(Collections.emptySet(), completionStreamListener(latch)).get();
    List<FilteredPartition> partitions = Util.getAll(Util.cmd(cfs).build());
    assertEquals(1, partitions.size());
    assertEquals("key1", AsciiType.instance.getString(partitions.get(0).partitionKey().getKey()));
    assertEquals(ByteBufferUtil.bytes("100"), partitions.get(0).getRow(Clustering.make(ByteBufferUtil.bytes("col1"))).getCell(metadata.getColumn(ByteBufferUtil.bytes("val"))).value());
    // The stream future is signalled when the work is complete but before releasing references. Wait for release
    // before cleanup (CASSANDRA-10118).
    latch.await();
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) CountDownLatch(java.util.concurrent.CountDownLatch) OutputHandler(org.apache.cassandra.utils.OutputHandler) File(java.io.File) Test(org.junit.Test)

Example 37 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class MockSchema method newCFS.

public static ColumnFamilyStore newCFS(String ksname) {
    String cfname = "mockcf" + (id.incrementAndGet());
    TableMetadata metadata = newTableMetadata(ksname, cfname);
    return new ColumnFamilyStore(ks, cfname, 0, new TableMetadataRef(metadata), new Directories(metadata), false, false, false);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) TableMetadataRef(org.apache.cassandra.schema.TableMetadataRef)

Example 38 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class QueryPagerTest method sliceQuery.

private static SinglePartitionReadCommand sliceQuery(String key, String start, String end, boolean reversed, int count) {
    ClusteringComparator cmp = cfs().getComparator();
    TableMetadata metadata = cfs().metadata();
    Slice slice = Slice.make(cmp.make(start), cmp.make(end));
    ClusteringIndexSliceFilter filter = new ClusteringIndexSliceFilter(Slices.with(cmp, slice), reversed);
    return SinglePartitionReadCommand.create(metadata, nowInSec, ColumnFilter.all(metadata), RowFilter.NONE, DataLimits.NONE, Util.dk(key), filter);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata)

Example 39 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class TriggerExecutorTest method differentKeyColumnFamilies.

@Test(expected = InvalidRequestException.class)
public void differentKeyColumnFamilies() throws ConfigurationException, InvalidRequestException {
    TableMetadata metadata = makeTableMetadata("ks1", "cf1", TriggerMetadata.create("test", DifferentKeyTrigger.class.getName()));
    TriggerExecutor.instance.execute(makeCf(metadata, "k1", "v1", null));
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Test(org.junit.Test)

Example 40 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class TriggersSchemaTest method addNewCfWithTriggerToKs.

@Test
public void addNewCfWithTriggerToKs() throws Exception {
    KeyspaceMetadata ksm = KeyspaceMetadata.create(ksName, KeyspaceParams.simple(1));
    MigrationManager.announceNewKeyspace(ksm);
    TableMetadata metadata = CreateTableStatement.parse(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName).triggers(Triggers.of(TriggerMetadata.create(triggerName, triggerClass))).build();
    MigrationManager.announceNewTable(metadata);
    metadata = Schema.instance.getTableMetadata(ksName, cfName);
    assertFalse(metadata.triggers.isEmpty());
    assertEquals(1, metadata.triggers.size());
    assertEquals(TriggerMetadata.create(triggerName, triggerClass), metadata.triggers.get(triggerName).get());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) Test(org.junit.Test)

Aggregations

TableMetadata (org.apache.cassandra.schema.TableMetadata)129 Test (org.junit.Test)63 ByteBuffer (java.nio.ByteBuffer)29 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)17 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)13 File (java.io.File)10 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)10 Mutation (org.apache.cassandra.db.Mutation)8 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)8 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)8 Descriptor (org.apache.cassandra.io.sstable.Descriptor)7 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)6 IOException (java.io.IOException)5 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)5 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)5 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)5 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)4 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)4 AbstractType (org.apache.cassandra.db.marshal.AbstractType)4 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)4