TimefoldAI / TimefoldAI/timefold-solver

ConstraintStreams: accumulate or outer right join

Open
#1,399 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

process/needs triage
Dominant language
Java
Stars
1.8k
Forks
228
Avg merge
1d 13h
Merged PRs (30d)
46

Description

This pattern is common:

   f.forEach(MyEntity)
    .groupBy(MyEntity::myGrouping, count())
    .join(MinMaxRule, ... same myGrouping ...)

It's also buggy. If nothing is assigned to the grouping, the MinMaxRule isn't checked.

This is because join() is an inner join in SQL talk. We need an outer right join instead.
Some models have helper code for that:

    @SafeVarargs
    private <A, B> BiConstraintStream<A, B> joinOuterRight(UniConstraintStream<A> sourceStream,
            Class<B> joinedClass, BiJoiner<A, B>... joiners) {
        return sourceStream.join(joinedClass, joiners)
                .concat(sourceStream.ifNotExists(joinedClass, joiners));
    }

Let's standardize it.

Proposal A)

Add syntactic sugar + tests for Uni/Bi/Tri/QuadConstraintStream.joinOuterRight(...), as shown above.
Later implementations can potentially optimize the implementation, but for now the facade is enough.

Naming to be discussed.
Later we might want to implement a left outer join (.joinOuterLeft()) and a full outer join (.joinOuterFull()) too.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the UniConstraintStream, BiConstraintStream, TriConstraintStream, and QuadConstraintStream join and ifNotExists entry points, using the helper pattern shown in the issue as the reference. Add tests for the proposed outer-right-join behavior across all four stream types, and confirm that the naming and behavior are consistent before considering the work done.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.