|
@@ -17,13 +17,11 @@ import org.apache.calcite.util.Sources;
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
-import java.sql.ResultSet;
|
|
|
-import java.sql.Statement;
|
|
|
import java.util.*;
|
|
|
|
|
|
public class JsonToCalciteExample {
|
|
|
|
|
|
- public static SchemaPlus jsonTotable(String schemaName, String jsonDate) {
|
|
|
+ public void jsonTotable(String schemaName, String jsonDate) {
|
|
|
// 1. JSON 数据
|
|
|
|
|
|
try{
|
|
@@ -46,7 +44,7 @@ public class JsonToCalciteExample {
|
|
|
schema.add(tableName, new JsonScannableTable(Sources.of(tableData.toString())));
|
|
|
});
|
|
|
// 4. 执行 SQL 查询
|
|
|
- Statement statement = connection.createStatement();
|
|
|
+ /*Statement statement = connection.createStatement();
|
|
|
String sql = """
|
|
|
SELECT "test"."input"."method" FROM "test"."input"
|
|
|
""";
|
|
@@ -55,7 +53,7 @@ public class JsonToCalciteExample {
|
|
|
while (resultSet.next()){
|
|
|
String method=resultSet.getString("method");
|
|
|
System.out.println(method);
|
|
|
- }
|
|
|
+ }*/
|
|
|
// 打印查询结果
|
|
|
/*while (resultSet.next()) {
|
|
|
System.out.printf("Order ID: %d, Amount: %.2f, Name: %s%n",
|
|
@@ -66,10 +64,26 @@ public class JsonToCalciteExample {
|
|
|
}*/
|
|
|
|
|
|
// 关闭连接
|
|
|
- resultSet.close();
|
|
|
- statement.close();
|
|
|
+ /*resultSet.close();
|
|
|
+ statement.close();*/
|
|
|
+ //获取域
|
|
|
+ SchemaPlus rootSchemafter = calciteConnection.getRootSchema();
|
|
|
+ //根域中获取子域
|
|
|
+ SchemaPlus childrenSchema=rootSchemafter.getSubSchema("test");
|
|
|
+ //子域名
|
|
|
+ String childrenName = childrenSchema.getName();
|
|
|
+ System.out.println("childrenName: " + childrenName);
|
|
|
+ //子域中表名
|
|
|
+ Set<String> tableNames = childrenSchema.getTableNames();
|
|
|
+ for (String tableName : tableNames) {
|
|
|
+ System.out.println("Table: " + tableName);
|
|
|
+ }
|
|
|
+
|
|
|
+ //调用张艳杰接收连接方法,传参 calciteConnection
|
|
|
+ //方法示例
|
|
|
+ //userConnection(calciteConnection)
|
|
|
+
|
|
|
connection.close();
|
|
|
- return rootSchema;
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|