Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JoinPredicates don't have correct types #7

Open
colestew opened this issue May 14, 2015 · 5 comments
Open

JoinPredicates don't have correct types #7

colestew opened this issue May 14, 2015 · 5 comments
Labels
Milestone

Comments

@colestew
Copy link
Contributor

When performing a join, the predicates are typed as HgBiPredicate<Object, Object> instead of the actual types of the fields being joined on. Obviously this needs to be changed. It's likely going to be difficult to fix this problem as it will require some substantial refactorings.

@colestew colestew added the bug label May 14, 2015
@colestew colestew added this to the 0.7.0 milestone May 14, 2015
@colestew
Copy link
Contributor Author

Observe the following:

        HgDB.join(new JoinPredicate(
                PersonTable.on.birthday(),
                PersonTable.as(PERSON_ALIAS).on.birthday(),
                (HgBiPredicate<Date, Date>)(d1, d2) -> {
                    Calendar.getInstance().setTime(d1);
                    int d1Month = Calendar.getInstance().get(Calendar.MONTH);
                    Calendar.getInstance().getInstance().setTime(d2);
                    int d2Month = Calendar.getInstance().get(Calendar.MONTH);
                    return d1Month == d2Month;
                }
        ));

Eclipse does not need the cast to work correctly, however IntelliJ does. Also, IntelliJ claims this cast is redundant, but removing it breaks the statement. This could just be an intelliJ problem.

@dilijev
Copy link
Contributor

dilijev commented May 14, 2015

Regardless of IntelliJ's warning/error, does it compile in Gradle?

@dilijev
Copy link
Contributor

dilijev commented May 14, 2015

We might do this to help the compiler figure out the types:

public static <T1, T2> HgPolyTupleStream join(
            HgTupleStream a,
            HgTupleStream b,
            HgBiPredicate<T1, T2> relation) {
        return join(new JoinPredicate(a, b, relation));
    }

@dilijev
Copy link
Contributor

dilijev commented May 14, 2015

We might also do something like this to help advertise all of the relevant types, as long as it doesn't increase the complexity of the user-facing API.

public static HgPolyTupleStream join(
            HgTupleStream<T1, F1> a, // or just <F1>
            HgTupleStream<T2, F2> b, // or just <F2>
            HgBiPredicate<F1, F2> relation) {
        return join(new JoinPredicate(a, b, relation));
    }

Where each HgTupleStream advertises the type and field it is joining on. T1 is the type of the containing class and F1 is the type of the field, for each parameter.

@dilijev
Copy link
Contributor

dilijev commented May 14, 2015

Also you can give types to the parameters of a lambda directly:

        HgDB.join(new JoinPredicate(
                PersonTable.on.birthday(),
                PersonTable.as(PERSON_ALIAS).on.birthday(),
                (Date d1, Date d2) -> {
                    cal1.setTime(d1);
                    int d1Month = cal1.get(Calendar.MONTH);
                    cal2.setTime(d2);
                    int d2Month = cal2.get(Calendar.MONTH);
                    return d1Month == d2Month;
                }
        ))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants