Search in sources :

Example 96 with TeiidRuntimeException

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceNavigation info) {
    try {
        DocumentNode navigationResource = DocumentNode.build((EdmEntityType) info.getType(), info.getKeyPredicates(), this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService);
        Query query = new Query();
        query.setSelect(new Select(Arrays.asList(new AggregateSymbol(AggregateSymbol.Type.COUNT.name(), false, null))));
        query.setFrom(new From(Arrays.asList(navigationResource.getFromClause())));
        Criteria criteria = this.ctxQuery.buildJoinCriteria(navigationResource, info.getProperty());
        if (criteria == null) {
            throw new TeiidException(ODataPlugin.Event.TEIID16037, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16037));
        }
        query.setCriteria(criteria);
        this.stack.add(new ScalarSubquery(query));
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 97 with TeiidRuntimeException

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(Method expr) {
    List<org.teiid.query.sql.symbol.Expression> teiidExprs = new ArrayList<org.teiid.query.sql.symbol.Expression>();
    for (Expression exp : expr.getParameters()) {
        accept(exp);
        teiidExprs.add(this.stack.pop());
    }
    switch(expr.getMethod()) {
        case CONTAINS:
            CompareCriteria criteria = new CompareCriteria(new Function("LOCATE", new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(1), teiidExprs.get(0), new Constant(1) }), CompareCriteria.GE, // $NON-NLS-1$
            new Constant(1));
            this.stack.push(criteria);
            break;
        case STARTSWITH:
            criteria = new CompareCriteria(new Function("LOCATE", new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(1), teiidExprs.get(0), new Constant(1) }), CompareCriteria.EQ, // $NON-NLS-1$
            new Constant(1));
            this.stack.push(criteria);
            break;
        case ENDSWITH:
            criteria = new CompareCriteria(new Function("ENDSWITH", new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(1), teiidExprs.get(0) }), CompareCriteria.EQ, // $NON-NLS-1$
            new Constant(Boolean.TRUE));
            this.stack.push(criteria);
            break;
        case LENGTH:
            this.stack.push(new Function("LENGTH", // $NON-NLS-1$
            new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0) }));
            break;
        case INDEXOF:
            stack.push(minusOne(new Function("LOCATE", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(1), teiidExprs.get(0) })));
            break;
        case SUBSTRING:
            org.teiid.query.sql.symbol.Expression[] exprs = teiidExprs.toArray(new org.teiid.query.sql.symbol.Expression[teiidExprs.size()]);
            exprs[1] = addOne(exprs[1]);
            // $NON-NLS-1$
            this.stack.push(new Function("SUBSTRING", exprs));
            break;
        case TOLOWER:
            this.stack.push(new Function("LCASE", // $NON-NLS-1$
            new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0) }));
            break;
        case TOUPPER:
            this.stack.push(new Function("UCASE", // $NON-NLS-1$
            new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0) }));
            break;
        case TRIM:
            this.stack.push(new Function("TRIM", new org.teiid.query.sql.symbol.Expression[] { new Constant("BOTH"), new Constant(' '), // $NON-NLS-1$ //$NON-NLS-2$
            teiidExprs.get(0) }));
            break;
        case CONCAT:
            this.stack.push(new Function("CONCAT", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0), teiidExprs.get(1) }));
            break;
        case YEAR:
            this.stack.push(new Function("YEAR", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case MONTH:
            this.stack.push(new Function("MONTH", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case DAY:
            this.stack.push(new Function("DAYOFMONTH", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case HOUR:
            this.stack.push(new Function("HOUR", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case MINUTE:
            this.stack.push(new Function("MINUTE", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case SECOND:
            this.stack.push(new Function("SECOND", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case NOW:
            // $NON-NLS-1$
            this.stack.push(new Function("NOW", new org.teiid.query.sql.symbol.Expression[] {}));
            break;
        case ROUND:
            stack.push(new Function("ROUND", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0), new Constant(0) }));
            break;
        case FLOOR:
            this.stack.push(new Function("FLOOR", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case CEILING:
            this.stack.push(new Function("CEILING", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
            { teiidExprs.get(0) }));
            break;
        case CAST:
            this.stack.push(new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0), teiidExprs.get(1) }));
            break;
        case DATE:
            this.stack.push(new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0), new Constant(DataTypeManager.DefaultDataTypes.DATE) }));
            break;
        case TIME:
            this.stack.push(new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0), new Constant(DataTypeManager.DefaultDataTypes.TIME) }));
            break;
        case FRACTIONALSECONDS:
        case TOTALSECONDS:
        case TOTALOFFSETMINUTES:
        case MINDATETIME:
        case MAXDATETIME:
        case GEODISTANCE:
        case GEOLENGTH:
        case GEOINTERSECTS:
        case ISOF:
        default:
            throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16027, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16027, expr.getMethod())));
    }
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Function(org.teiid.query.sql.symbol.Function) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression)

