org.apache.calcite.avatica.AvaticaParameter Java Examples

The following examples show how to use org.apache.calcite.avatica.AvaticaParameter. 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: RemoteMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
private MetaResultSet toResultSet(Class clazz,
    Service.ResultSetResponse response) {
  if (response.updateCount != -1) {
    return MetaResultSet.count(response.connectionId, response.statementId,
        response.updateCount);
  }
  Signature signature0 = response.signature;
  if (signature0 == null) {
    final List<ColumnMetaData> columns =
        clazz == null
            ? Collections.<ColumnMetaData>emptyList()
            : fieldMetaData(clazz).columns;
    signature0 = Signature.create(columns,
        "?", Collections.<AvaticaParameter>emptyList(), CursorFactory.ARRAY,
        Meta.StatementType.SELECT);
  }
  return MetaResultSet.create(response.connectionId, response.statementId,
      response.ownStatement, signature0, response.firstFrame);
}
 
Example #2
Source File: CalcitePrepare.java    From calcite with Apache License 2.0 6 votes vote down vote up
public CalciteSignature(String sql,
    List<AvaticaParameter> parameterList,
    Map<String, Object> internalParameters,
    RelDataType rowType,
    List<ColumnMetaData> columns,
    Meta.CursorFactory cursorFactory,
    CalciteSchema rootSchema,
    List<RelCollation> collationList,
    long maxRowCount,
    Bindable<T> bindable,
    Meta.StatementType statementType) {
  super(columns, sql, parameterList, internalParameters, cursorFactory,
      statementType);
  this.rowType = rowType;
  this.rootSchema = rootSchema;
  this.collationList = collationList;
  this.maxRowCount = maxRowCount;
  this.bindable = bindable;
}
 
Example #3
Source File: QuarkMetaImpl.java    From quark with Apache License 2.0 6 votes vote down vote up
/**
 * Converts from JDBC metadata to Avatica parameters
 */
protected static List<AvaticaParameter> parameters(ParameterMetaData metaData)
    throws SQLException {
  if (metaData == null) {
    return Collections.emptyList();
  }
  final List<AvaticaParameter> params = new ArrayList<>();
  for (int i = 1; i <= metaData.getParameterCount(); i++) {
    params.add(
        new AvaticaParameter(metaData.isSigned(i), metaData.getPrecision(i),
            metaData.getScale(i), metaData.getParameterType(i),
            metaData.getParameterTypeName(i),
            metaData.getParameterClassName(i), "?" + i));
  }
  return params;
}
 
Example #4
Source File: QuarkMetaImpl.java    From quark with Apache License 2.0 6 votes vote down vote up
protected MetaResultSet createResultSet(
    Map<String, Object> internalParameters, List<ColumnMetaData> columns,
    CursorFactory cursorFactory, final Frame firstFrame) {
  try {
    final QuarkConnectionImpl connection = getConnection();
    final AvaticaStatement statement = connection.createStatement();
    final CalcitePrepare.CalciteSignature<Object> signature =
        new CalcitePrepare.CalciteSignature<Object>("",
            ImmutableList.<AvaticaParameter>of(), internalParameters, null,
            columns, cursorFactory, null, ImmutableList.<RelCollation>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);
  }
}
 
Example #5
Source File: JsonHandlerTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public ExecuteResponse apply(ExecuteRequest request) {
  expectedParameterValues.addAll(request.parameterValues);

  final Meta.Signature signature =
      new Meta.Signature(Collections.<ColumnMetaData>emptyList(),
          "SELECT 1 FROM VALUE()",
          Collections.<AvaticaParameter>emptyList(),
          Collections.<String, Object>emptyMap(),
          CursorFactory.LIST, Meta.StatementType.SELECT);

  final Service.ResultSetResponse resultSetResponse =
      new Service.ResultSetResponse(UUID.randomUUID().toString(),
          RANDOM.nextInt(), false, signature, Meta.Frame.EMPTY, -1L, null);

  return new Service.ExecuteResponse(
      Collections.singletonList(resultSetResponse), false, null);
}
 
Example #6
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 #7
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
/**
 * Converts from JDBC metadata to Avatica parameters
 */
