Java Code Examples for org.apache.calcite.avatica.Meta#Frame
The following examples show how to use
org.apache.calcite.avatica.Meta#Frame .
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: CalciteMetaImpl.java From Quicksql with MIT License | 6 votes |
@Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues, int maxRowsInFirstFrame) throws NoSuchStatementException { final CalciteConnectionImpl calciteConnection = getConnection(); CalciteServerStatement stmt = calciteConnection.server.getStatement(h); final Signature signature = stmt.getSignature(); MetaResultSet metaResultSet; if (signature.statementType.canUpdate()) { final Iterable<Object> iterable = _createIterable(h, signature, parameterValues, null); final Iterator<Object> iterator = iterable.iterator(); stmt.setResultSet(iterator); metaResultSet = MetaResultSet.count(h.connectionId, h.id, ((Number) iterator.next()).intValue()); } else { // Don't populate the first frame. // It's not worth saving a round-trip, since we're local. final Meta.Frame frame = new Meta.Frame(0, false, Collections.emptyList()); metaResultSet = MetaResultSet.create(h.connectionId, h.id, false, signature, frame); } return new ExecuteResult(ImmutableList.of(metaResultSet)); }
Example 2
Source File: QuarkResultSet.java From quark with Apache License 2.0 | 6 votes |
@Override public ResultSet create(ColumnMetaData.AvaticaType elementType, Iterable<Object> iterable) { final List<ColumnMetaData> columnMetaDataList; if (elementType instanceof ColumnMetaData.StructType) { columnMetaDataList = ((ColumnMetaData.StructType) elementType).columns; } else { columnMetaDataList = ImmutableList.of(ColumnMetaData.dummy(elementType, false)); } final CalcitePrepare.CalciteSignature signature = (CalcitePrepare.CalciteSignature) this.signature; final CalcitePrepare.CalciteSignature<Object> newSignature = new CalcitePrepare.CalciteSignature<>(signature.sql, signature.parameters, signature.internalParameters, signature.rowType, columnMetaDataList, Meta.CursorFactory.ARRAY, signature.rootSchema, ImmutableList.<RelCollation>of(), -1, null); ResultSetMetaData subResultSetMetaData = new AvaticaResultSetMetaData(statement, null, newSignature); final QuarkResultSet resultSet = new QuarkResultSet(statement, signature, subResultSetMetaData, localCalendar.getTimeZone(), new Meta.Frame(0, true, iterable)); final Cursor cursor = resultSet.createCursor(elementType, iterable); return resultSet.execute2(cursor, columnMetaDataList); }
Example 3
Source File: QuarkMetaImpl.java From quark with Apache License 2.0 | 6 votes |
@Override public Frame fetch(StatementHandle h, long offset, int fetchMaxRowCount) { final QuarkConnectionImpl calciteConnection = getConnection(); QuarkJdbcStatement stmt = calciteConnection.server.getStatement(h); final Signature signature = stmt.getSignature(); final Iterator<Object> iterator; if (stmt.getResultSet() == null) { final Iterable<Object> iterable = Linq4j.emptyEnumerable(); iterator = iterable.iterator(); stmt.setResultSet(iterator); } else { iterator = stmt.getResultSet(); } final List<List<Object>> list = new ArrayList<>(); List<List<Object>> rows = MetaImpl.collect(signature.cursorFactory, LimitIterator.of(iterator, fetchMaxRowCount), list); boolean done = fetchMaxRowCount == 0 || list.size() < fetchMaxRowCount; return new Meta.Frame(offset, done, (List<Object>) (List) rows); }
Example 4
Source File: Service.java From calcite-avatica with Apache License 2.0 | 6 votes |
@JsonCreator public ResultSetResponse( @JsonProperty("connectionId") String connectionId, @JsonProperty("statementId") int statementId, @JsonProperty("ownStatement") boolean ownStatement, @JsonProperty("signature") Meta.Signature signature, @JsonProperty("firstFrame") Meta.Frame firstFrame, @JsonProperty("updateCount") long updateCount, @JsonProperty("rpcMetadata") RpcMetadataResponse rpcMetadata) { this.connectionId = connectionId; this.statementId = statementId; this.ownStatement = ownStatement; this.signature = signature; this.firstFrame = firstFrame; this.updateCount = updateCount; this.rpcMetadata = rpcMetadata; }
Example 5
Source File: JdbcResultSet.java From calcite-avatica with Apache License 2.0 | 6 votes |
public static JdbcResultSet create(String connectionId, int statementId, ResultSet resultSet, int maxRowCount, Meta.Signature signature) { try { final Calendar calendar = DateTimeUtils.calendar(); final int fetchRowCount; if (maxRowCount == JdbcMeta.UNLIMITED_COUNT) { fetchRowCount = -1; } else if (maxRowCount < 0L) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else if (maxRowCount > AvaticaStatement.DEFAULT_FETCH_SIZE) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else { fetchRowCount = maxRowCount; } final Meta.Frame firstFrame = frame(null, resultSet, 0, fetchRowCount, calendar, Optional.of(signature)); if (firstFrame.done) { resultSet.close(); } return new JdbcResultSet(connectionId, statementId, true, signature, firstFrame); } catch (SQLException e) { throw new RuntimeException(e); } }
Example 6
Source File: QuicksqlServerResultSet.java From Quicksql with MIT License | 6 votes |
public static QuicksqlServerResultSet create(String connectionId, int statementId, ResultSet resultSet, int maxRowCount, Signature signature) { try { final Calendar calendar = DateTimeUtils.calendar(); final int fetchRowCount; if (maxRowCount == QuicksqlServerMeta.UNLIMITED_COUNT) { fetchRowCount = -1; } else if (maxRowCount < 0L) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else if (maxRowCount > AvaticaStatement.DEFAULT_FETCH_SIZE) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else { fetchRowCount = maxRowCount; } final Meta.Frame firstFrame = frame(null, resultSet,0, fetchRowCount, calendar, Optional.of(signature)); if (firstFrame.done) { resultSet.close(); } return new QuicksqlServerResultSet(connectionId, statementId, true, signature, firstFrame); } catch (SQLException e) { throw new RuntimeException(e); } }
Example 7
Source File: QuarkMetaResultSet.java From quark with Apache License 2.0 | 6 votes |
/** * Creates a frame containing a given number or unlimited number of rows * from a result set. */ static Meta.Frame frame(ResultSet resultSet, long offset, int fetchMaxRowCount, Calendar calendar) throws SQLException { final ResultSetMetaData metaData = resultSet.getMetaData(); final int columnCount = metaData.getColumnCount(); final int[] types = new int[columnCount]; for (int i = 0; i < types.length; i++) { types[i] = metaData.getColumnType(i + 1); } final List<Object> rows = new ArrayList<>(); // Meta prepare/prepareAndExecute 0 return 0 row and done boolean done = fetchMaxRowCount == 0; for (int i = 0; fetchMaxRowCount < 0 || i < fetchMaxRowCount; i++) { if (!resultSet.next()) { done = true; resultSet.close(); break; } Object[] columns = new Object[columnCount]; for (int j = 0; j < columnCount; j++) { columns[j] = getValue(resultSet, types[j], j, calendar); } rows.add(columns); } return new Meta.Frame(offset, done, rows); }
Example 8
Source File: QuarkMetaResultSet.java From quark with Apache License 2.0 | 6 votes |
public static QuarkMetaResultSet create(String connectionId, int statementId, ResultSet resultSet, long maxRowCount, Meta.Signature signature) { try { final Calendar calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE); final int fetchRowCount; if (maxRowCount == QuarkMetaImpl.UNLIMITED_COUNT) { fetchRowCount = -1; } else if (maxRowCount < 0L) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else if (maxRowCount > AvaticaStatement.DEFAULT_FETCH_SIZE) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else { fetchRowCount = (int) maxRowCount; } final Meta.Frame firstFrame = frame(resultSet, 0, fetchRowCount, calendar); if (firstFrame.done) { resultSet.close(); } return new QuarkMetaResultSet(connectionId, statementId, true, signature, firstFrame); } catch (SQLException e) { throw new RuntimeException(e); } }
Example 9
Source File: CalciteMetaImpl.java From Quicksql with MIT License | 6 votes |
@Override public Frame fetch(StatementHandle h, long offset, int fetchMaxRowCount) throws NoSuchStatementException { final CalciteConnectionImpl calciteConnection = getConnection(); CalciteServerStatement stmt = calciteConnection.server.getStatement(h); final Signature signature = stmt.getSignature(); final Iterator<Object> iterator; if (stmt.getResultSet() == null) { final Iterable<Object> iterable = _createIterable(h, signature, null, null); iterator = iterable.iterator(); stmt.setResultSet(iterator); } else { iterator = stmt.getResultSet(); } final List rows = MetaImpl.collect(signature.cursorFactory, LimitIterator.of(iterator, fetchMaxRowCount), new ArrayList<List<Object>>()); boolean done = fetchMaxRowCount == 0 || rows.size() < fetchMaxRowCount; @SuppressWarnings("unchecked") List<Object> rows1 = (List<Object>) rows; return new Meta.Frame(offset, done, rows1); }
Example 10
Source File: QuarkJdbc41Factory.java From quark with Apache License 2.0 | 5 votes |
@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 11
Source File: QuicksqlJdbc41Factory.java From Quicksql with MIT License | 5 votes |
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 12
Source File: DremioJdbc41Factory.java From dremio-oss with Apache License 2.0 | 5 votes |
@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 13
Source File: CalciteJdbc41Factory.java From calcite with Apache License 2.0 | 5 votes |
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 14
Source File: DremioResultSetImpl.java From dremio-oss with Apache License 2.0 | 5 votes |
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 15
Source File: QuarkMetaResultSet.java From quark with Apache License 2.0 | 5 votes |
protected QuarkMetaResultSet(String connectionId, int statementId, boolean ownStatement, Meta.Signature signature, Meta.Frame firstFrame, long updateCount) { super(connectionId, statementId, ownStatement, signature, firstFrame, updateCount); }
Example 16
Source File: QuarkMetaResultSet.java From quark with Apache License 2.0 | 5 votes |
public static QuarkMetaResultSet create(String connectionId, int statementId, Iterator iterator, long maxRowCount, Meta.Signature signature) { try { final Calendar calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE); final int fetchRowCount; if (maxRowCount == QuarkMetaImpl.UNLIMITED_COUNT) { fetchRowCount = -1; } else if (maxRowCount < 0L) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else if (maxRowCount > AvaticaStatement.DEFAULT_FETCH_SIZE) { fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE; } else { fetchRowCount = (int) maxRowCount; } final Meta.Frame firstFrame; if (!iterator.hasNext()) { firstFrame = Meta.Frame.EMPTY; } else { firstFrame = frame(iterator, signature.columns, 0, fetchRowCount, calendar); } return new QuarkMetaResultSet(connectionId, statementId, true, signature, firstFrame); } catch (SQLException e) { throw new RuntimeException(e); } }
Example 17
Source File: CalciteJdbc41Factory.java From Quicksql with MIT License | 5 votes |
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 18
Source File: Service.java From calcite-avatica with Apache License 2.0 | 5 votes |
@JsonCreator public FetchResponse(@JsonProperty("frame") Meta.Frame frame, @JsonProperty("missingStatement") boolean missingStatement, @JsonProperty("missingResults") boolean missingResults, @JsonProperty("rpcMetadata") RpcMetadataResponse rpcMetadata) { this.frame = frame; this.missingStatement = missingStatement; this.missingResults = missingResults; this.rpcMetadata = rpcMetadata; }
Example 19
Source File: QuarkResultSet.java From quark with Apache License 2.0 | 4 votes |
QuarkResultSet(AvaticaStatement statement, Meta.Signature signature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Meta.Frame firstFrame) { super(statement, null, signature, resultSetMetaData, timeZone, firstFrame); }
Example 20
Source File: JdbcResultSet.java From calcite-avatica with Apache License 2.0 | 4 votes |
protected JdbcResultSet(String connectionId, int statementId, boolean ownStatement, Meta.Signature signature, Meta.Frame firstFrame) { this(connectionId, statementId, ownStatement, signature, firstFrame, -1L); }