Tabnine Logo
RexProgram
Code IndexAdd Tabnine to your IDE (free)

How to use
RexProgram
in
org.apache.calcite.rex

Best Java code snippets using org.apache.calcite.rex.RexProgram (Showing top 20 results out of 315)

origin: apache/storm

RexLocalRef condition = program.getCondition();
if (condition != null) {
  RexNode conditionNode = program.expandLocalRef(condition);
  filterInstance = planCreator.createScalarInstance(Lists.newArrayList(conditionNode), inputRowType,
                           StormRelUtils.getClassName(this));
List<RexLocalRef> projectList = program.getProjectList();
if (projectList != null && !projectList.isEmpty()) {
  List<RexNode> expandedNodes = new ArrayList<>();
  for (RexLocalRef project : projectList) {
    expandedNodes.add(program.expandLocalRef(project));
origin: apache/storm

private BlockBuilder compileToBlock(final RexProgram program, ParameterExpression context,
                  ParameterExpression outputValues) {
  RelDataType inputRowType = program.getInputRowType();
  final BlockBuilder builder = new BlockBuilder();
  final JavaTypeFactoryImpl javaTypeFactory =
origin: apache/kylin

@Override
public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) {
  if (getInput() instanceof OLAPFilterRel) {
    // merge project & filter
    OLAPFilterRel filter = (OLAPFilterRel) getInput();
    RelNode inputOfFilter = inputs.get(0).getInput(0);
    RexProgram program = RexProgram.create(inputOfFilter.getRowType(), this.rewriteProjects,
        filter.getCondition(), this.rowType, getCluster().getRexBuilder());
    return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), //
        inputOfFilter, program);
  } else {
    // keep project for table scan
    EnumerableRel input = sole(inputs);
    RexProgram program = RexProgram.create(input.getRowType(), this.rewriteProjects, null, this.rowType,
        getCluster().getRexBuilder());
    return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), //
        input, program);
  }
}
origin: Qihoo360/Quicksql

/**
 * Returns whether this program returns its input exactly.
 *
 * <p>This is a stronger condition than {@link #projectsIdentity(boolean)}.
 */
public boolean isTrivial() {
 return getCondition() == null && projectsOnlyIdentity();
}
origin: org.apache.calcite/calcite-core

 RexBuilder rexBuilder,
 boolean normalize) {
assert program.isValid(Litmus.THROW, null);
final RelDataType inputRowType = program.getInputRowType();
final List<RexLocalRef> projectRefs = program.getProjectList();
final RexLocalRef conditionRef = program.getCondition();
final List<RexNode> exprs = program.getExprList();
final RelDataType outputRowType = program.getOutputRowType();
return create(
  rexBuilder,
origin: dremio/dremio-oss

public RexProgram copyOf(RexProgram program) {
 return new RexProgram(
  copyOf(program.getInputRowType()),
  copyRexNodes(program.getExprList()),
  Lists.transform(program.getProjectList(), COPY_REX_LOCAL_REF),
  (RexLocalRef) copyOf(program.getCondition()),
  copyOf(program.getOutputRowType())
 );
}
origin: org.apache.calcite/calcite-core

public static double estimateFilteredRows(RelNode child, RexProgram program,
  RelMetadataQuery mq) {
 // convert the program's RexLocalRef condition to an expanded RexNode
 RexLocalRef programCondition = program.getCondition();
 RexNode condition;
 if (programCondition == null) {
  condition = null;
 } else {
  condition = program.expandLocalRef(programCondition);
 }
 return estimateFilteredRows(child, condition, mq);
}
origin: Qihoo360/Quicksql

 @Override protected RelNode handle(RelNode rel) {
  if (!(rel instanceof LogicalCalc)) {
   return rel;
  }
  final LogicalCalc calc = (LogicalCalc) rel;
  final RexProgram program = calc.getProgram();
  relBuilder.push(calc.getInput());
  if (program.getCondition() != null) {
   relBuilder.filter(
     program.expandLocalRef(program.getCondition()));
  }
  if (!program.projectsOnlyIdentity()) {
   relBuilder.project(
     Lists.transform(program.getProjectList(),
       program::expandLocalRef),
     calc.getRowType().getFieldNames());
  }
  return relBuilder.build();
 }
};
origin: Qihoo360/Quicksql

private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) {
 final List<RexNode> exprList = program.getExprList();
 final List<RexLocalRef> projectRefList = new ArrayList<>();
 final RexShuttle shuttle = new RegisterOutputShuttle(exprList);
 // For each project, lookup the expr and expand it so it is in terms of
 // bottomCalc's input fields
 for (RexLocalRef topProject : program.getProjectList()) {
  final RexNode topExpr = exprList.get(topProject.getIndex());
  final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle);
  // Remember the expr, but don't add to the project list yet.
  projectRefList.add(expanded);
 }
 // Similarly for the condition.
 final RexLocalRef topCondition = program.getCondition();
 if (topCondition != null) {
  final RexNode topExpr = exprList.get(topCondition.getIndex());
  final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle);
  addCondition(registerInput(expanded));
 }
 return projectRefList;
}
origin: Qihoo360/Quicksql

