use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class SymbolPrinterTest method testPrintRelationColumn.
@Test
public void testPrintRelationColumn() throws Exception {
Symbol relationColumn = new RelationColumn(new QualifiedName(TABLE_NAME), 42, DataTypes.STRING);
assertPrint(relationColumn, "RELCOL(formatter, 42)");
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class MultiSourceFetchPushDown method process.
void process() {
remainingOutputs = statement.querySpec().outputs();
statement.querySpec().outputs(new ArrayList<>());
HashMap<Symbol, Symbol> topLevelOutputMap = new HashMap<>(statement.canBeFetched().size());
HashMap<Symbol, Symbol> mssOutputMap = new HashMap<>(statement.querySpec().outputs().size() + 2);
ArrayList<Symbol> mssOutputs = new ArrayList<>(statement.sources().size() + statement.requiredForQuery().size());
for (Map.Entry<QualifiedName, RelationSource> entry : statement.sources().entrySet()) {
RelationSource source = entry.getValue();
if (!(source.relation() instanceof DocTableRelation)) {
int index = 0;
for (Symbol output : source.querySpec().outputs()) {
RelationColumn rc = new RelationColumn(entry.getKey(), index++, output.valueType());
mssOutputs.add(rc);
mssOutputMap.put(output, rc);
topLevelOutputMap.put(output, new InputColumn(mssOutputs.size() - 1, output.valueType()));
}
continue;
}
DocTableRelation rel = (DocTableRelation) source.relation();
HashSet<Field> canBeFetched = filterByRelation(statement.canBeFetched(), rel);
if (!canBeFetched.isEmpty()) {
RelationColumn fetchIdColumn = new RelationColumn(entry.getKey(), 0, DataTypes.LONG);
mssOutputs.add(fetchIdColumn);
InputColumn fetchIdInput = new InputColumn(mssOutputs.size() - 1);
ArrayList<Symbol> qtOutputs = new ArrayList<>(source.querySpec().outputs().size() - canBeFetched.size() + 1);
Reference fetchId = rel.tableInfo().getReference(DocSysColumns.FETCHID);
qtOutputs.add(fetchId);
for (Symbol output : source.querySpec().outputs()) {
if (!canBeFetched.contains(output)) {
qtOutputs.add(output);
RelationColumn rc = new RelationColumn(entry.getKey(), qtOutputs.size() - 1, output.valueType());
mssOutputs.add(rc);
mssOutputMap.put(output, rc);
topLevelOutputMap.put(output, new InputColumn(mssOutputs.size() - 1, output.valueType()));
}
}
for (Field field : canBeFetched) {
FetchReference fr = new FetchReference(fetchIdInput, DocReferenceConverter.toSourceLookup(rel.resolveField(field)));
allocateFetchedReference(fr, rel);
topLevelOutputMap.put(field, fr);
}
source.querySpec().outputs(qtOutputs);
} else {
int index = 0;
for (Symbol output : source.querySpec().outputs()) {
RelationColumn rc = new RelationColumn(entry.getKey(), index++, output.valueType());
mssOutputs.add(rc);
mssOutputMap.put(output, rc);
topLevelOutputMap.put(output, new InputColumn(mssOutputs.size() - 1, output.valueType()));
}
}
}
statement.querySpec().outputs(mssOutputs);
MappingSymbolVisitor.inPlace().processInplace(remainingOutputs, topLevelOutputMap);
if (statement.querySpec().orderBy().isPresent()) {
MappingSymbolVisitor.inPlace().processInplace(statement.querySpec().orderBy().get().orderBySymbols(), mssOutputMap);
}
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class FieldProviderTest method testRelationFromTwoTables.
@Test
public void testRelationFromTwoTables() throws Exception {
// select name from doc.t, custom.t
FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(Arrays.asList("custom", "t")), new DummyRelation("address"), new QualifiedName(Arrays.asList("doc", "t")), new DummyRelation("name")));
resolver.resolveField(new QualifiedName(Arrays.asList("t", "name")), Operation.READ);
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class FieldProviderTest method testRelationFromTwoTablesWithSameNameDifferentSchemaIsAmbiguous.
@Test
public void testRelationFromTwoTablesWithSameNameDifferentSchemaIsAmbiguous() throws Exception {
// select t.name from custom.t.name, doc.t.name
expectedException.expect(AmbiguousColumnException.class);
expectedException.expectMessage("Column \"name\" is ambiguous");
FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(Arrays.asList("custom", "t")), new DummyRelation("name"), new QualifiedName(Arrays.asList("doc", "t")), new DummyRelation("name")));
resolver.resolveField(new QualifiedName(Arrays.asList("t", "name")), Operation.READ);
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class FieldProviderTest method testRelationOutputFromAlias.
@Test
public void testRelationOutputFromAlias() throws Exception {
// t.name from doc.foo t
AnalyzedRelation relation = new DummyRelation("name");
FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(new QualifiedName(Arrays.asList("t")), relation));
Field field = resolver.resolveField(newQN("t.name"), Operation.READ);
assertThat(field.relation(), equalTo(relation));
assertThat(field.path().outputName(), is("name"));
}
Aggregations