org.apache.calcite.avatica.util.Quoting Java Examples

The following examples show how to use org.apache.calcite.avatica.util.Quoting. 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 File: SqlWorker.java    From quark with 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 #2
Source File: ParserFactory.java    From quark with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #3
Source File: UserSession.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(UserSession session, String value) {
  if (value == null) {
    return;
  }
  final Quoting quoting;
  switch(value.toUpperCase(Locale.ROOT)) {
  case "BACK_TICK":
    quoting = Quoting.BACK_TICK;
    break;

  case "DOUBLE_QUOTE":
    quoting = Quoting.DOUBLE_QUOTE;
    break;

  case "BRACKET":
    quoting = Quoting.BRACKET;
    break;

  default:
    logger.warn("Ignoring message to use initial quoting of type {}.", value);
    return;
  }
  session.initialQuoting = quoting;
}
 
Example #4
Source File: SqlReservedKeywordGenerator.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
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);
      }
    }
  }
}
 
Example #5
Source File: SubtreeSyncopatorTest.java    From Quicksql with MIT License 6 votes vote down vote up
private void initPlannerConfig(String jsonPath) throws IOException {
    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);

    new ModelHandler(rootSchema, jsonPath);
    final SqlToRelConverter.Config convertConfig = SqlToRelConverter.configBuilder()
        .withTrimUnusedFields(false)
        .withConvertTableAccess(false)
        .withExpand(false)
        .build();

    final SqlParser.Config parserConfig = SqlParser.configBuilder()
        .setConformance(SqlConformanceEnum.MYSQL_5)
        .setQuoting(Quoting.BACK_TICK)
        .setUnquotedCasing(Casing.UNCHANGED)
        // .setUnquotedCasing(Casing.UNCHANGED)
        .build();

    this.config = Frameworks.newConfigBuilder()
        .parserConfig(parserConfig)
        .defaultSchema(rootSchema)
        .traitDefs((List<RelTraitDef>) null)
        .sqlToRelConverterConfig(convertConfig)
        .build();
}
 
Example #6
Source File: QueryProcedureProducer.java    From Quicksql with MIT License 6 votes vote down vote up
private void initPlannerConfig(String jsonPath) throws IOException {
    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);

    new ModelHandler(rootSchema, jsonPath);
    final SqlToRelConverter.Config convertConfig = SqlToRelConverter.configBuilder()
        .withTrimUnusedFields(false)
        .withConvertTableAccess(false)
        .withExpand(false)
        .build();

    final SqlParser.Config parserConfig = SqlParser.configBuilder()
        .setConformance(SqlConformanceEnum.MYSQL_5)
        .setQuoting(Quoting.BACK_TICK)
        .setCaseSensitive(false)
        .setUnquotedCasing(Casing.UNCHANGED)
        .build();

    this.config = Frameworks.newConfigBuilder()
        .parserConfig(parserConfig)
        .defaultSchema(rootSchema)
        .traitDefs((List<RelTraitDef>) null)
        .sqlToRelConverterConfig(convertConfig)
        .build();
}
 
Example #7
Source File: FlinkDDLDataTypeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private SqlParser getSqlParser(String sql) {
	return SqlParser.create(sql,
		SqlParser.configBuilder()
			.setParserFactory(FlinkSqlParserImpl.FACTORY)
			.setQuoting(Quoting.BACK_TICK)
			.setUnquotedCasing(Casing.UNCHANGED)
			.setQuotedCasing(Casing.UNCHANGED)
			.setConformance(conformance)
			.build());
}
 
Example #8
Source File: SqlTestFactory.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static SqlParser.Config createParserConfig(ImmutableMap<String, Object> options) {
  return SqlParser.configBuilder()
      .setQuoting((Quoting) options.get("quoting"))
      .setUnquotedCasing((Casing) options.get("unquotedCasing"))
      .setQuotedCasing((Casing) options.get("quotedCasing"))
      .setConformance((SqlConformance) options.get("conformance"))
      .setCaseSensitive((boolean) options.get("caseSensitive"))
      .build();
}
 
