use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class OperationTest method testSatisfiedByWithClustering.
@Test
public void testSatisfiedByWithClustering() {
ColumnMetadata location = getColumn(CLUSTERING_BACKEND, UTF8Type.instance.decompose("location"));
ColumnMetadata age = getColumn(CLUSTERING_BACKEND, UTF8Type.instance.decompose("age"));
ColumnMetadata height = getColumn(CLUSTERING_BACKEND, UTF8Type.instance.decompose("height"));
ColumnMetadata score = getColumn(CLUSTERING_BACKEND, UTF8Type.instance.decompose("score"));
Unfiltered row = buildRow(Clustering.make(UTF8Type.instance.fromString("US"), Int32Type.instance.decompose(27)), buildCell(height, Int32Type.instance.decompose(182), System.currentTimeMillis()), buildCell(score, DoubleType.instance.decompose(1.0d), System.currentTimeMillis()));
Row staticRow = buildRow(Clustering.STATIC_CLUSTERING);
Operation.Builder builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(age, Operator.EQ, Int32Type.instance.decompose(27)));
builder.add(new SimpleExpression(height, Operator.EQ, Int32Type.instance.decompose(182)));
Assert.assertTrue(builder.complete().satisfiedBy(row, staticRow, false));
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(age, Operator.EQ, Int32Type.instance.decompose(28)));
builder.add(new SimpleExpression(height, Operator.EQ, Int32Type.instance.decompose(182)));
Assert.assertFalse(builder.complete().satisfiedBy(row, staticRow, false));
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(location, Operator.EQ, UTF8Type.instance.decompose("US")));
builder.add(new SimpleExpression(age, Operator.GTE, Int32Type.instance.decompose(27)));
Assert.assertTrue(builder.complete().satisfiedBy(row, staticRow, false));
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(location, Operator.EQ, UTF8Type.instance.decompose("BY")));
builder.add(new SimpleExpression(age, Operator.GTE, Int32Type.instance.decompose(28)));
Assert.assertFalse(builder.complete().satisfiedBy(row, staticRow, false));
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(location, Operator.EQ, UTF8Type.instance.decompose("US")));
builder.add(new SimpleExpression(age, Operator.LTE, Int32Type.instance.decompose(27)));
builder.add(new SimpleExpression(height, Operator.GTE, Int32Type.instance.decompose(182)));
Assert.assertTrue(builder.complete().satisfiedBy(row, staticRow, false));
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(location, Operator.EQ, UTF8Type.instance.decompose("US")));
builder.add(new SimpleExpression(height, Operator.GTE, Int32Type.instance.decompose(182)));
builder.add(new SimpleExpression(score, Operator.EQ, DoubleType.instance.decompose(1.0d)));
Assert.assertTrue(builder.complete().satisfiedBy(row, staticRow, false));
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(height, Operator.GTE, Int32Type.instance.decompose(182)));
builder.add(new SimpleExpression(score, Operator.EQ, DoubleType.instance.decompose(1.0d)));
Assert.assertTrue(builder.complete().satisfiedBy(row, staticRow, false));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class OperationTest method testSatisfiedByWithMultipleTerms.
@Test
public void testSatisfiedByWithMultipleTerms() {
final ColumnMetadata comment = getColumn(UTF8Type.instance.decompose("comment"));
Unfiltered row = buildRow(buildCell(comment, UTF8Type.instance.decompose("software engineer is working on a project"), System.currentTimeMillis()));
Row staticRow = buildRow(Clustering.STATIC_CLUSTERING);
Operation.Builder builder = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(comment, Operator.LIKE_CONTAINS, UTF8Type.instance.decompose("eng is a work")));
Operation op = builder.complete();
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
builder = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(comment, Operator.LIKE_CONTAINS, UTF8Type.instance.decompose("soft works fine")));
op = builder.complete();
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class OperationTest method testSatisfiedBy.
@Test
public void testSatisfiedBy() throws Exception {
final ColumnMetadata timestamp = getColumn(UTF8Type.instance.decompose("timestamp"));
final ColumnMetadata age = getColumn(UTF8Type.instance.decompose("age"));
Operation.Builder builder = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(age, Operator.NEQ, Int32Type.instance.decompose(5)));
Operation op = builder.complete();
Unfiltered row = buildRow(buildCell(age, Int32Type.instance.decompose(6), System.currentTimeMillis()));
Row staticRow = buildRow(Clustering.STATIC_CLUSTERING);
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
row = buildRow(buildCell(age, Int32Type.instance.decompose(5), System.currentTimeMillis()));
// and reject incorrect value
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
row = buildRow(buildCell(age, Int32Type.instance.decompose(6), System.currentTimeMillis()));
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
// range with exclusions - age != 5 AND age > 1 AND age != 6 AND age <= 10
builder = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(age, Operator.NEQ, Int32Type.instance.decompose(5)), new SimpleExpression(age, Operator.GT, Int32Type.instance.decompose(1)), new SimpleExpression(age, Operator.NEQ, Int32Type.instance.decompose(6)), new SimpleExpression(age, Operator.LTE, Int32Type.instance.decompose(10)));
op = builder.complete();
Set<Integer> exclusions = Sets.newHashSet(0, 1, 5, 6, 11);
for (int i = 0; i <= 11; i++) {
row = buildRow(buildCell(age, Int32Type.instance.decompose(i), System.currentTimeMillis()));
boolean result = op.satisfiedBy(row, staticRow, false);
Assert.assertTrue(exclusions.contains(i) != result);
}
// now let's do something more complex - age = 5 OR age = 6
builder = new Operation.Builder(OperationType.OR, controller, new SimpleExpression(age, Operator.EQ, Int32Type.instance.decompose(5)), new SimpleExpression(age, Operator.EQ, Int32Type.instance.decompose(6)));
op = builder.complete();
exclusions = Sets.newHashSet(0, 1, 2, 3, 4, 7, 8, 9, 10);
for (int i = 0; i <= 10; i++) {
row = buildRow(buildCell(age, Int32Type.instance.decompose(i), System.currentTimeMillis()));
boolean result = op.satisfiedBy(row, staticRow, false);
Assert.assertTrue(exclusions.contains(i) != result);
}
// now let's test aggregated AND commands
builder = new Operation.Builder(OperationType.AND, controller);
// logical should be ignored by analyzer, but we still what to make sure that it is
//IndexExpression logical = new IndexExpression(ByteBufferUtil.EMPTY_BYTE_BUFFER, IndexOperator.EQ, ByteBufferUtil.EMPTY_BYTE_BUFFER);
//logical.setLogicalOp(LogicalIndexOperator.AND);
//builder.add(logical);
builder.add(new SimpleExpression(age, Operator.GTE, Int32Type.instance.decompose(0)));
builder.add(new SimpleExpression(age, Operator.LT, Int32Type.instance.decompose(10)));
builder.add(new SimpleExpression(age, Operator.NEQ, Int32Type.instance.decompose(7)));
op = builder.complete();
exclusions = Sets.newHashSet(7);
for (int i = 0; i < 10; i++) {
row = buildRow(buildCell(age, Int32Type.instance.decompose(i), System.currentTimeMillis()));
boolean result = op.satisfiedBy(row, staticRow, false);
Assert.assertTrue(exclusions.contains(i) != result);
}
// multiple analyzed expressions in the Operation timestamp >= 10 AND age = 5
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(timestamp, Operator.GTE, LongType.instance.decompose(10L)));
builder.add(new SimpleExpression(age, Operator.EQ, Int32Type.instance.decompose(5)));
op = builder.complete();
row = buildRow(buildCell(age, Int32Type.instance.decompose(6), System.currentTimeMillis()), buildCell(timestamp, LongType.instance.decompose(11L), System.currentTimeMillis()));
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
row = buildRow(buildCell(age, Int32Type.instance.decompose(5), System.currentTimeMillis()), buildCell(timestamp, LongType.instance.decompose(22L), System.currentTimeMillis()));
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
row = buildRow(buildCell(age, Int32Type.instance.decompose(5), System.currentTimeMillis()), buildCell(timestamp, LongType.instance.decompose(9L), System.currentTimeMillis()));
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
// operation with internal expressions and right child
builder = new Operation.Builder(OperationType.OR, controller, new SimpleExpression(timestamp, Operator.GT, LongType.instance.decompose(10L)));
builder.setRight(new Operation.Builder(OperationType.AND, controller, new SimpleExpression(age, Operator.GT, Int32Type.instance.decompose(0)), new SimpleExpression(age, Operator.LT, Int32Type.instance.decompose(10))));
op = builder.complete();
row = buildRow(buildCell(age, Int32Type.instance.decompose(5), System.currentTimeMillis()), buildCell(timestamp, LongType.instance.decompose(9L), System.currentTimeMillis()));
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
row = buildRow(buildCell(age, Int32Type.instance.decompose(20), System.currentTimeMillis()), buildCell(timestamp, LongType.instance.decompose(11L), System.currentTimeMillis()));
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
row = buildRow(buildCell(age, Int32Type.instance.decompose(0), System.currentTimeMillis()), buildCell(timestamp, LongType.instance.decompose(9L), System.currentTimeMillis()));
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
// and for desert let's try out null and deleted rows etc.
builder = new Operation.Builder(OperationType.AND, controller);
builder.add(new SimpleExpression(age, Operator.EQ, Int32Type.instance.decompose(30)));
op = builder.complete();
Assert.assertFalse(op.satisfiedBy(null, staticRow, false));
Assert.assertFalse(op.satisfiedBy(row, null, false));
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
long now = System.currentTimeMillis();
row = OperationTest.buildRow(Row.Deletion.regular(new DeletionTime(now - 10, (int) (now / 1000))), buildCell(age, Int32Type.instance.decompose(6), System.currentTimeMillis()));
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
row = buildRow(deletedCell(age, System.currentTimeMillis(), FBUtilities.nowInSeconds()));
Assert.assertFalse(op.satisfiedBy(row, staticRow, true));
try {
Assert.assertFalse(op.satisfiedBy(buildRow(), staticRow, false));
} catch (IllegalStateException e) {
// expected
}
try {
Assert.assertFalse(op.satisfiedBy(buildRow(), staticRow, true));
} catch (IllegalStateException e) {
Assert.fail("IllegalStateException should not be thrown when missing column and allowMissingColumns=true");
}
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class OperationTest method testSatisfiedByWithStatic.
@Test
public void testSatisfiedByWithStatic() {
final ColumnMetadata sensorType = getColumn(STATIC_BACKEND, UTF8Type.instance.decompose("sensor_type"));
final ColumnMetadata value = getColumn(STATIC_BACKEND, UTF8Type.instance.decompose("value"));
Unfiltered row = buildRow(Clustering.make(UTF8Type.instance.fromString("date"), LongType.instance.decompose(20160401L)), buildCell(value, DoubleType.instance.decompose(24.56), System.currentTimeMillis()));
Row staticRow = buildRow(Clustering.STATIC_CLUSTERING, buildCell(sensorType, UTF8Type.instance.decompose("TEMPERATURE"), System.currentTimeMillis()));
// sensor_type ='TEMPERATURE' AND value = 24.56
Operation op = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(sensorType, Operator.EQ, UTF8Type.instance.decompose("TEMPERATURE")), new SimpleExpression(value, Operator.EQ, DoubleType.instance.decompose(24.56))).complete();
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
// sensor_type ='TEMPERATURE' AND value = 30
op = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(sensorType, Operator.EQ, UTF8Type.instance.decompose("TEMPERATURE")), new SimpleExpression(value, Operator.EQ, DoubleType.instance.decompose(30.00))).complete();
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
// sensor_type ='PRESSURE' OR value = 24.56
op = new Operation.Builder(OperationType.OR, controller, new SimpleExpression(sensorType, Operator.EQ, UTF8Type.instance.decompose("TEMPERATURE")), new SimpleExpression(value, Operator.EQ, DoubleType.instance.decompose(24.56))).complete();
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
// sensor_type ='PRESSURE' OR value = 30
op = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(sensorType, Operator.EQ, UTF8Type.instance.decompose("PRESSURE")), new SimpleExpression(value, Operator.EQ, DoubleType.instance.decompose(30.00))).complete();
Assert.assertFalse(op.satisfiedBy(row, staticRow, false));
// (sensor_type = 'TEMPERATURE' OR sensor_type = 'PRESSURE') AND value = 24.56
op = new Operation.Builder(OperationType.OR, controller, new SimpleExpression(sensorType, Operator.EQ, UTF8Type.instance.decompose("TEMPERATURE")), new SimpleExpression(sensorType, Operator.EQ, UTF8Type.instance.decompose("PRESSURE"))).setRight(new Operation.Builder(OperationType.AND, controller, new SimpleExpression(value, Operator.EQ, DoubleType.instance.decompose(24.56)))).complete();
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
// sensor_type = LIKE 'TEMP%' AND value = 24.56
op = new Operation.Builder(OperationType.AND, controller, new SimpleExpression(sensorType, Operator.LIKE_PREFIX, UTF8Type.instance.decompose("TEMP")), new SimpleExpression(value, Operator.EQ, DoubleType.instance.decompose(24.56))).complete();
Assert.assertTrue(op.satisfiedBy(row, staticRow, false));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class StressProfile method getOfflineGenerator.
public PartitionGenerator getOfflineGenerator() {
org.apache.cassandra.schema.TableMetadata metadata = CreateTableStatement.parse(tableCql, keyspaceName).build();
//Add missing column configs
Iterator<ColumnMetadata> it = metadata.allColumnsInSelectOrder();
while (it.hasNext()) {
ColumnMetadata c = it.next();
if (!columnConfigs.containsKey(c.name.toString()))
columnConfigs.put(c.name.toString(), new GeneratorConfig(seedStr + c.name.toString(), null, null, null));
}
List<Generator> partitionColumns = metadata.partitionKeyColumns().stream().map(c -> new ColumnInfo(c.name.toString(), c.type.asCQL3Type().toString(), "", columnConfigs.get(c.name.toString()))).map(c -> c.getGenerator()).collect(Collectors.toList());
List<Generator> clusteringColumns = metadata.clusteringColumns().stream().map(c -> new ColumnInfo(c.name.toString(), c.type.asCQL3Type().toString(), "", columnConfigs.get(c.name.toString()))).map(c -> c.getGenerator()).collect(Collectors.toList());
List<Generator> regularColumns = com.google.common.collect.Lists.newArrayList(metadata.regularAndStaticColumns().selectOrderIterator()).stream().map(c -> new ColumnInfo(c.name.toString(), c.type.asCQL3Type().toString(), "", columnConfigs.get(c.name.toString()))).map(c -> c.getGenerator()).collect(Collectors.toList());
return new PartitionGenerator(partitionColumns, clusteringColumns, regularColumns, PartitionGenerator.Order.ARBITRARY);
}
Aggregations