You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Raja Ranjan Senapati <ra...@gmail.com> on 2023/11/08 16:58:21 UTC

Ability to access Calcite JDBC remotely from another JDBC client such as DBeaver/DataGrip

Team,
  I am a newbie to Calcite and am excited about its potential. I have a
question. According to the status section on the docs page
<https://calcite.apache.org/docs/>, calcite supports Local and remote JDBC
drivers using Avatica.  My interpretation of that statement is we can wrap
any data source using Calcite and expose the data by creating a JDBC
server. This JDBC server can be accessed remotely using the remote Calcite
JDBC driver, from tools such as DBeaver/DataGrip.

 I can create a local JDBC wrapper on my data source and use it from the
same JVM. However, I cannot find any sample code that would create a JDBC
server and serve remote clients using a remote JDBC server. I explored
concepts like Avatica Http Server
<https://calcite.apache.org/avatica/javadocAggregate/org/apache/calcite/avatica/server/HttpServer.html>but
could not find any concrete implementation using Calcite. Can you please
point me to some references/samples? I think it would be awesome if you
could add this to some FAQ/Tutorial page in Calcite as well.

Thanks,
Raja Senapati

Re: Ability to access Calcite JDBC remotely from another JDBC client such as DBeaver/DataGrip

Posted by Gavin Ray <ra...@gmail.com>.
Heya, I actually wrote quite a long tutorial on how to connect to Calcite
via SQuirreL/DBeaver or similar tools.
It's not a simple process.

Here is the guide:
Making Apache Calcite work in SQuirreL SQL Client (github.com)
<https://gist.github.com/GavinRay97/44fcd0f17e5c62ed6e7880fed0b0042e>



On Wed, Nov 8, 2023 at 1:55 PM TJ Banghart <tj...@google.com.invalid>
wrote:

> Hello Raja and welcome to Calcite!
>
> I have found it helpful to think of an Avatica server in terms of its main
> interfaces Service
> <
> https://github.com/apache/calcite-avatica/blob/519d1ceeb04cd99530bceb60c1a8e0966c413541/core/src/main/java/org/apache/calcite/avatica/remote/Service.java#L59C7-L59C7
> >
> and Meta
> <
> https://github.com/apache/calcite-avatica/blob/519d1ceeb04cd99530bceb60c1a8e0966c413541/core/src/main/java/org/apache/calcite/avatica/Meta.java#L53
> >.
> The service implementation determines what RPC message format to use as
> well as what RPCs are available. The meta implementation determines how the
> server retrieves metadata, executes queries, etc.
> When starting the server we can supply both the service and meta
> implementations we want to use. In this case we want the server to access
> Calcite locally while using the generic Avatica driver from a JDBC client
> like DBeaver. For example (in Kotlin):
>
> class MyJdbcServer(port: Int) {
>     val meta: Meta = MyCalciteMetaFactory().create()
>     val service: Service = LocalService(meta)
>     val server: HttpServer = HttpServer(port, AvaticaJsonHandler(service))
>
>     ... methods to start/stop server etc...
> }
>
> class MyCalciteMetaFactory() : Meta.Factory {
>     override fun create(args: List<String?>?): Meta {
>         val info: Properties = ...some method to generate Calcite
> connection props...
>         val driver: Driver = Driver()
>         val connection: AvaticaConnection = driver.connect("jdbc:calcite:",
> info) as AvaticaConnection?
>
>         return driver.createMeta(connection)
>     }
> }
>
>
> All RPCs from the JDBC client using the generic Avatica driver should be
> handled by the local CalciteMetaImpl
> <
> https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
> >
> instance
> associated with the server. This is the same as if you had a local Calcite
> connection. Note that this will not work behind a load-balancer as local
> Calcite connections are "stateful" (see CALCITE-668
> <https://issues.apache.org/jira/browse/CALCITE-668>).
> I'm sure others might have a better way but this has worked for us so far!
>
> On Wed, Nov 8, 2023 at 9:00 AM Raja Ranjan Senapati <raja.ranjan@gmail.com
> >
> wrote:
>
> > Team,
> >   I am a newbie to Calcite and am excited about its potential. I have a
> > question. According to the status section on the docs page
> > <https://calcite.apache.org/docs/>, calcite supports Local and remote
> JDBC
> > drivers using Avatica.  My interpretation of that statement is we can
> wrap
> > any data source using Calcite and expose the data by creating a JDBC
> > server. This JDBC server can be accessed remotely using the remote
> Calcite
> > JDBC driver, from tools such as DBeaver/DataGrip.
> >
> >  I can create a local JDBC wrapper on my data source and use it from the
> > same JVM. However, I cannot find any sample code that would create a JDBC
> > server and serve remote clients using a remote JDBC server. I explored
> > concepts like Avatica Http Server
> > <
> >
> https://calcite.apache.org/avatica/javadocAggregate/org/apache/calcite/avatica/server/HttpServer.html
> > >but
> > could not find any concrete implementation using Calcite. Can you please
> > point me to some references/samples? I think it would be awesome if you
> > could add this to some FAQ/Tutorial page in Calcite as well.
> >
> > Thanks,
> > Raja Senapati
> >
>
>
> --
>
> TJ
>

Re: Ability to access Calcite JDBC remotely from another JDBC client such as DBeaver/DataGrip

Posted by TJ Banghart <tj...@google.com.INVALID>.
Hello Raja and welcome to Calcite!

I have found it helpful to think of an Avatica server in terms of its main
interfaces Service
<https://github.com/apache/calcite-avatica/blob/519d1ceeb04cd99530bceb60c1a8e0966c413541/core/src/main/java/org/apache/calcite/avatica/remote/Service.java#L59C7-L59C7>
and Meta
<https://github.com/apache/calcite-avatica/blob/519d1ceeb04cd99530bceb60c1a8e0966c413541/core/src/main/java/org/apache/calcite/avatica/Meta.java#L53>.
The service implementation determines what RPC message format to use as
well as what RPCs are available. The meta implementation determines how the
server retrieves metadata, executes queries, etc.
When starting the server we can supply both the service and meta
implementations we want to use. In this case we want the server to access
Calcite locally while using the generic Avatica driver from a JDBC client
like DBeaver. For example (in Kotlin):

class MyJdbcServer(port: Int) {
    val meta: Meta = MyCalciteMetaFactory().create()
    val service: Service = LocalService(meta)
    val server: HttpServer = HttpServer(port, AvaticaJsonHandler(service))

    ... methods to start/stop server etc...
}

class MyCalciteMetaFactory() : Meta.Factory {
    override fun create(args: List<String?>?): Meta {
        val info: Properties = ...some method to generate Calcite
connection props...
        val driver: Driver = Driver()
        val connection: AvaticaConnection = driver.connect("jdbc:calcite:",
info) as AvaticaConnection?

        return driver.createMeta(connection)
    }
}


All RPCs from the JDBC client using the generic Avatica driver should be
handled by the local CalciteMetaImpl
<https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java>
instance
associated with the server. This is the same as if you had a local Calcite
connection. Note that this will not work behind a load-balancer as local
Calcite connections are "stateful" (see CALCITE-668
<https://issues.apache.org/jira/browse/CALCITE-668>).
I'm sure others might have a better way but this has worked for us so far!

On Wed, Nov 8, 2023 at 9:00 AM Raja Ranjan Senapati <ra...@gmail.com>
wrote:

> Team,
>   I am a newbie to Calcite and am excited about its potential. I have a
> question. According to the status section on the docs page
> <https://calcite.apache.org/docs/>, calcite supports Local and remote JDBC
> drivers using Avatica.  My interpretation of that statement is we can wrap
> any data source using Calcite and expose the data by creating a JDBC
> server. This JDBC server can be accessed remotely using the remote Calcite
> JDBC driver, from tools such as DBeaver/DataGrip.
>
>  I can create a local JDBC wrapper on my data source and use it from the
> same JVM. However, I cannot find any sample code that would create a JDBC
> server and serve remote clients using a remote JDBC server. I explored
> concepts like Avatica Http Server
> <
> https://calcite.apache.org/avatica/javadocAggregate/org/apache/calcite/avatica/server/HttpServer.html
> >but
> could not find any concrete implementation using Calcite. Can you please
> point me to some references/samples? I think it would be awesome if you
> could add this to some FAQ/Tutorial page in Calcite as well.
>
> Thanks,
> Raja Senapati
>


-- 

TJ