protected static List<AvaticaParameter> parameters(ParameterMetaData metaData)
    throws SQLException {
  if (metaData == null) {
    return Collections.emptyList();
  }
  final List<AvaticaParameter> params = new ArrayList<>();
  for (int i = 1; i <= metaData.getParameterCount(); i++) {
    params.add(
        new AvaticaParameter(metaData.isSigned(i), metaData.getPrecision(i),
            metaData.getScale(i), metaData.getParameterType(i),
            metaData.getParameterTypeName(i),
            metaData.getParameterClassName(i), "?" + i));
  }
  return params;
}
 
Example #8
Source File: CalcitePrepare.java    From Quicksql with MIT License 6 votes vote down vote up
public CalciteSignature(String sql,
    List<AvaticaParameter> parameterList,
    Map<String, Object> internalParameters,
    RelDataType rowType,
    List<ColumnMetaData> columns,
    Meta.CursorFactory cursorFactory,
    CalciteSchema rootSchema,
    List<RelCollation> collationList,
    long maxRowCount,
    Bindable<T> bindable,
    Meta.StatementType statementType) {
  super(columns, sql, parameterList, internalParameters, cursorFactory,
      statementType);
  this.rowType = rowType;
  this.rootSchema = rootSchema;
  this.collationList = collationList;
  this.maxRowCount = maxRowCount;
  this.bindable = bindable;
}
 
Example #9
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 6 votes vote down vote up
/**
 * Converts from JDBC metadata to Avatica parameters
 */
protected static List<AvaticaParameter> parameters(ParameterMetaData metaData)
    throws SQLException {
    if (metaData == null) {
        return Collections.emptyList();
    }
    final List<AvaticaParameter> params = new ArrayList<>();
    for (int i = 1; i <= metaData.getParameterCount(); i++) {
        params.add(
            new AvaticaParameter(metaData.isSigned(i), metaData.getPrecision(i),
                metaData.getScale(i), metaData.getParameterType(i),
                metaData.getParameterTypeName(i),
                metaData.getParameterClassName(i), "?" + i));
    }
    return params;
}
 
Example #10
Source File: QuicksqlRemoteMeta.java    From Quicksql with MIT License 6 votes vote down vote up
private MetaResultSet toResultSet(Class clazz,
    Service.ResultSetResponse response) {
  if (response.updateCount != -1) {
    return MetaResultSet.count(response.connectionId, response.statementId,
        response.updateCount);
  }
  Signature signature0 = response.signature;
  if (signature0 == null) {
    final List<ColumnMetaData> columns =
        clazz == null
            ? Collections.<ColumnMetaData>emptyList()
            : fieldMetaData(clazz).columns;
    signature0 = Signature.create(columns,
        "?", Collections.<AvaticaParameter>emptyList(), CursorFactory.ARRAY,
        StatementType.SELECT);
  }
  return MetaResultSet.create(response.connectionId, response.statementId,
      response.ownStatement, signature0, response.firstFrame);
}
 
Example #11
Source File: DremioMetaImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
static Signature newSignature(String sql) {
  return new Signature(
      new DremioColumnMetaDataList(),
      sql,
      Collections.<AvaticaParameter> emptyList(),
      Collections.<String, Object>emptyMap(),
      null, // CursorFactory set to null, as SQL requests use DremioCursor
      StatementType.SELECT
      );
}
 
Example #12
Source File: CalcitePrepare.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public CalciteSignature(String sql, List<AvaticaParameter> parameterList,
    Map<String, Object> internalParameters, RelDataType rowType,
    List<ColumnMetaData> columns, Meta.CursorFactory cursorFactory,
    CalciteSchema rootSchema, List<RelCollation> collationList,
    long maxRowCount, Bindable<T> bindable) {
  this(sql, parameterList, internalParameters, rowType, columns,
      cursorFactory, rootSchema, collationList, maxRowCount, bindable,
      null);
}
 
Example #13
Source File: KylinConnection.java    From kylin with Apache License 2.0 5 votes vote down vote up
Signature mockPreparedSignature(String sql) {
    List<AvaticaParameter> params = new ArrayList<AvaticaParameter>();
    int startIndex = 0;
    while (sql.indexOf("?", startIndex) >= 0) {
        AvaticaParameter param = new AvaticaParameter(false, 0, 0, 0, null, null, null);
        params.add(param);
        startIndex = sql.indexOf("?", startIndex) + 1;
    }

    ArrayList<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    Map<String, Object> internalParams = Collections.<String, Object> emptyMap();

    return new Meta.Signature(columns, sql, params, internalParams, CursorFactory.ARRAY, Meta.StatementType.SELECT);
}
 
