Java Code Examples for org.apache.calcite.sql2rel.StandardConvertletTable

The following examples show how to use org.apache.calcite.sql2rel.StandardConvertletTable. These examples are extracted from open source projects. 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 Project: Bats   Source File: DrillConvertletTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public SqlRexConvertlet get(SqlCall call) {
  SqlRexConvertlet convertlet;
  if(call.getOperator() instanceof DrillCalciteSqlWrapper) {
    final SqlOperator wrapper = call.getOperator();
    final SqlOperator wrapped = DrillCalciteWrapperUtility.extractSqlOperatorFromWrapper(call.getOperator());
    if ((convertlet = map.get(wrapped)) != null) {
      return convertlet;
    }

    ((SqlBasicCall) call).setOperator(wrapped);
    SqlRexConvertlet sqlRexConvertlet = StandardConvertletTable.INSTANCE.get(call);
    ((SqlBasicCall) call).setOperator(wrapper);
    return sqlRexConvertlet;
  }

  if ((convertlet = map.get(call.getOperator())) != null) {
    return convertlet;
  }

  return StandardConvertletTable.INSTANCE.get(call);
}
 
Example 2
Source Project: quark   Source File: SqlWorker.java    License: Apache License 2.0 6 votes vote down vote up
private Planner buildPlanner(QueryContext context) {
  final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
  traitDefs.add(ConventionTraitDef.INSTANCE);
  traitDefs.add(RelCollationTraitDef.INSTANCE);
  final ChainedSqlOperatorTable opTab =
      new ChainedSqlOperatorTable(
          ImmutableList.of(SqlStdOperatorTable.instance(),
              HiveSqlOperatorTable.instance(), catalogReader));
  FrameworkConfig config = Frameworks.newConfigBuilder() //
      .parserConfig(SqlParser.configBuilder()
          .setQuotedCasing(Casing.UNCHANGED)
          .setUnquotedCasing(Casing.TO_UPPER)
          .setQuoting(Quoting.DOUBLE_QUOTE)
          .build()) //
      .defaultSchema(context.getDefaultSchema()) //
      .operatorTable(opTab) //
      .traitDefs(traitDefs) //
      .convertletTable(StandardConvertletTable.INSTANCE)//
      .programs(getPrograms()) //
      .typeSystem(RelDataTypeSystem.DEFAULT) //
      .build();
  return Frameworks.getPlanner(config);
}
 
Example 3
Source Project: calcite   Source File: SqlToRelTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected SqlToRelConverter createSqlToRelConverter(
    final SqlValidator validator,
    final Prepare.CatalogReader catalogReader,
    final RelDataTypeFactory typeFactory,
    final SqlToRelConverter.Config config) {
  final RexBuilder rexBuilder = new RexBuilder(typeFactory);
  RelOptCluster cluster =
      RelOptCluster.create(getPlanner(), rexBuilder);
  if (clusterFactory != null) {
    cluster = clusterFactory.apply(cluster);
  }
  RelOptTable.ViewExpander viewExpander =
      new MockViewExpander(validator, catalogReader, cluster, config);
  return new SqlToRelConverter(viewExpander, validator, catalogReader, cluster,
      StandardConvertletTable.INSTANCE, config);
}
 
Example 4
Source Project: calcite   Source File: AbstractMaterializedViewTest.java    License: Apache License 2.0 6 votes vote down vote up
private RelNode toRel(RelOptCluster cluster, SchemaPlus rootSchema,
    SchemaPlus defaultSchema, String sql) throws SqlParseException {
  final SqlParser parser = SqlParser.create(sql, SqlParser.Config.DEFAULT);
  final SqlNode parsed = parser.parseStmt();

  final CalciteCatalogReader catalogReader = new CalciteCatalogReader(
      CalciteSchema.from(rootSchema),
      CalciteSchema.from(defaultSchema).path(null),
      new JavaTypeFactoryImpl(), new CalciteConnectionConfigImpl(new Properties()));

  final SqlValidator validator = new ValidatorForTest(SqlStdOperatorTable.instance(),
      catalogReader, new JavaTypeFactoryImpl(), SqlConformanceEnum.DEFAULT);
  final SqlNode validated = validator.validate(parsed);
  final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder()
      .withTrimUnusedFields(true)
      .withExpand(true)
      .withDecorrelationEnabled(true)
      .build();
  final SqlToRelConverter converter = new SqlToRelConverter(
      (rowType, queryString, schemaPath, viewPath) -> {
        throw new UnsupportedOperationException("cannot expand view");
      }, validator, catalogReader, cluster, StandardConvertletTable.INSTANCE, config);
  return converter.convertQuery(validated, false, true).rel;
}
 
