Java Code Examples for org.apache.calcite.avatica.util.Casing

The following examples show how to use org.apache.calcite.avatica.util.Casing. 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: Quicksql   Source File: SqlParserUtil.java    License: MIT License 6 votes vote down vote up
/**
 * Unquotes a quoted string, using different quotes for beginning and end.
 */
public static String strip(String s, String startQuote, String endQuote,
    String escape, Casing casing) {
  if (startQuote != null) {
    assert endQuote != null;
    assert startQuote.length() == 1;
    assert endQuote.length() == 1;
    assert escape != null;
    assert s.startsWith(startQuote) && s.endsWith(endQuote) : s;
    s = s.substring(1, s.length() - 1).replace(escape, endQuote);
  }
  switch (casing) {
  case TO_UPPER:
    return s.toUpperCase(Locale.ROOT);
  case TO_LOWER:
    return s.toLowerCase(Locale.ROOT);
  default:
    return s;
  }
}
 
Example 2
Source Project: Quicksql   Source File: QueryProcedureProducer.java    License: 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 3
Source Project: quark   Source File: ParserFactory.java    License: 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 4
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 5
Source Project: calcite   Source File: SqlParserUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Unquotes a quoted string, using different quotes for beginning and end.
 */
public static String strip(String s, String startQuote, String endQuote,
    String escape, Casing casing) {
  if (startQuote != null) {
    assert endQuote != null;
    assert startQuote.length() == 1;
    assert endQuote.length() == 1;
    assert escape != null;
    assert s.startsWith(startQuote) && s.endsWith(endQuote) : s;
    s = s.substring(1, s.length() - 1).replace(escape, endQuote);
  }
  switch (casing) {
  case TO_UPPER:
    return s.toUpperCase(Locale.ROOT);
  case TO_LOWER:
    return s.toLowerCase(Locale.ROOT);
  default:
    return s;
  }
}
 
Example 6
Source Project: flink   Source File: FlinkDDLDataTypeTest.java    License: 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 7
Source Project: flink   Source File: FlinkDDLDataTypeTest.java    License: Apache License 2.0 5 votes vote down vote up
private SqlDialect getSqlDialect() {
	return new CalciteSqlDialect(SqlDialect.EMPTY_CONTEXT
		.withQuotedCasing(Casing.UNCHANGED)
		.withConformance(conformance)
		.withUnquotedCasing(Casing.UNCHANGED)
		.withIdentifierQuoteString("`"));
}
 
Example 8
Source Project: Quicksql   Source File: SqlParser.java    License: 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 9
Source Project: Quicksql   Source File: SqlDialect.java    License: MIT License 5 votes vote down vote up
/** Creates an empty context. Use {@link #EMPTY_CONTEXT} if possible. */
protected static Context emptyContext() {
  return new ContextImpl(DatabaseProduct.UNKNOWN, null, null, -1, -1,
      "'", "''", null,
      Casing.UNCHANGED, Casing.TO_UPPER, true, SqlConformanceEnum.DEFAULT,
      NullCollation.HIGH, RelDataTypeSystemImpl.DEFAULT,
      JethroDataSqlDialect.JethroInfo.EMPTY);
}
 
Example 10
Source Project: Quicksql   Source File: SqlDialect.java    License: MIT License 5 votes vote down vote up
@Nonnull public Context withUnquotedCasing(Casing unquotedCasing) {
  return new ContextImpl(databaseProduct, databaseProductName,
      databaseVersion, databaseMajorVersion, databaseMinorVersion,
      literalQuoteString, literalEscapedQuoteString,
      identifierQuoteString, quotedCasing, unquotedCasing, caseSensitive,
      conformance, nullCollation, dataTypeSystem, jethroInfo);
}
 
Example 11
Source Project: kylin-on-parquet-v2   Source File: QueryConnectionTest.java    License: 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 12
Source Project: calcite   Source File: SqlDialect.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull public Context withUnquotedCasing(Casing unquotedCasing) {
  return new ContextImpl(databaseProduct, databaseProductName,
      databaseVersion, databaseMajorVersion, databaseMinorVersion,
      literalQuoteString, literalEscapedQuoteString,
      identifierQuoteString, quotedCasing, unquotedCasing, caseSensitive,
      conformance, nullCollation, dataTypeSystem, jethroInfo);
}
 
Example 13
Source Project: dremio-oss   Source File: ServerMetaProvider.java    License: Apache License 2.0 5 votes vote down vote up
public static IdentifierCasing getIdentifierCasing(Casing casing, boolean caseSensitive) {
  switch(casing) {
  case TO_LOWER:
    return IdentifierCasing.IC_STORES_LOWER;

  case TO_UPPER:
    return IdentifierCasing.IC_STORES_UPPER;

  case UNCHANGED:
    return caseSensitive ? IdentifierCasing.IC_SUPPORTS_MIXED : IdentifierCasing.IC_STORES_MIXED;

  default:
    throw new AssertionError("Unknown casing:" + casing);
  }
}
 
Example 14
Source Project: kylin   Source File: QueryConnectionTest.java    License: 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 15
Source Project: flink   Source File: FlinkDDLDataTypeTest.java    License: 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 16
Source Project: flink   Source File: FlinkDDLDataTypeTest.java    License: 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 17
Source Project: calcite   Source File: SqlParserUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts the contents of an sql quoted string literal into the
 * corresponding Java string representation (removing leading and trailing
 * quotes and unescaping internal doubled quotes).
 */
public static String parseString(String s) {
  int i = s.indexOf("'"); // start of body
  if (i > 0) {
    s = s.substring(i);
  }
  return strip(s, "'", "'", "''", Casing.UNCHANGED);
}
 
Example 18
Source Project: calcite   Source File: SqlTestFactory.java    License: 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 19
Source Project: calcite   Source File: SqlParser.java    License: 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 20
Source Project: calcite   Source File: SqlDialect.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates an empty context. Use {@link #EMPTY_CONTEXT} to reference the instance. */
private static Context emptyContext() {
  return new ContextImpl(DatabaseProduct.UNKNOWN, null, null, -1, -1,
      "'", "''", null,
      Casing.UNCHANGED, Casing.TO_UPPER, true, SqlConformanceEnum.DEFAULT,
      NullCollation.HIGH, RelDataTypeSystemImpl.DEFAULT,
      JethroDataSqlDialect.JethroInfo.EMPTY);
}
 
Example 21
Source Project: calcite   Source File: SqlDialect.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull public Context withQuotedCasing(Casing quotedCasing) {
  return new ContextImpl(databaseProduct, databaseProductName,
      databaseVersion, databaseMajorVersion, databaseMinorVersion,
      literalQuoteString, literalEscapedQuoteString,
      identifierQuoteString, quotedCasing, unquotedCasing, caseSensitive,
      conformance, nullCollation, dataTypeSystem, jethroInfo);
}
 
Example 22
Source Project: Quicksql   Source File: SqlParser.java    License: MIT License 4 votes vote down vote up
public ConfigBuilder setQuotedCasing(Casing quotedCasing) {
  this.quotedCasing = Objects.requireNonNull(quotedCasing);
  return this;
}
 
Example 23
Source Project: Quicksql   Source File: SqlParser.java    License: MIT License 4 votes vote down vote up
public ConfigBuilder setUnquotedCasing(Casing unquotedCasing) {
  this.unquotedCasing = Objects.requireNonNull(unquotedCasing);
  return this;
}
 
Example 24
Source Project: Quicksql   Source File: SqlParser.java    License: MIT License 4 votes vote down vote up
public Casing quotedCasing() {
  return quotedCasing;
}
 
Example 25
Source Project: Quicksql   Source File: SqlParser.java    License: MIT License 4 votes vote down vote up
public Casing unquotedCasing() {
  return unquotedCasing;
}
 
Example 26
Source Project: Quicksql   Source File: SqlDialect.java    License: MIT License 4 votes vote down vote up
/** Returns how unquoted identifiers are stored. */
public Casing getUnquotedCasing() {
  return unquotedCasing;
}
 
Example 27
Source Project: Quicksql   Source File: SqlDialect.java    License: MIT License 4 votes vote down vote up
/** Returns how quoted identifiers are stored. */
public Casing getQuotedCasing() {
  return quotedCasing;
}
 
Example 28
Source Project: calcite   Source File: CalciteConnectionConfig.java    License: Apache License 2.0 4 votes vote down vote up
/** @see CalciteConnectionProperty#QUOTED_CASING */
Casing quotedCasing();
 
Example 29
Source Project: Quicksql   Source File: SqlDialect.java    License: MIT License 4 votes vote down vote up
@Nonnull public Casing unquotedCasing() {
  return unquotedCasing;
}
 
Example 30
Source Project: calcite   Source File: CalciteConnectionConfigImpl.java    License: Apache License 2.0 4 votes vote down vote up
public Casing quotedCasing() {
  return CalciteConnectionProperty.QUOTED_CASING.wrap(properties)
      .getEnum(Casing.class, lex().quotedCasing);
}