org.apache.phoenix.iterate.PeekingResultIterator Java Examples
The following examples show how to use
org.apache.phoenix.iterate.PeekingResultIterator.
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: AggregatePlan.java From phoenix with Apache License 2.0 | 6 votes |
@Override public PeekingResultIterator newIterator(StatementContext context, ResultIterator scanner, Scan scan, String tableName, QueryPlan plan) throws SQLException { /** * Sort the result tuples by the GroupBy expressions. * When orderByReverse is false,if some GroupBy expression is SortOrder.DESC, then sorted results on that expression are DESC, not ASC. * When orderByReverse is true,if some GroupBy expression is SortOrder.DESC, then sorted results on that expression are ASC, not DESC. */ OrderByExpression orderByExpression = OrderByExpression.createByCheckIfOrderByReverse( RowKeyExpression.INSTANCE, false, true, this.orderBy == OrderBy.REV_ROW_KEY_ORDER_BY); long threshold = services.getProps().getLong(QueryServices.CLIENT_SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_CLIENT_SPOOL_THRESHOLD_BYTES); boolean spoolingEnabled = services.getProps().getBoolean( QueryServices.CLIENT_ORDERBY_SPOOLING_ENABLED_ATTRIB, QueryServicesOptions.DEFAULT_CLIENT_ORDERBY_SPOOLING_ENABLED); return new OrderedResultIterator(scanner, Collections.<OrderByExpression> singletonList(orderByExpression), spoolingEnabled, threshold); }
Example #2
Source File: AggregatePlan.java From phoenix with Apache License 2.0 | 5 votes |
@Override public PeekingResultIterator newIterator(StatementContext context, ResultIterator scanner, Scan scan) throws SQLException { Expression expression = RowKeyExpression.INSTANCE; OrderByExpression orderByExpression = new OrderByExpression(expression, false, true); int threshold = services.getProps().getInt(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES); return new OrderedResultIterator(scanner, Collections.<OrderByExpression>singletonList(orderByExpression), threshold); }
Example #3
Source File: MutatingParallelIteratorFactory.java From phoenix with Apache License 2.0 | 4 votes |
@Override public PeekingResultIterator newIterator(StatementContext context, ResultIterator iterator, Scan scan) throws SQLException { final PhoenixConnection connection = new PhoenixConnection(this.connection); MutationState state = mutate(context, iterator, connection); long totalRowCount = state.getUpdateCount(); if (connection.getAutoCommit()) { connection.getMutationState().join(state); connection.commit(); ConnectionQueryServices services = connection.getQueryServices(); int maxSize = services.getProps().getInt(QueryServices.MAX_MUTATION_SIZE_ATTRIB,QueryServicesOptions.DEFAULT_MAX_MUTATION_SIZE); state = new MutationState(maxSize, connection, totalRowCount); } final MutationState finalState = state; byte[] value = PLong.INSTANCE.toBytes(totalRowCount); KeyValue keyValue = KeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, AGG_TIMESTAMP, value, 0, value.length); final Tuple tuple = new SingleKeyValueTuple(keyValue); return new PeekingResultIterator() { private boolean done = false; @Override public Tuple next() throws SQLException { if (done) { return null; } done = true; return tuple; } @Override public void explain(List<String> planSteps) { } @Override public void close() throws SQLException { try { // Join the child mutation states in close, since this is called in a single threaded manner // after the parallel results have been processed. if (!connection.getAutoCommit()) { MutatingParallelIteratorFactory.this.connection.getMutationState().join(finalState); } } finally { connection.close(); } } @Override public Tuple peek() throws SQLException { return done ? null : tuple; } }; }
Example #4
Source File: AggregatePlan.java From phoenix with Apache License 2.0 | 4 votes |
@Override public PeekingResultIterator newIterator(StatementContext context, ResultIterator scanner, Scan scan) throws SQLException { PeekingResultIterator iterator = innerFactory.newIterator(context, scanner, scan); return outerFactory.newIterator(context, iterator, scan); }
Example #5
Source File: ClientAggregatePlan.java From phoenix with Apache License 2.0 | 4 votes |
public ClientGroupedAggregatingResultIterator(PeekingResultIterator iterator, Aggregators aggregators, List<Expression> groupByExpressions) { super(iterator, aggregators); this.groupByExpressions = groupByExpressions; }
Example #6
Source File: ClientAggregatePlan.java From phoenix with Apache License 2.0 | 4 votes |
public ClientUngroupedAggregatingResultIterator(PeekingResultIterator iterator, Aggregators aggregators) { super(iterator, aggregators); }
Example #7
Source File: MutatingParallelIteratorFactory.java From phoenix with Apache License 2.0 | 4 votes |
@Override public PeekingResultIterator newIterator(final StatementContext parentContext, ResultIterator iterator, Scan scan, String tableName, QueryPlan plan) throws SQLException { final PhoenixConnection clonedConnection = new PhoenixConnection(this.connection); try { MutationState state = mutate(parentContext, iterator, clonedConnection); final long totalRowCount = state.getUpdateCount(); final boolean autoFlush = connection.getAutoCommit() || plan.getTableRef().getTable().isTransactional(); if (autoFlush) { clonedConnection.getMutationState().join(state); state = clonedConnection.getMutationState(); } final MutationState finalState = state; byte[] value = PLong.INSTANCE.toBytes(totalRowCount); Cell keyValue = PhoenixKeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, AGG_TIMESTAMP, value, 0, value.length); final Tuple tuple = new SingleKeyValueTuple(keyValue); return new PeekingResultIterator() { private boolean done = false; @Override public Tuple next() { if (done) { return null; } done = true; return tuple; } @Override public void explain(List<String> planSteps) { } @Override public void close() throws SQLException { try { /* * Join the child mutation states in close, since this is called in a single * threaded manner after the parallel results have been processed. * If auto-commit is on for the cloned child connection, then the finalState * here is an empty mutation state (with no mutations). However, it still * has the metrics for mutation work done by the mutating-iterator. * Joining the mutation state makes sure those metrics are passed over * to the parent connection. */ MutatingParallelIteratorFactory.this.connection.getMutationState() .join(finalState); } finally { clonedConnection.close(); } } @Override public Tuple peek() { return done ? null : tuple; } }; } catch (Throwable ex) { // Catch just to make sure we close the cloned connection and then rethrow try { // closeQuietly only handles IOException clonedConnection.close(); } catch (SQLException sqlEx) { LOGGER.error("Closing cloned Phoenix connection inside iterator, failed with: ", sqlEx); } throw ex; } }
Example #8
Source File: AggregatePlan.java From phoenix with Apache License 2.0 | 4 votes |
@Override public PeekingResultIterator newIterator(StatementContext context, ResultIterator scanner, Scan scan, String tableName, QueryPlan plan) throws SQLException { PeekingResultIterator iterator = innerFactory.newIterator(context, scanner, scan, tableName, plan); return outerFactory.newIterator(context, iterator, scan, tableName, plan); }
Example #9
Source File: ClientAggregatePlan.java From phoenix with Apache License 2.0 | 4 votes |
public ClientGroupedAggregatingResultIterator(PeekingResultIterator iterator, Aggregators aggregators, List<Expression> groupByExpressions) { super(iterator, aggregators); this.groupByExpressions = groupByExpressions; }
Example #10
Source File: ClientAggregatePlan.java From phoenix with Apache License 2.0 | 4 votes |
public ClientUngroupedAggregatingResultIterator(PeekingResultIterator iterator, Aggregators aggregators) { super(iterator, aggregators); }