Search in sources :

Example 21 with TableInfo

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

the class PlannerTest method testAllocateRouting.

@Test
public void testAllocateRouting() throws Exception {
    TableIdent custom = new TableIdent("custom", "t1");
    TableInfo tableInfo1 = TestingTableInfo.builder(custom, shardRouting("t1")).add("id", DataTypes.INTEGER, null).build();
    TableInfo tableInfo2 = TestingTableInfo.builder(custom, shardRoutingForReplicas("t1")).add("id", DataTypes.INTEGER, null).build();
    Planner.Context plannerContext = new Planner.Context(e.planner, clusterService, UUID.randomUUID(), null, normalizer, new TransactionContext(SessionContext.SYSTEM_SESSION), 0, 0);
    WhereClause whereClause = new WhereClause(new Function(new FunctionInfo(new FunctionIdent(EqOperator.NAME, Arrays.<DataType>asList(DataTypes.INTEGER, DataTypes.INTEGER)), DataTypes.BOOLEAN), Arrays.asList(tableInfo1.getReference(new ColumnIdent("id")), Literal.of(2))));
    plannerContext.allocateRouting(tableInfo1, WhereClause.MATCH_ALL, null);
    plannerContext.allocateRouting(tableInfo2, whereClause, null);
    // 2 routing allocations with different where clause must result in 2 allocated routings
    java.lang.reflect.Field tableRoutings = Planner.Context.class.getDeclaredField("tableRoutings");
    tableRoutings.setAccessible(true);
    Multimap<TableIdent, Planner.TableRouting> routing = (Multimap<TableIdent, Planner.TableRouting>) tableRoutings.get(plannerContext);
    assertThat(routing.size(), is(2));
    // The routings must be the same after merging the locations
    Iterator<Planner.TableRouting> iterator = routing.values().iterator();
    Routing routing1 = iterator.next().routing;
    Routing routing2 = iterator.next().routing;
    assertThat(routing1, is(routing2));
}
Also used : SessionContext(io.crate.action.sql.SessionContext) WhereClause(io.crate.analyze.WhereClause) TableDefinitions.shardRouting(io.crate.analyze.TableDefinitions.shardRouting) Function(io.crate.analyze.symbol.Function) Multimap(com.google.common.collect.Multimap) DataType(io.crate.types.DataType) TableInfo(io.crate.metadata.table.TableInfo) TestingTableInfo(io.crate.metadata.table.TestingTableInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 22 with TableInfo

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

the class RelationAnalyzer method visitTableFunction.

@Override
public AnalyzedRelation visitTableFunction(TableFunction node, StatementAnalysisContext statementContext) {
    RelationAnalysisContext context = statementContext.currentRelationContext();
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, statementContext.sessionContext(), statementContext.convertParamFunction(), new FieldProvider() {

        @Override
        public Symbol resolveField(QualifiedName qualifiedName, Operation operation) {
            throw new UnsupportedOperationException("Can only resolve literals");
        }

        @Override
        public Symbol resolveField(QualifiedName qualifiedName, @Nullable List path, Operation operation) {
            throw new UnsupportedOperationException("Can only resolve literals");
        }
    }, null);
    Function function = (Function) expressionAnalyzer.convert(node.functionCall(), context.expressionAnalysisContext());
    FunctionImplementation functionImplementation = functions.getSafe(function.info().ident());
    if (functionImplementation.info().type() != FunctionInfo.Type.TABLE) {
        throw new UnsupportedFeatureException("Non table function " + function.info().ident().name() + " is not supported in from clause");
    }
    TableFunctionImplementation tableFunction = (TableFunctionImplementation) functionImplementation;
    TableInfo tableInfo = tableFunction.createTableInfo(clusterService);
    Operation.blockedRaiseException(tableInfo, statementContext.currentOperation());
    TableRelation tableRelation = new TableFunctionRelation(tableInfo, tableFunction, function);
    context.addSourceRelation(node.name(), tableRelation);
    return tableRelation;
}
Also used : TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) Operation(io.crate.metadata.table.Operation) Function(io.crate.analyze.symbol.Function) ImmutableList(com.google.common.collect.ImmutableList) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo)

Example 23 with TableInfo

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

the class RefreshTableAnalyzer method getIndexNames.

private static Set<String> getIndexNames(List<Table> tables, Schemas schemas, ParameterContext parameterContext, @Nullable String defaultSchema) {
    Set<String> indexNames = new HashSet<>(tables.size());
    for (Table nodeTable : tables) {
        TableInfo tableInfo = schemas.getTableInfo(TableIdent.of(nodeTable, defaultSchema));
        Preconditions.checkArgument(tableInfo instanceof DocTableInfo, "operation cannot be performed on system and blob tables: table '%s'", tableInfo.ident().fqn());
        indexNames.addAll(TableAnalyzer.filteredIndices(parameterContext, nodeTable.partitionProperties(), (DocTableInfo) tableInfo));
    }
    return indexNames;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) Table(io.crate.sql.tree.Table) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) HashSet(java.util.HashSet)

Example 24 with TableInfo

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

the class DeleteAnalyzerTest method testDeleteWhere.

@Test
public void testDeleteWhere() throws Exception {
    DeleteAnalyzedStatement statement = e.analyze("delete from users where name='Trillian'");
    DocTableRelation tableRelation = statement.analyzedRelation;
    TableInfo tableInfo = tableRelation.tableInfo();
    assertThat(USER_TABLE_IDENT, equalTo(tableInfo.ident()));
    assertThat(tableInfo.rowGranularity(), is(RowGranularity.DOC));
    Function whereClause = (Function) statement.whereClauses.get(0).query();
    assertEquals(EqOperator.NAME, whereClause.info().ident().name());
    assertFalse(whereClause.info().type() == FunctionInfo.Type.AGGREGATE);
    assertThat(whereClause.arguments().get(0), isReference("name"));
    assertThat(whereClause.arguments().get(1), isLiteral("Trillian"));
}
Also used : Function(io.crate.analyze.symbol.Function) DocTableRelation(io.crate.analyze.relations.DocTableRelation) TableInfo(io.crate.metadata.table.TableInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 25 with TableInfo

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

the class CopyAnalyzerTest method testCopyToFileWithSelectedColumnsAndOutputFormatParam.

@Test
public void testCopyToFileWithSelectedColumnsAndOutputFormatParam() throws Exception {
    CopyToAnalyzedStatement analysis = e.analyze("copy users (id, name) to directory '/blah' with (format='json_object')");
    TableInfo tableInfo = analysis.subQueryRelation().tableRelation().tableInfo();
    assertThat(tableInfo.ident(), is(USER_TABLE_IDENT));
    assertThat(analysis.uri(), isLiteral("/blah"));
    assertThat(analysis.outputFormat(), is(WriterProjection.OutputFormat.JSON_OBJECT));
    assertThat(analysis.outputNames(), contains("id", "name"));
}
Also used : TableInfo(io.crate.metadata.table.TableInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

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