/** * Creates a partial mapping. * * <p>Initially, no element is mapped to any other: * * <table border="1"> * <caption>Example</caption> * <tr> * <th>source</th> * <td>0</td> * <td>1</td> * <td>2</td> * </tr> * <tr> * <th>target</th> * <td>-1</td> * <td>-1</td> * <td>-1</td> * </tr> * </table> * * <table border="1"> * <caption>Example</caption> * <tr> * <th>target</th> * <td>0</td> * <td>1</td> * <td>2</td> * <td>3</td> * </tr> * <tr> * <th>source</th> * <td>-1</td> * <td>-1</td> * <td>-1</td> * <td>-1</td> * </tr> * </table> * * @param sourceCount Number of source elements * @param targetCount Number of target elements * @param mappingType Mapping type; must not allow multiple sources per target or multiple * targets per source */ public PartialMapping(int sourceCount, int targetCount, MappingType mappingType) { this.mappingType = mappingType; assert mappingType.isSingleSource() : mappingType; assert mappingType.isSingleTarget() : mappingType; this.sources = new int[targetCount]; this.targets = new int[sourceCount]; Arrays.fill(sources, -1); Arrays.fill(targets, -1); }
public PartialFunctionImpl(int sourceCount, int targetCount, MappingType mappingType) { super(); if (sourceCount < 0) { throw new IllegalArgumentException("Sources must be finite"); } this.sourceCount = sourceCount; this.targetCount = targetCount; this.mappingType = mappingType; if (!mappingType.isSingleTarget()) { throw new IllegalArgumentException("Must have at most one target"); } this.targets = new int[sourceCount]; Arrays.fill(targets, -1); }
public void onMatch(RelOptRuleCall call) { JoinRel join = (JoinRel) call.rels[0]; List<RexNode> expList = new ArrayList<RexNode>(Arrays.asList(join.getChildExps())); if (reduceExpressions(join, expList)) { call.transformTo( new JoinRel( join.getCluster(), join.getLeft(), join.getRight(), expList.get(0), join.getJoinType(), join.getVariablesStopped())); // New plan is absolutely better than old plan. call.getPlanner().setImportance(join, 0.0); } }
public void onMatch(RelOptRuleCall call) { ProjectRel project = (ProjectRel) call.rels[0]; List<RexNode> expList = new ArrayList<RexNode>(Arrays.asList(project.getChildExps())); if (reduceExpressions(project, expList)) { call.transformTo( new ProjectRel( project.getCluster(), project.getChild(), expList.toArray(new RexNode[expList.size()]), project.getRowType(), ProjectRel.Flags.Boxed, Collections.<RelCollation>emptyList())); // New plan is absolutely better than old plan. call.getPlanner().setImportance(project, 0.0); } }
/** * Creates a partial mapping from a list. For example, <code> * PartialMapping({1, 2, 4}, 6)</code> creates the mapping * * <table border="1"> * <caption>Example</caption> * <tr> * <th>source</th> * <td>0</td> * <td>1</td> * <td>2</td> * <td>3</td> * <td>4</td> * <td>5</td> * </tr> * <tr> * <th>target</th> * <td>-1</td> * <td>0</td> * <td>1</td> * <td>-1</td> * <td>2</td> * <td>-1</td> * </tr> * </table> * * @param sourceList List whose i'th element is the source of target #i * @param sourceCount Number of elements in the source domain * @param mappingType Mapping type, must be {@link * org.eigenbase.util.mapping.MappingType#PARTIAL_SURJECTION} or stronger. */ public PartialMapping(List<Integer> sourceList, int sourceCount, MappingType mappingType) { this.mappingType = mappingType; assert mappingType.isSingleSource(); assert mappingType.isSingleTarget(); int targetCount = sourceList.size(); this.targets = new int[sourceCount]; this.sources = new int[targetCount]; Arrays.fill(sources, -1); for (int i = 0; i < sourceList.size(); ++i) { final int source = sourceList.get(i); sources[i] = source; if (source >= 0) { targets[source] = i; } else { assert !this.mappingType.isMandatorySource(); } } }
public void onMatch(RelOptRuleCall call) { FilterRel filter = (FilterRel) call.rels[0]; List<RexNode> expList = new ArrayList<RexNode>(Arrays.asList(filter.getChildExps())); RexNode newConditionExp; boolean reduced; if (reduceExpressions(filter, expList)) { assert (expList.size() == 1); newConditionExp = expList.get(0); reduced = true; } else { // No reduction, but let's still test the original // predicate to see if it was already a constant, // in which case we don't need any runtime decision // about filtering. newConditionExp = filter.getChildExps()[0]; reduced = false; } if (newConditionExp.isAlwaysTrue()) { call.transformTo(filter.getChild()); } else if ((newConditionExp instanceof RexLiteral) || RexUtil.isNullLiteral(newConditionExp, true)) { call.transformTo(new EmptyRel(filter.getCluster(), filter.getRowType())); } else if (reduced) { call.transformTo(CalcRel.createFilter(filter.getChild(), expList.get(0))); } else { if (newConditionExp instanceof RexCall) { RexCall rexCall = (RexCall) newConditionExp; boolean reverse = (rexCall.getOperator() == SqlStdOperatorTable.notOperator); if (reverse) { rexCall = (RexCall) rexCall.getOperands()[0]; } reduceNotNullableFilter(call, filter, rexCall, reverse); } return; } // New plan is absolutely better than old plan. call.getPlanner().setImportance(filter, 0.0); }
public void clear() { Arrays.fill(sources, -1); Arrays.fill(targets, -1); }