use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class FieldProviderTest method testTooManyParts.
@Test
public void testTooManyParts() throws Exception {
expectedException.expect(IllegalArgumentException.class);
FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(dummySources);
resolver.resolveField(new QualifiedName(Arrays.asList("a", "b", "c", "d")), Operation.READ);
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class QuerySplitterTest method testSplitQueryWith2TableJoinAnd3TableJoin.
@Test
public void testSplitQueryWith2TableJoinAnd3TableJoin() throws Exception {
Symbol symbol = asSymbol("t1.a = t2.b and t2.b = t3.c || t1.a");
Map<Set<QualifiedName>, Symbol> split = QuerySplitter.split(symbol);
assertThat(split.size(), is(2));
Symbol t1t2 = asSymbol("t1.a = t2.b");
Symbol t1t2t3 = asSymbol("t2.b = t3.c || t1.a");
Set<QualifiedName> tr1AndTr2 = Sets.newHashSet(tr1, tr2);
assertThat(split.containsKey(tr1AndTr2), is(true));
assertThat(split.get(tr1AndTr2), is(t1t2));
Set<QualifiedName> tr1AndTr2AndTr3 = Sets.newHashSet(tr1, tr2, tr3);
assertThat(split.containsKey(tr1AndTr2AndTr3), is(true));
assertThat(split.get(tr1AndTr2AndTr3), is(t1t2t3));
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class ManyTableConsumerTest method testNoOptimizeWithSortingAndOuterJoin.
@Test
public void testNoOptimizeWithSortingAndOuterJoin() throws Exception {
JoinPair pair1 = new JoinPair(T3.T1, T3.T2, JoinType.LEFT);
JoinPair pair2 = new JoinPair(T3.T2, T3.T3, JoinType.LEFT);
@SuppressWarnings("unchecked") Collection<QualifiedName> qualifiedNames = ManyTableConsumer.orderByJoinConditions(Arrays.asList(T3.T1, T3.T2, T3.T3), ImmutableSet.<Set<QualifiedName>>of(), ImmutableList.of(pair1, pair2), ImmutableList.of(T3.T3, T3.T2));
assertThat(qualifiedNames, Matchers.contains(T3.T1, T3.T2, T3.T3));
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class FullQualifedNameFieldProvider method resolveField.
public Field resolveField(QualifiedName qualifiedName, @Nullable List<String> path, Operation operation) {
List<String> parts = qualifiedName.getParts();
String columnSchema = null;
String columnTableName = null;
ColumnIdent columnIdent = new ColumnIdent(parts.get(parts.size() - 1), path);
switch(parts.size()) {
case 1:
break;
case 2:
columnTableName = parts.get(0);
break;
case 3:
columnSchema = parts.get(0);
columnTableName = parts.get(1);
break;
default:
throw new IllegalArgumentException("Column reference \"%s\" has too many parts. " + "A column reference can have at most 3 parts and must have one of the following formats: " + "\"<column>\", \"<table>.<column>\" or \"<schema>.<table>.<column>\"");
}
boolean schemaMatched = false;
boolean tableNameMatched = false;
Field lastField = null;
for (Map.Entry<QualifiedName, AnalyzedRelation> entry : sources.entrySet()) {
List<String> sourceParts = entry.getKey().getParts();
String sourceSchema = null;
String sourceTableOrAlias;
if (sourceParts.size() == 1) {
sourceTableOrAlias = sourceParts.get(0);
} else if (sourceParts.size() == 2) {
sourceSchema = sourceParts.get(0);
sourceTableOrAlias = sourceParts.get(1);
} else {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "sources key (QualifiedName) must have 1 or 2 parts, not %d", sourceParts.size()));
}
AnalyzedRelation sourceRelation = entry.getValue();
if (columnSchema != null && sourceSchema != null && !columnSchema.equals(sourceSchema)) {
continue;
}
schemaMatched = true;
if (columnTableName != null && !sourceTableOrAlias.equals(columnTableName)) {
continue;
}
tableNameMatched = true;
Field newField = sourceRelation.getField(columnIdent, operation);
if (newField != null) {
if (lastField != null) {
throw new AmbiguousColumnException(columnIdent);
}
lastField = newField;
}
}
if (lastField == null) {
if (!schemaMatched || !tableNameMatched) {
throw RelationUnknownException.of(columnSchema, columnTableName);
}
throw new ColumnUnknownException(columnIdent.sqlFqn());
}
return lastField;
}
use of io.crate.sql.tree.QualifiedName in project crate by crate.
the class RelationAnalysisContext method addJoinType.
void addJoinType(JoinType joinType, @Nullable Symbol joinCondition) {
int size = sources.size();
assert size >= 2 : "sources must be added first, cannot add join type for only 1 source";
Iterator<QualifiedName> it = sources.keySet().iterator();
QualifiedName left = null;
QualifiedName right = null;
int idx = 0;
while (it.hasNext()) {
QualifiedName sourceName = it.next();
if (idx == size - 2) {
left = sourceName;
} else if (idx == size - 1) {
right = sourceName;
}
idx++;
}
addJoinPair(new JoinPair(left, right, joinType, joinCondition));
}
Aggregations