Search in sources :

Example 1 with AbstractMetadataRecord

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

the class AccumuloQueryVisitor method visit.

@Override
public void visit(Select obj) {
    visitNodes(obj.getFrom());
    visitNodes(obj.getDerivedColumns());
    visitNode(obj.getWhere());
    visitNode(obj.getGroupBy());
    visitNode(obj.getHaving());
    visitNode(obj.getOrderBy());
    visitNode(obj.getLimit());
    if (this.doScanEvaluation) {
        HashMap<String, String> options = buildEvaluatorOptions(this.scanTable);
        SQLStringVisitor visitor = new SQLStringVisitor() {

            @Override
            public String getName(AbstractMetadataRecord object) {
                return object.getName();
            }
        };
        visitor.append(obj.getWhere());
        options.put(EvaluatorIterator.QUERYSTRING, visitor.toString());
        IteratorSetting it = new IteratorSetting(1, EvaluatorIterator.class, options);
        this.scanIterators.add(it);
    }
}
Also used : SQLStringVisitor(org.teiid.language.visitor.SQLStringVisitor) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 2 with AbstractMetadataRecord

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

the class QueryExecutionImpl method extractValuesFromElement.

// TODO: this looks inefficient as getChild is linear
private List<Object[]> extractValuesFromElement(XmlObject sObject, List<Object[]> result, String sObjectName) throws TranslatorException {
    Object[] row = new Object[visitor.getSelectSymbolCount()];
    for (int j = 0; j < visitor.getSelectSymbolCount(); j++) {
        // must be a column reference as we won't allow an agg over a join
        Column element = ((ColumnReference) visitor.getSelectSymbolMetadata(j)).getMetadataObject();
        AbstractMetadataRecord table = element.getParent();
        if (table.getSourceName().equals(sObjectName)) {
            XmlObject child = sObject.getChild(element.getSourceName());
            Object cell = getCellDatum(element.getSourceName(), element.getJavaType(), child);
            setElementValueInColumn(j, cell, row);
        }
    }
    result.add(row);
    return result;
}
Also used : Column(org.teiid.metadata.Column) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 3 with AbstractMetadataRecord

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

the class InfinispanUpdateExecution method execute.

