[ 
https://issues.apache.org/jira/browse/CALCITE-3778?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17219408#comment-17219408
 ] 

Guangyuan Wang edited comment on CALCITE-3778 at 10/23/20, 1:59 AM:
--------------------------------------------------------------------

I've tested JDBC Adapter.

I change model.json in "example/csv/src/test/resources", is bellow:

{quote}
{
 "version": "1.0",
 "defaultSchema": "demo",
 "schemas": [
 {
 "name": "demo",
 "type": "custom",
 "factory": "org.apache.calcite.adapter.jdbc.JdbcSchema$Factory",
 "operand": {
 "jdbcDriver": "com.mysql.jdbc.Driver",
 "jdbcUrl": "jdbc:mysql://localhost:3306/demo?useSSL=false",
 "jdbcUser": "root",
 "jdbcPassword": "root"
 }
 }
 ]
}
{quote}

I run ./sqlline in "example/csv/src" ,  and execute SQL below:
{quote}
0: jdbc:calcite:model=src/test/resources/mode> EXPLAIN PLAN FOR SELECT * FROM 
TEST1 JOIN TEST2 ON TEST1.ID = TEST2.NUM WHERE TEST1.ID = 1;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PLAN |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| JdbcToEnumerableConverter
  JdbcJoin(condition=[=($0, $2)], joinType=[inner])
      JdbcFilter(condition=[=($0, 1)])
          JdbcTableScan(table=[[demo, TEST1]])
  JdbcTableScan(table=[[demo, TEST2]])
 |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row selected (0.115 seconds)
{quote}
It seems that calcite has already support explain downstream SQL.

 


was (Author: wangguangyuan):
I've tested JDBC Adapter.

I change model.json in "example/csv/src/test/resources", is bellow:

{quote}
{
 "version": "1.0",
 "defaultSchema": "demo",
 "schemas": [
 {
 "name": "demo",
 "type": "custom",
 "factory": "org.apache.calcite.adapter.jdbc.JdbcSchema$Factory",
 "operand": {
 "jdbcDriver": "com.mysql.jdbc.Driver",
 "jdbcUrl": "jdbc:mysql://localhost:3306/demo?useSSL=false",
 "jdbcUser": "root",
 "jdbcPassword": "root"
 }
 }
 ]
}
{quote}

{
 "version": "1.0",
 "defaultSchema": "demo",
 "schemas": [
 {
 "name": "demo",
 "type": "custom",
 "factory": "org.apache.calcite.adapter.jdbc.JdbcSchema$Factory",
 "operand": {
 "jdbcDriver": "com.mysql.jdbc.Driver",
 "jdbcUrl": "jdbc:mysql://localhost:3306/demo?useSSL=false",
 "jdbcUser": "root",
 "jdbcPassword": "root"
 }
 }
 ]
}

I run ./sqlline in "example/csv/src" ,  and execute SQL below:

0: jdbc:calcite:model=src/test/resources/mode> EXPLAIN PLAN FOR SELECT * FROM 
TEST1 JOIN TEST2 ON TEST1.ID = TEST2.NUM WHERE TEST1.ID = 1;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PLAN |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| JdbcToEnumerableConverter
  JdbcJoin(condition=[=($0, $2)], joinType=[inner])
      JdbcFilter(condition=[=($0, 1)])
          JdbcTableScan(table=[[demo, TEST1]])
  JdbcTableScan(table=[[demo, TEST2]])
 |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row selected (0.115 seconds)

It seems that calcite has already support explain downstream SQL.

 

> Include downstream SQL in EXPLAIN output
> ----------------------------------------
>
>                 Key: CALCITE-3778
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3778
>             Project: Calcite
>          Issue Type: New Feature
>          Components: core
>            Reporter: jerryleooo
>            Assignee: Guangyuan Wang
>            Priority: Minor
>              Labels: newbie
>
> I am using Calcite JDBC, when executing a multiple join, I want to check if 
> the queries/SQLs sent to databases are right. Currently seems there is no 
> easy way to do this.
> I have enabled 'calcite.debug=true' but it just gave me some Java code.
> {code:java}
> val connection = DriverManager.getConnection("jdbc:calcite:") 
> val calciteConnection = connection.asInstanceOf[CalciteConnection] 
> val rootSchema = calciteConnection.getRootSchema() 
> val dsInsightUser = 
> JdbcSchema.dataSource("jdbc:mysql://localhost:13306/insight?useSSL=false&serverTimezone=UTC",
>  "com.mysql.jdbc.Driver", "insight_admin","xxxxxx") 
> val dsPerm = 
> JdbcSchema.dataSource("jdbc:mysql://localhost:13307/permission?useSSL=false&serverTimezone=UTC",
>  "com.mysql.jdbc.Driver", "perm_admin", "xxxxxx") 
> rootSchema.add("insight_user", JdbcSchema.create(rootSchema, "insight_user", 
> dsInsightUser, null, null)) 
> rootSchema.add("perm", JdbcSchema.create(rootSchema, "perm", dsPerm, null, 
> null)) val stmt = connection.createStatement() 
> val rs = stmt.executeQuery("""explain plan for select "perm"."user_table".* 
> from "perm"."user_table" join "insight_user"."user_tab" on 
> "perm"."user_table"."id"="insight_user"."user_tab"."id" """) 
> val metaData = rs.getMetaData() 
> while(rs.next()) { 
>     for(i <- 1 to metaData.getColumnCount) printf("%s ", rs.getObject(i)) 
>     println() 
> }
> {code}
> Tried post the same question on Stackoverflow and mail list but got few 
> replies, so tried here, forgive my taking the liberty.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to