/** * Creates a rule with an explicit description. * * @param operand root operand, must not be null * @param description Description, or null to guess description * @param relBuilderFactory Builder for relational expressions */ public RelOptRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, String description) { this.operand = Objects.requireNonNull(operand); this.relBuilderFactory = Objects.requireNonNull(relBuilderFactory); if (description == null) { description = guessDescription(getClass().getName()); } if (!description.matches("[A-Za-z][-A-Za-z0-9_.():]*")) { throw new RuntimeException("Rule description '" + description + "' is not valid"); } this.description = description; this.operands = flattenOperands(operand); assignSolveOrder(); }
/** * Creates a rule with an explicit description. * * @param operand root operand, must not be null * @param description Description, or null to guess description * @param relBuilderFactory Builder for relational expressions */ public RelOptRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, String description) { this.operand = Objects.requireNonNull(operand); this.relBuilderFactory = Objects.requireNonNull(relBuilderFactory); if (description == null) { description = guessDescription(getClass().getName()); } if (!description.matches("[A-Za-z][-A-Za-z0-9_.():]*")) { throw new RuntimeException("Rule description '" + description + "' is not valid"); } this.description = description; this.operands = flattenOperands(operand); assignSolveOrder(); }
/** * Tests the rules for how we name rules. */ @Test public void testRuleGuessDescription() { assertEquals("Bar", RelOptRule.guessDescription("com.foo.Bar")); assertEquals("Baz", RelOptRule.guessDescription("com.flatten.Bar$Baz")); // yields "1" (which as an integer is an invalid try { Util.discard(RelOptRule.guessDescription("com.foo.Bar$1")); fail("expected exception"); } catch (RuntimeException e) { assertEquals("Derived description of rule class com.foo.Bar$1 is an " + "integer, not valid. Supply a description manually.", e.getMessage()); } }
/** * Tests the rules for how we name rules. */ @Test public void testRuleGuessDescription() { assertEquals("Bar", RelOptRule.guessDescription("com.foo.Bar")); assertEquals("Baz", RelOptRule.guessDescription("com.flatten.Bar$Baz")); // yields "1" (which as an integer is an invalid try { Util.discard(RelOptRule.guessDescription("com.foo.Bar$1")); fail("expected exception"); } catch (RuntimeException e) { assertEquals("Derived description of rule class com.foo.Bar$1 is an " + "integer, not valid. Supply a description manually.", e.getMessage()); } }