本文整理汇总了Java中org.apache.calcite.rel.core.Filter类的典型用法代码示例。如果您正苦于以下问题:Java Filter类的具体用法?Java Filter怎么用?Java Filter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Filter类属于org.apache.calcite.rel.core包,在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trans
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
private String trans(String sql) throws Exception {
Properties info = new Properties();
info.setProperty("lex", "JAVA");
String jsonFile = SolrSqlTest.class.getClassLoader().getResource("solr.json").toString().replaceAll("file:/", "");
try {
Class.forName("org.apache.calcite.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
CalciteConnection connection = (CalciteConnection) DriverManager.getConnection("jdbc:calcite:model="+jsonFile, info);
final SchemaPlus schema = connection.getRootSchema().getSubSchema("solr");
connection.close();
ConfigBuilder builder = Frameworks.newConfigBuilder().defaultSchema(schema).parserConfig(SqlParser.configBuilder().setCaseSensitive(false).build());
FrameworkConfig config = builder.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode sqlNode = planner.parse(sql);
SqlNode node = planner.validate(sqlNode);
RelRoot relRoot = planner.rel(node);
RelNode project = relRoot.project();
RexNode condition = ((Filter) ((Project) project).getInput()).getCondition();
return _trans.translate(condition).toSolrQueryString();
}
示例2: onMatch
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
Filter filterRel = call.rel(0);
Project projRel = call.rel(1);
// Don't push Filter past Project if the Filter is referencing an ITEM or a FLATTEN expression
// from the Project.
//\TODO: Ideally we should split up the filter conditions into ones that
// reference the ITEM expression and ones that don't and push the latter past the Project
if (findItemOrFlatten(filterRel.getCondition(), projRel.getProjects()) != null) {
return;
}
// convert the filter to one that references the child of the project
RexNode newCondition =
RelOptUtil.pushFilterPastProject(filterRel.getCondition(), projRel);
Filter newFilterRel = LogicalFilter.create(projRel.getInput(), newCondition);
Project newProjRel =
(Project) RelOptUtil.createProject(
newFilterRel,
projRel.getNamedProjects(),
false);
call.transformTo(newProjRel);
}
示例3: empty
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
/** Creates a relational expression that reads from an input and throws
* all of the rows away.
*/
@Override
public RelBuilder empty() {
final Frame frame = stack.pop();
final RelNode input;
// If the rel that we are limiting the output of a rel, we should just add a limit 0 on top.
// If the rel that we are limiting is a Filter replace it as well since Filter does not
// change the row type.
if (!(frame.rel instanceof Filter)) {
input = frame.rel;
} else {
input = frame.rel.getInput(0);
}
final RelNode sort = sortFactory.createSort(input, RelCollations.EMPTY,
frame.rel.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(0)),
frame.rel.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(0)));
push(sort);
return this;
}
示例4: visitFilter
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
@Override
public Void visitFilter(Filter filter, List<Void> inputStreams) throws Exception {
beginStage(filter);
List<RexNode> childExps = filter.getChildExps();
RelDataType inputRowType = filter.getInput(0).getRowType();
pw.print("Context context = new StreamlineContext(Processor.dataContext);\n");
pw.print("context.values = _data.toArray();\n");
pw.print("Object[] outputValues = new Object[1];\n");
pw.write(rexCompiler.compileToBlock(childExps, inputRowType).toString());
String r = "((Boolean) outputValues[0])";
if (filter.getCondition().getType().isNullable()) {
pw.print(String.format(" if (%s != null && %s) { ctx.emit(_data); }\n", r, r));
} else {
pw.print(String.format(" if (%s) { ctx.emit(_data); }\n", r, r));
}
endStage();
return null;
}
示例5: isLatticeFilterSatisfied
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
/**
* Checks if filter satisfies the lattice filter
* i.e., it needs data captured by the lattice
*/
private boolean isLatticeFilterSatisfied(final RelOptLattice lattice,
final Filter filter,
final StarTable.StarTableScan scan) {
if (lattice.lattice.filter == null) {
return true;
}
RexExecutorImpl rexImpl =
(RexExecutorImpl) (scan.getCluster().getPlanner().getExecutor());
RexImplicationChecker solver =
new RexImplicationChecker(scan.getCluster().getRexBuilder(),
rexImpl, scan.getRowType());
try {
return solver.implies(filter.getCondition(), lattice.lattice.filter);
} catch (Exception e) {
LOG.debug("Exception thrown while solving "
+ filter.getCondition()
+ " => "
+ lattice.lattice.filter);
return false;
}
}
示例6: signature
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
/** Returns a string describing the operations inside this query.
*
* <p>For example, "sfpaol" means {@link TableScan} (s)
* followed by {@link Filter} (f)
* followed by {@link Project} (p)
* followed by {@link Aggregate} (a)
* followed by {@link Project} (o)
* followed by {@link Sort} (l).
*
* @see #isValidSignature(String)
*/
String signature() {
final StringBuilder b = new StringBuilder();
boolean flag = false;
for (RelNode rel : rels) {
b.append(rel instanceof TableScan ? 's'
: (rel instanceof Project && flag) ? 'o'
: rel instanceof Filter ? 'f'
: rel instanceof Aggregate ? 'a'
: rel instanceof Sort ? 'l'
: rel instanceof Project ? 'p'
: '!');
flag = flag || rel instanceof Aggregate;
}
return b.toString();
}
示例7: getDistinctRowCount
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
public Double getDistinctRowCount(Filter rel, RelMetadataQuery mq,
ImmutableBitSet groupKey, RexNode predicate) {
if (predicate == null || predicate.isAlwaysTrue()) {
if (groupKey.isEmpty()) {
return 1D;
}
}
// REVIEW zfong 4/18/06 - In the Broadbase code, duplicates are not
// removed from the two filter lists. However, the code below is
// doing so.
RexNode unionPreds =
RelMdUtil.unionPreds(
rel.getCluster().getRexBuilder(),
predicate,
rel.getCondition());
return mq.getDistinctRowCount(rel.getInput(), groupKey, unionPreds);
}
示例8: getSelectivity
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
public Double getSelectivity(Filter rel, RelMetadataQuery mq,
RexNode predicate) {
// Take the difference between the predicate passed in and the
// predicate in the filter's condition, so we don't apply the
// selectivity of the filter twice. If no predicate is passed in,
// use the filter's condition.
if (predicate != null) {
return mq.getSelectivity(rel.getInput(),
RelMdUtil.minusPreds(
rel.getCluster().getRexBuilder(),
predicate,
rel.getCondition()));
} else {
return mq.getSelectivity(rel.getInput(), rel.getCondition());
}
}
示例9: areColumnsUnique
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
public Boolean areColumnsUnique(RelSubset rel, RelMetadataQuery mq,
ImmutableBitSet columns, boolean ignoreNulls) {
int nullCount = 0;
for (RelNode rel2 : rel.getRels()) {
if (rel2 instanceof Aggregate
|| rel2 instanceof Filter
|| rel2 instanceof Values
|| rel2 instanceof TableScan
|| simplyProjects(rel2, columns)) {
try {
final Boolean unique = mq.areColumnsUnique(rel2, columns, ignoreNulls);
if (unique != null) {
if (unique) {
return true;
}
} else {
++nullCount;
}
} catch (CyclicMetadataException e) {
// Ignore this relational expression; there will be non-cyclic ones
// in this set.
}
}
}
return nullCount == 0 ? false : null;
}
示例10: onMatch
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
@Override public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
final String timeZone = filter.getCluster().getPlanner().getContext()
.unwrap(CalciteConnectionConfig.class).timeZone();
final RexNode condition =
replaceTimeUnits(rexBuilder, filter.getCondition(), timeZone);
if (RexUtil.eq(condition, filter.getCondition())) {
return;
}
final RelBuilder relBuilder =
relBuilderFactory.create(filter.getCluster(), null);
relBuilder.push(filter.getInput())
.filter(condition);
call.transformTo(relBuilder.build());
}
示例11: apply
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) {
final ImmutableIntList projects;
final ImmutableList.Builder<RexNode> filters = ImmutableList.builder();
if (scan instanceof Bindables.BindableTableScan) {
final Bindables.BindableTableScan bindableScan =
(Bindables.BindableTableScan) scan;
filters.addAll(bindableScan.filters);
projects = bindableScan.projects;
} else {
projects = scan.identity();
}
final Mapping mapping = Mappings.target(projects,
scan.getTable().getRowType().getFieldCount());
filters.add(
RexUtil.apply(mapping, filter.getCondition()));
call.transformTo(
Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(),
filters.build(), projects));
}
示例12: DrillMergeFilterRule
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
/**
* Creates a MergeFilterRule.
*/
private DrillMergeFilterRule(RelFactories.FilterFactory filterFactory) {
super(
operand(Filter.class,
operand(Filter.class, any())));
this.filterFactory = filterFactory;
}
示例13: onMatch
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
Filter topFilter = call.rel(0);
Filter bottomFilter = call.rel(1);
// use RexPrograms to merge the two FilterRels into a single program
// so we can convert the two FilterRel conditions to directly
// reference the bottom FilterRel's child
RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
RexProgram bottomProgram = createProgram(bottomFilter);
RexProgram topProgram = createProgram(topFilter);
RexProgram mergedProgram =
RexProgramBuilder.mergePrograms(
topProgram,
bottomProgram,
rexBuilder);
RexNode newCondition =
mergedProgram.expandLocalRef(
mergedProgram.getCondition());
// if(!RexUtil.isFlat(newCondition)){
// RexCall newCall = (RexCall) newCondition;
// newCondition = rexBuilder.makeFlatCall( newCall.getOperator(), newCall.getOperands());
// }
Filter newFilterRel =
(Filter) filterFactory.createFilter(
bottomFilter.getInput(),
RexUtil.flatten(rexBuilder, newCondition));
call.transformTo(newFilterRel);
}
示例14: createProgram
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
/**
* Creates a RexProgram corresponding to a LogicalFilter
*
* @param filterRel the LogicalFilter
* @return created RexProgram
*/
private RexProgram createProgram(Filter filterRel) {
RexProgramBuilder programBuilder =
new RexProgramBuilder(
filterRel.getRowType(),
filterRel.getCluster().getRexBuilder());
programBuilder.addIdentity();
programBuilder.addCondition(filterRel.getCondition());
return programBuilder.getProgram();
}
示例15: estimateCpuCost
import org.apache.calcite.rel.core.Filter; //导入依赖的package包/类
private double estimateCpuCost() {
RelNode child = this.getInput();
double compNum = RelMetadataQuery.getRowCount(child);
for (int i = 0; i< numConjuncts; i++) {
RexNode conjFilter = RexUtil.composeConjunction(this.getCluster().getRexBuilder(), conjunctions.subList(0, i + 1), false);
compNum += Filter.estimateFilteredRows(child, conjFilter);
}
return compNum * DrillCostBase.COMPARE_CPU_COST;
}