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));
}
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;
}
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;
}
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"));
}
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"));
}
Aggregations