Caican Cai created CALCITE-6613:
-----------------------------------

             Summary: Make the Background code examples in Calcite official 
documentation clearer
                 Key: CALCITE-6613
                 URL: https://issues.apache.org/jira/browse/CALCITE-6613
             Project: Calcite
          Issue Type: Improvement
            Reporter: Caican Cai



{code:java}
public static class HrSchema {
  public final Employee[] emps = 0;
  public final Department[] depts = 0;
}
Class.forName("org.apache.calcite.jdbc.Driver");
Properties info = new Properties();
info.setProperty("lex", "JAVA");
Connection connection =
    DriverManager.getConnection("jdbc:calcite:", info);
CalciteConnection calciteConnection =
    connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
Schema schema = new ReflectiveSchema(new HrSchema());
rootSchema.add("hr", schema);
Statement statement = calciteConnection.createStatement();
ResultSet resultSet = statement.executeQuery(
    "select d.deptno, min(e.empid)\n"
    + "from hr.emps as e\n"
    + "join hr.depts as d\n"
    + "  on e.deptno = d.deptno\n"
    + "group by d.deptno\n"
    + "having count(*) > 1");
print(resultSet);
resultSet.close();
statement.close();
connection.close();
Where is the database? There is no database. The connection is completely empty 
until new ReflectiveSchema registers a Java object as a schema and its 
collection fields emps and depts as tables.

Calcite does not want to own data; it does not even have a favorite data 
format. This example used in-memory data sets, and processed them using 
operators such as groupBy and join from the linq4j library. But Calcite can 
also process data in other data formats, such as JDBC. In the first example, 
replace

Schema schema = new ReflectiveSchema(new HrSchema());
with

Class.forName("com.mysql.jdbc.Driver");
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl("jdbc:mysql://localhost");
dataSource.setUsername("username");
dataSource.setPassword("password");
Schema schema = JdbcSchema.create(rootSchema, "hr", dataSource,
    null, "name");
{code}

Currently, the data of emps and depts are both 0, and it is not reasonable to 
not create a new object. We can create new Employee[0] and add some data, which 
may be more reasonable.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to