Example #9
Source File: SqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns the quoting scheme, or null if the combination of
 * {@link #identifierQuoteString} and {@link #identifierEndQuoteString}
 * does not correspond to any known quoting scheme. */
protected Quoting getQuoting() {
  if ("\"".equals(identifierQuoteString)
      && "\"".equals(identifierEndQuoteString)) {
    return Quoting.DOUBLE_QUOTE;
  } else if ("`".equals(identifierQuoteString)
      && "`".equals(identifierEndQuoteString)) {
    return Quoting.BACK_TICK;
  } else if ("[".equals(identifierQuoteString)
      && "]".equals(identifierEndQuoteString)) {
    return Quoting.BRACKET;
  } else {
    return null;
  }
}
 
Example #10
Source File: SqlParser.java    From calcite with Apache License 2.0 5 votes vote down vote up
private ConfigImpl(int identifierMaxLength, Casing quotedCasing,
    Casing unquotedCasing, Quoting quoting, boolean caseSensitive,
    SqlConformance conformance, SqlParserImplFactory parserFactory) {
  this.identifierMaxLength = identifierMaxLength;
  this.caseSensitive = caseSensitive;
  this.conformance = Objects.requireNonNull(conformance);
  this.quotedCasing = Objects.requireNonNull(quotedCasing);
  this.unquotedCasing = Objects.requireNonNull(unquotedCasing);
  this.quoting = Objects.requireNonNull(quoting);
  this.parserFactory = Objects.requireNonNull(parserFactory);
}
 
Example #11
Source File: FlinkDDLDataTypeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> buildDefaultOptions() {
	final Map<String, Object> m = new HashMap<>();
	m.put("quoting", Quoting.BACK_TICK);
	m.put("quotedCasing", Casing.UNCHANGED);
	m.put("unquotedCasing", Casing.UNCHANGED);
	m.put("caseSensitive", true);
	m.put("enableTypeCoercion", false);
	m.put("conformance", SqlConformanceEnum.DEFAULT);
	m.put("operatorTable", SqlStdOperatorTable.instance());
	m.put("parserFactory", FlinkSqlParserImpl.FACTORY);
	return Collections.unmodifiableMap(m);
}
 
Example #12
Source File: FlinkDDLDataTypeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static SqlParser.Config createParserConfig(Map<String, Object> options) {
	return SqlParser.configBuilder()
		.setQuoting((Quoting) options.get("quoting"))
		.setUnquotedCasing((Casing) options.get("unquotedCasing"))
		.setQuotedCasing((Casing) options.get("quotedCasing"))
		.setConformance((SqlConformance) options.get("conformance"))
		.setCaseSensitive((boolean) options.get("caseSensitive"))
		.setParserFactory((SqlParserImplFactory) options.get("parserFactory"))
		.build();
}
 
Example #13
Source File: QueryConnectionTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetConnection() throws SQLException, IllegalAccessException {
    Connection connection = QueryConnection.getConnection("default");
    assertNotNull(connection);
    Map<InternalProperty, Object> properties = dirtyReadProperties(connection);
    assertEquals(true, properties.get(InternalProperty.CASE_SENSITIVE));
    assertEquals(Casing.TO_UPPER, properties.get(InternalProperty.UNQUOTED_CASING));
    assertEquals(Quoting.DOUBLE_QUOTE, properties.get(InternalProperty.QUOTING));

    ResultSet resultSet = connection.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery();
    String columnName = resultSet.getMetaData().getColumnName(1);
    assertEquals("VALUE_ALIAS", columnName);

    // override connection properties
    KylinConfig conf = KylinConfig.getInstanceFromEnv();
    conf.setProperty("kylin.query.calcite.extras-props.caseSensitive", "false");
    conf.setProperty("kylin.query.calcite.extras-props.unquotedCasing", "UNCHANGED");
    conf.setProperty("kylin.query.calcite.extras-props.quoting", "BRACKET");
    Connection conn2 = QueryConnection.getConnection("default");
    Map<InternalProperty, Object> props = dirtyReadProperties(conn2);
    assertEquals(false, props.get(InternalProperty.CASE_SENSITIVE));
    assertEquals(Casing.UNCHANGED, props.get(InternalProperty.UNQUOTED_CASING));
    assertEquals(Quoting.BRACKET, props.get(InternalProperty.QUOTING));

    ResultSet resultSet1 = conn2.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery();
    assertEquals("value_ALIAS", resultSet1.getMetaData().getColumnName(1));
}
 
Example #14
Source File: TestServerMetaProvider.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@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.DOUBLE_QUOTE.string, serverMeta.getIdentifierQuoteString());
}
 
Example #15
Source File: QueryConnectionTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetConnection() throws SQLException, IllegalAccessException {
    Connection connection = QueryConnection.getConnection("default");
    assertNotNull(connection);
    Map<InternalProperty, Object> properties = dirtyReadProperties(connection);
    assertEquals(true, properties.get(InternalProperty.CASE_SENSITIVE));
    assertEquals(Casing.TO_UPPER, properties.get(InternalProperty.UNQUOTED_CASING));
    assertEquals(Quoting.DOUBLE_QUOTE, properties.get(InternalProperty.QUOTING));

    ResultSet resultSet = connection.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery();
    String columnName = resultSet.getMetaData().getColumnName(1);
    assertEquals("VALUE_ALIAS", columnName);

    // override connection properties
    KylinConfig conf = KylinConfig.getInstanceFromEnv();
    conf.setProperty("kylin.query.calcite.extras-props.caseSensitive", "false");
    conf.setProperty("kylin.query.calcite.extras-props.unquotedCasing", "UNCHANGED");
    conf.setProperty("kylin.query.calcite.extras-props.quoting", "BRACKET");
    Connection conn2 = QueryConnection.getConnection("default");
    Map<InternalProperty, Object> props = dirtyReadProperties(conn2);
    assertEquals(false, props.get(InternalProperty.CASE_SENSITIVE));
    assertEquals(Casing.UNCHANGED, props.get(InternalProperty.UNQUOTED_CASING));
    assertEquals(Quoting.BRACKET, props.get(InternalProperty.QUOTING));

    ResultSet resultSet1 = conn2.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery();
    assertEquals("value_ALIAS", resultSet1.getMetaData().getColumnName(1));
}
 
