Java Code Examples for org.apache.commons.lang3.tuple.ImmutableTriple#of()

The following examples show how to use org.apache.commons.lang3.tuple.ImmutableTriple#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DruidRules.java    From Quicksql with MIT License 6 votes vote down vote up
/**
 * Given a list of conditions that contain Druid valid operations and
 * a list that contains those that contain any non-supported operation,
 * it outputs a triple with three different categories:
 * 1-l) condition filters on the timestamp column,
 * 2-m) condition filters that can be pushed to Druid,
 * 3-r) condition filters that cannot be pushed to Druid.
 */
private static Triple<List<RexNode>, List<RexNode>, List<RexNode>> splitFilters(
        final RexBuilder rexBuilder, final DruidQuery input, final List<RexNode> validPreds,
        final List<RexNode> nonValidPreds, final int timestampFieldIdx) {
  final List<RexNode> timeRangeNodes = new ArrayList<>();
  final List<RexNode> pushableNodes = new ArrayList<>();
  final List<RexNode> nonPushableNodes = new ArrayList<>(nonValidPreds);
  // Number of columns with the dimensions and timestamp
  for (RexNode conj : validPreds) {
    final RelOptUtil.InputReferencedVisitor visitor = new RelOptUtil.InputReferencedVisitor();
    conj.accept(visitor);
    if (visitor.inputPosReferenced.contains(timestampFieldIdx)) {
      if (visitor.inputPosReferenced.size() != 1) {
        // Complex predicate, transformation currently not supported
        nonPushableNodes.add(conj);
      } else {
        timeRangeNodes.add(conj);
      }
    } else {
      pushableNodes.add(conj);
    }
  }
  return ImmutableTriple.of(timeRangeNodes, pushableNodes, nonPushableNodes);
}
 
Example 2
Source File: RandomValueGenerator.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
public ImmutableTriple<Country, Country, Country> generateTeamTriple() {
	Set<Country> countries = countryService.getAvailableCountriesWithoutNoneEntry();
	List<Country> availCountries = new ArrayList<Country>(countries);
	if (CollectionUtils.isEmpty(availCountries)) {
		return null;
	}

	Country countryOne = generateRandomCountry(availCountries);
	availCountries.remove(countryOne);

	if (CollectionUtils.isEmpty(availCountries)) {
		return ImmutableTriple.of(countryOne, countryOne, countryOne);
	}

	Country countryTwo = generateRandomCountry(availCountries);
	availCountries.remove(countryTwo);

	if (CollectionUtils.isEmpty(availCountries)) {
		return ImmutableTriple.of(countryOne, countryTwo, countryTwo);
	}

	Country countryThree = generateRandomCountry(availCountries);

	return ImmutableTriple.of(countryOne, countryTwo, countryThree);
}
 
Example 3
Source File: DruidRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Given a list of conditions that contain Druid valid operations and
 * a list that contains those that contain any non-supported operation,
 * it outputs a triple with three different categories:
 * 1-l) condition filters on the timestamp column,
 * 2-m) condition filters that can be pushed to Druid,
 * 3-r) condition filters that cannot be pushed to Druid.
 */
private static Triple<List<RexNode>, List<RexNode>, List<RexNode>> splitFilters(
    final RexBuilder rexBuilder, final DruidQuery input, final List<RexNode> validPreds,
    final List<RexNode> nonValidPreds, final int timestampFieldIdx) {
  final List<RexNode> timeRangeNodes = new ArrayList<>();
  final List<RexNode> pushableNodes = new ArrayList<>();
  final List<RexNode> nonPushableNodes = new ArrayList<>(nonValidPreds);
  // Number of columns with the dimensions and timestamp
  for (RexNode conj : validPreds) {
    final RelOptUtil.InputReferencedVisitor visitor = new RelOptUtil.InputReferencedVisitor();
    conj.accept(visitor);
    if (visitor.inputPosReferenced.contains(timestampFieldIdx)
        && visitor.inputPosReferenced.size() == 1) {
      timeRangeNodes.add(conj);
    } else {
      pushableNodes.add(conj);
    }
  }
  return ImmutableTriple.of(timeRangeNodes, pushableNodes, nonPushableNodes);
}
 
Example 4
Source File: MultipleReturnValuesUsingApacheCommonsTriple.java    From tutorials with MIT License 5 votes vote down vote up
static ImmutableTriple<Double, Double, Double> getMinAvgMaxTriple(
  List<Coordinates> coordinatesList,
  Coordinates target) {

    List<Double> distanceList = coordinatesList.stream()
      .map(coordinates -> coordinates.calculateDistance(target))
      .collect(Collectors.toList());
    Double minDistance = distanceList.stream().mapToDouble(Double::doubleValue).min().getAsDouble();
    Double avgDistance = distanceList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0D);
    Double maxDistance = distanceList.stream().mapToDouble(Double::doubleValue).max().getAsDouble();

    return ImmutableTriple.of(minDistance, avgDistance, maxDistance);
}
 
Example 5
Source File: AbstractMaterializedViewRule.java    From Bats with Apache License 2.0 4 votes vote down vote up
/**
 * Classifies each of the predicates in the list into one of these three
 * categories:
 *
 * <ul>
 * <li> 1-l) column equality predicates, or
 * <li> 2-m) range predicates, comprising &lt;, &le;, &gt;, &ge;, and =
 *      between a reference and a constant, or
 * <li> 3-r) residual predicates, all the rest
 * </ul>
 *
 * <p>For each category, it creates the conjunction of the predicates. The
 * result is an array of three RexNode objects corresponding to each
 * category.
 */
