• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Quoting类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  if (args.length != 1) {
    throw new IllegalArgumentException("Usage: java {cp} " + SqlReservedKeywordGenerator.class.getName() +
        " path/where/to/write/the/file");
  }

  final File outputFile = new File(args[0], RESERVED_KEYWORD_FILE_NAME);
  System.out.println("Writing reserved SQL keywords to file: " + outputFile.getAbsolutePath());

  try(PrintWriter outFile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile), UTF_8))) {
    outFile.printf("# AUTO-GENERATED LIST OF SQL RESERVED KEYWORDS (generated by %s)",
        SqlReservedKeywordGenerator.class.getName());
    outFile.println();

    final SqlAbstractParserImpl.Metadata metadata = SqlParser.create("", new ParserConfig(Quoting.DOUBLE_QUOTE, 256)).getMetadata();
    for (String s : metadata.getTokens()) {
      if (metadata.isKeyword(s) && metadata.isReservedWord(s)) {
        outFile.println(s);
      }
    }
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:SqlReservedKeywordGenerator.java


示例2: testDoubleQuotesForQuotingIdentifiers

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testDoubleQuotesForQuotingIdentifiers() throws Exception {
  try {
    test("ALTER SESSION SET `%s` = '%s'", PlannerSettings.QUOTING_IDENTIFIERS_KEY,
        Quoting.DOUBLE_QUOTE.string);
    testBuilder()
        .sqlQuery("select \"employee_id\", \"full_name\" from cp.\"employee.json\" limit 1")
        .ordered()
        .baselineColumns("employee_id", "full_name")
        .baselineValues(1L, "Sheri Nowmer")
        .go();

    // Other quoting characters are not acceptable while particular one is chosen,
    // since calcite doesn't support parsing sql statements with several quoting identifiers characters
    errorMsgTestHelper("select `employee_id`, `full_name` from cp.`employee.json` limit 1", "Encountered: \"`\"");
    // Mix of different quotes in the one SQL statement is not acceptable
    errorMsgTestHelper("select \"employee_id\", \"full_name\" from cp.`employee.json` limit 1", "Encountered: \"`\"");
  } finally {
    test("ALTER SESSION RESET %s", PlannerSettings.QUOTING_IDENTIFIERS_KEY);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:22,代码来源:TestDrillSQLWorker.java


示例3: testQuotingIdentifiersProperty

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testQuotingIdentifiersProperty() throws SQLException {
  try {
    // Test DoubleQuotes for the DrillProperty#QUOTING_IDENTIFIERS in connection URL
    connection = connect("jdbc:drill:zk=local;quoting_identifiers='\"'");
    dbmd = connection.getMetaData();
    assertThat(dbmd.getIdentifierQuoteString(), equalTo(Quoting.DOUBLE_QUOTE.string));
    reset();

    // Test Brackets for the DrillProperty#QUOTING_IDENTIFIERS in connection URL
    connection = connect("jdbc:drill:zk=local;quoting_identifiers=[");
    dbmd = connection.getMetaData();
    assertThat(dbmd.getIdentifierQuoteString(), equalTo(Quoting.BRACKET.string));
  } finally {
    reset();
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:18,代码来源:ConnectionInfoTest.java


示例4: getParser

import org.apache.calcite.avatica.util.Quoting; //导入依赖的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


示例5: buildPlanner

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
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);
}
 
开发者ID:qubole,项目名称:quark,代码行数:24,代码来源:SqlWorker.java


示例6: testBracketIdentifier

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test public void testBracketIdentifier() {
  quoting = Quoting.BRACKET;
  checkExp("ab", "`AB`");
  checkExp("     [a  \" b!c]", "`a  \" b!c`");
  checkExpFails("     ^`^a  \" b!c`", "(?s).*Encountered.*");
  checkExpFails("     ^\"^a  \"\" b!c\"", "(?s).*Encountered.*");

  checkExp("[x`y`z]", "`x``y``z`");
  checkExpFails("^\"^x`y`z\"", "(?s).*Encountered.*");
  checkExpFails("^`^x``y``z`", "(?s).*Encountered.*");

  checkExp("[anything [even brackets]] is].[ok]",
      "`anything [even brackets] is`.`ok`");

  // What would be a call to the 'item' function in DOUBLE_QUOTE and BACK_TICK
  // is a table alias.
  check("select * from myMap[field], myArray[1 + 2]",
      "SELECT *\n"
          + "FROM `MYMAP` AS `field`,\n"
          + "`MYARRAY` AS `1 + 2`");
  check("select * from myMap [field], myArray [1 + 2]",
      "SELECT *\n"
          + "FROM `MYMAP` AS `field`,\n"
          + "`MYARRAY` AS `1 + 2`");
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:SqlParserTest.java


示例7: testCaseInsensitive

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/** Tests using case-insensitive matching of identifiers. */
@Test public void testCaseInsensitive() {
  final SqlTester tester1 = tester
      .withCaseSensitive(false)
      .withQuoting(Quoting.BRACKET);
  final SqlTester tester2 = tester.withQuoting(Quoting.BRACKET);

  tester1.checkQuery("select EMPNO from EMP");
  tester1.checkQuery("select empno from emp");
  tester1.checkQuery("select [empno] from [emp]");
  tester1.checkQuery("select [E].[empno] from [emp] as e");
  tester1.checkQuery("select t.[x] from (\n"
      + "  select [E].[empno] as x from [emp] as e) as [t]");

  // correlating variable
  tester1.checkQuery(
      "select * from emp as [e] where exists (\n"
          + "select 1 from dept where dept.deptno = [E].deptno)");
  tester2.checkQueryFails(
      "select * from emp as [e] where exists (\n"
          + "select 1 from dept where dept.deptno = ^[E]^.deptno)",
      "(?s).*Table 'E' not found; did you mean 'e'\\?");

  checkFails("select count(1), ^empno^ from emp",
      "Expression 'EMPNO' is not being grouped");
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:SqlValidatorTest.java


示例8: testCaseInsensitiveTableAlias

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-319">[CALCITE-319]
 * Table aliases should follow case-sensitivity policy</a>. */
@Test public void testCaseInsensitiveTableAlias() {
  final SqlTester tester1 = tester
      .withCaseSensitive(false)
      .withQuoting(Quoting.BRACKET);
  final SqlTester tester2 = tester.withQuoting(Quoting.BRACKET);
  // Table aliases should follow case-sensitivity preference.
  //
  // In MySQL, table aliases are case-insensitive:
  // mysql> select `D`.day from DAYS as `d`, DAYS as `D`;
  // ERROR 1066 (42000): Not unique table/alias: 'D'
  tester1.checkQueryFails("select count(*) from dept as [D], ^dept as [d]^",
      "Duplicate relation name 'd' in FROM clause");
  tester2.checkQuery("select count(*) from dept as [D], dept as [d]");
  tester2.checkQueryFails("select count(*) from dept as [D], ^dept as [D]^",
      "Duplicate relation name 'D' in FROM clause");
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:SqlValidatorTest.java


示例9: testCaseInsensitiveSubQuery

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/** Tests referencing columns from a sub-query that has duplicate column
 * names. (The standard says it should be an error, but we don't right
 * now.) */
@Test public void testCaseInsensitiveSubQuery() {
  final SqlTester insensitive = tester
      .withCaseSensitive(false)
      .withQuoting(Quoting.BRACKET);
  final SqlTester sensitive = tester
      .withCaseSensitive(true)
      .withQuoting(Quoting.BRACKET);
  String sql = "select [e] from (\n"
      + "select empno as [e], deptno as d, 1 as [e] from EMP)";
  sensitive.checkQuery(sql);
  insensitive.checkQuery(sql);
  String sql1 = "select e from (\n"
      + "select empno as [e], deptno as d, 1 as [E] from EMP)";
  insensitive.checkQuery(sql1);
  sensitive.checkQuery(sql1);
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:SqlValidatorTest.java


示例10: testServerMeta

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testServerMeta() throws Exception {
  GetServerMetaResp resp = client.getServerMeta().get();
  assertNotNull(resp);
  assertEquals(RequestStatus.OK, resp.getStatus());
  assertNotNull(resp.getServerMeta());

  ServerMeta serverMeta = resp.getServerMeta();
  logger.trace("Server metadata: {}", serverMeta);

  assertEquals(Quoting.BACK_TICK.string, serverMeta.getIdentifierQuoteString());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:13,代码来源:TestServerMetaProvider.java


示例11: testUpdateSql

import org.apache.calcite.avatica.util.Quoting; //导入依赖的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


示例12: getQuotingIdentifiers

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/**
 * @return Quoting enum for current quoting identifiers character
 */
public Quoting getQuotingIdentifiers() {
  String quotingIdentifiersCharacter = options.getOption(QUOTING_IDENTIFIERS);
  for (Quoting value : Quoting.values()) {
    if (value.string.equals(quotingIdentifiersCharacter)) {
      return value;
    }
  }
  // this is never reached
  throw UserException.validationError()
      .message("Unknown quoting identifier character '%s'", quotingIdentifiersCharacter)
      .build(logger);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:16,代码来源:PlannerSettings.java


示例13: testBracketsForQuotingIdentifiers

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testBracketsForQuotingIdentifiers() throws Exception {
  try {
    test("ALTER SESSION SET `%s` = '%s'", PlannerSettings.QUOTING_IDENTIFIERS_KEY,
        Quoting.BRACKET.string);
    testBuilder()
        .sqlQuery("select [employee_id], [full_name] from cp.[employee.json] limit 1")
        .ordered()
        .baselineColumns("employee_id", "full_name")
        .baselineValues(1L, "Sheri Nowmer")
        .go();
  } finally {
    test("ALTER SESSION RESET %s", PlannerSettings.QUOTING_IDENTIFIERS_KEY);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:16,代码来源:TestDrillSQLWorker.java


示例14: getIdentifierQuoteString

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Override
public String getIdentifierQuoteString() throws SQLException {
  throwIfClosed();
  if (!getServerMetaSupported()) {
    return Quoting.BACK_TICK.string;
  }
  return getServerMeta().getIdentifierQuoteString();
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:9,代码来源:DrillDatabaseMetaDataImpl.java


示例15: parseSql

import org.apache.calcite.avatica.util.Quoting; //导入依赖的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


示例16: ConfigImpl

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
private ConfigImpl(int identifierMaxLength, Casing quotedCasing,
    Casing unquotedCasing, Quoting quoting, boolean caseSensitive,
    SqlConformance conformance, SqlParserImplFactory parserFactory) {
  this.identifierMaxLength = identifierMaxLength;
  this.caseSensitive = caseSensitive;
  this.conformance = Preconditions.checkNotNull(conformance);
  this.quotedCasing = Preconditions.checkNotNull(quotedCasing);
  this.unquotedCasing = Preconditions.checkNotNull(unquotedCasing);
  this.quoting = Preconditions.checkNotNull(quoting);
  this.parserFactory = Preconditions.checkNotNull(parserFactory);
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:SqlParser.java


示例17: testBackTickIdentifier

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test public void testBackTickIdentifier() {
  quoting = Quoting.BACK_TICK;
  checkExp("ab", "`AB`");
  checkExp("     `a  \" b!c`", "`a  \" b!c`");
  checkExpFails("     ^\"^a  \"\" b!c\"", "(?s).*Encountered.*");

  checkExpFails("^\"^x`y`z\"", "(?s).*Encountered.*");
  checkExp("`x``y``z`", "`x``y``z`");

  checkExp("myMap[field] + myArray[1 + 2]",
      "(`MYMAP`[`FIELD`] + `MYARRAY`[(1 + 2)])");
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:SqlParserTest.java


示例18: testBackTickQuery

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test public void testBackTickQuery() {
  quoting = Quoting.BACK_TICK;
  check(
      "select `x`.`b baz` from `emp` as `x` where `x`.deptno in (10, 20)",
      "SELECT `x`.`b baz`\n"
          + "FROM `emp` AS `x`\n"
          + "WHERE (`x`.`DEPTNO` IN (10, 20))");
}
 
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:SqlParserTest.java


示例19: check

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Override public void check(String sql, String expected) {
  SqlNode sqlNode = parseStmtAndHandleEx(sql);

  // Unparse with no dialect, always parenthesize.
  final String actual = sqlNode.toSqlString(null, true).getSql();
  assertEquals(expected, linux(actual));

  // Unparse again in Calcite dialect (which we can parse), and
  // minimal parentheses.
  final String sql1 =
      sqlNode.toSqlString(CalciteSqlDialect.DEFAULT, false).getSql();

  // Parse and unparse again.
  SqlNode sqlNode2;
  final Quoting q = quoting;
  try {
    quoting = Quoting.DOUBLE_QUOTE;
    sqlNode2 = parseStmtAndHandleEx(sql1);
  } finally {
    quoting = q;
  }
  final String sql2 =
      sqlNode2.toSqlString(CalciteSqlDialect.DEFAULT, false).getSql();

  // Should be the same as we started with.
  assertEquals(sql1, sql2);

  // Now unparse again in the null dialect.
  // If the unparser is not including sufficient parens to override
  // precedence, the problem will show up here.
  final String actual2 = sqlNode2.toSqlString(null, true).getSql();
  assertEquals(expected, linux(actual2));
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:SqlParserTest.java


示例20: checkExp

import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Override public void checkExp(String sql, String expected) {
  SqlNode sqlNode = parseExpressionAndHandleEx(sql);

  // Unparse with no dialect, always parenthesize.
  final String actual = sqlNode.toSqlString(null, true).getSql();
  assertEquals(expected, linux(actual));

  // Unparse again in Calcite dialect (which we can parse), and
  // minimal parentheses.
  final String sql1 =
      sqlNode.toSqlString(CalciteSqlDialect.DEFAULT, false).getSql();

  // Parse and unparse again.
  SqlNode sqlNode2;
  final Quoting q = quoting;
  try {
    quoting = Quoting.DOUBLE_QUOTE;
    sqlNode2 = parseExpressionAndHandleEx(sql1);
  } finally {
    quoting = q;
  }
  final String sql2 =
      sqlNode2.toSqlString(CalciteSqlDialect.DEFAULT, false).getSql();

  // Should be the same as we started with.
  assertEquals(sql1, sql2);

  // Now unparse again in the null dialect.
  // If the unparser is not including sufficient parens to override
  // precedence, the problem will show up here.
  final String actual2 = sqlNode2.toSqlString(null, true).getSql();
  assertEquals(expected, linux(actual2));
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:SqlParserTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HeadBucketRequest类代码示例发布时间:2022-05-22
下一篇:
Java HiveCharObjectInspector类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap