Search in sources :

Example 46 with Column

use of org.teiid.metadata.Column in project teiid by teiid.

the class IckleConversionVisitor method visit.

@Override
public void visit(NamedTable obj) {
    this.queriedTable = obj;
    if (obj.getCorrelationName() == null) {
        obj.setCorrelationName(obj.getMetadataObject().getName().toLowerCase() + "_" + aliasCounter.getAndIncrement());
    }
    if (this.rootNode == null) {
        String messageName = null;
        String aliasName = null;
        String mergedTableName = ProtobufMetadataProcessor.getMerge(obj.getMetadataObject());
        if (mergedTableName == null) {
            aliasName = obj.getCorrelationName();
            messageName = getMessageName(obj.getMetadataObject());
            this.parentTable = obj;
            this.rootNode = new DocumentNode(obj.getMetadataObject(), true);
            this.joinedNode = this.rootNode;
            // check to see if there is one-2-one rows
            Set<String> tags = new HashSet<>();
            for (Column column : obj.getMetadataObject().getColumns()) {
                if (ProtobufMetadataProcessor.getParentTag(column) != -1) {
                    String childMessageName = ProtobufMetadataProcessor.getMessageName(column);
                    if (!tags.contains(childMessageName)) {
                        tags.add(childMessageName);
                        // TODO: DocumentNode needs to be refactored to just take name, not table
                        Table t = new Table();
                        t.setName(childMessageName);
                        this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(t, false));
                    }
                }
            }
        } else {
            try {
                Table mergedTable = this.metadata.getTable(mergedTableName);
                messageName = getMessageName(mergedTable);
                aliasName = mergedTable.getName().toLowerCase() + "_" + aliasCounter.getAndIncrement();
                this.parentTable = new NamedTable(mergedTable.getName(), aliasName, mergedTable);
                this.rootNode = new DocumentNode(mergedTable, true);
                this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(obj.getMetadataObject(), true));
                this.nested = true;
            } catch (TranslatorException e) {
                this.exceptions.add(e);
            }
        }
        buffer.append(messageName);
        if (aliasName != null) {
            buffer.append(Tokens.SPACE);
            buffer.append(aliasName);
        }
        if (this.includePK) {
            KeyRecord pk = this.parentTable.getMetadataObject().getPrimaryKey();
            if (pk != null) {
                for (Column column : pk.getColumns()) {
                    projectedExpressions.add(new ColumnReference(obj, column.getName(), column, column.getJavaType()));
                }
            }
        }
    }
}
Also used : KeyRecord(org.teiid.metadata.KeyRecord) Table(org.teiid.metadata.Table) DocumentNode(org.teiid.translator.document.DocumentNode) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) HashSet(java.util.HashSet)

Example 47 with Column

use of org.teiid.metadata.Column in project teiid by teiid.

the class IckleConversionVisitor method visit.

@Override
public void visit(Comparison obj) {
    if (obj.getOperator() == Operator.EQ && obj.getLeftExpression() instanceof ColumnReference && obj.getRightExpression() instanceof ColumnReference) {
        // this typically is join.
        Column left = ((ColumnReference) obj.getLeftExpression()).getMetadataObject();
        Column right = ((ColumnReference) obj.getRightExpression()).getMetadataObject();
        if (getQualifiedName(left).equals(getQualifiedName(right))) {
            return;
        }
    }
    super.visit(obj);
}
Also used : Column(org.teiid.metadata.Column)

Example 48 with Column

use of org.teiid.metadata.Column in project teiid by teiid.

the class IckleConversionVisitor method visit.

@Override
public void visit(DerivedColumn obj) {
    if (obj.getExpression() instanceof ColumnReference) {
        Column column = ((ColumnReference) obj.getExpression()).getMetadataObject();
        if (!column.isSelectable()) {
            this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25001, column.getName())));
        }
        column = normalizePseudoColumn(column);
        if (!this.includePK || !isPartOfPrimaryKey(column.getName())) {
            if (column.getParent().equals(this.parentTable.getMetadataObject())) {
                this.projectedExpressions.add(new ColumnReference(this.parentTable, column.getName(), column, column.getJavaType()));
            } else {
                this.projectedExpressions.add(new ColumnReference(this.queriedTable, column.getName(), column, column.getJavaType()));
            }
        }
        boolean nested = false;
        if (ProtobufMetadataProcessor.getParentTag(column) != -1 || ProtobufMetadataProcessor.getParentTag((Table) column.getParent()) != -1) {
            this.avoidProjection = true;
            nested = true;
        }
        try {
            this.projectedDocumentAttributes.put(MarshallerBuilder.getDocumentAttributeName(column, nested, this.metadata), column.getJavaType());
        } catch (TranslatorException e) {
            this.exceptions.add(e);
        }
    } else if (obj.getExpression() instanceof Function) {
        if (!this.parentTable.equals(this.queriedTable)) {
            this.exceptions.add(new TranslatorException(InfinispanPlugin.Event.TEIID25008, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25008)));
        }
        AggregateFunction func = (AggregateFunction) obj.getExpression();
        this.projectedExpressions.add(func);
        // Aggregate functions can not be part of the implicit query projection when the complex object is involved
        // thus not adding to projectedDocumentAttributes. i.e. sum(g2.g3.e1) is not supported by Infinispan AFAIK.
        this.projectedDocumentAttributes.put(obj.getAlias(), func.getType());
    } else {
        this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25002, obj)));
    }
}
Also used : Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException)

