protected final OperatorFactory createHashProjectOperator(int operatorId, PlanNodeId planNodeId, List<Type> types) { ImmutableMap.Builder<Symbol, Type> symbolTypes = ImmutableMap.builder(); ImmutableMap.Builder<Symbol, Integer> symbolToInputMapping = ImmutableMap.builder(); ImmutableList.Builder<PageProjection> projections = ImmutableList.builder(); for (int channel = 0; channel < types.size(); channel++) { Symbol symbol = new Symbol("h" + channel); symbolTypes.put(symbol, types.get(channel)); symbolToInputMapping.put(symbol, channel); projections.add(new InputPageProjection(channel, types.get(channel))); } Optional<Expression> hashExpression = HashGenerationOptimizer.getHashExpression(ImmutableList.copyOf(symbolTypes.build().keySet())); verify(hashExpression.isPresent()); projections.add(new InterpretedPageProjection( hashExpression.get(), TypeProvider.copyOf(symbolTypes.build()), symbolToInputMapping.build(), localQueryRunner.getMetadata(), localQueryRunner.getSqlParser(), session)); return new FilterAndProjectOperator.FilterAndProjectOperatorFactory( operatorId, planNodeId, () -> new PageProcessor(Optional.empty(), projections.build()), ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))), getFilterAndProjectMinOutputPageSize(session), getFilterAndProjectMinOutputPageRowCount(session)); }
public RuleTester(List<Plugin> plugins, Map<String, String> sessionProperties, Optional<Integer> nodeCountForStats) { Session.SessionBuilder sessionBuilder = testSessionBuilder() .setCatalog(CATALOG_ID) .setSchema("tiny") .setSystemProperty("task_concurrency", "1"); // these tests don't handle exchanges from local parallel for (Map.Entry<String, String> entry : sessionProperties.entrySet()) { sessionBuilder.setSystemProperty(entry.getKey(), entry.getValue()); } session = sessionBuilder.build(); queryRunner = nodeCountForStats .map(nodeCount -> LocalQueryRunner.queryRunnerWithFakeNodeCountForStats(session, nodeCount)) .orElseGet(() -> new LocalQueryRunner(session)); queryRunner.createCatalog(session.getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of()); plugins.stream().forEach(queryRunner::installPlugin); this.metadata = queryRunner.getMetadata(); this.transactionManager = queryRunner.getTransactionManager(); this.splitManager = queryRunner.getSplitManager(); this.pageSourceManager = queryRunner.getPageSourceManager(); this.accessControl = queryRunner.getAccessControl(); this.sqlParser = queryRunner.getSqlParser(); }
@BeforeClass public void setup() { metadata = getQueryRunner().getMetadata(); sqlParser = getQueryRunner().getSqlParser(); ConnectorId connectorId = getCurrentConnectorId(); nationTableHandle = new TableHandle( connectorId, new TpchTableHandle("nation", 1.0)); nationTableLayoutHandle = new TableLayoutHandle(connectorId, TestingTransactionHandle.create(), new TpchTableLayoutHandle((TpchTableHandle) nationTableHandle.getConnectorHandle(), TupleDomain.all())); }
private void assertUnitPlan(@Language("SQL") String sql, PlanMatchPattern pattern) { List<PlanOptimizer> optimizers = ImmutableList.of( new UnaliasSymbolReferences(), new PredicatePushDown(getQueryRunner().getMetadata(), getQueryRunner().getSqlParser()), new IterativeOptimizer( new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getEstimatedExchangesCostCalculator(), ImmutableSet.of( new RemoveRedundantIdentityProjections(), new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(0), new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(1), new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(2))), new PruneUnreferencedOutputs()); assertPlan(sql, pattern, optimizers); } }
protected final OperatorFactory createHashProjectOperator(int operatorId, PlanNodeId planNodeId, List<Type> types) { ImmutableMap.Builder<Symbol, Type> symbolTypes = ImmutableMap.builder(); ImmutableMap.Builder<Symbol, Integer> symbolToInputMapping = ImmutableMap.builder(); ImmutableList.Builder<PageProjection> projections = ImmutableList.builder(); for (int channel = 0; channel < types.size(); channel++) { Symbol symbol = new Symbol("h" + channel); symbolTypes.put(symbol, types.get(channel)); symbolToInputMapping.put(symbol, channel); projections.add(new InputPageProjection(channel, types.get(channel))); } Optional<Expression> hashExpression = HashGenerationOptimizer.getHashExpression(ImmutableList.copyOf(symbolTypes.build().keySet())); verify(hashExpression.isPresent()); projections.add(new InterpretedPageProjection( hashExpression.get(), TypeProvider.copyOf(symbolTypes.build()), symbolToInputMapping.build(), localQueryRunner.getMetadata(), localQueryRunner.getSqlParser(), session)); return new FilterAndProjectOperator.FilterAndProjectOperatorFactory( operatorId, planNodeId, () -> new PageProcessor(Optional.empty(), projections.build()), ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))), getFilterAndProjectMinOutputPageSize(session), getFilterAndProjectMinOutputPageRowCount(session)); }