org.apache.calcite.avatica.QueryState Java Examples

The following examples show how to use org.apache.calcite.avatica.QueryState. 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: QuicksqlRemoteMeta.java    From Quicksql with MIT License 6 votes vote down vote up
@Override public boolean syncResults(final StatementHandle h, final QueryState state,
    final long offset) throws NoSuchStatementException {
  try {
    return connection.invokeWithRetries(
        new CallableWithoutException<Boolean>() {
          public Boolean call() {
            final Service.SyncResultsResponse response =
                service.apply(
                    new Service.SyncResultsRequest(h.connectionId, h.id, state, offset));
            if (response.missingStatement) {
              throw new RuntimeException(new NoSuchStatementException(h));
            }
            return response.moreResults;
          }
        });
  } catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof NoSuchStatementException) {
      throw (NoSuchStatementException) cause;
    }
    throw e;
  }
}
 
Example #2
Source File: RemoteMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public boolean syncResults(final StatementHandle h, final QueryState state,
    final long offset) throws NoSuchStatementException {
  try {
    return connection.invokeWithRetries(
        new CallableWithoutException<Boolean>() {
          public Boolean call() {
            final Service.SyncResultsResponse response =
                service.apply(
                    new Service.SyncResultsRequest(h.connectionId, h.id, state, offset));
            if (response.missingStatement) {
              throw new RuntimeException(new NoSuchStatementException(h));
            }
            return response.moreResults;
          }
        });
  } catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof NoSuchStatementException) {
      throw (NoSuchStatementException) cause;
    }
    throw e;
  }
}
 
Example #3
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 #4
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
public boolean syncResults(StatementHandle sh, QueryState state, long offset)
    throws NoSuchStatementException {
  try {
    final Connection conn = getConnection(sh.connectionId);
    final StatementInfo info = statementCache.getIfPresent(sh.id);
    if (null == info) {
      throw new NoSuchStatementException(sh);
    }
    final Statement statement = info.statement;
    // Let the state recreate the necessary ResultSet on the Statement
    info.setResultSet(state.invoke(conn, statement));

    if (null != info.getResultSet()) {
      // If it is non-null, try to advance to the requested offset.
      return info.advanceResultSetToOffset(info.getResultSet(), offset);
    }

    // No results, nothing to do. Client can move on.
    return false;
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
Example #5
Source File: Service.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
Request deserialize(Message genericMsg) {
  final Requests.SyncResultsRequest msg = ProtobufService.castProtobufMessage(genericMsg,
      Requests.SyncResultsRequest.class);

  String connectionId = null;
  if (msg.hasField(CONNECTION_ID_DESCRIPTOR)) {
    connectionId = msg.getConnectionId();
  }

  int statementId = 0;
  if (msg.hasField(STATEMENT_ID_DESCRIPTOR)) {
    statementId = msg.getStatementId();
  }

  Common.QueryState state = null;
  if (msg.hasField(STATE_DESCRIPTOR)) {
    state = msg.getState();
  }

  long offset = 0;
  if (msg.hasField(OFFSET_DESCRIPTOR)) {
    offset = msg.getOffset();
  }

  return new SyncResultsRequest(connectionId, statementId,
      null == state ? null : QueryState.fromProto(msg.getState()), offset);
}
 
Example #6
Source File: CalciteJdbc41Factory.java    From calcite with Apache License 2.0 5 votes vote down vote up
public CalciteResultSet newResultSet(AvaticaStatement statement, QueryState state,
    Meta.Signature signature, TimeZone timeZone, Meta.Frame firstFrame)
    throws SQLException {
  final ResultSetMetaData metaData =
      newResultSetMetaData(statement, signature);
  final CalcitePrepare.CalciteSignature calciteSignature =
      (CalcitePrepare.CalciteSignature) signature;
  return new CalciteResultSet(statement, calciteSignature, metaData, timeZone,
      firstFrame);
}
 
Example #7
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 #8
Source File: DremioJdbc41Factory.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public DremioResultSetImpl newResultSet(AvaticaStatement statement,
                                       QueryState state,
                                       Meta.Signature signature,
                                       TimeZone timeZone,
                                       Meta.Frame firstFrame) throws SQLException {
  final ResultSetMetaData metaData = newResultSetMetaData(statement, signature);
  return new DremioResultSetImpl(statement, state, signature, metaData, timeZone, firstFrame);
}
 
Example #9
Source File: DremioResultSetImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
DremioResultSetImpl(AvaticaStatement statement, QueryState state,
                   Meta.Signature signature, ResultSetMetaData resultSetMetaData,
                   TimeZone timeZone, Meta.Frame firstFrame) throws SQLException {
  super(statement, state, signature, resultSetMetaData, timeZone, firstFrame);
  connection = (DremioConnectionImpl) statement.getConnection();
  cursor = new DremioCursor(connection, statement, signature);
}
 
Example #10
Source File: ProtobufTranslationImplTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
private static QueryState getMetadataQueryState1() {
  return new QueryState(MetaDataOperation.GET_COLUMNS, new Object[] {
      "",
      null,
      "%",
      "%"
  });
}
 
Example #11
Source File: Service.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public SyncResultsRequest(@JsonProperty("connectionId") String connectionId,
    @JsonProperty("statementId") int statementId, @JsonProperty("state") QueryState state,
    @JsonProperty("offset") long offset) {
  this.connectionId = connectionId;
  this.statementId = statementId;
  this.state = state;
  this.offset = offset;
}
 
Example #12
Source File: CalciteJdbc41Factory.java    From Quicksql with MIT License 5 votes vote down vote up
public CalciteResultSet newResultSet(AvaticaStatement statement, QueryState state,
    Meta.Signature signature, TimeZone timeZone, Meta.Frame firstFrame)
    throws SQLException {
  final ResultSetMetaData metaData =
      newResultSetMetaData(statement, signature);
  final CalcitePrepare.CalciteSignature calciteSignature =
      (CalcitePrepare.CalciteSignature) signature;
  return new CalciteResultSet(statement, calciteSignature, metaData, timeZone,
      firstFrame);
}
 
Example #13
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 #14
Source File: DremioMetaImpl.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public boolean syncResults(StatementHandle sh, QueryState state, long offset) throws NoSuchStatementException {
  throw new UnsupportedOperationException();
}
 
Example #15
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 4 votes vote down vote up
@Override public Iterable<Object> createIterable(StatementHandle handle, QueryState state,
    Signature signature, List<TypedValue> parameterValues, Frame firstFrame) {
  // Drop QueryState
  return _createIterable(handle, signature, parameterValues, firstFrame);
}
 
Example #16
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
public boolean syncResults(StatementHandle h, QueryState state, long offset)
    throws NoSuchStatementException {
  // Doesn't have application in Calcite itself.
  throw new UnsupportedOperationException();
}
 
Example #17
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public Iterable<Object> createIterable(StatementHandle handle, QueryState state,
    Signature signature, List<TypedValue> parameterValues, Frame firstFrame) {
  // Drop QueryState
  return _createIterable(handle, signature, parameterValues, firstFrame);
}
 
Example #18
Source File: KylinMeta.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean syncResults(StatementHandle sh, QueryState state, long offset) throws NoSuchStatementException {
    // TODO Auto-generated method stub
    return false;
}
 
Example #19
Source File: KylinResultSet.java    From kylin with Apache License 2.0 4 votes vote down vote up
public KylinResultSet(AvaticaStatement statement, QueryState state, Signature signature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Frame firstFrame) throws SQLException {
    super(statement, state, signature, resultSetMetaData, timeZone, firstFrame);
}
 
Example #20
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);
}
 