@Override
public void execute() throws TranslatorException {
    if (useAliasCache) {
        if (useAliasCache) {
            InfinispanQueryExecution.useModifiedGroups(this.connection, this.executionContext, this.metadata, this.command);
        }
    }
    final InfinispanUpdateVisitor visitor = new InfinispanUpdateVisitor(this.metadata);
    visitor.append(this.command);
    if (!visitor.exceptions.isEmpty()) {
        throw visitor.exceptions.get(0);
    }
    TeiidTableMarsheller marshaller = null;
    try {
        Table table = visitor.getParentTable();
        Column pkColumn = visitor.getPrimaryKey();
        if (pkColumn == null) {
            throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25013, table.getName()));
        }
        final String PK = MarshallerBuilder.getDocumentAttributeName(pkColumn, false, this.metadata);
        DocumentFilter docFilter = null;
        if (visitor.isNestedOperation() && visitor.getWhereClause() != null) {
            Action action = Action.ALWAYSADD;
            if (command instanceof Delete) {
                action = Action.REMOVE;
            }
            SQLStringVisitor ssv = new SQLStringVisitor() {

                @Override
                public void visit(ColumnReference obj) {
                    String groupName = null;
                    NamedTable group = obj.getTable();
                    if (group.getCorrelationName() != null) {
                        groupName = group.getCorrelationName();
                    } else {
                        Table groupID = group.getMetadataObject();
                        if (groupID.getFullName().equals(visitor.getParentTable().getFullName())) {
                            groupName = visitor.getParentNamedTable().getCorrelationName();
                        } else {
                            groupName = visitor.getQueryNamedTable().getCorrelationName();
                        }
                    }
                    buffer.append(groupName).append(Tokens.DOT).append(getName(obj.getMetadataObject()));
                }

                @Override
                public String getName(AbstractMetadataRecord object) {
                    return object.getName();
                }
            };
            ssv.append(visitor.getWhereClause());
            docFilter = new ComplexDocumentFilter(visitor.getParentNamedTable(), visitor.getQueryNamedTable(), this.metadata, ssv.toString(), action);
        }
        marshaller = MarshallerBuilder.getMarshaller(table, this.metadata, docFilter);
        this.connection.registerMarshaller(marshaller);
        // if the message in defined in different cache than the default, switch it out now.
        final RemoteCache<Object, Object> cache = InfinispanQueryExecution.getCache(table, connection);
        if (visitor.getOperationType() == OperationType.DELETE) {
            paginateDeleteResults(cache, visitor.getDeleteQuery(), new Task() {

                @Override
                public void run(Object row) throws TranslatorException {
                    if (visitor.isNestedOperation()) {
                        String childName = ProtobufMetadataProcessor.getMessageName(visitor.getQueryTable());
                        InfinispanDocument document = (InfinispanDocument) row;
                        cache.replace(document.getProperties().get(PK), document);
                        // false below means count that not matched, i.e. deleted count
                        updateCount = updateCount + document.getUpdateCount(childName, false);
                    } else {
                        Object key = ((Object[]) row)[0];
                        cache.remove(key);
                        updateCount++;
                    }
                }
            }, this.executionContext.getBatchSize());
        } else if (visitor.getOperationType() == OperationType.UPDATE) {
            paginateUpdateResults(cache, visitor.getUpdateQuery(), new Task() {

                @Override
                public void run(Object row) throws TranslatorException {
                    InfinispanDocument previous = (InfinispanDocument) row;
                    Object key = previous.getProperties().get(PK);
                    int count = previous.merge(visitor.getInsertPayload());
                    cache.replace(key, previous);
                    updateCount = updateCount + count;
                }
            }, this.executionContext.getBatchSize());
        } else if (visitor.getOperationType() == OperationType.INSERT) {
            performInsert(visitor, table, cache, false, marshaller);
        } else if (visitor.getOperationType() == OperationType.UPSERT) {
            performInsert(visitor, table, cache, true, marshaller);
        }
    } finally {
        if (marshaller != null) {
            this.connection.unRegisterMarshaller(marshaller);
        }
    }
}
Also used : Delete(org.teiid.language.Delete) NamedTable(org.teiid.language.NamedTable) Action(org.teiid.infinispan.api.DocumentFilter.Action) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) SQLStringVisitor(org.teiid.language.visitor.SQLStringVisitor) TeiidTableMarsheller(org.teiid.infinispan.api.TeiidTableMarsheller) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) DocumentFilter(org.teiid.infinispan.api.DocumentFilter) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) ColumnReference(org.teiid.language.ColumnReference)

Example 4 with AbstractMetadataRecord

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

the class TestTranslationUtility method testGetRMD.

public void testGetRMD() throws Exception {
    TranslationUtility util = new TranslationUtility(getTestVDB());
    // Translate command to get some ids
    // $NON-NLS-1$
    Select query = (Select) util.parseCommand("select * from partssupplier.parts");
    NamedTable group = (NamedTable) query.getFrom().get(0);
    AbstractMetadataRecord mid = group.getMetadataObject();
    // $NON-NLS-1$
    assertEquals("PartsSupplier.PARTSSUPPLIER.PARTS", mid.getFullName());
    // Use RMD to get stuff
    // $NON-NLS-1$
    assertEquals("PARTS", mid.getNameInSource());
}
Also used : NamedTable(org.teiid.language.NamedTable) Select(org.teiid.language.Select) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 5 with AbstractMetadataRecord

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

the class MockConnector method createResultSetExecution.

