@Override public KeySlots visitLeave(InListExpression node, List<KeySlots> childParts) { if (childParts.isEmpty()) { return null; } List<Expression> keyExpressions = node.getKeyExpressions(); Set<KeyRange> ranges = Sets.newHashSetWithExpectedSize(keyExpressions.size()); KeySlot childSlot = childParts.get(0).getSlots().get(0); KeyPart childPart = childSlot.getKeyPart(); // Handles cases like WHERE substr(foo,1,3) IN ('aaa','bbb') for (Expression key : keyExpressions) { KeyRange range = childPart.getKeyRange(CompareOp.EQUAL, key); if (range == null) { return null; } if (range != KeyRange.EMPTY_RANGE) { // null means it can't possibly be in range ranges.add(range); } } return newKeyParts(childSlot, node, new ArrayList<KeyRange>(ranges)); }
public final KeySlot concatExtractNodes(List<Expression> extractNodes) { return new KeySlot( new BaseKeyPart(this.getKeyPart().getTable(), this.getKeyPart().getColumn(), SchemaUtil.concat(this.getKeyPart().getExtractNodes(),extractNodes)), this.getPKPosition(), this.getPKSpan(), this.getKeyRanges(), this.getOrderPreserving()); }
private KeySlots newKeyParts(KeySlot slot, Expression extractNode, List<KeyRange> keyRanges) { if (isDegenerate(keyRanges)) { return EMPTY_KEY_SLOTS; } List<Expression> extractNodes = extractNode == null || slot.getKeyPart().getExtractNodes().isEmpty() ? Collections.<Expression>emptyList() : Collections.<Expression>singletonList(extractNode); return new SingleKeySlot(new BaseKeyPart(table, slot.getKeyPart().getColumn(), extractNodes), slot.getPKPosition(), slot.getPKSpan(), keyRanges, slot.getOrderPreserving()); }
@Override public PColumn getColumn() { return childPart.getColumn(); }
@Override public PTable getTable() { return childPart.getTable(); } };
@Override public List<Expression> getExtractNodes() { return childPart.getExtractNodes(); }
@Override public KeySlots visitLeave(ComparisonExpression node, List<KeySlots> childParts) { // Delay adding to extractedNodes, until we're done traversing, // since we can't yet tell whether or not the PK column references // are contiguous if (childParts.isEmpty()) { return null; } Expression rhs = node.getChildren().get(1); KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.iterator().next(); KeyPart childPart = childSlot.getKeyPart(); SortOrder sortOrder = childPart.getColumn().getSortOrder(); CompareOp op = sortOrder.transform(node.getFilterOp()); KeyRange keyRange = childPart.getKeyRange(op, rhs); return newKeyParts(childSlot, node, keyRange); }
@Override public PColumn getColumn() { return childPart.getColumn(); }
@Override public PTable getTable() { return childPart.getTable(); } }, slot.getPKPosition(), slot.getKeyRanges());
@Override public boolean isPartialExtraction() { return this.slots.get(0).getKeyPart().getExtractNodes().isEmpty(); }
private KeySlots newKeyParts(KeySlot slot, Expression extractNode, List<KeyRange> keyRanges) { if (isDegenerate(keyRanges)) { return EMPTY_KEY_SLOTS; } List<Expression> extractNodes = extractNode == null || slot.getKeyPart().getExtractNodes().isEmpty() ? Collections.<Expression>emptyList() : Collections.<Expression>singletonList(extractNode); return new SingleKeySlot(new BaseKeyPart(table, slot.getKeyPart().getColumn(), extractNodes), slot.getPKPosition(), slot.getPKSpan(), keyRanges, slot.getOrderPreserving()); }
@Override public KeySlots visitLeave(ComparisonExpression node, List<KeySlots> childParts) { // Delay adding to extractedNodes, until we're done traversing, // since we can't yet tell whether or not the PK column references // are contiguous if (childParts.isEmpty()) { return null; } Expression rhs = node.getChildren().get(1); KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.getSlots().get(0); KeyPart childPart = childSlot.getKeyPart(); //SortOrder sortOrder = childPart.getColumn().getSortOrder(); CompareOp op = node.getFilterOp(); //CompareOp op = sortOrder.transform(node.getFilterOp()); KeyRange keyRange = childPart.getKeyRange(op, rhs); return newKeyParts(childSlot, node, keyRange); }
public final KeySlot concatExtractNodes(List<Expression> extractNodes) { return new KeySlot( new BaseKeyPart(this.getKeyPart().getTable(), this.getKeyPart().getColumn(), SchemaUtil.concat(this.getKeyPart().getExtractNodes(),extractNodes)), this.getPKPosition(), this.getPKSpan(), this.getKeyRanges(), this.getOrderPreserving()); }
@Override public PColumn getColumn() { return childPart.getColumn(); }
@Override public PTable getTable() { return childPart.getTable(); } };
KeySlots slots = childSlots.get(i); KeySlot keySlot = slots.getSlots().iterator().next(); List<Expression> childExtractNodes = keySlot.getKeyPart().getExtractNodes();
private KeySlots newKeyParts(KeySlot slot, Expression extractNode, List<KeyRange> keyRanges, KeyRange minMaxRange) { if (isDegenerate(keyRanges)) { return EMPTY_KEY_SLOTS; } List<Expression> extractNodes = extractNode == null || slot.getKeyPart().getExtractNodes().isEmpty() ? Collections.<Expression>emptyList() : Collections.<Expression>singletonList(extractNode); return new SingleKeySlot(new BaseKeyPart(table, slot.getKeyPart().getColumn(), extractNodes), slot.getPKPosition(), slot.getPKSpan(), keyRanges, minMaxRange, slot.getOrderPreserving()); }
/** * Checks that a given KeyPart produces the right key ranges for each relational operator and * a variety of right-hand-side decimals. * @param exprType the rounding expression type used to create this KeyPart * @param scale the scale used to create this KeyPart * @param keyPart the KeyPart to test */ private void verifyKeyPart(RoundingType exprType, int scale, KeyPart keyPart) throws SQLException { for(BigDecimal rhsDecimal : DECIMALS) { LiteralExpression rhsExpression = LiteralExpression.newConstant(rhsDecimal, PDecimal.INSTANCE); for(Relation relation : Relation.values()) { KeyRange keyRange = keyPart.getKeyRange(relation.compareOp, rhsExpression); verifyKeyRange(exprType, scale, relation, rhsDecimal, keyRange); } } }
public final KeySlot concatExtractNodes(List<Expression> extractNodes) { return new KeySlot( new BaseKeyPart(this.getKeyPart().getTable(), this.getKeyPart().getColumn(), SchemaUtil.concat(this.getKeyPart().getExtractNodes(),extractNodes)), this.getPKPosition(), this.getPKSpan(), this.getKeyRanges(), this.getOrderPreserving()); }
@Override public PColumn getColumn() { return childPart.getColumn(); }