Search in sources :

Example 26 with TableInfo

use of io.crate.metadata.table.TableInfo in project crate by crate.

the class CopyAnalyzerTest method testCopyToFileWithPartitionedTable.

@Test
public void testCopyToFileWithPartitionedTable() throws Exception {
    CopyToAnalyzedStatement analysis = e.analyze("copy parted to directory '/blah'");
    TableInfo tableInfo = analysis.subQueryRelation().tableRelation().tableInfo();
    assertThat(tableInfo.ident(), is(TEST_PARTITIONED_TABLE_IDENT));
    assertThat(analysis.overwrites().size(), is(1));
}
Also used : TableInfo(io.crate.metadata.table.TableInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 27 with TableInfo

use of io.crate.metadata.table.TableInfo in project crate by crate.

the class CopyAnalyzerTest method testCopyToFileWithCompressionParams.

@Test
public void testCopyToFileWithCompressionParams() throws Exception {
    CopyToAnalyzedStatement analysis = e.analyze("copy users to directory '/blah' with (compression='gzip')");
    TableInfo tableInfo = analysis.subQueryRelation().tableRelation().tableInfo();
    assertThat(tableInfo.ident(), is(USER_TABLE_IDENT));
    assertThat(analysis.uri(), isLiteral("/blah"));
    assertThat(analysis.compressionType(), is(WriterProjection.CompressionType.GZIP));
}
Also used : TableInfo(io.crate.metadata.table.TableInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 28 with TableInfo

use of io.crate.metadata.table.TableInfo 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)

Example 29 with TableInfo

use of io.crate.metadata.table.TableInfo in project crate by crate.

the class HandlerSideLevelCollectTest method testClusterLevel.

@Test
public void testClusterLevel() throws Exception {
    Schemas schemas = internalCluster().getInstance(Schemas.class);
    TableInfo tableInfo = schemas.getTableInfo(new TableIdent("sys", "cluster"));
    Routing routing = tableInfo.getRouting(WhereClause.MATCH_ALL, null);
    Reference clusterNameRef = new Reference(new ReferenceIdent(SysClusterTableInfo.IDENT, new ColumnIdent(ClusterNameExpression.NAME)), RowGranularity.CLUSTER, DataTypes.STRING);
    RoutedCollectPhase collectNode = collectNode(routing, Arrays.<Symbol>asList(clusterNameRef), RowGranularity.CLUSTER);
    Bucket result = collect(collectNode);
    assertThat(result.size(), is(1));
    assertThat(((BytesRef) result.iterator().next().get(0)).utf8ToString(), Matchers.startsWith("SUITE-"));
}
Also used : Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 30 with TableInfo

use of io.crate.metadata.table.TableInfo in project crate by crate.

the class HandlerSideLevelCollectTest method testInformationSchemaTables.

@Test
public void testInformationSchemaTables() throws Exception {
    InformationSchemaInfo schemaInfo = internalCluster().getInstance(InformationSchemaInfo.class);
    TableInfo tablesTableInfo = schemaInfo.getTableInfo("tables");
    Routing routing = tablesTableInfo.getRouting(WhereClause.MATCH_ALL, null);
    List<Symbol> toCollect = new ArrayList<>();
    for (Reference reference : tablesTableInfo.columns()) {
        toCollect.add(reference);
    }
    Symbol tableNameRef = toCollect.get(8);
    FunctionImplementation eqImpl = functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.of(DataTypes.STRING, DataTypes.STRING)));
    Function whereClause = new Function(eqImpl.info(), Arrays.asList(tableNameRef, Literal.of("shards")));
    RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC, new WhereClause(whereClause));
    Bucket result = collect(collectNode);
    assertThat(TestingHelpers.printedTable(result), is("NULL| NULL| strict| 0| 1| NULL| NULL| NULL| shards| sys| NULL\n"));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) ArrayList(java.util.ArrayList) WhereClause(io.crate.analyze.WhereClause) Function(io.crate.analyze.symbol.Function) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Aggregations

TableInfo (io.crate.metadata.table.TableInfo)30 Test (org.junit.Test)16 DocTableInfo (io.crate.metadata.doc.DocTableInfo)15 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)7 Symbol (io.crate.analyze.symbol.Symbol)6 WhereClause (io.crate.analyze.WhereClause)5 Function (io.crate.analyze.symbol.Function)5 SysClusterTableInfo (io.crate.metadata.sys.SysClusterTableInfo)5 InformationSchemaInfo (io.crate.metadata.information.InformationSchemaInfo)4 SchemaInfo (io.crate.metadata.table.SchemaInfo)4 ArrayList (java.util.ArrayList)4 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)3 Bucket (io.crate.data.Bucket)3 CollectionBucket (io.crate.data.CollectionBucket)3 Table (io.crate.sql.tree.Table)3 SessionContext (io.crate.action.sql.SessionContext)2 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)2 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)2 DocTableRelation (io.crate.analyze.relations.DocTableRelation)2