use of org.teiid.metadata.Table in project teiid by teiid.
the class ODataFilterVisitor method visit.
@Override
public void visit(ColumnReference obj) {
Column column = obj.getMetadataObject();
ODataDocumentNode schemaElement = this.query.getSchemaElement((Table) column.getParent());
// check if the column on pseudo column, then move it to the parent.
if (ODataMetadataProcessor.isPseudo(column)) {
try {
Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
schemaElement = this.query.getSchemaElement((Table) realColumn.getParent());
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
if (this.filterOnElement == null) {
this.filterOnElement = schemaElement;
} else if (schemaElement.isExpandType() && (!this.filterOnElement.isExpandType())) {
this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17026)));
}
try {
if (this.filterOnElement.isComplexType()) {
if (ODataMetadataProcessor.isPseudo(column)) {
Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
this.filter.append(realColumn.getName());
} else {
this.filter.append(this.filterOnElement.getName()).append("/").append(column.getName());
}
} else {
if (ODataMetadataProcessor.isPseudo(column)) {
Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
this.filter.append(realColumn.getName());
} else {
this.filter.append(column.getName());
}
}
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class JoinQueryVisitor method visit.
// Has to be a left outer join of only 2 tables. criteria must be a compare
@Override
public void visit(Join join) {
try {
TableReference left = join.getLeftItem();
NamedTable leftGroup = (NamedTable) left;
leftTableInJoin = leftGroup.getMetadataObject();
loadColumnMetadata(leftGroup);
TableReference right = join.getRightItem();
NamedTable rightGroup = (NamedTable) right;
rightTableInJoin = rightGroup.getMetadataObject();
loadColumnMetadata((NamedTable) right);
Comparison criteria = (Comparison) join.getCondition();
Expression lExp = criteria.getLeftExpression();
Expression rExp = criteria.getRightExpression();
if (isIdColumn(rExp) || isIdColumn(lExp)) {
Column rColumn = ((ColumnReference) rExp).getMetadataObject();
String rTableName = rColumn.getParent().getSourceName();
Column lColumn = ((ColumnReference) lExp).getMetadataObject();
String lTableName = lColumn.getParent().getSourceName();
if (leftTableInJoin.getSourceName().equals(rTableName) || leftTableInJoin.getSourceName().equals(lTableName) && rightTableInJoin.getSourceName().equals(rTableName) || rightTableInJoin.getSourceName().equals(lTableName) && !rTableName.equals(lTableName)) {
// This is the join criteria, the one that is the ID is the parent.
Expression fKey = !isIdColumn(lExp) ? lExp : rExp;
ColumnReference columnReference = (ColumnReference) fKey;
table = childTable = (Table) columnReference.getMetadataObject().getParent();
String name = columnReference.getMetadataObject().getSourceName();
if (StringUtil.endsWithIgnoreCase(name, "id")) {
this.parentName = name.substring(0, name.length() - 2);
} else if (name.endsWith("__c")) {
// $NON-NLS-1$
// $NON-NLS-1$
this.parentName = name.substring(0, name.length() - 1) + "r";
}
Table parent = leftTableInJoin;
if (isChildToParentJoin()) {
parent = rightTableInJoin;
}
for (ForeignKey fk : childTable.getForeignKeys()) {
if (fk.getColumns().get(0).equals(columnReference.getMetadataObject()) && fk.getReferenceKey().equals(parent.getPrimaryKey())) {
foreignKey = fk;
break;
}
}
// inner joins require special handling as relationship queries are outer by default
if (join.getJoinType() == JoinType.INNER_JOIN) {
if (!isChildToParentJoin()) {
// flip the relationship
Table t = leftTableInJoin;
this.leftTableInJoin = rightTableInJoin;
this.rightTableInJoin = t;
}
// add is null criteria
addCriteria(new Comparison(fKey, new Literal(null, fKey.getType()), Comparison.Operator.NE));
}
} else {
// Only add the criteria to the query if it is not the join criteria.
// The join criteria is implicit in the salesforce syntax.
// TODO: not valid
super.visit(criteria);
}
} else {
// TODO: not valid
super.visit(criteria);
}
} catch (TranslatorException ce) {
exceptions.add(ce);
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestOptimizer method testUnnamedAggInView.
@Test
public void testUnnamedAggInView() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema bqt1 = RealMetadataFactory.createPhysicalModel("BQT1", metadataStore);
// $NON-NLS-1$
Schema vqt = RealMetadataFactory.createVirtualModel("VQT", metadataStore);
// $NON-NLS-1$
Table bqt1SmallA = RealMetadataFactory.createPhysicalGroup("SmallA", bqt1);
RealMetadataFactory.createElement("col", bqt1SmallA, DataTypeManager.DefaultDataTypes.STRING);
Table agg3 = RealMetadataFactory.createVirtualGroup("Agg3", vqt, new QueryNode("select count(*) from smalla"));
RealMetadataFactory.createElement("count", agg3, DataTypeManager.DefaultDataTypes.INTEGER);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "x");
BasicSourceCapabilities bac = getTypicalCapabilities();
bac.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
bac.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
bac.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
helpPlan("select count(*) from agg3", metadata, new String[] {}, new DefaultCapabilitiesFinder(bac), ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestConformedTables method oneTimeSetup.
@BeforeClass
public static void oneTimeSetup() throws Exception {
tm = RealMetadataFactory.example1();
Table t = tm.getGroupID("pm1.g1");
t.setProperty(RulePlaceAccess.CONFORMED_SOURCES, "pm2");
t = tm.getGroupID("pm2.g3");
t.setProperty(RulePlaceAccess.CONFORMED_SOURCES, "pm1");
t = tm.getGroupID("pm2.g1");
t.setProperty(RulePlaceAccess.CONFORMED_SOURCES, "pm3");
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestJoinOptimization method testPathologicalAccessPatternCaseCase2976Defect19018.
/**
* <p>In RuleBreakMultiJoin terminology:
* If any of the regions contains a group with any unsatisfied access patterns, one
* of those access patterns could be satisfied by arranging for a dependent join,
* provided that group has join criteria which covers the column(s) in an access
* pattern, and which joins the group to group(s) in other region(s). The task, then,
* is to ensure that an ordering isn't picked which makes such a dependent join
* impossible.</p>
*
* <p>A physical group can have zero or more access patterns; each access pattern can have one
* or more columns. So a group could implicitly be dependent on one or more other physical
* groups in one or more other regions. A table can be used to illustrate the potential
* complexity of access patterns:
* <pre>
* Region with | Target
* Access Patterns| Regions
* -------------------------
* Reg3 | Reg1, Reg2
* Reg3 | Reg4
* Reg1 | Reg2
* Reg4 | Reg3
* </pre></p>
*
* This tests now passes with RulePlanJoins
*/
@Test
public void testPathologicalAccessPatternCaseCase2976Defect19018() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.example1();
// add single access pattern to pm1.g4 containing elements e1, e2, and e3
Table pm4g1 = metadata.getGroupID("pm4.g1");
List<Column> cols = new ArrayList<Column>(pm4g1.getColumns());
cols.remove(2);
RealMetadataFactory.createKey(Type.AccessPattern, "pm4.g1.ap1", pm4g1, cols);
String sql = // $NON-NLS-1$
"SELECT pm1.g1.e1, pm2.g1.e1, pm4.g1.e1 " + // $NON-NLS-1$
"FROM pm1.g1, pm2.g1, pm4.g1 WHERE " + // $NON-NLS-1$
"pm1.g1.e1 = pm4.g1.e1 AND pm2.g1.e2 = pm4.g1.e2 AND pm1.g1.e4 = pm2.g1.e4 " + // $NON-NLS-1$
"AND pm4.g1.e4 = 3.2";
String[] expected = new String[] { // $NON-NLS-1$
"SELECT g_0.e4 AS c_0, g_0.e1 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", // $NON-NLS-1$
"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm4.g1 AS g_0 WHERE (g_0.e4 = 3.2) AND (g_0.e1 IN (<dependent values>)) AND (g_0.e2 IN (<dependent values>)) ORDER BY c_0, c_1", // $NON-NLS-1$
"SELECT g_0.e4 AS c_0, g_0.e2 AS c_1, g_0.e1 AS c_2 FROM pm2.g1 AS g_0 ORDER BY c_0" };
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, expected, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
1, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
2, // Null
0, // PlanExecution
0, // Project
1, // Select
0, // Sort
0, // UnionAll
0 });
}
Aggregations