org.apache.calcite.avatica.InternalProperty Java Examples

The following examples show how to use org.apache.calcite.avatica.InternalProperty. 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: QuarkConnectionImpl.java    From quark with Apache License 2.0 6 votes vote down vote up
protected QuarkConnectionImpl(QuarkDriver driver, AvaticaFactory factory, String url,
                              Properties info, CalciteRootSchema rootSchema,
                              JavaTypeFactory typeFactory) throws SQLException {
  super(driver, factory, url, info);

  CalciteConnectionConfig cfg = new CalciteConnectionConfigImpl(info);

  if (typeFactory != null) {
    this.typeFactory = typeFactory;
  } else {
    final RelDataTypeSystem typeSystem =
        cfg.typeSystem(RelDataTypeSystem.class, RelDataTypeSystem.DEFAULT);
    this.typeFactory = new JavaTypeFactoryImpl(typeSystem);
  }

  this.properties.put(InternalProperty.CASE_SENSITIVE, cfg.caseSensitive());
  this.properties.put(InternalProperty.UNQUOTED_CASING, cfg.unquotedCasing());
  this.properties.put(InternalProperty.QUOTED_CASING, cfg.quotedCasing());
  this.properties.put(InternalProperty.QUOTING, cfg.quoting());
}
 
Example #2
Source File: CalciteConnectionImpl.java    From Quicksql with MIT License 5 votes vote down vote up
/**
 * Creates a CalciteConnectionImpl.
 *
 * <p>Not public; method is called only from the driver.</p>
 *
 * @param driver Driver
 * @param factory Factory for JDBC objects
 * @param url Server URL
 * @param info Other connection properties
 * @param rootSchema Root schema, or null
 * @param typeFactory Type factory, or null
 */
protected CalciteConnectionImpl(Driver driver, AvaticaFactory factory,
    String url, Properties info, CalciteSchema rootSchema,
    JavaTypeFactory typeFactory) {
  super(driver, factory, url, info);
  CalciteConnectionConfig cfg = new CalciteConnectionConfigImpl(info);
  this.prepareFactory = driver.prepareFactory;
  if (typeFactory != null) {
    this.typeFactory = typeFactory;
  } else {
    RelDataTypeSystem typeSystem =
        cfg.typeSystem(RelDataTypeSystem.class, RelDataTypeSystem.DEFAULT);
    if (cfg.conformance().shouldConvertRaggedUnionTypesToVarying()) {
      typeSystem =
          new DelegatingTypeSystem(typeSystem) {
            @Override public boolean
            shouldConvertRaggedUnionTypesToVarying() {
              return true;
            }
          };
    }
    this.typeFactory = new JavaTypeFactoryImpl(typeSystem);
  }
  this.rootSchema =
      Objects.requireNonNull(rootSchema != null
          ? rootSchema
          : CalciteSchema.createRootSchema(true));
  Preconditions.checkArgument(this.rootSchema.isRoot(), "must be root schema");
  this.properties.put(InternalProperty.CASE_SENSITIVE, cfg.caseSensitive());
  this.properties.put(InternalProperty.UNQUOTED_CASING, cfg.unquotedCasing());
  this.properties.put(InternalProperty.QUOTED_CASING, cfg.quotedCasing());
  this.properties.put(InternalProperty.QUOTING, cfg.quoting());
}
 
Example #3
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 #4
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 #5
Source File: QueryConnectionTest.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static Map<InternalProperty, Object> dirtyReadProperties(Connection connection) throws IllegalAccessException {
    assertTrue(connection instanceof CalciteConnection);
    return (Map<InternalProperty, Object>) FieldUtils.readField(connection, "properties");

}
 
Example #6
Source File: QueryConnectionTest.java    From kylin with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static Map<InternalProperty, Object> dirtyReadProperties(Connection connection) throws IllegalAccessException {
    assertTrue(connection instanceof CalciteConnection);
    return (Map<InternalProperty, Object>) FieldUtils.readField(connection, "properties");

}