|
@@ -25,7 +25,7 @@ import java.util.concurrent.Executors;
|
|
|
|
|
|
public class JsonToCalciteExample {
|
|
|
|
|
|
- public static void main(String[] args) throws Exception {
|
|
|
+ public static SchemaPlus jsonTotable(String aa) throws Exception {
|
|
|
// 1. JSON 数据
|
|
|
String jsonData = """
|
|
|
{
|
|
@@ -42,7 +42,7 @@ public class JsonToCalciteExample {
|
|
|
|
|
|
// 2. 使用 Jackson 解析 JSON 数据
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- JsonNode rootNode = objectMapper.readTree(jsonData);
|
|
|
+ JsonNode rootNode = objectMapper.readTree(aa);
|
|
|
|
|
|
// 3. 创建 Calcite Schema
|
|
|
Connection connection = DriverManager.getConnection("jdbc:calcite:");
|
|
@@ -61,10 +61,8 @@ public class JsonToCalciteExample {
|
|
|
// 4. 执行 SQL 查询
|
|
|
Statement statement = connection.createStatement();
|
|
|
String sql = """
|
|
|
- SELECT "orders"."order_id", "orders"."amount", "users"."name"
|
|
|
- FROM "orders"
|
|
|
- JOIN "users"
|
|
|
- ON "orders"."user_id" = "users"."user_id"
|
|
|
+ SELECT "input"."method"
|
|
|
+ FROM "input"
|
|
|
""";
|
|
|
|
|
|
ResultSet resultSet = statement.executeQuery(sql);
|
|
@@ -72,10 +70,12 @@ public class JsonToCalciteExample {
|
|
|
// 打印查询结果
|
|
|
System.out.println("Query Results:");
|
|
|
while (resultSet.next()) {
|
|
|
- System.out.printf("Order ID: %d, Amount: %.2f, Name: %s%n",
|
|
|
- resultSet.getInt("order_id"),
|
|
|
+ /*System.out.printf("Order ID: %d, Amount: %.2f, Name: %s%n",
|
|
|
+ resultSet.getInt("user_id"),
|
|
|
resultSet.getDouble("amount"),
|
|
|
- resultSet.getString("name"));
|
|
|
+ resultSet.getString("name"))*/;
|
|
|
+ System.out.println(resultSet.getString("method"));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 关闭连接
|
|
@@ -87,6 +87,7 @@ public class JsonToCalciteExample {
|
|
|
executor.execute(()-> System.out.println("ExecutorService is runing..."));
|
|
|
//保存至数据库
|
|
|
executor.shutdown();//关闭线程池
|
|
|
+ return rootSchema;
|
|
|
}
|
|
|
|
|
|
// 自定义表类实现
|