use of io.crate.analyze.relations.TableRelation in project crate by crate.
the class InternalCountOperationTest method testCount.
@Test
public void testCount() throws Exception {
execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
ensureYellow();
execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
execute("refresh table t");
CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
assertThat(countOperation.count("t", 0, WhereClause.MATCH_ALL), is(3L));
Schemas schemas = internalCluster().getInstance(Schemas.class);
TableInfo tableInfo = schemas.getTableInfo(new TableIdent(null, "t"));
TableRelation tableRelation = new TableRelation(tableInfo);
Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(tableInfo.ident().name()), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'")));
assertThat(countOperation.count("t", 0, whereClause), is(1L));
}
Aggregations