class OptimizeCollectWhereClauseAccess implements Rule<Collect> {

    private final Pattern<Collect> pattern;

    public OptimizeCollectWhereClauseAccess() {
        this.pattern = typeOf(Collect.class)
            .with(collect ->
                      collect.relation() instanceof DocTableRelation
                      && collect.where().hasQuery()
                      && !Symbols.containsColumn(collect.outputs(), DocSysColumns.FETCHID)
            );
    }

    @Override
    public Pattern<Collect> pattern() {
        return pattern;
    }

    @Override
    public LogicalPlan apply(Collect collect,
                             Captures captures,
                             PlanStats planStats,
                             TransactionContext txnCtx,
                             NodeContext nodeCtx,
                             UnaryOperator<LogicalPlan> resolvePlan) {<FILL_FUNCTION_BODY>}
}

        var relation = (DocTableRelation) collect.relation();
        var normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, relation);
        WhereClause where = collect.where();
        var detailedQuery = WhereClauseOptimizer.optimize(
            normalizer,
            where.queryOrFallback(),
            relation.tableInfo(),
            txnCtx,
            nodeCtx
        );
        Optional<DocKeys> docKeys = detailedQuery.docKeys();
        //noinspection OptionalIsPresent no capturing lambda allocation
        if (docKeys.isPresent()) {
            return new Get(
                relation,
                docKeys.get(),
                detailedQuery.query(),
                collect.outputs(),
                detailedQuery.queryHasPkSymbolsOnly()
            );
        } else if (!detailedQuery.clusteredBy().isEmpty() && collect.detailedQuery() == null) {
            return new Collect(collect, detailedQuery);
        } else {
            return null;
        }
    
<no_super_class>