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


Java SqlParser.create方法代码示例

本文整理汇总了Java中org.apache.calcite.sql.parser.SqlParser.create方法的典型用法代码示例。如果您正苦于以下问题:Java SqlParser.create方法的具体用法?Java SqlParser.create怎么用?Java SqlParser.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.sql.parser.SqlParser的用法示例。


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

示例1: getParser

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public Parser getParser(String sql, Properties info)
    throws SQLException {
  SqlParser parser = SqlParser.create(sql,
      SqlParser.configBuilder()
          .setQuotedCasing(Casing.UNCHANGED)
          .setUnquotedCasing(Casing.UNCHANGED)
          .setQuoting(Quoting.DOUBLE_QUOTE)
          .setParserFactory(QuarkParserImpl.FACTORY)
          .build());
  SqlNode sqlNode;
  try {
    sqlNode = parser.parseStmt();
  } catch (SqlParseException e) {
    throw new RuntimeException(
        "parse failed: " + e.getMessage(), e);
  }
  if (sqlNode.getKind().equals(SqlKind.OTHER_DDL)) {
    return new DDLParser();
  } else  {
    return getSqlQueryParser(info);
  }
}
 
开发者ID:qubole,项目名称:quark,代码行数:23,代码来源:ParserFactory.java

示例2: testUpdateSql

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@Test
public void testUpdateSql() throws Exception {
  final String sql = "select foo, bar as b from tbl";
  SqlParser parser = SqlParser.create(sql, new ParserConfig(Quoting.DOUBLE_QUOTE, 128));
  final SqlNode sqlNode = parser.parseStmt();


  final JavaTypeFactory typeFactory = new JavaTypeFactoryImpl();
  final RelDataType rowType = new RelRecordType(Arrays.<RelDataTypeField>asList(
      new RelDataTypeFieldImpl("foo", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)),
      new RelDataTypeFieldImpl("b", 0, typeFactory.createSqlType(SqlTypeName.INTEGER))
  ));

  TransformActor actor = new TransformActor(state, false, "test_user", null) {
    @Override
    protected QueryMetadata getMetadata(SqlQuery query) {
      return new QueryMetadata(null, null, null, null, sqlNode, rowType, null, null, null, null, BatchSchema.fromCalciteRowType(rowType));
    }

    @Override
    protected boolean hasMetadata() {
      return true;
    }
  };

  TransformResult result = new TransformUpdateSQL(sql).accept(actor);
  VirtualDatasetState newState = result.getNewState();

  assertEquals(2, newState.getColumnsList().size());
  assertEquals("foo", newState.getColumnsList().get(0).getName());
  assertEquals(new ExpColumnReference("foo").wrap(), newState.getColumnsList().get(0).getValue());
  assertEquals("b", newState.getColumnsList().get(1).getName());
  assertEquals(new ExpColumnReference("bar").wrap(), newState.getColumnsList().get(1).getValue());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:35,代码来源:TestTransformer.java

示例3: parse

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlNode parse(String sql) {
  try {
    SqlParser parser = SqlParser.create(sql, parserConfig);
    return parser.parseStmt();
  } catch (SqlParseException e) {
    UserException.Builder builder = UserException
        .parseError(e)
        .addContext("SQL Query", formatSQLParsingError(sql, e.getPos()));
    if (isInnerQuery) {
      builder.message("Failure parsing a view your query is dependent upon.");
    }
    throw builder.build(logger);
  }

}
 
开发者ID:axbaretto,项目名称:drill,代码行数:16,代码来源:SqlConverter.java

示例4: parseSql

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private T parseSql(String sql) throws SQLException {
    logger.debug("[parseSql]");
    try {
        SqlParser sqlParser = SqlParser.create(sql, SqlParser.configBuilder()
                .setParserFactory(SqlParserImpl.FACTORY)
                .setUnquotedCasing(Casing.TO_LOWER)
                .setQuoting(Quoting.DOUBLE_QUOTE)
                .build());
        return (T) sqlParser.parseStmt();
    } catch (SqlParseException exc) {
        throw new SQLException("Could not parse sql: " + sql, exc);
    }
}
 
开发者ID:axibase,项目名称:atsd-jdbc,代码行数:15,代码来源:AtsdSqlConverter.java

示例5: getSqlParser

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlParser getSqlParser(String sql) {
  try {
    final CalciteConnectionConfig config = context.getCfg();
    return SqlParser.create(sql,
        SqlParser.configBuilder()
            .setQuotedCasing(config.quotedCasing())
            .setUnquotedCasing(config.unquotedCasing())
            .setQuoting(config.quoting())
            .build());
  } catch (Exception e) {
    return SqlParser.create(sql);
  }
}
 
开发者ID:qubole,项目名称:quark,代码行数:14,代码来源:SqlQueryParser.java

