Search in sources :

Example 16 with ColumnMetadata

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

the class SchemaSyncTest method testCreateWithTimeUUID.

@Test
public void testCreateWithTimeUUID() {
    EntityTypeParser.remove(EntityWithTimeUUID.class);
    System.out.println(SchemaSync.getScript(keyspace, session, EntityWithTimeUUID.class));
    SchemaSync.sync(keyspace, session, EntityWithTimeUUID.class);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithTimeUUID.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    assertNotNull(tableMetadata);
    assertEquals("test_entity_timeuuid", tableMetadata.getName());
    assertEquals(3, tableMetadata.getColumns().size());
    ColumnMetadata columnMetadata = tableMetadata.getColumn("name");
    assertNotNull(columnMetadata);
    assertEquals(DataType.text(), columnMetadata.getType());
    columnMetadata = tableMetadata.getColumn("convId");
    assertNotNull(columnMetadata);
    assertEquals(DataType.timeuuid(), columnMetadata.getType());
    columnMetadata = tableMetadata.getColumn("msgId");
    assertNotNull(columnMetadata);
    assertEquals(DataType.timeuuid(), columnMetadata.getType());
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) EntityWithTimeUUID(com.datastax.driver.mapping.entity.EntityWithTimeUUID) Test(org.junit.Test)

Example 17 with ColumnMetadata

use of com.datastax.driver.core.ColumnMetadata in project DataX by alibaba.

the class CassandraReaderHelper method getQueryString.

public static String getQueryString(Configuration taskConfig, Cluster cluster) {
    List<String> columnMeta = taskConfig.getList(Key.COLUMN, String.class);
    String keyspace = taskConfig.getString(Key.KEYSPACE);
    String table = taskConfig.getString(Key.TABLE);
    StringBuilder columns = new StringBuilder();
    for (String column : columnMeta) {
        if (columns.length() > 0) {
            columns.append(",");
        }
        columns.append(column);
    }
    StringBuilder where = new StringBuilder();
    String whereString = taskConfig.getString(Key.WHERE);
    if (whereString != null && !whereString.isEmpty()) {
        where.append(whereString);
    }
    String minToken = taskConfig.getString(Key.MIN_TOKEN);
    String maxToken = taskConfig.getString(Key.MAX_TOKEN);
    if (minToken != null || maxToken != null) {
        LOG.info("range:" + minToken + "~" + maxToken);
        List<ColumnMetadata> pks = cluster.getMetadata().getKeyspace(keyspace).getTable(table).getPartitionKey();
        StringBuilder sb = new StringBuilder();
        for (ColumnMetadata pk : pks) {
            if (sb.length() > 0) {
                sb.append(",");
            }
            sb.append(pk.getName());
        }
        String s = sb.toString();
        if (minToken != null && !minToken.isEmpty()) {
            if (where.length() > 0) {
                where.append(" AND ");
            }
            where.append("token(").append(s).append(")").append(" > ").append(minToken);
        }
        if (maxToken != null && !maxToken.isEmpty()) {
            if (where.length() > 0) {
                where.append(" AND ");
            }
            where.append("token(").append(s).append(")").append(" <= ").append(maxToken);
        }
    }
    boolean allowFiltering = taskConfig.getBool(Key.ALLOW_FILTERING, false);
    StringBuilder select = new StringBuilder();
    select.append("SELECT ").append(columns.toString()).append(" FROM ").append(table);
    if (where.length() > 0) {
        select.append(" where ").append(where.toString());
    }
    if (allowFiltering) {
        select.append(" ALLOW FILTERING");
    }
    select.append(";");
    return select.toString();
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata)

Example 18 with ColumnMetadata

use of com.datastax.driver.core.ColumnMetadata in project apex-malhar by apache.

the class AbstractUpsertOutputOperator method registerNonPKColumnDefinitions.

private void registerNonPKColumnDefinitions(final TableMetadata tableMetadata) {
    List<ColumnMetadata> colInfoForTable = tableMetadata.getColumns();
    for (ColumnMetadata aColumnDefinition : colInfoForTable) {
        if (aColumnDefinition.getType().isCollection()) {
            collectionColumns.add(aColumnDefinition.getName());
        }
        if (!pkColumnNames.contains(aColumnDefinition.getName())) {
            columnDefinitions.put(aColumnDefinition.getName(), aColumnDefinition.getType());
            regularColumns.add(aColumnDefinition.getName());
        }
        parseForSpecialDataType(aColumnDefinition);
    }
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata)

Example 19 with ColumnMetadata

use of com.datastax.driver.core.ColumnMetadata in project SimpleFlatMapper by arnaudroger.

the class DatastaxCrudFactory method deleteQueryWithTimestamp.

private static String deleteQueryWithTimestamp(TableMetadata tableMetadata) {
    Delete delete = QueryBuilder.delete().from(tableMetadata);
    delete.using(QueryBuilder.timestamp(QueryBuilder.bindMarker()));
    Delete.Where where = delete.where();
    List<ColumnMetadata> columns = tableMetadata.getPrimaryKey();
    for (ColumnMetadata column : columns) {
        where.and(QueryBuilder.eq(column.getName(), QueryBuilder.bindMarker()));
    }
    return delete.toString();
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata)

Example 20 with ColumnMetadata

use of com.datastax.driver.core.ColumnMetadata in project SimpleFlatMapper by arnaudroger.

the class DatastaxCrudFactory method readQuery.

private static String readQuery(TableMetadata tableMetadata) {
    Select.Selection select = QueryBuilder.select();
    List<ColumnMetadata> columns = tableMetadata.getColumns();
    for (ColumnMetadata column : columns) {
        select.column(column.getName());
    }
    Select.Where where = select.from(tableMetadata).where();
    columns = tableMetadata.getPrimaryKey();
    for (ColumnMetadata column : columns) {
        where.and(QueryBuilder.eq(column.getName(), QueryBuilder.bindMarker()));
    }
    return where.toString();
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata)

Aggregations

ColumnMetadata (com.datastax.driver.core.ColumnMetadata)37 Test (org.testng.annotations.Test)11 TableMetadata (com.datastax.driver.core.TableMetadata)8 CassandraVersion (com.datastax.driver.core.utils.CassandraVersion)8 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 AbstractTableMetadata (com.datastax.driver.core.AbstractTableMetadata)2 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)2 ByteBuffer (java.nio.ByteBuffer)2 BoundStatementMapper (org.simpleflatmapper.datastax.BoundStatementMapper)2 Cluster (com.datastax.driver.core.Cluster)1 DataType (com.datastax.driver.core.DataType)1 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)1 RegularStatement (com.datastax.driver.core.RegularStatement)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