Search in sources :

Example 1 with RelDistribution

use of org.apache.calcite.rel.RelDistribution in project hive by apache.

the class HiveAlgorithmsUtil method getJoinDistribution.

public static RelDistribution getJoinDistribution(JoinPredicateInfo joinPredInfo, MapJoinStreamingRelation streamingRelation) {
    // Compute distribution
    ImmutableList.Builder<Integer> leftKeysListBuilder = new ImmutableList.Builder<Integer>();
    ImmutableList.Builder<Integer> rightKeysListBuilder = new ImmutableList.Builder<Integer>();
    for (int i = 0; i < joinPredInfo.getEquiJoinPredicateElements().size(); i++) {
        JoinLeafPredicateInfo joinLeafPredInfo = joinPredInfo.getEquiJoinPredicateElements().get(i);
        for (int leftPos : joinLeafPredInfo.getProjsFromLeftPartOfJoinKeysInJoinSchema()) {
            leftKeysListBuilder.add(leftPos);
        }
        for (int rightPos : joinLeafPredInfo.getProjsFromRightPartOfJoinKeysInJoinSchema()) {
            rightKeysListBuilder.add(rightPos);
        }
    }
    RelDistribution distribution = null;
    // Keep buckets from the streaming relation
    if (streamingRelation == MapJoinStreamingRelation.LEFT_RELATION) {
        distribution = new HiveRelDistribution(RelDistribution.Type.HASH_DISTRIBUTED, leftKeysListBuilder.build());
    } else if (streamingRelation == MapJoinStreamingRelation.RIGHT_RELATION) {
        distribution = new HiveRelDistribution(RelDistribution.Type.HASH_DISTRIBUTED, rightKeysListBuilder.build());
    }
    return distribution;
}
Also used : HiveRelDistribution(org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelDistribution) JoinLeafPredicateInfo(org.apache.hadoop.hive.ql.optimizer.calcite.HiveCalciteUtil.JoinLeafPredicateInfo) ImmutableList(com.google.common.collect.ImmutableList) RelDistribution(org.apache.calcite.rel.RelDistribution) HiveRelDistribution(org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelDistribution)

Example 2 with RelDistribution

use of org.apache.calcite.rel.RelDistribution in project hive by apache.

the class HiveOpConverter method visit.

OpAttr visit(HiveSortExchange exchangeRel) throws SemanticException {
    OpAttr inputOpAf = dispatch(exchangeRel.getInput());
    String tabAlias = inputOpAf.tabAlias;
    if (tabAlias == null || tabAlias.length() == 0) {
        tabAlias = getHiveDerivedTableAlias();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Translating operator rel#" + exchangeRel.getId() + ":" + exchangeRel.getRelTypeName() + " with row type: [" + exchangeRel.getRowType() + "]");
    }
    RelDistribution distribution = exchangeRel.getDistribution();
    if (distribution.getType() != Type.HASH_DISTRIBUTED) {
        throw new SemanticException("Only hash distribution supported for LogicalExchange");
    }
    ExprNodeDesc[] expressions = new ExprNodeDesc[exchangeRel.getJoinKeys().size()];
    for (int index = 0; index < exchangeRel.getJoinKeys().size(); index++) {
        expressions[index] = convertToExprNode(exchangeRel.getJoinKeys().get(index), exchangeRel.getInput(), inputOpAf.tabAlias, inputOpAf);
    }
    exchangeRel.setJoinExpressions(expressions);
    ReduceSinkOperator rsOp = genReduceSink(inputOpAf.inputs.get(0), tabAlias, expressions, -1, -1, Operation.NOT_ACID, hiveConf);
    return new OpAttr(tabAlias, inputOpAf.vcolsInCalcite, rsOp);
}
Also used : ReduceSinkOperator(org.apache.hadoop.hive.ql.exec.ReduceSinkOperator) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) RelDistribution(org.apache.calcite.rel.RelDistribution) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

RelDistribution (org.apache.calcite.rel.RelDistribution)2 ImmutableList (com.google.common.collect.ImmutableList)1 ReduceSinkOperator (org.apache.hadoop.hive.ql.exec.ReduceSinkOperator)1 JoinLeafPredicateInfo (org.apache.hadoop.hive.ql.optimizer.calcite.HiveCalciteUtil.JoinLeafPredicateInfo)1 HiveRelDistribution (org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelDistribution)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1