示例6: setup

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@Setup
public void setup() throws SqlParseException {
  StringBuilder sb = new StringBuilder((int) (length * 1.2));
  sb.append("select 1");
  Random rnd = new Random();
  rnd.setSeed(424242);
  for (; sb.length() < length;) {
    for (int i = 0; i < 7 && sb.length() < length; i++) {
      sb.append(", ");
      switch (rnd.nextInt(3)) {
      case 0:
        sb.append("?");
        break;
      case 1:
        sb.append(rnd.nextInt());
        break;
      case 2:
        sb.append('\'').append(rnd.nextLong()).append(rnd.nextLong())
            .append('\'');
        break;
      }
    }
    if (comments && sb.length() < length) {
      sb.append("// sb.append('\\'').append(rnd.nextLong()).append(rnd.nextLong()).append(rnd"
          + ".nextLong())");
    }
    sb.append('\n');
  }
  sb.append(" from dual");
  parser = SqlParser.create("values(1)");
  sql = sb.toString();
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:ParserBenchmark.java

示例7: populate

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/** Populates a materialization record, converting a table path
 * (essentially a list of strings, like ["hr", "sales"]) into a table object
 * that can be used in the planning process. */
void populate(Materialization materialization) {
  SqlParser parser = SqlParser.create(materialization.sql);
  SqlNode node;
  try {
    node = parser.parseStmt();
  } catch (SqlParseException e) {
    throw new RuntimeException("parse failed", e);
  }
  final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder()
      .withTrimUnusedFields(true).build();
  SqlToRelConverter sqlToRelConverter2 =
      getSqlToRelConverter(getSqlValidator(), catalogReader, config);

  materialization.queryRel =
      sqlToRelConverter2.convertQuery(node, true, true).rel;

  // Identify and substitute a StarTable in queryRel.
  //
  // It is possible that no StarTables match. That is OK, but the
  // materialization patterns that are recognized will not be as rich.
  //
  // It is possible that more than one StarTable matches. TBD: should we
  // take the best (whatever that means), or all of them?
  useStar(schema, materialization);

  RelOptTable table =
      this.catalogReader.getTable(materialization.materializedTable.path());
  materialization.tableRel = sqlToRelConverter2.toRel(table);
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:CalciteMaterializer.java

示例8: parse

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlNode parse(final String sql) throws SqlParseException {
  switch (state) {
  case STATE_0_CLOSED:
  case STATE_1_RESET:
    ready();
  }
  ensure(State.STATE_2_READY);
  SqlParser parser = SqlParser.create(sql, parserConfig);
  SqlNode sqlNode = parser.parseStmt();
  state = State.STATE_3_PARSED;
  return sqlNode;
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:PlannerImpl.java

示例9: expandView

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@Override public RelRoot expandView(RelDataType rowType, String queryString,
  List<String> schemaPath, List<String> viewPath) {
  SqlParser parser = SqlParser.create(queryString, parserConfig);
  SqlNode sqlNode;
  try {
    sqlNode = parser.parseQuery();
  } catch (SqlParseException e) {
    throw new RuntimeException("parse failed", e);
  }

  final SqlConformance conformance = conformance();
  final CalciteCatalogReader catalogReader =
      createCatalogReader().withSchemaPath(schemaPath);
  final SqlValidator validator =
      new CalciteSqlValidator(operatorTable, catalogReader, typeFactory,
          conformance);
  validator.setIdentifierExpansion(true);
  final SqlNode validatedSqlNode = validator.validate(sqlNode);

  final RexBuilder rexBuilder = createRexBuilder();
  final RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder);
  final SqlToRelConverter.Config config = SqlToRelConverter
      .configBuilder()
      .withConfig(sqlToRelConverterConfig)
      .withTrimUnusedFields(false)
      .withConvertTableAccess(false)
      .build();
  final SqlToRelConverter sqlToRelConverter =
      new SqlToRelConverter(new ViewExpanderImpl(), validator,
          catalogReader, cluster, convertletTable, config);

  root = sqlToRelConverter.convertQuery(validatedSqlNode, true, false);
  root = root.withRel(sqlToRelConverter.flattenTypes(root.rel, true));
  root = root.withRel(RelDecorrelator.decorrelateQuery(root.rel));

  return PlannerImpl.this.root;
}
 
开发者ID:apache,项目名称:calcite,代码行数:38,代码来源:PlannerImpl.java

示例10: createParser

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlParser createParser(SqlTestFactory factory, String sql) {
  return SqlParser.create(sql,
      SqlParser.configBuilder()
          .setQuoting((Quoting) factory.get("quoting"))
          .setUnquotedCasing((Casing) factory.get("unquotedCasing"))
          .setQuotedCasing((Casing) factory.get("quotedCasing"))
          .setConformance((SqlConformance) factory.get("conformance"))
          .build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:10,代码来源:DefaultSqlTestFactory.java

示例11: parse

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
private SqlNode parse(String toParse) throws SqlParseException{
  ParserConfig config = new ParserConfig(Quoting.DOUBLE_QUOTE, 255);
  SqlParser parser = SqlParser.create(toParse, config);
  return parser.parseStmt();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:6,代码来源:TestDDLAliases.java

示例12: parse

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public static SqlNode parse(String sql) throws SqlParseException {
    SqlParser.ConfigBuilder parserBuilder = SqlParser.configBuilder();
    SqlParser sqlParser = SqlParser.create(sql, parserBuilder.build());
    return sqlParser.parseQuery();
}
 
开发者ID:apache,项目名称:kylin,代码行数:6,代码来源:CalciteParser.java

示例13: createParser

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/** Factory method for SQL parser with a given configuration. */
protected SqlParser createParser(String sql,
                                 SqlParser.ConfigBuilder parserConfig) {
  return SqlParser.create(sql, parserConfig.build());
}
 
开发者ID:apache,项目名称:kylin,代码行数:6,代码来源:CalcitePrepareImpl.java

示例14: createParser

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/** Factory method for SQL parser with a given configuration. */
protected SqlParser createParser(String sql,
    SqlParser.ConfigBuilder parserConfig) {
  return SqlParser.create(sql, parserConfig.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:6,代码来源:CalcitePrepareImpl.java

示例15: parseQuery

import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlNode parseQuery(String sql) throws Exception {
  SqlParser parser = SqlParser.create(sql);
  return parser.parseQuery();
}
 
开发者ID:apache,项目名称:calcite,代码行数:5,代码来源:SqlToRelTestBase.java


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