public static boolean isStar(RexProgram program) {
 int i = 0;
 for (RexLocalRef ref : program.getProjectList()) {
  if (ref.getIndex() != i++) {
   return false;
  }
 }
 return i == program.getInputRowType().getFieldCount();
}
origin: Qihoo360/Quicksql

/**
 * Returns whether this program is in canonical form.
 *
 * @param litmus     What to do if an error is detected (program is not in
 *                   canonical form)
 * @param rexBuilder Rex builder
 * @return whether in canonical form
 */
public boolean isNormalized(Litmus litmus, RexBuilder rexBuilder) {
 final RexProgram normalizedProgram = normalize(rexBuilder, null);
 String normalized = normalizedProgram.toString();
 String string = toString();
 if (!normalized.equals(string)) {
  final String message = "Program is not normalized:\n"
    + "program:    {}\n"
    + "normalized: {}\n";
  return litmus.fail(message, string, normalized);
 }
 return litmus.succeed();
}
origin: Qihoo360/Quicksql

public void onMatch(RelOptRuleCall call) {
 LogicalCalc calc = call.rel(0);
 // Expand decimals in every expression in this program. If no
 // expression changes, don't apply the rule.
 final RexProgram program = calc.getProgram();
 if (!RexUtil.requiresDecimalExpansion(program, true)) {
  return;
 }
 final RexBuilder rexBuilder = calc.getCluster().getRexBuilder();
 final RexShuttle shuttle = new DecimalShuttle(rexBuilder);
 RexProgramBuilder programBuilder =
   RexProgramBuilder.create(
     rexBuilder,
     calc.getInput().getRowType(),
     program.getExprList(),
     program.getProjectList(),
     program.getCondition(),
     program.getOutputRowType(),
     shuttle,
     true);
 final RexProgram newProgram = programBuilder.getProgram();
 LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram);
 call.transformTo(newCalc);
}
origin: qubole/quark

  || calc.getProgram().containsAggs()) {
 return;
final int[] adjustments = new int[calc.getProgram().getExprCount()];
if (rightJoinChild == calc.getInput()) {
 int offset = leftJoinChild.getRowType().getFieldList().size();
    joinRel.getRowType().getFieldList(),
    adjustments);
if (calc.getProgram().getCondition() != null) {
 RexNode cond =
   calc.getProgram().expandLocalRef(calc.getProgram().getCondition());
 final RexLocalRef rexLocalRef =
   topProgramBuilder.addExpr(cond.accept(rexInputConverter));
origin: qubole/quark

public Result visitCalc(Calc e) {
 Result x = visitChild(0, e.getInput());
 final RexProgram program = e.getProgram();
 Builder builder =
   program.getCondition() != null
     ? x.builder(e, Clause.WHERE)
     : x.builder(e);
 if (!isStar(program)) {
  final List<SqlNode> selectList = new ArrayList<>();
  for (RexLocalRef ref : program.getProjectList()) {
   SqlNode sqlExpr = builder.context.toSql(program, ref);
   addSelect(selectList, sqlExpr, e.getRowType());
  }
  builder.setSelect(new SqlNodeList(selectList, POS));
 }
 if (program.getCondition() != null) {
  builder.setWhere(
    builder.context.toSql(program, program.getCondition()));
 }
 return builder.result();
}
origin: Qihoo360/Quicksql

 protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet,
   RelBuilder relBuilder, RelNode input, RexProgram program) {
  Preconditions.checkArgument(program.getCondition() == null,
    "WindowedAggregateRel cannot accept a condition");
  return LogicalWindow.create(cluster, traitSet, relBuilder, input,
    program);
 }
}
origin: Qihoo360/Quicksql