Example #21
Source File: QuarkMetaImpl.java    From quark with Apache License 2.0 4 votes vote down vote up
public boolean syncResults(StatementHandle h, QueryState state, long offset)
    throws NoSuchStatementException {
  // Doesn't have application in Calcite itself.
  throw new UnsupportedOperationException();
}
 
Example #22
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 4 votes vote down vote up
public boolean syncResults(StatementHandle h, QueryState state, long offset)
    throws NoSuchStatementException {
  // Doesn't have application in Calcite itself.
  throw new UnsupportedOperationException();
}
 
Example #23
Source File: KylinMeta.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean syncResults(StatementHandle sh, QueryState state, long offset) throws NoSuchStatementException {
    // TODO Auto-generated method stub
    return false;
}
 
Example #24
Source File: ProtobufTranslationImplTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
private static QueryState getMetadataQueryState2() {
  return new QueryState(MetaDataOperation.GET_CATALOGS, new Object[0]);
}
 
Example #25
Source File: QuicksqlMetaImpl.java    From Quicksql with MIT License 4 votes vote down vote up
public boolean syncResults(StatementHandle h, QueryState state, long offset) {
    return false;
}
 
Example #26
Source File: ProtobufTranslationImplTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
private static QueryState getSqlQueryState() {
  return new QueryState("SELECT * from TABLE");
}
 
Example #27
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 4 votes vote down vote up
public Iterable<Object> createIterable(StatementHandle handle, QueryState state,
    Signature signature, List<TypedValue> parameterValues, Frame firstFrame) {
    return null;
}
 
Example #28
Source File: MetaImpl.java    From kareldb with Apache License 2.0 4 votes vote down vote up
public boolean syncResults(StatementHandle h, QueryState state, long offset)
    throws NoSuchStatementException {
    // Doesn't have application in Calcite itself.
    throw new UnsupportedOperationException();
}
 
Example #29
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 4 votes vote down vote up
public boolean syncResults(StatementHandle sh, QueryState state, long offset) {
    return true;
}
 
Example #30
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);
}