use of io.crate.metadata.RelationName in project crate by crate.
the class ExcludedFieldProviderTest method testResolveFieldsAndValues.
@Test
public void testResolveFieldsAndValues() {
QualifiedName normalField1 = QualifiedName.of("field1");
QualifiedName normalField2 = QualifiedName.of("normal", "field2");
QualifiedName excludedName = QualifiedName.of("excluded", "field3");
FieldProvider<?> fieldProvider = (qualifiedName, path, operation, errorOnUnknownObjectKey) -> new ScopedSymbol(new RelationName("doc", "dummy"), new ColumnIdent(qualifiedName.toString()), DataTypes.INTEGER);
ValuesResolver valuesResolver = argumentColumn -> {
assertThat(argumentColumn, isField("field3"));
return Literal.of(42);
};
ExcludedFieldProvider excludedFieldProvider = new ExcludedFieldProvider(fieldProvider, valuesResolver);
assertThat(excludedFieldProvider.resolveField(normalField1, null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY), isField(normalField1.toString()));
assertThat(excludedFieldProvider.resolveField(normalField2, null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY), isField(normalField2.toString()));
assertThat(excludedFieldProvider.resolveField(excludedName, null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY), isLiteral(42));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class DocTableRelationTest method testUpdatingCompoundPrimaryKeyThrowsCorrectException.
@Test
public void testUpdatingCompoundPrimaryKeyThrowsCorrectException() {
DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (i int, j int, primary key (i, j))", clusterService);
DocTableRelation rel = new DocTableRelation(tableInfo);
expectedException.expect(ColumnValidationException.class);
expectedException.expectMessage("Validation failed for i: Updating a primary key is not supported");
rel.ensureColumnCanBeUpdated(new ColumnIdent("i"));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class FieldProviderTest method testMultipleSourcesWithDynamicReferenceAndReference.
@Test
public void testMultipleSourcesWithDynamicReferenceAndReference() throws Exception {
AnalyzedRelation barT = new DummyRelation(new RelationName("bar", "t"), "name");
AnalyzedRelation fooT = new DummyRelation(new RelationName("foo", "t"), "name");
AnalyzedRelation fooA = new DummyRelation(new RelationName("foo", "a"), "name");
AnalyzedRelation customT = new DummyRelation(new RelationName("custom", "t"), "tags");
FieldProvider<Symbol> resolver = newFQFieldProvider(Map.of(newQN("bar.t"), barT, newQN("foo.t"), fooT, newQN("foo.a"), fooA, newQN("custom.t"), customT));
Symbol field = resolver.resolveField(newQN("foo.t.name"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
assertThat(field, isField("name", fooT.relationName()));
Symbol tags = resolver.resolveField(newQN("tags"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
assertThat(tags, isField("tags", customT.relationName()));
field = resolver.resolveField(newQN("a.name"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
assertThat(field, isField("name", fooA.relationName()));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class FieldProviderTest method testAliasRelationNameResolver.
@Test
public void testAliasRelationNameResolver() throws Exception {
AnalyzedRelation barT = new DummyRelation(new RelationName("doc", "Bar"), "name");
FieldProvider<Symbol> resolver = newFQFieldProvider(Map.of(newQN("\"Bar\""), barT));
Symbol field = resolver.resolveField(newQN("\"Bar\".name"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
assertThat(field, isField("name", barT.relationName()));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class QuerySplitterTest method testSplitQueryWith3Relations.
@Test
public void testSplitQueryWith3Relations() throws Exception {
Symbol symbol = asSymbol("t1.a = t2.b and t2.b = t3.c");
Map<Set<RelationName>, Symbol> split = QuerySplitter.split(symbol);
assertThat(split.size(), is(2));
Symbol t1t2 = asSymbol("t1.a = t2.b");
Symbol t2t3 = asSymbol("t2.b = t3.c");
Set<RelationName> tr1AndTr2 = Set.of(tr1, tr2);
assertThat(split.containsKey(tr1AndTr2), is(true));
assertThat(split.get(tr1AndTr2), is(t1t2));
Set<RelationName> tr2AndTr3 = Set.of(tr2, tr3);
assertThat(split.containsKey(tr2AndTr3), is(true));
assertThat(split.get(tr2AndTr3), is(t2t3));
}
Aggregations