org.apache.calcite.jdbc.Driver Java Examples

The following examples show how to use org.apache.calcite.jdbc.Driver. 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: QueryConnection.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public static Connection getConnection(String project) throws SQLException {
    if (!isRegister) {
        try {
            Class<?> aClass = Thread.currentThread().getContextClassLoader()
                    .loadClass("org.apache.calcite.jdbc.Driver");
            Driver o = (Driver) aClass.getDeclaredConstructor().newInstance();
            DriverManager.registerDriver(o);
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            e.printStackTrace();
        }
        isRegister = true;
    }
    File olapTmp = OLAPSchemaFactory.createTempOLAPJson(project, KylinConfig.getInstanceFromEnv());
    Properties info = new Properties();
    info.putAll(KylinConfig.getInstanceFromEnv().getCalciteExtrasProperties());
    // Import calcite props from jdbc client(override the kylin.properties)
    info.putAll(BackdoorToggles.getJdbcDriverClientCalciteProps());
    info.put("model", olapTmp.getAbsolutePath());
    info.put("typeSystem", "org.apache.kylin.query.calcite.KylinRelDataTypeSystem");
    return DriverManager.getConnection("jdbc:calcite:", info);
}
 
Example #2
Source File: QueryConnection.java    From kylin with Apache License 2.0 6 votes vote down vote up
public static Connection getConnection(String project) throws SQLException {
    if (!isRegister) {
        try {
            Class<?> aClass = Thread.currentThread().getContextClassLoader()
                    .loadClass("org.apache.calcite.jdbc.Driver");
            Driver o = (Driver) aClass.getDeclaredConstructor().newInstance();
            DriverManager.registerDriver(o);
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            e.printStackTrace();
        }
        isRegister = true;
    }
    File olapTmp = OLAPSchemaFactory.createTempOLAPJson(project, KylinConfig.getInstanceFromEnv());
    Properties info = new Properties();
    info.putAll(KylinConfig.getInstanceFromEnv().getCalciteExtrasProperties());
    // Import calcite props from jdbc client(override the kylin.properties)
    info.putAll(BackdoorToggles.getJdbcDriverClientCalciteProps());
    info.put("model", olapTmp.getAbsolutePath());
    info.put("typeSystem", "org.apache.kylin.query.calcite.KylinRelDataTypeSystem");
    return DriverManager.getConnection("jdbc:calcite:", info);
}
 
Example #3
Source File: ReflectiveSchemaTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1919">[CALCITE-1919]
 * NPE when target in ReflectiveSchema belongs to the unnamed package</a>. */
@Test void testReflectiveSchemaInUnnamedPackage() throws Exception {
  final Driver driver = new Driver();
  try (CalciteConnection connection = (CalciteConnection)
      driver.connect("jdbc:calcite:", new Properties())) {
    SchemaPlus rootSchema = connection.getRootSchema();
    final Class<?> c = Class.forName("RootHr");
    final Object o = c.getDeclaredConstructor().newInstance();
    rootSchema.add("hr", new ReflectiveSchema(o));
    connection.setSchema("hr");
    final Statement statement = connection.createStatement();
    final String sql = "select * from \"emps\"";
    final ResultSet resultSet = statement.executeQuery(sql);
    final String expected = "empid=100; name=Bill\n"
        + "empid=200; name=Eric\n"
        + "empid=150; name=Sebastian\n";
    assertThat(CalciteAssert.toString(resultSet), is(expected));
  }
}
 
Example #4
Source File: MultiJdbcSchemaJoinTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Tests {@link org.apache.calcite.adapter.jdbc.JdbcCatalogSchema}. */
@Test void test3() throws SQLException {
  final BasicDataSource dataSource = new BasicDataSource();
  dataSource.setUrl(TempDb.INSTANCE.getUrl());
  dataSource.setUsername("");
  dataSource.setPassword("");
  final JdbcCatalogSchema schema =
      JdbcCatalogSchema.create(null, "", dataSource, "PUBLIC");
  assertThat(schema.getSubSchemaNames(),
      is(Sets.newHashSet("INFORMATION_SCHEMA", "PUBLIC", "SYSTEM_LOBS")));
  final CalciteSchema rootSchema0 =
      CalciteSchema.createRootSchema(false, false, "", schema);
  final Driver driver = new Driver();
  final CalciteJdbc41Factory factory = new CalciteJdbc41Factory();
  final String sql = "select count(*) as c from information_schema.schemata";
  try (Connection connection =
           factory.newConnection(driver, factory,
               "jdbc:calcite:", new Properties(), rootSchema0, null);
       Statement stmt3 = connection.createStatement();
       ResultSet rs = stmt3.executeQuery(sql)) {
    assertThat(CalciteAssert.toString(rs), equalTo("C=3\n"));
  }
}