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);
}
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);
}
}
Aggregations