Search in sources :

Example 1 with TableInfo

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

the class SchemasITest method testClusterTable.

@Test
public void testClusterTable() throws Exception {
    TableInfo ti = schemas.getTableInfo(new TableIdent("sys", "cluster"));
    assertThat(ti.getRouting(null, null).locations().size(), is(1));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 2 with TableInfo

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

the class CopyAnalyzerTest method testCopyToDirectory.

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

Example 3 with TableInfo

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

the class ExpressionAnalyzerTest method testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation.

@Test
public void testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation() throws Exception {
    TableInfo tableInfo = mock(TableInfo.class);
    when(tableInfo.getReference(new ColumnIdent("id"))).thenReturn(new Reference(new ReferenceIdent(new TableIdent("doc", "t"), "id"), RowGranularity.DOC, DataTypes.INTEGER));
    when(tableInfo.ident()).thenReturn(new TableIdent("doc", "t"));
    TableRelation tr1 = new TableRelation(tableInfo);
    TableRelation tr2 = new TableRelation(tableInfo);
    Map<QualifiedName, AnalyzedRelation> sources = ImmutableMap.of(new QualifiedName("t1"), tr1, new QualifiedName("t2"), tr2);
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, SessionContext.SYSTEM_SESSION, paramTypeHints, new FullQualifedNameFieldProvider(sources), null);
    Function andFunction = (Function) expressionAnalyzer.convert(SqlParser.createExpression("not t1.id = 1 and not t2.id = 1"), context);
    Field t1Id = ((Field) ((Function) ((Function) andFunction.arguments().get(0)).arguments().get(0)).arguments().get(0));
    Field t2Id = ((Field) ((Function) ((Function) andFunction.arguments().get(1)).arguments().get(0)).arguments().get(0));
    assertTrue(t1Id.relation() != t2Id.relation());
}
Also used : AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) TableRelation(io.crate.analyze.relations.TableRelation) Function(io.crate.analyze.symbol.Function) SymbolMatchers.isField(io.crate.testing.SymbolMatchers.isField) Field(io.crate.analyze.symbol.Field) TableInfo(io.crate.metadata.table.TableInfo) FullQualifedNameFieldProvider(io.crate.analyze.relations.FullQualifedNameFieldProvider) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with TableInfo

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

the class Schemas method getDroppableTable.

public DocTableInfo getDroppableTable(TableIdent tableIdent) {
    TableInfo tableInfo = getTableInfo(tableIdent);
    if (!(tableInfo instanceof DocTableInfo)) {
        throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "The table %s is not dropable.", tableInfo.ident()));
    }
    DocTableInfo docTableInfo = (DocTableInfo) tableInfo;
    if (docTableInfo.isAlias() && !docTableInfo.isPartitioned() && !isOrphanedAlias(docTableInfo)) {
        throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "%s is an alias and hence not dropable.", tableInfo.ident()));
    }
    return docTableInfo;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo)

Example 5 with TableInfo

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

the class TableFunctionCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase collectPhase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    TableFunctionCollectPhase phase = (TableFunctionCollectPhase) collectPhase;
    WhereClause whereClause = phase.whereClause();
    if (whereClause.noMatch()) {
        return RowsCollector.empty(consumer);
    }
    TableFunctionImplementation functionImplementation = phase.relation().functionImplementation();
    TableInfo tableInfo = functionImplementation.createTableInfo(clusterService);
    //noinspection unchecked  Only literals can be passed to table functions. Anything else is invalid SQL
    List<Input<?>> inputs = (List<Input<?>>) (List) phase.relation().function().arguments();
    List<Reference> columns = new ArrayList<>(tableInfo.columns());
    List<Input<?>> topLevelInputs = new ArrayList<>(phase.toCollect().size());
    InputFactory.Context<InputCollectExpression> ctx = inputFactory.ctxForRefs(i -> new InputCollectExpression(columns.indexOf(i)));
    for (Symbol symbol : phase.toCollect()) {
        topLevelInputs.add(ctx.add(symbol));
    }
    Iterable<Row> rows = Iterables.transform(functionImplementation.execute(inputs), new ValueAndInputRow<>(topLevelInputs, ctx.expressions()));
    if (whereClause.hasQuery()) {
        Input<Boolean> condition = (Input<Boolean>) ctx.add(whereClause.query());
        rows = Iterables.filter(rows, InputCondition.asPredicate(condition));
    }
    OrderBy orderBy = phase.orderBy();
    if (orderBy != null) {
        rows = RowsTransformer.sortRows(Iterables.transform(rows, Row::materialize), phase);
    }
    return RowsCollector.forRows(rows, phase.toCollect().size(), consumer);
}
Also used : OrderBy(io.crate.analyze.OrderBy) InputFactory(io.crate.operation.InputFactory) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) ArrayList(java.util.ArrayList) Input(io.crate.data.Input) TableInfo(io.crate.metadata.table.TableInfo) ArrayList(java.util.ArrayList) List(java.util.List) Row(io.crate.data.Row) TableFunctionCollectPhase(io.crate.planner.node.dql.TableFunctionCollectPhase)

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