private static Triple<RexNode, RexNode, RexNode> splitPredicates(RexBuilder rexBuilder, RexNode pred) {
    List<RexNode> equiColumnsPreds = new ArrayList<>();
    List<RexNode> rangePreds = new ArrayList<>();
    List<RexNode> residualPreds = new ArrayList<>();
    for (RexNode e : RelOptUtil.conjunctions(pred)) {
        switch (e.getKind()) {
        case EQUALS:
            RexCall eqCall = (RexCall) e;
            if (RexUtil.isReferenceOrAccess(eqCall.getOperands().get(0), false)
                    && RexUtil.isReferenceOrAccess(eqCall.getOperands().get(1), false)) {
                equiColumnsPreds.add(e);
            } else if ((RexUtil.isReferenceOrAccess(eqCall.getOperands().get(0), false)
                    && RexUtil.isConstant(eqCall.getOperands().get(1)))
                    || (RexUtil.isReferenceOrAccess(eqCall.getOperands().get(1), false)
                            && RexUtil.isConstant(eqCall.getOperands().get(0)))) {
                rangePreds.add(e);
            } else {
                residualPreds.add(e);
            }
            break;
        case LESS_THAN:
        case GREATER_THAN:
        case LESS_THAN_OR_EQUAL:
        case GREATER_THAN_OR_EQUAL:
        case NOT_EQUALS:
            RexCall rangeCall = (RexCall) e;
            if ((RexUtil.isReferenceOrAccess(rangeCall.getOperands().get(0), false)
                    && RexUtil.isConstant(rangeCall.getOperands().get(1)))
                    || (RexUtil.isReferenceOrAccess(rangeCall.getOperands().get(1), false)
                            && RexUtil.isConstant(rangeCall.getOperands().get(0)))) {
                rangePreds.add(e);
            } else {
                residualPreds.add(e);
            }
            break;
        default:
            residualPreds.add(e);
        }
    }
    return ImmutableTriple.of(RexUtil.composeConjunction(rexBuilder, equiColumnsPreds),
            RexUtil.composeConjunction(rexBuilder, rangePreds),
            RexUtil.composeConjunction(rexBuilder, residualPreds));
}
 
Example 6
Source File: AbstractMaterializedViewRule.java    From Bats with Apache License 2.0 4 votes vote down vote up
/**
 * We check whether the predicates in the source are contained in the predicates
 * in the target. The method treats separately the equi-column predicates, the
 * range predicates, and the rest of predicates.
 *
 * <p>If the containment is confirmed, we produce compensation predicates that
 * need to be added to the target to produce the results in the source. Thus,
 * if source and target expressions are equivalent, those predicates will be the
 * true constant.
 *
 * <p>In turn, if containment cannot be confirmed, the method returns null.
 */
private static Triple<RexNode, RexNode, RexNode> computeCompensationPredicates(RexBuilder rexBuilder,
        RexSimplify simplify, EquivalenceClasses sourceEC, Triple<RexNode, RexNode, RexNode> sourcePreds,
        EquivalenceClasses targetEC, Triple<RexNode, RexNode, RexNode> targetPreds,
        BiMap<RelTableRef, RelTableRef> sourceToTargetTableMapping) {
    final RexNode compensationColumnsEquiPred;
    final RexNode compensationRangePred;
    final RexNode compensationResidualPred;

    // 1. Establish relationship between source and target equivalence classes.
    // If every target equivalence class is not a subset of a source
    // equivalence class, we bail out.
    compensationColumnsEquiPred = generateEquivalenceClasses(rexBuilder, sourceEC, targetEC);
    if (compensationColumnsEquiPred == null) {
        // Cannot rewrite
        return null;
    }

    // 2. We check that range intervals for the source are contained in the target.
    // Compute compensating predicates.
    final RexNode queryRangePred = RexUtil.swapColumnReferences(rexBuilder, sourcePreds.getMiddle(),
            sourceEC.getEquivalenceClassesMap());
    final RexNode viewRangePred = RexUtil.swapTableColumnReferences(rexBuilder, targetPreds.getMiddle(),
            sourceToTargetTableMapping.inverse(), sourceEC.getEquivalenceClassesMap());
    compensationRangePred = SubstitutionVisitor.splitFilter(simplify, queryRangePred, viewRangePred);
    if (compensationRangePred == null) {
        // Cannot rewrite
        return null;
    }

    // 3. Finally, we check that residual predicates of the source are satisfied
    // within the target.
    // Compute compensating predicates.
    final RexNode queryResidualPred = RexUtil.swapColumnReferences(rexBuilder, sourcePreds.getRight(),
            sourceEC.getEquivalenceClassesMap());
    final RexNode viewResidualPred = RexUtil.swapTableColumnReferences(rexBuilder, targetPreds.getRight(),
            sourceToTargetTableMapping.inverse(), sourceEC.getEquivalenceClassesMap());
    compensationResidualPred = SubstitutionVisitor.splitFilter(simplify, queryResidualPred, viewResidualPred);
    if (compensationResidualPred == null) {
        // Cannot rewrite
        return null;
    }

    return ImmutableTriple.of(compensationColumnsEquiPred, compensationRangePred, compensationResidualPred);
}