Search in sources :

Example 86 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestProcErrors method testExceptionAndWarning.

@Test
public void testExceptionAndWarning() throws Exception {
    String ddl = "create virtual procedure vproc (x integer) returns integer as begin declare exception e = sqlexception 'hello'; raise sqlwarning e; raise sqlexception 'hello world' sqlstate 'abc', 1 chain e; end;";
    TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call vproc(1)";
    ProcessorPlan plan = getProcedurePlan(sql, tm);
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    try {
        helpTestProcess(plan, null, dataManager, tm);
        fail();
    } catch (TeiidProcessingException e) {
        TeiidSQLException tsw = (TeiidSQLException) plan.getContext().getAndClearWarnings().get(0);
        assertEquals("hello", tsw.getMessage());
        assertEquals(e.getCause().getCause(), tsw);
        TeiidSQLException tse = (TeiidSQLException) e.getCause();
        assertEquals("hello world", tse.getMessage());
        assertEquals("abc", tse.getSQLState());
        assertEquals(1, tse.getErrorCode());
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Test(org.junit.Test)

Example 87 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestJoinNode method testSortMergeWithDistinct.

@Test
public void testSortMergeWithDistinct() throws TeiidComponentException, TeiidProcessingException {
    this.leftTuples = new List[] { Arrays.asList(1, 2), Arrays.asList(1, 3) };
    this.rightTuples = new List[] { Arrays.asList(1, 4), Arrays.asList(1, 5) };
    expected = new List[] { Arrays.asList(1, 2, 1, 4), Arrays.asList(1, 2, 1, 5), Arrays.asList(1, 3, 1, 4), Arrays.asList(1, 3, 1, 5) };
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("e2");
    es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List leftElements = Arrays.asList(es1, es2);
    leftNode = new BlockingFakeRelationalNode(1, leftTuples);
    leftNode.setElements(leftElements);
    // $NON-NLS-1$
    ElementSymbol es3 = new ElementSymbol("e3");
    es3.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es4 = new ElementSymbol("e4");
    es4.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List rightElements = Arrays.asList(es3, es4);
    rightNode = new BlockingFakeRelationalNode(2, rightTuples) {

        @Override
        public boolean hasBuffer() {
            return false;
        }

        @Override
        public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
            fail();
            throw new AssertionError();
        }
    };
    rightNode.setElements(rightElements);
    List joinElements = new ArrayList();
    joinElements.addAll(leftElements);
    joinElements.addAll(rightElements);
    joinType = JoinType.JOIN_INNER;
    joinStrategy = new MergeJoinStrategy(SortOption.SORT_DISTINCT, SortOption.SORT_DISTINCT, false);
    join = new JoinNode(3);
    join.setElements(joinElements);
    join.setJoinType(joinType);
    join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es3));
    join.setJoinStrategy(joinStrategy);
    helpTestJoinDirect(expected, 100, 100000);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ArrayList(java.util.ArrayList) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) Test(org.junit.Test)

Example 88 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class ODataSQLBuilder method insert.

public Insert insert(EdmEntityType entityType, Entity entity, List<UriParameter> keys, boolean prepared) throws TeiidException {
    Table entityTable = findTable(entityType.getName(), this.metadata);
    DocumentNode resource = new DocumentNode(entityTable, new GroupSymbol(entityTable.getFullName()), entityType);
    List<Reference> referenceValues = new ArrayList<Reference>();
    List<Constant> constantValues = new ArrayList<Constant>();
    Insert insert = new Insert();
    insert.setGroup(resource.getGroupSymbol());
    if (keys != null) {
        for (UriParameter key : keys) {
            EdmProperty edmProperty = (EdmProperty) entityType.getProperty(key.getName());
            Column column = entityTable.getColumnByName(edmProperty.getName());
            Object propertyValue = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), key.getText());
            Property existing = entity.getProperty(edmProperty.getName());
            if (existing == null || (existing.getValue() == null && propertyValue != null) || (existing.getValue() != null && propertyValue == null) || (existing.getValue() != null && !existing.getValue().equals(propertyValue))) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16048, edmProperty.getName()));
            }
        }
    }
    int i = 0;
    for (Property prop : entity.getProperties()) {
        EdmProperty edmProp = (EdmProperty) entityType.getProperty(prop.getName());
        Column column = entityTable.getColumnByName(edmProp.getName());
        insert.addVariable(new ElementSymbol(column.getName(), resource.getGroupSymbol()));
        if (prepared) {
            referenceValues.add(new Reference(i++));
            this.params.add(asParam(edmProp, prop.getValue()));
        } else {
            constantValues.add(new Constant(asParam(edmProp, prop.getValue()).getValue()));
        }
    }
    if (prepared) {
        insert.setValues(referenceValues);
    } else {
        insert.setValues(constantValues);
    }
    return insert;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Column(org.teiid.metadata.Column) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) Property(org.apache.olingo.commons.api.data.Property) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty)

Example 89 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class ODataSQLBuilder method processExpandOption.

