I hate to bother with such a small question but I feel like I've hit a wall
after spending most of yesterday on it.

I get this when trying to execute a RelNode expression as a query, it seems
to
be because the "SchemaPlusImpl" throws "UnsupportedException" for the
"snapshot"
function.

https://github.com/apache/calcite/blob/4bc916619fd286b2c0cc4d5c653c96a68801d74e/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java#L654-L656

Not sure why/where "snapshot" is being called:
------------------------------------------------------------------------------
java.sql.SQLException: Error while preparing plan
[EnumerableTableScan(table=[[fake_database, hr, emps]]) ]
at org.apache.calcite.avatica.Helper.createException(Helper.java:56) at
org.apache.calcite.avatica.Helper.createException(Helper.java:41) at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:239)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.access$100(CalciteConnectionImpl.java:101)
at
org.apache.calcite.jdbc.CalciteConnectionImpl$2.prepareStatement(CalciteConnectionImpl.java:188)
at SchemaManager.executeQuery(SchemaManager.kt:83)

Caused by: java.lang.UnsupportedOperationException
at
org.apache.calcite.jdbc.CalciteSchema$SchemaPlusImpl.snapshot(CalciteSchema.java:655)
at
org.apache.calcite.jdbc.CachingCalciteSchema.snapshot(CachingCalciteSchema.java:260)

------------------------------------------------------------------------------
The code I am using to execute the query is:

object SchemaManager {
    val calciteConnection: CalciteConnection = run {
        val connection = DriverManager.getConnection("jdbc:calcite:")
        connection.unwrap(CalciteConnection::class.java)
    }
    val runner: RelRunner = calciteConnection.unwrap(RelRunner::class.java)
    val rootSchema: SchemaPlus = calciteConnection.rootSchema

    fun executeQuery(relRoot: RelNode): ResultSet {
        val optPlanner = relRoot.cluster.planner val desiredTraits =
        relRoot.cluster.traitSet().replace(EnumerableConvention.INSTANCE)
        optPlanner.root = optPlanner.changeTraits(relRoot, desiredTraits)
val
        bestExp = optPlanner.findBestExp()

        return runner.prepareStatement(bestExp).use { it.executeQuery() }
    }
}

Reply via email to