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