Search in sources :

Example 51 with TeiidRuntimeException

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

the class MaterializationManager method executeQuery.

public List<Map<String, String>> executeQuery(VDBMetaData vdb, String command) throws SQLException {
    final List<Map<String, String>> rows = new ArrayList<Map<String, String>>();
    try {
        Future<?> f = DQPCore.executeQuery(command, vdb, "embedded-async", "internal", -1, getDQP(), new // $NON-NLS-1$ //$NON-NLS-2$
        DQPCore.ResultsListener() {

            @Override
            public void onResults(List<String> columns, List<? extends List<?>> results) throws Exception {
                for (List<?> row : results) {
                    TreeMap<String, String> rowResult = new TreeMap<String, String>();
                    for (int colNum = 0; colNum < columns.size(); colNum++) {
                        Object value = row.get(colNum);
                        if (value != null) {
                            if (value instanceof Timestamp) {
                                value = ((Timestamp) value).getTime();
                            }
                        }
                        rowResult.put(columns.get(colNum), value == null ? null : value.toString());
                    }
                    rows.add(rowResult);
                }
            }
        });
        f.get();
    } catch (InterruptedException e) {
        // break
        throw new TeiidRuntimeException(e);
    } catch (ExecutionException e) {
        if (e.getCause() != null) {
            throw new SQLException(e.getCause());
        }
        throw new SQLException(e);
    } catch (Throwable e) {
        throw new SQLException(e);
    }
    return rows;
}
Also used : DQPCore(org.teiid.dqp.internal.process.DQPCore) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TreeMap(java.util.TreeMap) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 52 with TeiidRuntimeException

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

the class SocketListener method stop.

/**
 * Stops the {@link SocketListener}
 * @return a Future if the transport was started successfully
 * that can notify of successfully killing all clients
 */
public Future<?> stop() {
    ChannelFuture future = this.serverChannel.closeFuture();
    Future<?> shutdown = null;
    if (this.bootstrap != null) {
        shutdown = bootstrap.group().shutdownGracefully(0, 0, TimeUnit.SECONDS);
        bootstrap = null;
    }
    try {
        future.await();
    } catch (InterruptedException e) {
        throw new TeiidRuntimeException(e);
    }
    return shutdown;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 53 with TeiidRuntimeException

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

the class PISQLConversionVisitor method visit.

@Override
public void visit(Join obj) {
    TableReference leftItem = obj.getLeftItem();
    TableReference rightItem = obj.getRightItem();
    JoinType joinType = obj.getJoinType();
    boolean ignoreOnClause = false;
    Condition condition = obj.getCondition();
    if (useParensForJoins() && leftItem instanceof Join) {
        buffer.append(Tokens.LPAREN);
        append(leftItem);
        buffer.append(Tokens.RPAREN);
    } else {
        append(leftItem);
    }
    buffer.append(Tokens.SPACE);
    switch(joinType) {
        case CROSS_JOIN:
            if (hasLateralJoin(rightItem)) {
                if (!isTVF(rightItem)) {
                    throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11025, rightItem));
                }
                buffer.append(CROSS).append(Tokens.SPACE).append(APPLY).append(Tokens.SPACE);
                ignoreOnClause = true;
            } else {
                // "a cross join b" is the same as "a inner join b on (1 = 1)"
                buffer.append(INNER).append(Tokens.SPACE).append(JOIN).append(Tokens.SPACE);
                Literal e1 = LanguageFactory.INSTANCE.createLiteral(new Integer(1), Integer.class);
                Comparison criteria = new Comparison(e1, e1, Operator.EQ);
                condition = criteria;
            }
            break;
        case FULL_OUTER_JOIN:
            // should not get here as capabilities are turned off.
            throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11024, "FULL OUTER"));
        case INNER_JOIN:
            buffer.append(INNER).append(Tokens.SPACE).append(JOIN).append(Tokens.SPACE);
            break;
        case LEFT_OUTER_JOIN:
            if (!hasLateralJoin(leftItem) && !hasLateralJoin(rightItem)) {
                buffer.append(LEFT).append(Tokens.SPACE).append(OUTER).append(Tokens.SPACE).append(JOIN).append(Tokens.SPACE);
            } else if (hasLateralJoin(leftItem)) {
                throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11024, "RIGHT OUTER APPLY"));
            } else if (hasLateralJoin(rightItem)) {
                if (!isTVF(rightItem)) {
                    throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11025, rightItem));
                }
                buffer.append(OUTER).append(Tokens.SPACE).append(APPLY).append(Tokens.SPACE);
                ignoreOnClause = true;
            }
            break;
        case RIGHT_OUTER_JOIN:
            // right outer is never pushed, so we should probably never get here.
            throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11024, "RIGHT OUTER"));
        default:
            buffer.append(UNDEFINED);
    }
    if (rightItem instanceof Join && (useParensForJoins() || obj.getJoinType() == Join.JoinType.CROSS_JOIN)) {
        buffer.append(Tokens.LPAREN);
        append(hasLateralJoin(rightItem) ? unwrap(rightItem) : rightItem);
        buffer.append(Tokens.RPAREN);
    } else {
        append(hasLateralJoin(rightItem) ? unwrap(rightItem) : rightItem);
    }
    if (condition != null && !ignoreOnClause) {
        buffer.append(Tokens.SPACE).append(ON).append(Tokens.SPACE);
        append(condition);
    }
}
Also used : JoinType(org.teiid.language.Join.JoinType) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 54 with TeiidRuntimeException

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

the class TranslationHelper method loadUDFs.

public static void loadUDFs(String udf, TranslationUtility util) {
    try {
        Collection<FunctionMethod> methods = FunctionMetadataReader.loadFunctionMethods(TranslationHelper.class.getResource(udf).openStream());
        // $NON-NLS-1$
        util.addUDF("foo", methods);
    } catch (IOException e) {
        // $NON-NLS-1$
        throw new TeiidRuntimeException("failed to load UDF");
    } catch (XMLStreamException e) {
        // $NON-NLS-1$
        throw new TeiidRuntimeException("failed to load UDF");
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FunctionMethod(org.teiid.metadata.FunctionMethod) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 55 with TeiidRuntimeException

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

the class ODataEntitySchemaBuilder method buildMetadata.

static EdmDataServices buildMetadata(MetadataStore metadataStore) {
    try {
        List<EdmSchema.Builder> edmSchemas = new ArrayList<EdmSchema.Builder>();
        for (Schema schema : metadataStore.getSchemaList()) {
            buildEntityTypes(schema, edmSchemas, true);
            buildFunctionImports(schema, edmSchemas, true);
            buildAssosiationSets(schema, edmSchemas, true);
        }
        return EdmDataServices.newBuilder().addSchemas(edmSchemas).build();
    } catch (Exception e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : Builder(org.odata4j.edm.EdmSchema.Builder) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

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