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());
}
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();
}
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);
}
}
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();
}
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();
}
Aggregations