Example #14
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 #15
Source File: QuicksqlRemoteMeta.java    From Quicksql with MIT License 5 votes vote down vote up
Signature mockPreparedSignature(String sql) {
  List<AvaticaParameter> params = new ArrayList<AvaticaParameter>();
  int startIndex = 0;
  while (sql.indexOf("?", startIndex) >= 0) {
    AvaticaParameter param = new AvaticaParameter(false, 0, 0, 0, null, null, null);
    params.add(param);
    startIndex = sql.indexOf("?", startIndex) + 1;
  }

  ArrayList<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
  Map<String, Object> internalParams = Collections.<String, Object> emptyMap();

  return new Signature(columns, sql, params, internalParams, CursorFactory.ARRAY, StatementType.SELECT);
}
 
Example #16
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 #17
Source File: QuicksqlConnectionImpl.java    From Quicksql with MIT License 5 votes vote down vote up
public Signature mockPreparedSignature(String sql) {
    List<AvaticaParameter> params = new ArrayList<AvaticaParameter>();
    int startIndex = 0;
    while (sql.indexOf("?", startIndex) >= 0) {
        AvaticaParameter param = new AvaticaParameter(false, 0, 0, 0, null, null, null);
        params.add(param);
        startIndex = sql.indexOf("?", startIndex) + 1;
    }

    ArrayList<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    Map<String, Object> internalParams = Collections.<String, Object> emptyMap();

    return new Meta.Signature(columns, sql, params, internalParams, CursorFactory.ARRAY, Meta.StatementType.SELECT);
}
 
Example #18
Source File: CalcitePrepare.java    From Quicksql with MIT License 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public CalciteSignature(String sql, List<AvaticaParameter> parameterList,
    Map<String, Object> internalParameters, RelDataType rowType,
    List<ColumnMetaData> columns, Meta.CursorFactory cursorFactory,
    CalciteSchema rootSchema, List<RelCollation> collationList,
    long maxRowCount, Bindable<T> bindable) {
  this(sql, parameterList, internalParameters, rowType, columns,
      cursorFactory, rootSchema, collationList, maxRowCount, bindable,
      null);
}
 
Example #19
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 5 votes vote down vote up
public Signature preparedSignature(QueryResult res, String sql) {
    List<AvaticaParameter> params = new ArrayList<AvaticaParameter>();
    int startIndex = 0;
    while (sql.indexOf("?", startIndex) >= 0) {
        AvaticaParameter param = new AvaticaParameter(false, 0, 0, 0, null, null, null);
        params.add(param);
        startIndex = sql.indexOf("?", startIndex) + 1;
    }
    return new Signature(res.columnMeta, sql, params, Collections.<String, Object>emptyMap(), CursorFactory.ARRAY,
        StatementType.SELECT);
}
 
Example #20
Source File: KylinConnection.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
Signature mockPreparedSignature(String sql) {
    List<AvaticaParameter> params = new ArrayList<AvaticaParameter>();
    int startIndex = 0;
    while (sql.indexOf("?", startIndex) >= 0) {
        AvaticaParameter param = new AvaticaParameter(false, 0, 0, 0, null, null, null);
        params.add(param);
        startIndex = sql.indexOf("?", startIndex) + 1;
    }

    ArrayList<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    Map<String, Object> internalParams = Collections.<String, Object> emptyMap();

    return new Meta.Signature(columns, sql, params, internalParams, CursorFactory.ARRAY, Meta.StatementType.SELECT);
}
 
Example #21
Source File: DremioPreparedStatementImpl.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
protected AvaticaParameter getParameter(int param) throws SQLException {
  throwIfClosed();
  throw new SQLFeatureNotSupportedException(
      "Prepared-statement dynamic parameters are not supported.");
}
 
Example #22
Source File: ProtobufTranslationImplTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a collection of Responses whose serialization will be tested.
 */
