Search in sources :

Example 6 with TableRelation

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));
}
Also used : QualifiedName(io.crate.sql.tree.QualifiedName) WhereClause(io.crate.analyze.WhereClause) TableInfo(io.crate.metadata.table.TableInfo) TableIdent(io.crate.metadata.TableIdent) Schemas(io.crate.metadata.Schemas) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Aggregations

TableRelation (io.crate.analyze.relations.TableRelation)6 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)5 QualifiedName (io.crate.sql.tree.QualifiedName)5 SqlExpressions (io.crate.testing.SqlExpressions)5 WhereClause (io.crate.analyze.WhereClause)3 TableIdent (io.crate.metadata.TableIdent)3 DocTableInfo (io.crate.metadata.doc.DocTableInfo)3 Test (org.junit.Test)3 TableInfo (io.crate.metadata.table.TableInfo)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 ArrayType (io.crate.types.ArrayType)2 Before (org.junit.Before)2 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)1 FullQualifedNameFieldProvider (io.crate.analyze.relations.FullQualifedNameFieldProvider)1 Field (io.crate.analyze.symbol.Field)1 Function (io.crate.analyze.symbol.Function)1 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)1 CrateRegexQuery (io.crate.lucene.match.CrateRegexQuery)1 Schemas (io.crate.metadata.Schemas)1 SysNodesTableInfo (io.crate.metadata.sys.SysNodesTableInfo)1