Example 49 with Column

use of org.teiid.metadata.Column in project teiid by teiid.

the class IckleConversionVisitor method addSelectedColumns.

StringBuilder addSelectedColumns(StringBuilder sb) {
    sb.append(SQLConstants.Reserved.SELECT).append(Tokens.SPACE);
    boolean first = true;
    for (Expression expr : this.projectedExpressions) {
        if (!first) {
            sb.append(Tokens.COMMA).append(Tokens.SPACE);
        }
        if (expr instanceof ColumnReference) {
            Column column = ((ColumnReference) expr).getMetadataObject();
            String nis = getQualifiedName(column);
            sb.append(nis);
        } else if (expr instanceof Function) {
            Function func = (Function) expr;
            sb.append(func.getName()).append(Tokens.LPAREN);
            if (func.getParameters().isEmpty() && SQLConstants.NonReserved.COUNT.equalsIgnoreCase(func.getName())) {
                sb.append(Tokens.ALL_COLS);
            } else {
                ColumnReference columnRef = (ColumnReference) func.getParameters().get(0);
                Column column = columnRef.getMetadataObject();
                String nis = getQualifiedName(column);
                sb.append(nis);
            }
            sb.append(Tokens.RPAREN);
        }
        first = false;
    }
    return sb;
}
Also used : Column(org.teiid.metadata.Column)

Example 50 with Column

use of org.teiid.metadata.Column in project teiid by teiid.

the class InfinispanExecutionFactory method getMetadata.

@Override
public void getMetadata(MetadataFactory metadataFactory, InfinispanConnection conn) throws TranslatorException {
    ProtobufMetadataProcessor metadataProcessor = (ProtobufMetadataProcessor) getMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
    // This block is only invoked when NATIVE metadata is defined, by the time code got here if we have
    // tables already in schema, then user defined through other metadata repositories. In this case,
    // a .proto file need to be generated based on schema, then use that to generate final metadata and
    // register the .proto with the Infinispan
    Schema schema = metadataFactory.getSchema();
    ProtobufResource resource = null;
    ArrayList<Table> removedTables = new ArrayList<>();
    if (schema.getTables() != null && !schema.getTables().isEmpty()) {
        SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
        stpp.setIndexMessages(true);
        resource = stpp.process(metadataFactory, conn);
        metadataProcessor.setProtobufResource(resource);
        ArrayList<Table> tables = new ArrayList<>(schema.getTables().values());
        for (Table t : tables) {
            // remove the previous tables, as we want to introduce them with necessary
            // extension metadata generated with generated .proto file. As some of the default
            // extension metadata can be added.
            removedTables.add(schema.removeTable(t.getName()));
        }
    }
    metadataProcessor.process(metadataFactory, conn);
    // may be not carried forward, we need to make sure we copy those back.
    for (Table oldT : removedTables) {
        Table newT = schema.getTable(oldT.getName());
        Map<String, String> properties = oldT.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            newT.setProperty(entry.getKey(), entry.getValue());
        }
        newT.setSupportsUpdate(oldT.supportsUpdate());
        if (oldT.getAnnotation() != null) {
            newT.setAnnotation(oldT.getAnnotation());
        }
        List<Column> columns = oldT.getColumns();
        for (Column c : columns) {
            Column newCol = newT.getColumnByName(c.getName());
            if (newCol != null) {
                Map<String, String> colProperties = c.getProperties();
                for (Map.Entry<String, String> entry : colProperties.entrySet()) {
                    newCol.setProperty(entry.getKey(), entry.getValue());
                }
                newCol.setUpdatable(c.isUpdatable());
                if (c.getAnnotation() != null) {
                    newCol.setAnnotation(c.getAnnotation());
                }
            }
        }
    }
    resource = metadataProcessor.getProtobufResource();
    if (resource == null) {
        SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
        resource = stpp.process(metadataFactory, conn);
    }
    // register protobuf
    if (resource != null) {
        conn.registerProtobufFile(resource);
    }
}
Also used : Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) Column(org.teiid.metadata.Column) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) Map(java.util.Map)

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