Example 5
Source Project: Bats   Source File: BatsOptimizerTest.java    License: Apache License 2.0 5 votes vote down vote up
static RelNode testSqlToRelConverter(RelOptPlanner planner) throws Exception {
    RexBuilder rexBuilder = createRexBuilder();
    RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder);
    RelOptTable.ViewExpander viewExpander = ViewExpanders.simpleContext(cluster);

    Pair<SqlNode, SqlValidator> pair = testSqlValidator();
    SqlNode sqlNode = pair.left;
    SqlValidator validator = pair.right;
    CatalogReader catalogReader = createCalciteCatalogReader();
    SqlRexConvertletTable convertletTable = StandardConvertletTable.INSTANCE;
    SqlToRelConverter.Config config = SqlToRelConverter.Config.DEFAULT;
    // 不转换成EnumerableTableScan,而是LogicalTableScan
    config = SqlToRelConverter.configBuilder().withConvertTableAccess(false).build();

    SqlToRelConverter converter = new SqlToRelConverter(viewExpander, validator, catalogReader, cluster,
            convertletTable, config);

    boolean needsValidation = false;
    boolean top = false;
    RelRoot root = converter.convertQuery(sqlNode, needsValidation, top);
    RelNode relNode = root.rel;

    String plan = RelOptUtil.toString(relNode);
    System.out.println("Logical Plan:");
    System.out.println("------------------------------------------------------------------");
    System.out.println(plan);
    System.out.println();

    // testPrograms(root.rel);

    return relNode;
}
 
Example 6
Source Project: dremio-oss   Source File: ConvertletTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SqlRexConvertlet get(SqlCall call) {
  SqlRexConvertlet convertlet;

  if ((convertlet = super.get(call)) != null) {
    return convertlet;
  }

  return StandardConvertletTable.INSTANCE.get(call);
}
 
Example 7
Source Project: calcite   Source File: Frameworks.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates a ConfigBuilder, initializing to defaults. */
private ConfigBuilder() {
  convertletTable = StandardConvertletTable.INSTANCE;
  operatorTable = SqlStdOperatorTable.instance();
  programs = ImmutableList.of();
  context = Contexts.empty();
  parserConfig = SqlParser.Config.DEFAULT;
  sqlValidatorConfig = SqlValidator.Config.DEFAULT;
  sqlToRelConverterConfig = SqlToRelConverter.Config.DEFAULT;
  typeSystem = RelDataTypeSystem.DEFAULT;
  evolveLattice = false;
  statisticProvider = QuerySqlStatisticProvider.SILENT_CACHING_INSTANCE;
}
 
Example 8
Source Project: calcite   Source File: SqlToRelTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override public RelRoot expandView(RelDataType rowType, String queryString,
    List<String> schemaPath, List<String> viewPath) {
  try {
    SqlNode parsedNode = SqlParser.create(queryString).parseStmt();
    SqlNode validatedNode = validator.validate(parsedNode);
    SqlToRelConverter converter = new SqlToRelConverter(
        this, validator, catalogReader, cluster,
        StandardConvertletTable.INSTANCE, config);
    return converter.convertQuery(validatedNode, false, true);
  } catch (SqlParseException e) {
    throw new RuntimeException("Error happened while expanding view.", e);
  }
}
 
Example 9
Source Project: marble   Source File: TableEnv.java    License: Apache License 2.0 4 votes vote down vote up
public TableEnv(TableConfig tableConfig) {
  try {
    this.tableConfig = tableConfig;
    SqlParser.Config sqlParserConfig = tableConfig.getSqlParserConfig()
        != null ? tableConfig.getSqlParserConfig() : SqlParser
        .configBuilder().setCaseSensitive(false)
        .build();
    SqlOperatorTable sqlStdOperatorTable = tableConfig
        .getSqlOperatorTable()
        != null
        ? tableConfig.getSqlOperatorTable()
        : ChainedSqlOperatorTable.of(SqlStdOperatorTable.instance());
    CalciteConnectionConfig calciteConnectionConfig = tableConfig
        .getCalciteConnectionConfig()
        != null
        ? tableConfig.getCalciteConnectionConfig()
        : createDefaultConnectionConfig(sqlParserConfig);
    RelDataTypeSystem typeSystem = tableConfig.getRelDataTypeSystem() != null
        ? tableConfig.getRelDataTypeSystem()
        : calciteConnectionConfig.typeSystem(RelDataTypeSystem.class,
            RelDataTypeSystem.DEFAULT);
    SqlRexConvertletTable convertletTable = tableConfig
        .getConvertletTable()
        != null
        ? tableConfig
        .getConvertletTable()
        : StandardConvertletTable.INSTANCE;
    RexExecutor rexExecutor = tableConfig.getRexExecutor() != null
        ? tableConfig.getRexExecutor()
        : RexUtil.EXECUTOR;
    this.calciteCatalogReader = new CalciteCatalogReader(
        CalciteSchema.from(rootSchema),
        CalciteSchema.from(rootSchema).path(null),
        new JavaTypeFactoryImpl(typeSystem),
        calciteConnectionConfig);
    this.frameworkConfig = createFrameworkConfig(sqlParserConfig,
        ChainedSqlOperatorTable.of(sqlStdOperatorTable,
            calciteCatalogReader), convertletTable,
        calciteConnectionConfig, typeSystem, rexExecutor);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 10
Source Project: calcite   Source File: CalcitePrepareImpl.java    License: Apache License 2.0 4 votes vote down vote up
/** Factory method for default convertlet table. */
protected SqlRexConvertletTable createConvertletTable() {
  return StandardConvertletTable.INSTANCE;
}