79395220

Date: 2025-01-28 21:26:29
Score: 2
Natty:
Report link

Did anyone able to solve this? I have tried but throwing error for: Multiple entries with same key: primary=JdbcTable {primary} and primary=JdbcTable {primary}

Here is the relevant part of my Java code:

// Initialize Calcite connection with case-sensitive settings
Properties info = new Properties();
info.setProperty("lex", Lex.MYSQL.name());
info.setProperty("caseSensitive", "true");
Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();

// Connect to CockroachDB
org.postgresql.ds.PGSimpleDataSource cockroachDS = new org.postgresql.ds.PGSimpleDataSource();
cockroachDS.setUrl("jdbc:postgresql://localhost:26257/sample");
cockroachDS.setUser("root");
cockroachDS.setPassword("");

// Connect to H2
org.h2.jdbcx.JdbcDataSource h2DS = new org.h2.jdbcx.JdbcDataSource();
h2DS.setURL("jdbc:h2:testdata;AUTO_SERVER=TRUE");
h2DS.setUser("");
h2DS.setPassword("");

// Add schemas
rootSchema.add("CRDB", 
    JdbcSchema.create(rootSchema, "CRDB", cockroachDS, 
        "sample",  // catalog
        "public")); // schema

rootSchema.add("H2DB", 
    JdbcSchema.create(rootSchema, "H2DB", h2DS,
        "DEFAULT",  // catalog
        "PUBLIC")); // schema

// Execute join query with simplified schema references
String sql = 
    "SELECT c.customer_name, o.order_id, o.order_date " +
    "FROM CRDB.customers c " +
    "JOIN H2DB.orders o ON c.customer_id = o.customer_id";

try (Statement statement = calciteConnection.createStatement()) {
    System.out.println("Executing query: " + sql);
    
    // Enable debug logging
    statement.execute("EXPLAIN PLAN FOR " + sql);
    ResultSet explainRs = statement.getResultSet();
    System.out.println("\nQuery Plan:");
    while (explainRs.next()) {
        System.out.println(explainRs.getString(1));
    }
    
    // Execute actual query
    ResultSet rs = statement.executeQuery(sql);

    // Print results
    System.out.println("\nQuery Results:");
    while (rs.next()) {
        System.out.printf("Customer: %s, Order ID: %s, Date: %s%n",
            rs.getString(1),
            rs.getString(2),
            rs.getString(3));
    }
} catch (SQLException e) {
    System.err.println("Error executing query: " + e.getMessage());
    e.printStackTrace();
}

// Clean up
connection.close();
Reasons:
  • RegEx Blacklisted phrase (1.5): solve this?
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Did anyone
  • Low reputation (1):
Posted by: Anoop