Search in sources :

Example 6 with TableMetadata

use of com.datastax.driver.core.TableMetadata in project cassandra-driver-mapping by valchkou.

the class SchemaSyncTest method testDoNotAddColumn.

@Test
public void testDoNotAddColumn() {
    SyncOptions opt = SyncOptions.withOptions().add(SyncOptionTypes.DoNotAddColumns);
    SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexesV2.class, opt);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    // column counter2 should not be added
    ColumnMetadata columnMetadata = tableMetadata.getColumn("counter2");
    assertNull(columnMetadata);
    // column counter should have been dropped
    columnMetadata = tableMetadata.getColumn("counter");
    assertNull(columnMetadata);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 7 with TableMetadata

use of com.datastax.driver.core.TableMetadata in project cassandra-driver-mapping by valchkou.

the class SchemaSyncTest method testDrop.

@Test
public void testDrop() {
    SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
    SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    assertNull(tableMetadata);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 8 with TableMetadata

use of com.datastax.driver.core.TableMetadata in project cassandra-driver-mapping by valchkou.

the class SchemaSyncTest method testDoNotDropColumn.

@Test
public void testDoNotDropColumn() {
    SyncOptions opt = SyncOptions.withOptions().add(SyncOptionTypes.DoNotDropColumns);
    SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexesV2.class, opt);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    // column counter2 should not be added
    ColumnMetadata columnMetadata = tableMetadata.getColumn("counter2");
    assertNull(columnMetadata);
    // column counter should have been dropped
    columnMetadata = tableMetadata.getColumn("counter");
    assertNotNull(columnMetadata);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 9 with TableMetadata

use of com.datastax.driver.core.TableMetadata in project cassandra by apache.

the class StressProfile method maybeLoadSchemaInfo.

private void maybeLoadSchemaInfo(StressSettings settings) {
    if (tableMetaData == null) {
        JavaDriverClient client = settings.getJavaDriverClient();
        synchronized (client) {
            if (tableMetaData != null)
                return;
            TableMetadata metadata = client.getCluster().getMetadata().getKeyspace(keyspaceName).getTable(quoteIdentifier(tableName));
            if (metadata == null)
                throw new RuntimeException("Unable to find table " + keyspaceName + "." + tableName);
            //Fill in missing column configs
            for (com.datastax.driver.core.ColumnMetadata col : metadata.getColumns()) {
                if (columnConfigs.containsKey(col.getName()))
                    continue;
                columnConfigs.put(col.getName(), new GeneratorConfig(seedStr + col.getName(), null, null, null));
            }
            tableMetaData = metadata;
        }
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) JavaDriverClient(org.apache.cassandra.stress.util.JavaDriverClient) com.datastax.driver.core(com.datastax.driver.core)

Example 10 with TableMetadata

use of com.datastax.driver.core.TableMetadata in project presto by prestodb.

the class NativeCassandraSession method getAllTables.

@Override
public List<String> getAllTables(String schema) throws SchemaNotFoundException {
    KeyspaceMetadata meta = getCheckedKeyspaceMetadata(schema);
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (TableMetadata tableMeta : meta.getTables()) {
        builder.add(tableMeta.getName());
    }
    return builder.build();
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ImmutableList(com.google.common.collect.ImmutableList) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Aggregations

TableMetadata (com.datastax.driver.core.TableMetadata)18 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)9 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)8 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)8 Test (org.junit.Test)7 Cluster (com.datastax.driver.core.Cluster)3 DriverException (com.datastax.driver.core.exceptions.DriverException)3 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)3 ArrayList (java.util.ArrayList)3 RegularStatement (com.datastax.driver.core.RegularStatement)2 ImmutableList (com.google.common.collect.ImmutableList)2 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)2 com.datastax.driver.core (com.datastax.driver.core)1 EntityWithCompositeKey (com.datastax.driver.mapping.entity.EntityWithCompositeKey)1 EntityWithIndexes (com.datastax.driver.mapping.entity.EntityWithIndexes)1 EntityWithTimeUUID (com.datastax.driver.mapping.entity.EntityWithTimeUUID)1 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)1 PrestoException (com.facebook.presto.spi.PrestoException)1 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)1 QualifiedName (com.netflix.metacat.common.QualifiedName)1