当前位置: 首页>>代码示例>>Java>>正文


Java RelBuilder类代码示例

本文整理汇总了Java中org.apache.calcite.tools.RelBuilder的典型用法代码示例。如果您正苦于以下问题:Java RelBuilder类的具体用法?Java RelBuilder怎么用?Java RelBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RelBuilder类属于org.apache.calcite.tools包,在下文中一共展示了RelBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@Override
public RelNode visit(final LogicalFilter filter) {
  final RelBuilder relBuilder = newCalciteRelBuilderWithoutContext(filter.getCluster());
  RelNode input = filter.getInput().accept(this);
  relBuilder.push(input);

  RexNode newCondition = filter.getCondition().accept(new RexShuttle() {
    @Override
    public RexNode visitInputRef(RexInputRef inputRef) {
      return relBuilder.field(filter.getRowType().getFieldNames().get(inputRef.getIndex()));
    }
  });

  relBuilder.filter(newCondition);
  return relBuilder.build();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:IncrementalUpdateUtils.java

示例2: prepare

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@BeforeClass
public static void prepare() {
  relDataType = TYPE_FACTORY.builder()
      .add("order_id", SqlTypeName.BIGINT)
      .add("site_id", SqlTypeName.INTEGER)
      .add("price", SqlTypeName.DOUBLE)
      .add("order_time", SqlTypeName.BIGINT).build();

  beamRowType = CalciteUtils.toBeamRowType(relDataType);
  record = new BeamRecord(beamRowType
      , 1234567L, 0, 8.9, 1234567L);

  SchemaPlus schema = Frameworks.createRootSchema(true);
  final List<RelTraitDef> traitDefs = new ArrayList<>();
  traitDefs.add(ConventionTraitDef.INSTANCE);
  traitDefs.add(RelCollationTraitDef.INSTANCE);
  FrameworkConfig config = Frameworks.newConfigBuilder()
      .parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build()).defaultSchema(schema)
      .traitDefs(traitDefs).context(Contexts.EMPTY_CONTEXT).ruleSets(BeamRuleSets.getRuleSets())
      .costFactory(null).typeSystem(BeamRelDataTypeSystem.BEAM_REL_DATATYPE_SYSTEM).build();

  relBuilder = RelBuilder.create(config);
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:BeamSqlFnExecutorTestBase.java

示例3: evaluate

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
/**
 * Evaluates a {@link NumericHaving}.
 *
 * @param having  The NumericHaving filter to be evaluated.
 * @param builder  The RelBuilder used with Calcite to make queries.
 * @param apiToFieldMapper  A function to get the aliased aggregation's name from the metric name.
 *
 * @return the equivalent {@link RexNode} to be used in a sql query.
 */
public RexNode evaluate(NumericHaving having, RelBuilder builder, ApiToFieldMapper apiToFieldMapper) {
    Having.DefaultHavingType havingType = (Having.DefaultHavingType) having.getType();
    SqlOperator operator = null;
    switch (havingType) {
        case EQUAL_TO:
            operator = SqlStdOperatorTable.EQUALS;
            break;
        case LESS_THAN:
            operator = SqlStdOperatorTable.LESS_THAN;
            break;
        case GREATER_THAN:
            operator = SqlStdOperatorTable.GREATER_THAN;
            break;
    }
    return builder.call(
            operator,
            builder.field(apiToFieldMapper.apply(having.getAggregation())),
            builder.literal(having.getValue())
    );
}
 
开发者ID:yahoo,项目名称:fili,代码行数:30,代码来源:HavingEvaluator.java

示例4: listEvaluate

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
/**
 * Evaluates a {@link MultiClauseHaving} filter by performing it's operation over a list of other havings.
 *
 * @param multiClauseHaving  The MultiClauseHaving filter to be evaluated.
 * @param operator  The operator to be performed over the inner clauses of this having filter.
 * @param builder  The RelBuilder used with Calcite to make queries.
 * @param apiToFieldMapper  A function to get the aliased aggregation's name from the metric name.
 *
 * @return the equivalent {@link RexNode} to be used in a sql query.
 */
public RexNode listEvaluate(
        MultiClauseHaving multiClauseHaving,
        SqlOperator operator,
        RelBuilder builder,
        ApiToFieldMapper apiToFieldMapper
) {
    List<RexNode> rexNodes = multiClauseHaving.getHavings()
            .stream()
            .map(having -> dispatcher.invoke(having, builder, apiToFieldMapper))
            .collect(Collectors.toList());

    return builder.call(
            operator,
            rexNodes
    );
}
 
开发者ID:yahoo,项目名称:fili,代码行数:27,代码来源:HavingEvaluator.java

示例5: listEvaluate

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
/**
 * Evaluates a complex filter by performing a {@link SqlOperator} over a list of dimensions.
 *
 * @param complexFilter  A complexFilter to be evaluated.
 * @param operator  The sql operator to be applied to a complexFilter's fields.
 * @param builder  The RelBuilder used to build queries with Calcite.
 * @param apiToFieldMapper  A function to get the aliased aggregation's name from the metric name.
 *
 * @return a RexNode containing an equivalent filter to the one given.
 */
private RexNode listEvaluate(
        ComplexFilter complexFilter,
        SqlOperator operator,
        RelBuilder builder,
        ApiToFieldMapper apiToFieldMapper
) {
    List<RexNode> rexNodes = complexFilter.getFields()
            .stream()
            .map(filter -> dispatcher.invoke(filter, builder, apiToFieldMapper))
            .collect(Collectors.toList());

    return builder.call(
            operator,
            rexNodes
    );
}
 
开发者ID:yahoo,项目名称:fili,代码行数:27,代码来源:FilterEvaluator.java

示例6: getAllWhereFilters

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
/**
 * Returns the RexNode used to filter the druidQuery.
 *
 * @param builder  The RelBuilder created with Calcite.
 * @param druidQuery  The query from which to find filter all the filters for.
 * @param apiToFieldMapper  The mapping from api to physical names.
 * @param timestampColumn  The name of the timestamp column in the database.
 *
 * @return the combined RexNodes that should be filtered on.
 */
protected RexNode getAllWhereFilters(
        RelBuilder builder,
        DruidAggregationQuery<?> druidQuery,
        ApiToFieldMapper apiToFieldMapper,
        String timestampColumn
) {
    RexNode timeFilter = sqlTimeConverter.buildTimeFilters(
            builder,
            druidQuery,
            timestampColumn
    );

    if (druidQuery.getFilter() != null) {
        RexNode druidQueryFilter = filterEvaluator.evaluateFilter(
                druidQuery.getFilter(),
                builder,
                apiToFieldMapper
        );
        return builder.and(timeFilter, druidQueryFilter);
    }

    return timeFilter;
}
 
开发者ID:yahoo,项目名称:fili,代码行数:34,代码来源:DruidQueryToSqlConverter.java

示例7: getHavingFilter

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
/**
 * Gets the collection of having filters to be applied from the druid query.
 *
 * @param builder  The RelBuilder created with Calcite.
 * @param druidQuery  The query to find the having filter from.
 * @param apiToFieldMapper  The mapping from api to physical name.
 *
 * @return the collection of equivalent filters for calcite.
 */
protected Collection<RexNode> getHavingFilter(
        RelBuilder builder,
        DruidAggregationQuery<?> druidQuery,
        ApiToFieldMapper apiToFieldMapper
) {
    RexNode filter = null;
    if (druidQuery.getQueryType().equals(GROUP_BY)) {
        Having having = ((GroupByQuery) druidQuery).getHaving();

        if (having != null) {
            filter = havingEvaluator.evaluateHaving(having, builder, apiToFieldMapper);
        }
    }

    return Collections.singletonList(filter);
}
 
开发者ID:yahoo,项目名称:fili,代码行数:26,代码来源:DruidQueryToSqlConverter.java

示例8: getAllQueryAggregations

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
/**
 * Find all druid aggregations and convert them to {@link org.apache.calcite.tools.RelBuilder.AggCall}.
 *
 * @param builder  The RelBuilder created with Calcite.
 * @param druidQuery  The druid query to get the aggregations of.
 * @param apiToFieldMapper  The mapping from api to physical name.
 *
 * @return the list of aggregations.
 */
protected List<RelBuilder.AggCall> getAllQueryAggregations(
        RelBuilder builder,
        DruidAggregationQuery<?> druidQuery,
        ApiToFieldMapper apiToFieldMapper
) {
    return druidQuery.getAggregations()
            .stream()
            .map(aggregation -> druidSqlAggregationConverter.apply(aggregation, apiToFieldMapper))
            .map(optionalSqlAggregation -> optionalSqlAggregation.orElseThrow(() -> {
                String msg = "Couldn't build sql aggregation with " + optionalSqlAggregation;
                LOG.debug(msg);
                return new RuntimeException(msg);
            }))
            .map(sqlAggregation -> builder.aggregateCall(
                    sqlAggregation.getSqlAggFunction(),
                    false,
                    null,
                    sqlAggregation.getSqlAggregationAsName(),
                    builder.field(sqlAggregation.getSqlAggregationFieldName())
            ))
            .collect(Collectors.toList());
}
 
开发者ID:yahoo,项目名称:fili,代码行数:32,代码来源:DruidQueryToSqlConverter.java

示例9: getAllGroupByColumns

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
/**
 * Collects all the time columns and dimensions to be grouped on.
 *
 * @param builder  The RelBuilder created with Calcite.
 * @param druidQuery  The query to find grouping columns from.
 * @param apiToFieldMapper  The mapping from api to physical name.
 * @param timestampColumn  The name of the timestamp column in the database.
 *
 * @return all columns which should be grouped on.
 */
protected List<RexNode> getAllGroupByColumns(
        RelBuilder builder,
        DruidAggregationQuery<?> druidQuery,
        ApiToFieldMapper apiToFieldMapper,
        String timestampColumn
) {
    List<RexNode> timeFilters = sqlTimeConverter.buildGroupBy(
            builder,
            druidQuery.getGranularity(),
            timestampColumn
    );

    List<RexNode> dimensionFields = getDimensionFields(builder, druidQuery, apiToFieldMapper);

    List<RexNode> allGroupBys = new ArrayList<>(timeFilters.size() + dimensionFields.size());
    allGroupBys.addAll(timeFilters);
    allGroupBys.addAll(dimensionFields);
    return allGroupBys;
}
 
开发者ID:yahoo,项目名称:fili,代码行数:30,代码来源:DruidQueryToSqlConverter.java

示例10: testImplWithMultipleFilters

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@Test
@Ignore("CALCITE-1751")
public void testImplWithMultipleFilters() {
  final SchemaPlus schema = createTestSchema();
  final RelBuilder builder = createRelBuilder(schema);
  final RelNode node = builder.scan("t")
      .filter(
          builder.and(builder.call(GREATER_THAN, builder.field("tc0"), builder.literal("abc")),
              builder.call(EQUALS, builder.field("tc1"), builder.literal("3"))))
      .build();
  final RelNode optimized = optimizeWithVolcano(node);
  assertScriptAndResults("t", getPigScript(optimized, schema),
      "t = LOAD 'target/data.txt"
          + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n"
          + "t = FILTER t BY (tc0 > 'abc') AND (tc1 == '3');",
      new String[] { "(c,3)" });
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:PigRelBuilderStyleTest.java

示例11: testImplWithGroupByAndCount

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@Test
@Ignore("CALCITE-1751")
public void testImplWithGroupByAndCount() {
  final SchemaPlus schema = createTestSchema();
  final RelBuilder builder = createRelBuilder(schema);
  final RelNode node = builder.scan("t")
      .aggregate(builder.groupKey("tc0"), builder.count(false, "c", builder.field("tc1")))
      .build();
  final RelNode optimized = optimizeWithVolcano(node);
  assertScriptAndResults("t", getPigScript(optimized, schema),
      "t = LOAD 'target/data.txt"
          + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n"
          + "t = GROUP t BY (tc0);\n"
          + "t = FOREACH t {\n"
          + "  GENERATE group AS tc0, COUNT(t.tc1) AS c;\n"
          + "};",
      new String[] { "(a,1)", "(b,1)", "(c,1)" });
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:PigRelBuilderStyleTest.java

示例12: testImplWithCountWithoutGroupBy

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@Test
public void testImplWithCountWithoutGroupBy() {
  final SchemaPlus schema = createTestSchema();
  final RelBuilder builder = createRelBuilder(schema);
  final RelNode node = builder.scan("t")
      .aggregate(builder.groupKey(), builder.count(false, "c", builder.field("tc0"))).build();
  final RelNode optimized = optimizeWithVolcano(node);
  assertScriptAndResults("t", getPigScript(optimized, schema),
      "t = LOAD 'target/data.txt"
          + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n"
          + "t = GROUP t ALL;\n"
          + "t = FOREACH t {\n"
          + "  GENERATE COUNT(t.tc0) AS c;\n"
          + "};",
      new String[] { "(3)" });
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:PigRelBuilderStyleTest.java

示例13: testGetPredicatesForJoin

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@Test public void testGetPredicatesForJoin() throws Exception {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  RelNode join = builder
      .scan("EMP")
      .scan("DEPT")
      .join(JoinRelType.INNER, builder.call(NONDETERMINISTIC_OP))
      .build();
  RelMetadataQuery mq = RelMetadataQuery.instance();
  assertTrue(mq.getPulledUpPredicates(join).pulledUpPredicates.isEmpty());

  RelNode join1 = builder
      .scan("EMP")
      .scan("DEPT")
      .join(JoinRelType.INNER,
        builder.call(SqlStdOperatorTable.EQUALS,
          builder.field(2, 0, 0),
          builder.field(2, 1, 0)))
      .build();
  assertEquals("=($0, $8)",
      mq.getPulledUpPredicates(join1).pulledUpPredicates.get(0).toString());
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:RelMetadataTest.java

示例14: testDistinct

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@Test public void testDistinct() {
  // Equivalent SQL:
  //   SELECT DISTINCT deptno
  //   FROM emp
  final RelBuilder builder = RelBuilder.create(config().build());
  RelNode root =
      builder.scan("EMP")
          .project(builder.field("DEPTNO"))
          .distinct()
          .build();
  final String expected = "LogicalAggregate(group=[{0}])\n"
      + "  LogicalProject(DEPTNO=[$7])\n"
      + "    LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(str(root),
      is(expected));
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelBuilderTest.java

示例15: testScanFilterOr2

import org.apache.calcite.tools.RelBuilder; //导入依赖的package包/类
@Test public void testScanFilterOr2() {
  // Equivalent SQL:
  //   SELECT *
  //   FROM emp
  //   WHERE deptno = 20 OR deptno = 20
  // simplifies to
  //   SELECT *
  //   FROM emp
  //   WHERE deptno = 20
  final RelBuilder builder = RelBuilder.create(config().build());
  RelNode root =
      builder.scan("EMP")
          .filter(
              builder.call(SqlStdOperatorTable.OR,
                  builder.call(SqlStdOperatorTable.GREATER_THAN,
                      builder.field("DEPTNO"),
                      builder.literal(20)),
                  builder.call(SqlStdOperatorTable.GREATER_THAN,
                      builder.field("DEPTNO"),
                      builder.literal(20))))
          .build();
  assertThat(str(root),
      is("LogicalFilter(condition=[>($7, 20)])\n"
          + "  LogicalTableScan(table=[[scott, EMP]])\n"));
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:RelBuilderTest.java


注:本文中的org.apache.calcite.tools.RelBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。