public boolean isValid(Litmus litmus, Context context) {
 if (!RelOptUtil.equal(
   "program's input type",
   program.getInputRowType(),
   "child's output type",
   getInput().getRowType(), litmus)) {
  return litmus.fail(null);
 }
 if (!program.isValid(litmus, context)) {
  return litmus.fail(null);
 }
 if (!program.isNormalized(litmus, getCluster().getRexBuilder())) {
  return litmus.fail(null);
 }
 return litmus.succeed();
}
origin: Qihoo360/Quicksql

/**
 * Returns whether a program contains a multiset.
 */
public static boolean containsMultiset(RexProgram program) {
 return containsMultiset(program.getExprList(), true);
}
origin: com.alibaba.blink/flink-table

  public void onMatch(RelOptRuleCall call) {
    final Aggregate aggregate = call.rel(0);
    final Calc calc = call.rel(1);
    final RexProgram program = calc.getProgram();
    final List<RexNode> projects = new ArrayList<>();
    for (RexLocalRef localRef : program.getProjectList()) {
      projects.add(program.expandLocalRef(localRef));
    }
    final Project project = LogicalProject.create(calc.getInput(), projects, calc.getRowType());
    RelNode x = AggregateProjectMergeRule.apply(call, aggregate, project);
    if (x != null) {
      call.transformTo(x);
    }
  }
}
origin: Qihoo360/Quicksql

 /**
  * Returns whether this tester's <code>RelType</code> can implement a
  * given program.
  *
  * @param program Program
  * @return Whether this tester's <code>RelType</code> can implement a
  * given program.
  */
 public boolean canImplement(RexProgram program) {
  if ((program.getCondition() != null)
    && !canImplement(program.getCondition(), true)) {
   return false;
  }
  for (RexNode expr : program.getExprList()) {
   if (!canImplement(expr, false)) {
    return false;
   }
  }
  return true;
 }
}
origin: org.apache.calcite/calcite-core

  protected RelNode makeRel(RelOptCluster cluster,
    RelTraitSet traitSet, RelBuilder relBuilder, RelNode input,
    RexProgram program) {
   assert !program.containsAggs();
   program = program.normalize(cluster.getRexBuilder(), null);
   return super.makeRel(cluster, traitSet, relBuilder, input,
     program);
  }
},
org.apache.calcite.rexRexProgram

Javadoc

A collection of expressions which read inputs, compute output expressions, and optionally use a condition to filter rows.

Programs are immutable. It may help to use a RexProgramBuilder, which has the same relationship to RexProgram as StringBufferhas to String.

A program can contain aggregate functions. If it does, the arguments to each aggregate function must be an RexInputRef.

Most used methods

  • expandLocalRef
    Fully expands a RexLocalRef back into a pure RexNode tree containing no RexLocalRefs (reversing the
  • getCondition
    Returns the field reference of this program's filter condition, or null if there is no condition.
  • getInputRowType
    Returns the type of the input row to the program.
  • getProjectList
    Returns an array of references to the expressions which this program is to project. Never null, may
  • create
    Creates a program which calculates projections and filters rows based upon a condition. Does not att
  • getExprList
    Returns the common sub-expressions of this program.The list is never null but may be empty; each the
  • normalize
  • toString
  • <init>
    Creates a program.The expressions must be valid: they must not contain common expressions, forward r
  • containsAggs
    Returns whether this program contains windowed aggregate functions
  • getExprCount
    Returns the number of expressions in this program.
  • getOutputRowType
    Returns the type of the output row from this program.
  • getExprCount,
  • getOutputRowType,
  • collectExplainTerms,
  • countTrivial,
  • createIdentity,
  • deduceCollations,
  • explainCalc,
  • getCollations,
  • getPermutation,
  • getSourceField

Popular in Java

  • Making http post requests using okhttp
  • getSharedPreferences (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • onCreateOptionsMenu (Activity)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now