You can set a debug break point in the RelToSqlConverter I think.

Best,
Danny Chan
在 2020年2月11日 +0800 AM3:51,Yang Liu <[email protected]>,写道:
> Hi there, recently I am studying Apache Calcite, by now I can use explain
> plan for via JDBC to view the logical plan, and I am wondering how can I
> view the physical sql in the plan execution? Since there may be bugs in the
> physical sql generation so I need to make sure the correctness.
>
> 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()
> }
>
> result is
>
> EnumerableCalc(expr#0..3=[{inputs}], proj#0..2=[{exprs}])
> EnumerableHashJoin(condition=[=($0, $3)], joinType=[inner])
> JdbcToEnumerableConverter
> JdbcTableScan(table=[[perm, user_table]])
> JdbcToEnumerableConverter
> JdbcProject(id=[$0])
> JdbcTableScan(table=[[insight_user, user_tab]])

Reply via email to