@Override
public ResultSetExecution createResultSetExecution(QueryExpression query, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
    Properties groupProps = new Properties();
    // $NON-NLS-1$ //$NON-NLS-2$
    groupProps.setProperty("customName", "CustomTableA");
    NamedTable group = (NamedTable) query.getProjectedQuery().getFrom().get(0);
    AbstractMetadataRecord groupMD = group.getMetadataObject();
    TestCase.assertEquals(groupProps, groupMD.getProperties());
    DerivedColumn symbl = query.getProjectedQuery().getDerivedColumns().get(0);
    ColumnReference element = (ColumnReference) symbl.getExpression();
    Column elementMD = element.getMetadataObject();
    Properties elementProps = new Properties();
    // $NON-NLS-1$ //$NON-NLS-2$
    elementProps.setProperty("customPosition", "11");
    TestCase.assertEquals(0, elementMD.getLength());
    // $NON-NLS-1$
    TestCase.assertEquals("Foo", elementMD.getDefaultValue());
    // $NON-NLS-1$
    TestCase.assertEquals("TrimNulls", elementMD.getFormat());
    TestCase.assertEquals(String.class, elementMD.getJavaType());
    TestCase.assertEquals(null, elementMD.getMaximumValue());
    TestCase.assertEquals(null, elementMD.getMinimumValue());
    // $NON-NLS-1$
    TestCase.assertEquals("COLUMN1", elementMD.getNameInSource());
    // $NON-NLS-1$
    TestCase.assertEquals("STR", elementMD.getNativeType());
    TestCase.assertEquals(NullType.Nullable, elementMD.getNullType());
    TestCase.assertEquals(0, elementMD.getPosition());
    TestCase.assertEquals(0, elementMD.getPrecision());
    TestCase.assertEquals(0, elementMD.getScale());
    TestCase.assertEquals(SearchType.Searchable, elementMD.getSearchType());
    TestCase.assertEquals(false, elementMD.isAutoIncremented());
    TestCase.assertEquals(true, elementMD.isCaseSensitive());
    TestCase.assertEquals(elementProps, elementMD.getProperties());
    DerivedColumn symbl2 = query.getProjectedQuery().getDerivedColumns().get(1);
    ColumnReference element2 = (ColumnReference) symbl2.getExpression();
    Column elementMD2 = element2.getMetadataObject();
    Properties elementProps2 = new Properties();
    // $NON-NLS-1$ //$NON-NLS-2$
    elementProps2.setProperty("customPosition", "12");
    TestCase.assertEquals(10, elementMD2.getLength());
    // $NON-NLS-1$
    TestCase.assertEquals("23", elementMD2.getDefaultValue());
    // $NON-NLS-1$
    TestCase.assertEquals("YesFormat", elementMD2.getFormat());
    TestCase.assertEquals(Integer.class, elementMD2.getJavaType());
    // $NON-NLS-1$
    TestCase.assertEquals("1", elementMD2.getMaximumValue());
    // $NON-NLS-1$
    TestCase.assertEquals("100", elementMD2.getMinimumValue());
    // $NON-NLS-1$
    TestCase.assertEquals("COLUMN2", elementMD2.getNameInSource());
    // $NON-NLS-1$
    TestCase.assertEquals("INT", elementMD2.getNativeType());
    TestCase.assertEquals(NullType.No_Nulls, elementMD2.getNullType());
    TestCase.assertEquals(1, elementMD2.getPosition());
    TestCase.assertEquals(0, elementMD2.getPrecision());
    TestCase.assertEquals(10, elementMD2.getScale());
    TestCase.assertEquals(SearchType.Searchable, elementMD2.getSearchType());
    TestCase.assertEquals(true, elementMD2.isAutoIncremented());
    TestCase.assertEquals(false, elementMD2.isCaseSensitive());
    TestCase.assertEquals(elementProps2, elementMD2.getProperties());
    ResultSetExecution exec = Mockito.mock(ResultSetExecution.class);
    Mockito.stub(exec.next()).toReturn(null);
    return exec;
}
Also used : NamedTable(org.teiid.language.NamedTable) ResultSetExecution(org.teiid.translator.ResultSetExecution) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) Properties(java.util.Properties) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Aggregations

AbstractMetadataRecord (org.teiid.metadata.AbstractMetadataRecord)16 NamedTable (org.teiid.language.NamedTable)3 SQLStringVisitor (org.teiid.language.visitor.SQLStringVisitor)3 Column (org.teiid.metadata.Column)3 List (java.util.List)2 Properties (java.util.Properties)2 DocumentFilter (org.teiid.infinispan.api.DocumentFilter)2 ColumnReference (org.teiid.language.ColumnReference)2 Select (org.teiid.language.Select)2 Table (org.teiid.metadata.Table)2 SObject (com.sforce.soap.partner.sobject.SObject)1 XmlObject (com.sforce.ws.bind.XmlObject)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 Test (org.junit.Test)1 PermissionType (org.teiid.adminapi.DataPolicy.PermissionType)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)1 Cachable (org.teiid.cache.Cachable)1