private AggregatePlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, OrderBy orderBy, ParallelIteratorFactory parallelIteratorFactory, GroupBy groupBy, Expression having, Expression dynamicFilter, QueryPlan dataPlan) throws SQLException { super(context, statement, table, projector, context.getBindManager().getParameterMetaData(), limit, offset, orderBy, groupBy, parallelIteratorFactory, dynamicFilter, dataPlan); this.having = having; this.aggregators = context.getAggregationManager().getAggregators(); boolean hasSerialHint = statement.getHint().hasHint(HintNode.Hint.SERIAL); boolean canBeExecutedSerially = ScanUtil.canQueryBeExecutedSerially(table.getTable(), orderBy, context); if (hasSerialHint && !canBeExecutedSerially) { logger.warn("This query cannot be executed serially. Ignoring the hint"); } this.isSerial = hasSerialHint && canBeExecutedSerially; }
context.getScan().setAttribute(BaseScannerRegionObserver.AGGREGATORS, ServerAggregators.serialize(aggFuncs, minNullableIndex)); ClientAggregators clientAggregators = new ClientAggregators(aggFuncs, minNullableIndex); context.getAggregationManager().setAggregators(clientAggregators);
public ClientAggregatePlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, Expression where, OrderBy orderBy, GroupBy groupBy, Expression having, QueryPlan delegate) { super(context, statement, table, projector, limit, offset, where, orderBy, delegate); this.groupBy = groupBy; this.having = having; this.clientAggregators = context.getAggregationManager().getAggregators(); // We must deserialize rather than clone based off of client aggregators because // upon deserialization we create the server-side aggregators instead of the client-side // aggregators. We use the Configuration directly here to avoid the expense of creating // another one. this.serverAggregators = ServerAggregators.deserialize(context.getScan() .getAttribute(BaseScannerRegionObserver.AGGREGATORS), context.getConnection().getQueryServices().getConfiguration(), null); // Extract hash aggregate hint, if any. HintNode hints = statement.getHint(); useHashAgg = hints != null && hints.hasHint(HintNode.Hint.HASH_AGGREGATE); }
@Test public void testNoAggregatorForOrderBy() throws SQLException { Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)); conn.createStatement().execute("create table test (pk1 integer not null, pk2 integer not null, constraint pk primary key (pk1,pk2))"); StatementContext context = compileStatement("select count(distinct pk1) from test order by count(distinct pk2)"); assertEquals(1, context.getAggregationManager().getAggregators().getAggregatorCount()); context = compileStatement("select sum(pk1) from test order by count(distinct pk2)"); assertEquals(1, context.getAggregationManager().getAggregators().getAggregatorCount()); context = compileStatement("select min(pk1) from test order by count(distinct pk2)"); assertEquals(1, context.getAggregationManager().getAggregators().getAggregatorCount()); context = compileStatement("select max(pk1) from test order by count(distinct pk2)"); assertEquals(1, context.getAggregationManager().getAggregators().getAggregatorCount()); // here the ORDER BY is not optimized away context = compileStatement("select avg(pk1) from test order by count(distinct pk2)"); assertEquals(2, context.getAggregationManager().getAggregators().getAggregatorCount()); }
PhoenixStatement statement = new PhoenixStatement(pconn); StatementContext context = new StatementContext(statement, null, new Scan(), new SequenceManager(statement)); AggregationManager aggregationManager = context.getAggregationManager(); SumAggregateFunction func = new SumAggregateFunction(Arrays.<Expression>asList(new KeyValueColumnExpression(new PLongColumn() { @Override
context.getAggregationManager().compile(context, GroupBy.EMPTY_GROUP_BY); if (dataPlan.getProjector().projectEveryRow()) { projectorToBe = new RowProjector(projectorToBe,true);
throw ServerUtil.parseServerException(e); } catch(HashJoinCacheNotFoundException e1) { if(ScanUtil.isNonAggregateScan(scan) && plan.getContext().getAggregationManager().isEmpty()) {
RowProjector aggProjectorToBe = ProjectionCompiler.compile(statementContext, select, GroupBy .EMPTY_GROUP_BY); statementContext.getAggregationManager().compile(queryPlan.getContext() ,GroupBy.EMPTY_GROUP_BY); if (queryPlan.getProjector().projectEveryRow()) {
isInRowKeyOrder, where); context.getAggregationManager().compile(context, groupBy);
context.getAggregationManager().compile(context, GroupBy.EMPTY_GROUP_BY);
cols < plan.getTableRef().getTable().getRowKeySchema().getFieldCount() && plan.getGroupBy().isOrderPreserving() && (context.getAggregationManager().isEmpty() || plan.getGroupBy().isUngroupedAggregate())) {
if (limit != null && orderBy.getOrderByExpressions().isEmpty() && having == null && ( ( statement.isDistinct() && ! statement.isAggregate() ) || ( ! statement.isDistinct() && ( context.getAggregationManager().isEmpty() || BaseScannerRegionObserver.KEY_ORDERED_GROUP_BY_EXPRESSIONS.equals(groupBy.getScanAttribName()) ) ) ) ) {
private AggregatePlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, OrderBy orderBy, ParallelIteratorFactory parallelIteratorFactory, GroupBy groupBy, Expression having, Expression dynamicFilter, QueryPlan dataPlan) throws SQLException { super(context, statement, table, projector, context.getBindManager().getParameterMetaData(), limit, offset, orderBy, groupBy, parallelIteratorFactory, dynamicFilter, dataPlan); this.having = having; this.aggregators = context.getAggregationManager().getAggregators(); boolean hasSerialHint = statement.getHint().hasHint(HintNode.Hint.SERIAL); boolean canBeExecutedSerially = ScanUtil.canQueryBeExecutedSerially(table.getTable(), orderBy, context); if (hasSerialHint && !canBeExecutedSerially) { logger.warn("This query cannot be executed serially. Ignoring the hint"); } this.isSerial = hasSerialHint && canBeExecutedSerially; }
context.getScan().setAttribute(BaseScannerRegionObserver.AGGREGATORS, ServerAggregators.serialize(aggFuncs, minNullableIndex)); ClientAggregators clientAggregators = new ClientAggregators(aggFuncs, minNullableIndex); context.getAggregationManager().setAggregators(clientAggregators);
private AggregatePlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, OrderBy orderBy, ParallelIteratorFactory parallelIteratorFactory, GroupBy groupBy, Expression having, Expression dynamicFilter, QueryPlan dataPlan) throws SQLException { super(context, statement, table, projector, context.getBindManager().getParameterMetaData(), limit, offset, orderBy, groupBy, parallelIteratorFactory, dynamicFilter, dataPlan); this.having = having; this.aggregators = context.getAggregationManager().getAggregators(); boolean hasSerialHint = statement.getHint().hasHint(HintNode.Hint.SERIAL); boolean canBeExecutedSerially = ScanUtil.canQueryBeExecutedSerially(table.getTable(), orderBy, context); if (hasSerialHint && !canBeExecutedSerially) { logger.warn("This query cannot be executed serially. Ignoring the hint"); } this.isSerial = hasSerialHint && canBeExecutedSerially; }
context.getScan().setAttribute(BaseScannerRegionObserver.AGGREGATORS, ServerAggregators.serialize(aggFuncs, minNullableIndex)); ClientAggregators clientAggregators = new ClientAggregators(aggFuncs, minNullableIndex); context.getAggregationManager().setAggregators(clientAggregators);
public ClientAggregatePlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, Expression where, OrderBy orderBy, GroupBy groupBy, Expression having, QueryPlan delegate) { super(context, statement, table, projector, limit, offset, where, orderBy, delegate); this.groupBy = groupBy; this.having = having; this.clientAggregators = context.getAggregationManager().getAggregators(); // We must deserialize rather than clone based off of client aggregators because // upon deserialization we create the server-side aggregators instead of the client-side // aggregators. We use the Configuration directly here to avoid the expense of creating // another one. this.serverAggregators = ServerAggregators.deserialize(context.getScan() .getAttribute(BaseScannerRegionObserver.AGGREGATORS), context.getConnection().getQueryServices().getConfiguration(), null); }
public ClientAggregatePlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, Expression where, OrderBy orderBy, GroupBy groupBy, Expression having, QueryPlan delegate) { super(context, statement, table, projector, limit, offset, where, orderBy, delegate); this.groupBy = groupBy; this.having = having; this.clientAggregators = context.getAggregationManager().getAggregators(); // We must deserialize rather than clone based off of client aggregators because // upon deserialization we create the server-side aggregators instead of the client-side // aggregators. We use the Configuration directly here to avoid the expense of creating // another one. this.serverAggregators = ServerAggregators.deserialize(context.getScan() .getAttribute(BaseScannerRegionObserver.AGGREGATORS), context.getConnection().getQueryServices().getConfiguration(), null); // Extract hash aggregate hint, if any. HintNode hints = statement.getHint(); useHashAgg = hints != null && hints.hasHint(HintNode.Hint.HASH_AGGREGATE); }
throw ServerUtil.parseServerException(e); } catch(HashJoinCacheNotFoundException e1) { if(ScanUtil.isNonAggregateScan(scan) && plan.getContext().getAggregationManager().isEmpty()) {
throw ServerUtil.parseServerException(e); } catch(StaleRegionBoundaryCacheException | HashJoinCacheNotFoundException e1) { if(ScanUtil.isNonAggregateScan(scan) && plan.getContext().getAggregationManager().isEmpty()) {