org.apache.calcite.avatica.AvaticaResultSet Java Examples

The following examples show how to use org.apache.calcite.avatica.AvaticaResultSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrayFactoryImpl.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public ResultSet create(AvaticaType elementType, Iterable<Object> elements)
    throws SQLException {
  // The ColumnMetaData for offset "1" in the ResultSet for an Array.
  ScalarType arrayOffsetType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.PRIMITIVE_INT);
  // Two columns (types) in the ResultSet we will create
  List<ColumnMetaData> types = Arrays.asList(ColumnMetaData.dummy(arrayOffsetType, false),
      ColumnMetaData.dummy(elementType, true));
  List<List<Object>> rows = createResultSetRowsForArrayData(elements);
  // `(List<Object>) rows` is a compile error.
  @SuppressWarnings({ "unchecked", "rawtypes" })
  List<Object> untypedRows = (List<Object>) ((List) rows);
  try (ListIteratorCursor cursor = new ListIteratorCursor(rows.iterator())) {
    final String sql = "MOCKED";
    QueryState state = new QueryState(sql);
    Meta.Signature signature = new Meta.Signature(types, sql,
        Collections.<AvaticaParameter>emptyList(), Collections.<String, Object>emptyMap(),
        Meta.CursorFactory.LIST, Meta.StatementType.SELECT);
    AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(null, sql,
        signature);
    Meta.Frame frame = new Meta.Frame(0, true, untypedRows);
    AvaticaResultSet resultSet = new AvaticaResultSet(null, state, signature, resultSetMetaData,
        timeZone, frame);
    resultSet.execute2(cursor, types);
    return resultSet;
  }
}
 
Example #2
Source File: QuarkStatement.java    From quark with Apache License 2.0 6 votes vote down vote up
@Override
protected void close_() {
  if (!closed) {
    closed = true;
    final QuarkConnectionImpl connection1 =
        (QuarkConnectionImpl) connection;
    connection1.server.removeStatement(handle);
    if (openResultSet != null) {
      AvaticaResultSet c = openResultSet;
      openResultSet = null;
      c.close();
    }
    // If onStatementClose throws, this method will throw an exception (later
    // converted to SQLException), but this statement still gets closed.
    connection1.getDriver().handler.onStatementClose(this);
  }
}
 
Example #3
Source File: QuicksqlJdbc41Factory.java    From Quicksql with MIT License 5 votes vote down vote up
public AvaticaResultSet newResultSet(AvaticaStatement statement, QueryState state,
    Signature signature, TimeZone timeZone, Meta.Frame firstFrame)
    throws SQLException {
  final ResultSetMetaData metaData =
      newResultSetMetaData(statement, signature);
  QuicksqlConnectionImpl connection = (QuicksqlConnectionImpl)statement.getConnection();
  return new QuicksqlResultSet(statement, signature, metaData, timeZone,
      firstFrame);
}
 
Example #4
Source File: KylinResultSet.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected AvaticaResultSet execute() throws SQLException {

    // skip execution if result is already there (case of meta data lookup)
    if (this.firstFrame != null) {
        return super.execute();
    }

    String sql = signature.sql;
    List<AvaticaParameter> params = signature.parameters;
    List<Object> paramValues = null;
    if (!(statement instanceof KylinPreparedStatement)) {
        params = null;
    } else if (params != null && !params.isEmpty()) {
        paramValues = ((KylinPreparedStatement) statement).getParameterJDBCValues();
    }

    KylinConnection connection = (KylinConnection) statement.connection;
    IRemoteClient client = connection.getRemoteClient();

    Map<String, String> queryToggles = new HashMap<>();
    int maxRows = statement.getMaxRows();
    queryToggles.put("ATTR_STATEMENT_MAX_ROWS", String.valueOf(maxRows));
    addServerProps(queryToggles, connection);

    QueryResult result;
    try {
        result = client.executeQuery(sql, paramValues, queryToggles);
    } catch (IOException e) {
        throw new SQLException(e);
    }

    columnMetaDataList.clear();
    columnMetaDataList.addAll(result.columnMeta);

    cursor = MetaImpl.createCursor(signature.cursorFactory, result.iterable);
    return super.execute2(cursor, columnMetaDataList);
}
 
Example #5
Source File: QuarkJdbc41Factory.java    From quark with Apache License 2.0 5 votes vote down vote up
@Override
public AvaticaResultSet newResultSet(AvaticaStatement statement,
                                     QueryState state,
                                     Meta.Signature signature,
                                     TimeZone timeZone,
                                     Meta.Frame firstFrame) {
  final ResultSetMetaData metaData =
      newResultSetMetaData(statement, signature);
  return new QuarkResultSet(statement, signature, metaData, timeZone,
      firstFrame);
}
 
Example #6
Source File: KylinResultSet.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected AvaticaResultSet execute() throws SQLException {

    // skip execution if result is already there (case of meta data lookup)
    if (this.firstFrame != null) {
        return super.execute();
    }

    String sql = signature.sql;
    List<AvaticaParameter> params = signature.parameters;
    List<Object> paramValues = null;
    if (!(statement instanceof KylinPreparedStatement)) {
        params = null;
    } else if (params != null && !params.isEmpty()) {
        paramValues = ((KylinPreparedStatement) statement).getParameterJDBCValues();
    }

    KylinConnection connection = (KylinConnection) statement.connection;
    IRemoteClient client = connection.getRemoteClient();

    Map<String, String> queryToggles = new HashMap<>();
    int maxRows = statement.getMaxRows();
    queryToggles.put("ATTR_STATEMENT_MAX_ROWS", String.valueOf(maxRows));
    addServerProps(queryToggles, connection);

    QueryResult result;
    try {
        result = client.executeQuery(sql, paramValues, queryToggles);
    } catch (IOException e) {
        throw new SQLException(e);
    }

    columnMetaDataList.clear();
    columnMetaDataList.addAll(result.columnMeta);

    cursor = MetaImpl.createCursor(signature.cursorFactory, result.iterable);
    return super.execute2(cursor, columnMetaDataList);
}
 
Example #7
Source File: QuicksqlResultSet.java    From Quicksql with MIT License 4 votes vote down vote up
@Override
protected AvaticaResultSet execute() throws SQLException {
    return this;
}
 
Example #8
Source File: KylinJdbcFactory.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public AvaticaResultSet newResultSet(AvaticaStatement statement, QueryState state, Signature signature, TimeZone timeZone, Frame firstFrame) throws SQLException {
    AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(statement, null, signature);
    return new KylinResultSet(statement, state, signature, resultSetMetaData, timeZone, firstFrame);
}
 
Example #9
Source File: KylinJdbcFactory.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public AvaticaResultSet newResultSet(AvaticaStatement statement, QueryState state, Signature signature, TimeZone timeZone, Frame firstFrame) throws SQLException {
    AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(statement, null, signature);
    return new KylinResultSet(statement, state, signature, resultSetMetaData, timeZone, firstFrame);
}