Search in sources :

Example 46 with DataContext

use of org.apache.calcite.DataContext in project traindb by traindb-project.

the class CalciteConnectionImpl method enumerable.

public <T> Enumerable<T> enumerable(Meta.StatementHandle handle, CalcitePrepare.CalciteSignature<T> signature) throws SQLException {
    Map<String, Object> map = new LinkedHashMap<>();
    AvaticaStatement statement = lookupStatement(handle);
    final List<TypedValue> parameterValues = TROJAN.getParameterValues(statement);
    if (MetaImpl.checkParameterValueHasNull(parameterValues)) {
        throw new SQLException("exception while executing query: unbound parameter");
    }
    Ord.forEach(parameterValues, (e, i) -> map.put("?" + i, e.toLocal()));
    map.putAll(signature.internalParameters);
    final AtomicBoolean cancelFlag;
    try {
        cancelFlag = getCancelFlag(handle);
    } catch (NoSuchStatementException e) {
        throw new RuntimeException(e);
    }
    map.put(DataContext.Variable.CANCEL_FLAG.camelName, cancelFlag);
    int queryTimeout = statement.getQueryTimeout();
    // Avoid overflow
    if (queryTimeout > 0 && queryTimeout < Integer.MAX_VALUE / 1000) {
        map.put(DataContext.Variable.TIMEOUT.camelName, queryTimeout * 1000L);
    }
    final DataContext dataContext = createDataContext(map, signature.rootSchema);
    return signature.enumerable(dataContext);
}
Also used : SQLException(java.sql.SQLException) LinkedHashMap(java.util.LinkedHashMap) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataContext(org.apache.calcite.DataContext) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException) TypedValue(org.apache.calcite.avatica.remote.TypedValue)

Example 47 with DataContext

use of org.apache.calcite.DataContext in project traindb by traindb-project.

the class CalciteMetaImpl method createResultSet.

@Override
protected MetaResultSet createResultSet(Map<String, Object> internalParameters, List<ColumnMetaData> columns, CursorFactory cursorFactory, final Frame firstFrame) {
    try {
        final CalciteConnectionImpl connection = getConnection();
        final AvaticaStatement statement = connection.createStatement();
        final CalcitePrepare.CalciteSignature<Object> signature = new CalcitePrepare.CalciteSignature<Object>("", ImmutableList.of(), internalParameters, null, columns, cursorFactory, null, ImmutableList.of(), -1, null, Meta.StatementType.SELECT) {

            @Override
            public Enumerable<Object> enumerable(DataContext dataContext) {
                return Linq4j.asEnumerable(firstFrame.rows);
            }
        };
        return MetaResultSet.create(connection.id, statement.getId(), true, signature, firstFrame);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : DataContext(org.apache.calcite.DataContext) SQLException(java.sql.SQLException) CalcitePrepare(org.apache.calcite.jdbc.CalcitePrepare) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement)

Aggregations

DataContext (org.apache.calcite.DataContext)47 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)10 RexNode (org.apache.calcite.rex.RexNode)8 Nullable (org.checkerframework.checker.nullness.qual.Nullable)8 HashMap (java.util.HashMap)7 RelDataType (org.apache.calcite.rel.type.RelDataType)7 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)7 Values (org.apache.storm.tuple.Values)7 Context (org.apache.calcite.interpreter.Context)6 StormContext (org.apache.calcite.interpreter.StormContext)6 SQLException (java.sql.SQLException)5 AvaticaStatement (org.apache.calcite.avatica.AvaticaStatement)5 TypedValue (org.apache.calcite.avatica.remote.TypedValue)5 Enumerable (org.apache.calcite.linq4j.Enumerable)5 ScannableTable (org.apache.calcite.schema.ScannableTable)5 URL (java.net.URL)4 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)4 Enumerator (org.apache.calcite.linq4j.Enumerator)4 RexBuilder (org.apache.calcite.rex.RexBuilder)4