Example 98 with TeiidRuntimeException

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(Binary expr) {
    accept(expr.getLeftOperand());
    org.teiid.query.sql.symbol.Expression lhs = this.stack.pop();
    accept(expr.getRightOperand());
    org.teiid.query.sql.symbol.Expression rhs = this.stack.pop();
    org.teiid.query.sql.symbol.Expression binaryExpr = null;
    switch(expr.getOperator()) {
        case HAS:
            // TODO: not supported. What would be SQL equivalent?
            throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16036, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16036)));
        case MUL:
            // $NON-NLS-1$
            binaryExpr = new Function("*", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
            break;
        case DIV:
            // $NON-NLS-1$
            binaryExpr = new Function("/", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
            break;
        case MOD:
            // $NON-NLS-1$
            binaryExpr = new Function("MOD", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
            break;
        case ADD:
            // $NON-NLS-1$
            binaryExpr = new Function("+", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
            break;
        case SUB:
            // $NON-NLS-1$
            binaryExpr = new Function("-", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
            break;
        case GT:
            binaryExpr = new CompareCriteria(lhs, CompareCriteria.GT, rhs);
            break;
        case GE:
            binaryExpr = new CompareCriteria(lhs, CompareCriteria.GE, rhs);
            break;
        case LT:
            binaryExpr = new CompareCriteria(lhs, CompareCriteria.LT, rhs);
            break;
        case LE:
            binaryExpr = new CompareCriteria(lhs, CompareCriteria.LE, rhs);
            break;
        case EQ:
            if (rhs instanceof Constant && ((Constant) rhs).getType() == DataTypeManager.DefaultDataClasses.NULL) {
                binaryExpr = new IsNullCriteria(lhs);
            } else {
                binaryExpr = new CompareCriteria(lhs, CompareCriteria.EQ, rhs);
            }
            break;
        case NE:
            if (rhs instanceof Constant && ((Constant) rhs).getType() == DataTypeManager.DefaultDataClasses.NULL) {
                IsNullCriteria crit = new IsNullCriteria(lhs);
                crit.setNegated(true);
                binaryExpr = crit;
            } else {
                binaryExpr = new CompareCriteria(lhs, CompareCriteria.NE, rhs);
            }
            break;
        case AND:
            binaryExpr = new CompoundCriteria(CompoundCriteria.AND, (Criteria) lhs, (Criteria) rhs);
            break;
        case OR:
            binaryExpr = new CompoundCriteria(CompoundCriteria.OR, (Criteria) lhs, (Criteria) rhs);
            break;
    }
    this.stack.push(binaryExpr);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Function(org.teiid.query.sql.symbol.Function) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression)

Example 99 with TeiidRuntimeException

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

the class EventDistributorImpl method dataModification.

@Override
public ResultsFuture<?> dataModification(String vdbName, String vdbVersion, String schema, String tableName, Object[] oldValues, Object[] newValues, String[] columnNames) {
    VDBMetaData vdb = getVdbRepository().getLiveVDB(vdbName, vdbVersion);
    if (vdb == null) {
        return null;
    }
    TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
    if (tm == null) {
        return null;
    }
    // lookup, call triggers
    Table t = getTable(vdbName, vdbVersion, schema, tableName);
    if (t == null) {
        return null;
    }
    // notify of just the table modification
    dataModification(vdbName, vdbVersion, schema, tableName);
    if (oldValues == null && newValues == null) {
        return null;
    }
    if (!t.getTriggers().isEmpty()) {
        if (columnNames != null) {
            if ((oldValues != null && oldValues.length != columnNames.length) || (newValues != null && newValues.length != columnNames.length)) {
                throw new IllegalArgumentException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40162));
            }
        } else {
            if ((oldValues != null && oldValues.length != t.getColumns().size()) || (newValues != null && newValues.length != t.getColumns().size())) {
                throw new IllegalArgumentException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40163));
            }
        }
        // create command
        SourceEventCommand sec = new SourceEventCommand(t, oldValues, newValues, columnNames);
        try {
            return DQPCore.executeQuery(sec, vdb, "admin", "event-distributor", -1, getDQPCore(), new // $NON-NLS-1$ //$NON-NLS-2$
            DQPCore.ResultsListener() {

                @Override
                public void onResults(List<String> columns, List<? extends List<?>> results) throws Exception {
                // no result
                }
            });
        } catch (Throwable throwable) {
            throw new TeiidRuntimeException(throwable);
        }
    }
    return null;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) DQPCore(org.teiid.dqp.internal.process.DQPCore) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) SourceEventCommand(org.teiid.query.optimizer.SourceTriggerActionPlanner.SourceEventCommand) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData)

Example 100 with TeiidRuntimeException

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

the class EmbeddedServer method startTransport.

private SocketListener startTransport(SocketConfiguration socketConfig, BufferManager bm, int maxODBCLobSize) {
    InetSocketAddress address = null;
    try {
        address = new InetSocketAddress(socketConfig.getResolvedHostAddress(), socketConfig.getPortNumber());
    } catch (UnknownHostException e) {
        throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40065, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40065));
    }
    if (socketConfig.getProtocol() == WireProtocol.teiid) {
        return new SocketListener(address, socketConfig, this.services, bm) {

            @Override
            public ChannelListener createChannelListener(ObjectChannel channel) {
                // TODO: this is a little dirty, but allows us to inject the appropriate connection profile
                SocketClientInstance instance = (SocketClientInstance) super.createChannelListener(channel);
                instance.getWorkContext().setConnectionProfile(embeddedProfile);
                return instance;
            }
        };
    } else if (socketConfig.getProtocol() == WireProtocol.pg) {
        ODBCSocketListener odbc = new ODBCSocketListener(address, socketConfig, this.services, bm, maxODBCLobSize, this.logon, driver);
        return odbc;
    }
    // $NON-NLS-1$
    throw new AssertionError("Unknown protocol " + socketConfig.getProtocol());
}
Also used : UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ObjectChannel(org.teiid.net.socket.ObjectChannel)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4