Search in sources :

Example 41 with Column

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 });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 42 with Column

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();
        }
    }
}
Also used : Column(org.teiid.metadata.Column) Expression(org.teiid.language.Expression) TranslatorException(org.teiid.translator.TranslatorException) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 43 with Column

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());
            }
        }
    }
}
Also used : InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) Column(org.teiid.metadata.Column) TableWireFormat(org.teiid.infinispan.api.TableWireFormat)

Example 44 with Column

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;
}
Also used : Column(org.teiid.metadata.Column) TreeMap(java.util.TreeMap) TableWireFormat(org.teiid.infinispan.api.TableWireFormat)

Example 45 with Column

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);
    }
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) BlockedException(org.teiid.common.buffer.BlockedException) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Aggregations

Column (org.teiid.metadata.Column)210 Table (org.teiid.metadata.Table)72 ArrayList (java.util.ArrayList)47 TranslatorException (org.teiid.translator.TranslatorException)47 Test (org.junit.Test)39 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)21 MetadataFactory (org.teiid.metadata.MetadataFactory)20 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)19 KeyRecord (org.teiid.metadata.KeyRecord)18 Schema (org.teiid.metadata.Schema)18 MetadataStore (org.teiid.metadata.MetadataStore)17 Procedure (org.teiid.metadata.Procedure)14 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)14 ColumnReference (org.teiid.language.ColumnReference)12 DerivedColumn (org.teiid.language.DerivedColumn)12 Expression (org.teiid.language.Expression)12 Literal (org.teiid.language.Literal)10 QueryNode (org.teiid.query.mapping.relational.QueryNode)9 Connection (java.sql.Connection)7 ResultSet (java.sql.ResultSet)7