private void processExpandOption(ExpandOption option, DocumentNode node, Query outerQuery, int expandLevel, Integer cyclicLevel) throws TeiidException {
    checkExpandLevel(expandLevel);
    int starLevels = 0;
    HashSet<String> seen = new HashSet<String>();
    for (ExpandItem ei : option.getExpandItems()) {
        if (ei.getSearchOption() != null) {
            throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16035, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16035));
        }
        Integer levels = null;
        if (cyclicLevel != null) {
            levels = cyclicLevel - 1;
        } else if (ei.getLevelsOption() != null) {
            if (ei.getLevelsOption().isMax()) {
                levels = MAX_EXPAND_LEVEL - expandLevel + 1;
            } else {
                levels = ei.getLevelsOption().getValue();
                checkExpandLevel(expandLevel + levels - 1);
            }
        }
        ExpandSQLBuilder esb = new ExpandSQLBuilder(ei);
        EdmNavigationProperty property = esb.getNavigationProperty();
        if (property == null) {
            if (ei.isStar()) {
                if (starLevels > 0) {
                    throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, // $NON-NLS-1$
                    ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, "*"));
                }
                if (levels != null) {
                    starLevels = levels;
                } else {
                    starLevels = 1;
                }
                continue;
            }
            throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16057, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16057));
        }
        if (!seen.add(property.getName())) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, property.getName()));
        }
        // always pass in the root as the parent as that seems to be the definition of the current context
        // if instead it should refer to the parent expands, then we would pass in the node instead
        ExpandDocumentNode expandResource = ExpandDocumentNode.buildExpand(property, this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService, this.context);
        node.addExpand(expandResource);
        // process $filter
        if (ei.getFilterOption() != null) {
            Expression expandCriteria = processFilterOption(ei.getFilterOption(), expandResource);
            expandResource.addCriteria(expandCriteria);
        }
        OrderBy expandOrder = null;
        if (ei.getOrderByOption() != null) {
            expandOrder = new OrderBy();
            processOrderBy(expandOrder, ei.getOrderByOption().getOrders(), expandResource);
        } else {
            expandOrder = expandResource.addDefaultOrderBy();
        }
        // process $select
        processSelectOption(ei.getSelectOption(), expandResource, this.reference);
        if (ei.getSkipOption() != null) {
            expandResource.setSkip(ei.getSkipOption().getValue());
        }
        if (ei.getTopOption() != null) {
            expandResource.setTop(ei.getTopOption().getValue());
        }
        Query query = expandResource.buildQuery();
        if (ei.getExpandOption() != null) {
            processExpandOption(ei.getExpandOption(), expandResource, query, expandLevel + 1, null);
        } else if (levels != null) {
            // self reference check
            if (!property.getType().getFullQualifiedName().equals(node.getEdmEntityType().getFullQualifiedName())) {
                throw new TeiidProcessingException(ODataPlugin.Event.TEIID16060, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16060, node.getEdmEntityType().getFullQualifiedName(), property.getType().getFullQualifiedName()));
            }
            if (levels > 1) {
                ExpandOptionImpl eoi = new ExpandOptionImpl();
                eoi.addExpandItem(ei);
                processExpandOption(eoi, expandResource, query, expandLevel + 1, levels);
            }
        }
        buildAggregateQuery(node, outerQuery, expandResource, expandOrder, query, property);
    }
    if (starLevels > 0) {
        List<ExpandNode> starExpand = new ArrayList<TeiidServiceHandler.ExpandNode>();
        EdmEntityType edmEntityType = node.getEdmEntityType();
        buildExpandGraph(seen, starExpand, edmEntityType, starLevels - 1);
        if (!starExpand.isEmpty()) {
            processExpand(starExpand, node, outerQuery, expandLevel);
        }
    }
}
Also used : ExpandOptionImpl(org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl) ExpandNode(org.teiid.olingo.service.TeiidServiceHandler.ExpandNode) ArrayList(java.util.ArrayList) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Expression(org.teiid.query.sql.symbol.Expression) HashSet(java.util.HashSet)

Example 90 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class OperationResponseImpl method getComplexProperty.

private ComplexValue getComplexProperty(ResultSet rs) throws SQLException {
    HashMap<Integer, Property> properties = new HashMap<Integer, Property>();
    for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
        Object value = rs.getObject(i + 1);
        String propName = rs.getMetaData().getColumnLabel(i + 1);
        EdmElement element = ((EdmComplexType) this.procedureReturn.getReturnType().getType()).getProperty(propName);
        if (!(element instanceof EdmProperty) && !((EdmProperty) element).isPrimitive()) {
            throw new SQLException(new TeiidNotImplementedException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16024)));
        }
        EdmPropertyImpl edmProperty = (EdmPropertyImpl) element;
        Property property;
        try {
            property = EntityCollectionResponse.buildPropery(propName, (SingletonPrimitiveType) edmProperty.getType(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isCollection(), value);
            properties.put(i, property);
        } catch (IOException e) {
            throw new SQLException(e);
        } catch (TeiidProcessingException e) {
            throw new SQLException(e);
        }
    }
    // filter those columns out.
    return createComplex("result", properties.values());
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) IOException(java.io.IOException) EdmElement(org.apache.olingo.commons.api.edm.EdmElement) EdmComplexType(org.apache.olingo.commons.api.edm.EdmComplexType) EdmPropertyImpl(org.apache.olingo.commons.core.edm.EdmPropertyImpl) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) Property(org.apache.olingo.commons.api.data.Property) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6