private static List<Response> getResponses() {
  final RpcMetadataResponse rpcMetadata = new RpcMetadataResponse("localhost:8765");
  LinkedList<Response> responses = new LinkedList<>();

  // Nested classes (Signature, ColumnMetaData, CursorFactory, etc) are implicitly getting tested)

  // Stub out the metadata for a row
  ScalarType arrayComponentType = ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER);
  ColumnMetaData arrayColumnMetaData = getArrayColumnMetaData(arrayComponentType, 2, "counts");
  List<ColumnMetaData> columns =
      Arrays.asList(MetaImpl.columnMetaData("str", 0, String.class, true),
          MetaImpl.columnMetaData("count", 1, Integer.class, true),
          arrayColumnMetaData);
  List<AvaticaParameter> params =
      Arrays.asList(
          new AvaticaParameter(false, 10, 0, Types.VARCHAR, "VARCHAR",
              String.class.getName(), "str"));
  Meta.CursorFactory cursorFactory = Meta.CursorFactory.create(Style.LIST, Object.class,
      Arrays.asList("str", "count", "counts"));
  // The row values
  List<Object> rows = new ArrayList<>();
  rows.add(new Object[] {"str_value1", 50, Arrays.asList(1, 2, 3)});
  rows.add(new Object[] {"str_value2", 100, Arrays.asList(1)});

  // Create the signature and frame using the metadata and values
  Signature signature = Signature.create(columns, "sql", params, cursorFactory,
      Meta.StatementType.SELECT);
  Frame frame = Frame.create(Integer.MAX_VALUE, true, rows);

  // And then create a ResultSetResponse
  ResultSetResponse results1 = new ResultSetResponse("connectionId", Integer.MAX_VALUE, true,
      signature, frame, Long.MAX_VALUE, rpcMetadata);
  responses.add(results1);

  responses.add(new CloseStatementResponse(rpcMetadata));

  ConnectionPropertiesImpl connProps = new ConnectionPropertiesImpl(false, true,
      Integer.MAX_VALUE, "catalog", "schema");
  responses.add(new ConnectionSyncResponse(connProps, rpcMetadata));

  responses.add(new OpenConnectionResponse(rpcMetadata));
  responses.add(new CloseConnectionResponse(rpcMetadata));

  responses.add(new CreateStatementResponse("connectionId", Integer.MAX_VALUE, rpcMetadata));

  Map<Meta.DatabaseProperty, Object> propertyMap = new HashMap<>();
  for (Meta.DatabaseProperty prop : Meta.DatabaseProperty.values()) {
    propertyMap.put(prop, prop.defaultValue);
  }
  responses.add(new DatabasePropertyResponse(propertyMap, rpcMetadata));

  responses.add(
      new ExecuteResponse(Arrays.asList(results1, results1, results1), false, rpcMetadata));
  responses.add(new FetchResponse(frame, false, false, rpcMetadata));
  responses.add(new FetchResponse(frame, true, true, rpcMetadata));
  responses.add(new FetchResponse(frame, false, true, rpcMetadata));
  responses.add(
      new PrepareResponse(
          new Meta.StatementHandle("connectionId", Integer.MAX_VALUE, signature),
          rpcMetadata));

  StringWriter sw = new StringWriter();
  new Exception().printStackTrace(new PrintWriter(sw));
  responses.add(
      new ErrorResponse(Collections.singletonList(sw.toString()), "Test Error Message",
          ErrorResponse.UNKNOWN_ERROR_CODE, ErrorResponse.UNKNOWN_SQL_STATE,
          AvaticaSeverity.WARNING, rpcMetadata));

  // No more results, statement not missing
  responses.add(new SyncResultsResponse(false, false, rpcMetadata));
  // Missing statement, no results
  responses.add(new SyncResultsResponse(false, true, rpcMetadata));
  // More results, no missing statement
  responses.add(new SyncResultsResponse(true, false, rpcMetadata));

  // Some tests to make sure ErrorResponse doesn't fail.
  responses.add(new ErrorResponse((List<String>) null, null, 0, null, null, null));
  responses.add(
      new ErrorResponse(Arrays.asList("stacktrace1", "stacktrace2"), null, 0, null, null, null));

  responses.add(new CommitResponse());
  responses.add(new RollbackResponse());

  long[] updateCounts = new long[]{1, 0, 1, 1};
  responses.add(
      new ExecuteBatchResponse("connectionId", 12345, updateCounts, false, rpcMetadata));

  return responses;
}
 
