示例#1
0
  private PlanBuilder appendSemiJoin(PlanBuilder subPlan, InPredicate inPredicate) {
    TranslationMap translations = new TranslationMap(subPlan.getRelationPlan(), analysis);
    translations.copyMappingsFrom(subPlan.getTranslations());

    subPlan = appendProjections(subPlan, ImmutableList.of(inPredicate.getValue()));
    Symbol sourceJoinSymbol = subPlan.translate(inPredicate.getValue());

    checkState(inPredicate.getValueList() instanceof SubqueryExpression);
    SubqueryExpression subqueryExpression = (SubqueryExpression) inPredicate.getValueList();
    RelationPlanner relationPlanner =
        new RelationPlanner(analysis, symbolAllocator, idAllocator, metadata, session);
    RelationPlan valueListRelation = relationPlanner.process(subqueryExpression.getQuery(), null);
    Symbol filteringSourceJoinSymbol =
        Iterables.getOnlyElement(valueListRelation.getRoot().getOutputSymbols());

    Symbol semiJoinOutputSymbol = symbolAllocator.newSymbol("semijoinresult", BOOLEAN);

    translations.put(inPredicate, semiJoinOutputSymbol);

    return new PlanBuilder(
        translations,
        new SemiJoinNode(
            idAllocator.getNextId(),
            subPlan.getRoot(),
            valueListRelation.getRoot(),
            sourceJoinSymbol,
            filteringSourceJoinSymbol,
            semiJoinOutputSymbol,
            Optional.empty(),
            Optional.empty()),
        subPlan.getSampleWeight());
  }
示例#2
0
    @Override
    protected Type visitInPredicate(InPredicate node, AnalysisContext context) {
      Expression value = node.getValue();
      process(value, context);

      Expression valueList = node.getValueList();
      process(valueList, context);

      if (valueList instanceof InListExpression) {
        InListExpression inListExpression = (InListExpression) valueList;

        coerceToSingleType(
            context,
            "IN value and list items must be the same type: %s",
            ImmutableList.<Expression>builder()
                .add(value)
                .addAll(inListExpression.getValues())
                .build());
      } else if (valueList instanceof SubqueryExpression) {
        coerceToSingleType(
            context,
            node,
            "value and result of subquery must be of the same type for IN expression: %s vs %s",
            value,
            valueList);
        subqueryInPredicates.add(node);
      }

      expressionTypes.put(node, BOOLEAN);
      return BOOLEAN;
    }
示例#3
0
 @Override
 protected String visitInPredicate(InPredicate node, Boolean unmangleNames) {
   return "("
       + process(node.getValue(), unmangleNames)
       + " IN "
       + process(node.getValueList(), unmangleNames)
       + ")";
 }
示例#4
0
 @Override
 protected Void visitInPredicate(InPredicate node, Void context) {
   Expression valueList = node.getValueList();
   if (valueList instanceof SubqueryExpression) {
     process(node.getValue(), context);
     super.visitSubqueryExpression((SubqueryExpression) valueList, context);
   } else {
     super.visitInPredicate(node, context);
   }
   return null;
 }