Example #16
Source File: SqlTestFactory.java    From Quicksql with MIT License 5 votes vote down vote up
public static SqlParser.Config createParserConfig(ImmutableMap<String, Object> options) {
  return SqlParser.configBuilder()
      .setQuoting((Quoting) options.get("quoting"))
      .setUnquotedCasing((Casing) options.get("unquotedCasing"))
      .setQuotedCasing((Casing) options.get("quotedCasing"))
      .setConformance((SqlConformance) options.get("conformance"))
      .setCaseSensitive((boolean) options.get("caseSensitive"))
      .build();
}
 
Example #17
Source File: SqlDialect.java    From Quicksql with MIT License 5 votes vote down vote up
/** Returns the quoting scheme, or null if the combination of
 * {@link #identifierQuoteString} and {@link #identifierEndQuoteString}
 * does not correspond to any known quoting scheme. */
protected Quoting getQuoting() {
  if ("\"".equals(identifierQuoteString)
      && "\"".equals(identifierEndQuoteString)) {
    return Quoting.DOUBLE_QUOTE;
  } else if ("`".equals(identifierQuoteString)
      && "`".equals(identifierEndQuoteString)) {
    return Quoting.BACK_TICK;
  } else if ("[".equals(identifierQuoteString)
      && "]".equals(identifierEndQuoteString)) {
    return Quoting.BRACKET;
  } else {
    return null;
  }
}
 
Example #18
Source File: FlinkSqlParserImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
protected SqlParser getSqlParser(Reader source) {
	if (conformance0 == null) {
		return super.getSqlParser(source);
	} else {
		// overwrite the default sql conformance.
		return SqlParser.create(source,
			SqlParser.configBuilder()
				.setParserFactory(parserImplFactory())
				.setQuoting(Quoting.DOUBLE_QUOTE)
				.setUnquotedCasing(Casing.TO_UPPER)
				.setQuotedCasing(Casing.UNCHANGED)
				.setConformance(conformance0)
				.build());
	}
}
 
Example #19
Source File: SqlParser.java    From Quicksql with MIT License 5 votes vote down vote up
private ConfigImpl(int identifierMaxLength, Casing quotedCasing,
    Casing unquotedCasing, Quoting quoting, boolean caseSensitive,
    SqlConformance conformance, SqlParserImplFactory parserFactory) {
  this.identifierMaxLength = identifierMaxLength;
  this.caseSensitive = caseSensitive;
  this.conformance = Objects.requireNonNull(conformance);
  this.quotedCasing = Objects.requireNonNull(quotedCasing);
  this.unquotedCasing = Objects.requireNonNull(unquotedCasing);
  this.quoting = Objects.requireNonNull(quoting);
  this.parserFactory = Objects.requireNonNull(parserFactory);
}
 
Example #20
Source File: SqlSimpleParser.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Tokenizer(String sql, String hintToken, Quoting quoting) {
  this.sql = sql;
  this.hintToken = hintToken;
  this.openQuote = quoting.string.charAt(0);
  this.pos = 0;
}
 
Example #21
Source File: SqlSimpleParser.java    From Quicksql with MIT License 4 votes vote down vote up
@Deprecated
public Tokenizer(String sql, String hintToken) {
  this(sql, hintToken, Quoting.DOUBLE_QUOTE);
}
 
Example #22
Source File: SqlParser.java    From Quicksql with MIT License 4 votes vote down vote up
public Quoting quoting() {
  return quoting;
}
 
Example #23
Source File: SqlParser.java    From calcite with Apache License 2.0 4 votes vote down vote up
public ConfigBuilder setQuoting(Quoting quoting) {
  this.quoting = Objects.requireNonNull(quoting);
  return this;
}
 
Example #24
Source File: SqlParser.java    From Quicksql with MIT License 4 votes vote down vote up
public ConfigBuilder setQuoting(Quoting quoting) {
  this.quoting = Objects.requireNonNull(quoting);
  return this;
}
 
Example #25
Source File: SqlParser.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Quoting quoting() {
  return quoting;
}
 
Example #26
Source File: SqlSimpleParser.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public Tokenizer(String sql, String hintToken) {
  this(sql, hintToken, Quoting.DOUBLE_QUOTE);
}
 
Example #27
Source File: SqlValidatorTestCase.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Sql withQuoting(Quoting quoting) {
  return withTester(tester -> tester.withQuoting(quoting));
}
 
Example #28
Source File: CalciteConnectionConfigImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Quoting quoting() {
  return CalciteConnectionProperty.QUOTING.wrap(properties)
      .getEnum(Quoting.class, lex().quoting);
}
 
Example #29
Source File: CalciteConnectionConfig.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** @see CalciteConnectionProperty#QUOTING */
Quoting quoting();
 
Example #30
Source File: AbstractSqlTester.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlTester withQuoting(Quoting quoting) {
  return with("quoting", quoting);
}