Example #23
Source File: ProtobufTranslationImplTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a collection of Requests whose serialization will be tested.
 */
private static List<Request> getRequests() {
  LinkedList<Request> requests = new LinkedList<>();

  requests.add(new CatalogsRequest());
  requests.add(new DatabasePropertyRequest());
  requests.add(new SchemasRequest("connectionId", "catalog", "schemaPattern"));
  requests.add(
      new TablesRequest("connectionId", "catalog", "schemaPattern", "tableNamePattern",
          Arrays.asList("STRING", "BOOLEAN", "INT")));
  requests.add(new TableTypesRequest());
  requests.add(
      new ColumnsRequest("connectionId", "catalog", "schemaPattern", "tableNamePattern",
          "columnNamePattern"));
  requests.add(new TypeInfoRequest());
  requests.add(
      new PrepareAndExecuteRequest("connectionId", Integer.MAX_VALUE, "sql",
          Long.MAX_VALUE));
  requests.add(new PrepareRequest("connectionId", "sql", Long.MAX_VALUE));

  List<TypedValue> paramValues =
      Arrays.asList(TypedValue.create(Rep.BOOLEAN.name(), Boolean.TRUE),
          TypedValue.create(Rep.STRING.name(), "string"));
  FetchRequest fetchRequest = new FetchRequest("connectionId", Integer.MAX_VALUE,
      Long.MAX_VALUE, Integer.MAX_VALUE);
  requests.add(fetchRequest);

  requests.add(new CreateStatementRequest("connectionId"));
  requests.add(new CloseStatementRequest("connectionId", Integer.MAX_VALUE));
  Map<String, String> info = new HashMap<>();
  info.put("param1", "value1");
  info.put("param2", "value2");
  requests.add(new OpenConnectionRequest("connectionId", info));
  requests.add(new CloseConnectionRequest("connectionId"));
  requests.add(
      new ConnectionSyncRequest("connectionId",
          new ConnectionPropertiesImpl(Boolean.FALSE, Boolean.FALSE,
              Integer.MAX_VALUE, "catalog", "schema")));

  requests.add(new SyncResultsRequest("connectionId", 12345, getSqlQueryState(), 150));
  requests.add(new SyncResultsRequest("connectionId2", 54321, getMetadataQueryState1(), 0));
  requests.add(new SyncResultsRequest("connectionId3", 5, getMetadataQueryState2(), 10));

  requests.add(new CommitRequest("connectionId"));
  requests.add(new RollbackRequest("connectionId"));

  // ExecuteBatchRequest omitted because of the special protobuf conversion it does

  List<String> commands = Arrays.asList("command1", "command2", "command3");
  requests.add(new PrepareAndExecuteBatchRequest("connectionId", 12345, commands));


  List<ColumnMetaData> columns = Collections.emptyList();
  List<AvaticaParameter> params = Collections.emptyList();
  Meta.CursorFactory cursorFactory = Meta.CursorFactory.create(Style.LIST, Object.class,
      Collections.<String>emptyList());
  Signature signature = Signature.create(columns, "sql", params, cursorFactory,
      Meta.StatementType.SELECT);
  Meta.StatementHandle handle = new Meta.StatementHandle("1234", 1, signature);
  requests.add(new ExecuteRequest(handle, Arrays.<TypedValue>asList((TypedValue) null), 10));
  requests.add(new ExecuteRequest(handle, Arrays.asList(TypedValue.EXPLICIT_NULL), 10));

  return requests;
}
 
