@Override public Prel visitExchange(ExchangePrel prel, Void value) throws RuntimeException { Prel child = ((Prel)prel.getInput()).accept(this, null); // check if the hash expression has already been added for this particular exchange if (!child.getRowType().getFieldNames().contains(HashPrelUtil.HASH_EXPR_NAME)) { if (prel instanceof HashToMergeExchangePrel) { return visit(prel, ((HashToMergeExchangePrel) prel).getDistFields(), child); } if (prel instanceof HashToRandomExchangePrel) { return visit(prel, ((HashToRandomExchangePrel) prel).getFields(), child); } } return (Prel) prel.copy(prel.getTraitSet(), Collections.singletonList(((RelNode)child))); }
@Override public PrelWithDictionaryInfo visitExchange(ExchangePrel exchangePrel, Void value) throws RuntimeException { assert exchangePrel.getInputs().size() == 1; PrelWithDictionaryInfo newInput = ((Prel)exchangePrel.getInput()).accept(this, value); if (exchangePrel.getInput() == newInput.getPrel()) { return new PrelWithDictionaryInfo(exchangePrel); // none of fields are encoded } if (exchangePrel instanceof HashToMergeExchangePrel || exchangePrel instanceof HashToRandomExchangePrel) { final List<DistributionField> distributionFields; if (exchangePrel instanceof HashToMergeExchangePrel) { distributionFields = ((HashToMergeExchangePrel) exchangePrel).getDistFields(); } else { distributionFields = ((HashToRandomExchangePrel) exchangePrel).getFields(); } // decode used inputs by this filter newInput = newInput.decodeFields(Lists.transform(distributionFields, new Function<DistributionField, Integer>() { @Override public Integer apply(DistributionField input) { return input.getFieldId(); } })); } // pass thr rest of exchanges, exchange uses child input's row data type. return new PrelWithDictionaryInfo( (Prel)exchangePrel.copy(exchangePrel.getTraitSet(), Collections.<RelNode>singletonList(newInput.getPrel())), newInput.getFields()); }