use of org.teiid.metadata.Column 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 });
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class InfinispanUpdateVisitor method visit.
@Override
public void visit(Insert obj) {
this.operationType = OperationType.INSERT;
if (obj.isUpsert()) {
this.operationType = OperationType.UPSERT;
}
visitNode(obj.getTable());
Column pkColumn = getPrimaryKey();
if (pkColumn == null) {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25013, getParentTable().getName())));
return;
}
if (obj.getParameterValues() == null) {
List<Expression> values = ((ExpressionValueSource) obj.getValueSource()).getValues();
this.insertPayload = buildInsertPayload(obj, values);
if (this.insertPayload != null) {
this.identity = this.insertPayload.getIdentifier();
}
}
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class InfinispanUpdateVisitor method addDefaults.
private void addDefaults(InfinispanDocument parentDocument, Table table, boolean addDefaults) throws TranslatorException {
for (Column column : table.getColumns()) {
int parentTag = ProtobufMetadataProcessor.getParentTag(column);
if (parentTag != -1) {
String messageName = ProtobufMetadataProcessor.getMessageName(column);
List<?> children = parentDocument.getChildDocuments(messageName);
InfinispanDocument child = null;
if (children == null || children.isEmpty()) {
TableWireFormat twf = parentDocument.getWireMap().get(TableWireFormat.buildNestedTag(parentTag));
child = new InfinispanDocument(messageName, twf.getNestedWireMap(), parentDocument);
parentDocument.addChildDocument(messageName, child);
} else {
child = (InfinispanDocument) children.get(0);
}
if (addDefaults && column.getDefaultValue() != null) {
child.addProperty(getName(column), column.getDefaultValue());
}
} else {
if (addDefaults && column.getDefaultValue() != null) {
parentDocument.addProperty(getName(column), column.getDefaultValue());
}
}
}
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class MarshallerBuilder method buildWireMap.
private static TreeMap<Integer, TableWireFormat> buildWireMap(Table table, boolean nested, RuntimeMetadata metadata) throws TranslatorException {
TreeMap<Integer, TableWireFormat> wireMap = new TreeMap<>();
for (Column column : table.getColumns()) {
if (ProtobufMetadataProcessor.getPseudo(column) != null) {
continue;
}
int parentTag = ProtobufMetadataProcessor.getParentTag(column);
if (parentTag == -1) {
// normal columns
int tag = ProtobufMetadataProcessor.getTag(column);
String name = getDocumentAttributeName(column, nested, metadata);
TableWireFormat twf = new TableWireFormat(name, tag, column);
wireMap.put(twf.getReadTag(), twf);
} else {
// columns from one 2 one relation
int tag = ProtobufMetadataProcessor.getTag(column);
String name = getDocumentAttributeName(column, true, metadata);
TableWireFormat child = new TableWireFormat(name, tag, column);
String parentName = ProtobufMetadataProcessor.getMessageName(column);
TableWireFormat parent = null;
TableWireFormat existing = wireMap.get(TableWireFormat.buildNestedTag(parentTag));
if (existing == null) {
parent = new TableWireFormat(parentName, parentTag);
wireMap.put(parent.getReadTag(), parent);
} else {
parent = existing;
}
parent.addNested(child);
}
}
return wireMap;
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class ComplexDocumentFilter method matches.
@Override
public boolean matches(Map<String, Object> parentProperties, Map<String, Object> childProperties) throws TranslatorException {
try {
List<Object> tuple = new ArrayList<>();
int i = 0;
for (Column column : parentTable.getMetadataObject().getColumns()) {
tuple.add(i++, parentProperties.get(MarshallerBuilder.getDocumentAttributeName(column, false, metadata)));
}
for (Column column : childTable.getMetadataObject().getColumns()) {
tuple.add(i++, childProperties.get(MarshallerBuilder.getDocumentAttributeName(column, true, metadata)));
}
org.teiid.query.util.CommandContext cc = new org.teiid.query.util.CommandContext();
final Evaluator evaluator = new Evaluator(elementMap, null, cc);
return evaluator.evaluate(criteria, tuple);
} catch (ExpressionEvaluationException e) {
throw new TranslatorException(e);
} catch (BlockedException e) {
throw new TranslatorException(e);
} catch (TeiidComponentException e) {
throw new TranslatorException(e);
}
}
Aggregations