Example #24
Source File: PlanExecutor.java    From quark with Apache License 2.0 4 votes vote down vote up
private QuarkMetaResultSet getMetaResultSetFromIterator(Iterator<Object> iterator,
                                                QuarkConnectionImpl connection,
                                                ParserResult result,
                                                String sql,
                                                QuarkJdbcStatement stmt,
                                                Meta.StatementHandle h,
                                                long maxRowCount,
                                                Class clazz) throws SQLException {
  QuarkMetaResultSet metaResultSet;
  final JavaTypeFactory typeFactory =
      connection.getSqlQueryParser().getTypeFactory();
  final RelDataType x;
  switch (result.getKind()) {
    case INSERT:
    case EXPLAIN:
      x = RelOptUtil.createDmlRowType(result.getKind(), typeFactory);
      break;
    case OTHER_DDL:
      x = getRowType(clazz);
      break;
    default:
      x = result.getRelNode().getRowType();
  }
  RelDataType jdbcType = makeStruct(typeFactory, x);
  final List<ColumnMetaData> columns =
      getColumnMetaDataList(typeFactory, x, jdbcType);
  Meta.Signature signature = new Meta.Signature(columns,
      sql,
      new ArrayList<AvaticaParameter>(),
      new HashMap<String, Object>(),
      Meta.CursorFactory.ARRAY,
      Meta.StatementType.SELECT);
  stmt.setSignature(signature);
  stmt.setResultSet(iterator);
  if (signature.statementType.canUpdate()) {
    metaResultSet = QuarkMetaResultSet.count(h.connectionId, h.id,
        ((Number) iterator.next()).intValue());
  } else {
    metaResultSet = QuarkMetaResultSet.create(h.connectionId, h.id,
        iterator, maxRowCount, signature);
  }
  return metaResultSet;
}
 
Example #25
Source File: MockProtobufService.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
private Map<Request, Response> createMapping() {
  HashMap<Request, Response> mappings = new HashMap<>();

  // Add in mappings

  mappings.put(
      new OpenConnectionRequest(connectionId, new HashMap<String, String>()),
      new OpenConnectionResponse());

  // Get the schema, no.. schema..?
  mappings.put(
      new SchemasRequest(connectionId, null, null),
      // ownStatement=false just to avoid the extra close statement call.
      new ResultSetResponse(null, 1, false, null, Meta.Frame.EMPTY, -1, null));

  // Get the tables, no tables exist
  mappings.put(new TablesRequest(connectionId, null, null, null, Collections.<String>emptyList()),
      // ownStatement=false just to avoid the extra close statement call.
      new ResultSetResponse(null, 150, false, null, Meta.Frame.EMPTY, -1, null));

  // Create a statement, get back an id
  mappings.put(new CreateStatementRequest("0"), new CreateStatementResponse("0", 1, null));

  // Prepare and execute a query. Values and schema are returned
  mappings.put(
      new PrepareAndExecuteRequest(connectionId, 1,
          "select * from (\\n values (1, 'a'), (null, 'b'), (3, 'c')) as t (c1, c2)", -1),
      new ResultSetResponse("0", 1, true,
          Meta.Signature.create(
              Arrays.<ColumnMetaData>asList(
                  MetaImpl.columnMetaData("C1", 0, Integer.class, true),
                  MetaImpl.columnMetaData("C2", 1, String.class, true)),
              null, null, Meta.CursorFactory.ARRAY, Meta.StatementType.SELECT),
          Meta.Frame.create(0, true,
              Arrays.<Object>asList(new Object[] {1, "a"},
                  new Object[] {null, "b"}, new Object[] {3, "c"})), -1, null));

  // Prepare a query. Schema for results are returned, but no values
  mappings.put(
      new PrepareRequest(connectionId,
          "select * from (\\n values(1, 'a'), (null, 'b'), (3, 'c')), as t (c1, c2)", -1),
      new ResultSetResponse("0", 1, true,
          Meta.Signature.create(
              Arrays.<ColumnMetaData>asList(
                  MetaImpl.columnMetaData("C1", 0, Integer.class, true),
                  MetaImpl.columnMetaData("C2", 1, String.class, true)),
              null, Collections.<AvaticaParameter>emptyList(),
              Meta.CursorFactory.ARRAY, Meta.StatementType.SELECT),
          null, -1, null));

  mappings.put(
      new ColumnsRequest(connectionId, null, null, "my_table", null),
      new ResultSetResponse("00000000-0000-0000-0000-000000000000", -1, true,
          Meta.Signature.create(
              Arrays.<ColumnMetaData>asList(
                  MetaImpl.columnMetaData("TABLE_NAME", 0, String.class, true),
                  MetaImpl.columnMetaData("ORDINAL_POSITION", 1, Long.class, true)), null,
              Collections.<AvaticaParameter>emptyList(), Meta.CursorFactory.ARRAY, null),
          Meta.Frame.create(0, true,
              Arrays.<Object>asList(new Object[] {new Object[]{"my_table", 10}})), -1, null));

  return Collections.unmodifiableMap(mappings);
}