Apache Calcite Error: "Table Not Found" When Connecting to MySQL Database

64 views Asked by At

I'm encountering an issue when attempting to connect to a MySQL database and execute a simple query using Apache Calcite. The error message suggests that the table is not found. However, I've verified that the table exists, and I've successfully executed the same query using standard Java code without Calcite.

Here's the relevant code snippet:

public class Main {

    private static final String MYSQL_SCHEMA = "tpch";

    public static void main(String[] args) throws Exception {

        // Build our connection
        Connection connection = DriverManager.getConnection("jdbc:calcite:");

        // Unwrap our connection using the CalciteConnection
        CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);

        // Get a pointer to our root schema for our Calcite Connection
        SchemaPlus rootSchema = calciteConnection.getRootSchema()

        // Instantiate a data source, this can be autowired in using Spring as well
        DataSource mysqlDataSource = JdbcSchema.dataSource(
                "jdbc:mysql://localhost:3306/tpch",
                "com.mysql.jdbc.Driver", // Change this if you want to use something like MySQL, Oracle, etc.
                "username", // username
                "password"   // password
        );

        // Attach our MySQL Jdbc Datasource to our Root Schema
        rootSchema.add(MYSQL_SCHEMA, JdbcSchema.create(rootSchema, MYSQL_SCHEMA, mysqlDataSource, null, null));


        // Build a framework config to attach to our Calcite Planners and  Optimizers
        FrameworkConfig config = Frameworks.newConfigBuilder()
                .defaultSchema(rootSchema)
                .build();

        RelBuilder rb = RelBuilder.create(config);

        RelNode node = rb.scan("customer")
                .project(
                        rb.field("c_name"),
                        rb.field("c_address")
                )
                .limit(0, 5)
                .build();
    }
}

I've ensured that the schema name, classpath, and database connection details are correct. Can anyone please provide insights into what might be causing this issue when using Calcite?

0

There are 0 answers