[
https://issues.apache.org/jira/browse/CALCITE-2462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16582271#comment-16582271
]
Vladimir Sitnikov commented on CALCITE-2462:
--------------------------------------------
PS. there's a middle ground as well.
I've no strong opinion of that is required or not at the moment.
{code:java}
public interface RexProgramTestBuilder<T extends RexProgramTestBuilder.State> {
class State {
RexBuilder builder;
// other fields to keep builder running
}
T getState();
default RexBuilder getBuilder() {
// it can be a stand-alone method or just getState().builder repeated all
over the place
// Unfortunately, Java 8 does not support private methods in interfaces (it
is Java9+)
return getState().builder;
}
default RexNode isNull(RexNode node) {
return getBuilder().makeCall(SqlStdOperatorTable.IS_NULL, node);
}
{code}
Then it can be used in both ways:
1) Create stand-alone {{Fixture}} object
{code:java}
class Fixture extends RexProgramTestBuilder.State implements
RexProgramTestBuilder<RexProgramTestBuilder.State> {
@Override public State getState() {
return this;
}
}
{code}
2) Inherit all the builder methods to avoid {{f.}} all over the place:
{code:java}
public class RexBuilderTest implements
RexProgramTestBuilder<RexProgramTestBuilder.State> {
RexProgramTestBuilder.State fixture = new RexProgramTestBuilder.State();
@Override public State getState() {
return fixture;
}
...
}
{code}
> RexProgramTest: move "rex building" methods to base class
> ---------------------------------------------------------
>
> Key: CALCITE-2462
> URL: https://issues.apache.org/jira/browse/CALCITE-2462
> Project: Calcite
> Issue Type: Sub-task
> Components: core
> Affects Versions: 1.17.0
> Reporter: Vladimir Sitnikov
> Assignee: Julian Hyde
> Priority: Major
> Fix For: 1.18.0
>
>
> RexProgramTest is quite big (2000 lines now), and "easy to use" rex building
> is useful for many tests.
> So I suggest to move methods like {{gt}}, {{lt}}, etc to the base class, so
> multiple other tests can reuse it.
> Alternative option would be to use Kotlin for builders, yet I think Java
> tests will be there for quite a while, so it would be nice to simplify them
> as well.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)