You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Gavin Ray <ra...@gmail.com> on 2022/06/21 20:07:00 UTC

What is the difference between running expressions with RelRunner + RelNode vs JDBC Connection and SQL string

From what I've been able to tell, surface-level functionally the below work
the same
but I'm wondering whether there are any differences/any scenarios to prefer
one to the other?

======================================
fun executeQuery(sql: String): ResultSet {
    val planner = Frameworks.getPlanner(frameworkConfig)
    val sqlNode = planner.parse(sql)
    val validated = planner.validate(sqlNode)
    val relRoot = planner.rel(validated).project()

    relRoot.cluster.planner.root = relRoot.cluster.planner.changeTraits(
        relRoot,
        relRoot.cluster.traitSet().replace(EnumerableConvention.INSTANCE)
    )
    val bestExp = relRoot.cluster.planner.findBestExp()

    val relRunner = connection.unwrap(RelRunner::class.java)
    return relRunner.prepareStatement(bestExp).executeQuery()
}

======================================
fun executeQuery(sql: String): ResultSet {
    val stmt = CalciteSchemaService.connection.createStatement()
    return stmt.executeQuery(sql)
}

Re: What is the difference between running expressions with RelRunner + RelNode vs JDBC Connection and SQL string

Posted by Gavin Ray <ra...@gmail.com>.
Got it, thanks Julian, that makes sense.
Wanted to make sure there wasn't some hidden gotcha or specific situations
in which to look out for.

On Tue, Jun 21, 2022 at 4:13 PM Julian Hyde <jh...@gmail.com> wrote:

> Probably (and hopefully) not much difference. We know that not everyone
> has/wants a JDBC connection, and not every query is most naturally
> expressed in SQL, so we tried to make all of the combinations possible.
> Some of the non-JDBC options may still create a JDBC connection under the
> covers, which is not ideal.
>
>
> > On Jun 21, 2022, at 1:07 PM, Gavin Ray <ra...@gmail.com> wrote:
> >
> > From what I've been able to tell, surface-level functionally the below
> work
> > the same
> > but I'm wondering whether there are any differences/any scenarios to
> prefer
> > one to the other?
> >
> > ======================================
> > fun executeQuery(sql: String): ResultSet {
> >    val planner = Frameworks.getPlanner(frameworkConfig)
> >    val sqlNode = planner.parse(sql)
> >    val validated = planner.validate(sqlNode)
> >    val relRoot = planner.rel(validated).project()
> >
> >    relRoot.cluster.planner.root = relRoot.cluster.planner.changeTraits(
> >        relRoot,
> >        relRoot.cluster.traitSet().replace(EnumerableConvention.INSTANCE)
> >    )
> >    val bestExp = relRoot.cluster.planner.findBestExp()
> >
> >    val relRunner = connection.unwrap(RelRunner::class.java)
> >    return relRunner.prepareStatement(bestExp).executeQuery()
> > }
> >
> > ======================================
> > fun executeQuery(sql: String): ResultSet {
> >    val stmt = CalciteSchemaService.connection.createStatement()
> >    return stmt.executeQuery(sql)
> > }
>
>

Re: What is the difference between running expressions with RelRunner + RelNode vs JDBC Connection and SQL string

Posted by Julian Hyde <jh...@gmail.com>.
Probably (and hopefully) not much difference. We know that not everyone has/wants a JDBC connection, and not every query is most naturally expressed in SQL, so we tried to make all of the combinations possible. Some of the non-JDBC options may still create a JDBC connection under the covers, which is not ideal. 


> On Jun 21, 2022, at 1:07 PM, Gavin Ray <ra...@gmail.com> wrote:
> 
> From what I've been able to tell, surface-level functionally the below work
> the same
> but I'm wondering whether there are any differences/any scenarios to prefer
> one to the other?
> 
> ======================================
> fun executeQuery(sql: String): ResultSet {
>    val planner = Frameworks.getPlanner(frameworkConfig)
>    val sqlNode = planner.parse(sql)
>    val validated = planner.validate(sqlNode)
>    val relRoot = planner.rel(validated).project()
> 
>    relRoot.cluster.planner.root = relRoot.cluster.planner.changeTraits(
>        relRoot,
>        relRoot.cluster.traitSet().replace(EnumerableConvention.INSTANCE)
>    )
>    val bestExp = relRoot.cluster.planner.findBestExp()
> 
>    val relRunner = connection.unwrap(RelRunner::class.java)
>    return relRunner.prepareStatement(bestExp).executeQuery()
> }
> 
> ======================================
> fun executeQuery(sql: String): ResultSet {
>    val stmt = CalciteSchemaService.connection.createStatement()
>    return stmt.executeQuery(sql)
> }