From 4c633494ba8ed8333e33cd89ba15b4a3d986f084 Mon Sep 17 00:00:00 2001 From: "Morning.Chen" Date: Thu, 20 Oct 2022 16:31:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E4=BA=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=A1=A8=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=87=E6=A1=A3=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../server/DatasourceOperation.java | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0b149ab..c3ba256 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ String tableId = operation.createTable("HelloTable", "#分组Id(可选)"); **特别注意:csv文件需要使用utf-8编码,其他编码均无法正确解析** -**注意:** 当前暂时不支持追加数据,仅支持全部替换数据。 +**注意:** 当前默认为全量覆盖表数据,如需切换到增量更新,参考接口/api/v1/datasource/table/modify。 ```java Authentication authentication = new Authentication("#key", "#secret"); diff --git a/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java b/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java index 77a8d60..a48ae3a 100644 --- a/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java +++ b/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java @@ -134,18 +134,36 @@ public class DatasourceOperation { return data.getString("data"); } + /** + * 在指定的分组下创建 一个增量更新的数据源表 + * @param tableName 数据源表名 + * @param groupId 分组Id + * @return 数据源表Id + * @throws Exception 操作失败则抛出此异常 + */ + public String createTableIncreased(String tableName, String groupId) throws Exception { + JSONObject body = new JSONObject(); + body.put("tableName", tableName); + body.put("groupId", groupId); + body.put("increase", true); + HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); + String res = HttpKits.post(String.format("%s/api/v1/datasource/table/create", ProjectConstants.BASE_URI), headers(), entity); + JSONObject data = new JSONObject(res); + return data.getString("data"); + } + /** * 修改已有的数据源表的名字 * @param tableId 数据源表Id * @param newTableName 新的数据源表名字 - * @param replaceOldData 是否后续的数据是替换原数据的,true表示替换原数据,false表示在原数据之后追加 + * @param replaceOldData 是否后续的数据是替换原数据的,true表示在原数据之后追加,false表示替换原数据 * @throws Exception 操作失败则抛出此异常 */ public void modifyTable(String tableId, String newTableName, boolean replaceOldData) throws Exception { JSONObject body = new JSONObject(); body.put("tableId", tableId); body.put("tableName", newTableName); - body.put("increase", !replaceOldData); + body.put("increase", replaceOldData); HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); HttpKits.post(String.format("%s/api/v1/datasource/table/modify", ProjectConstants.BASE_URI), headers(), entity); } @@ -160,7 +178,7 @@ public class DatasourceOperation { JSONObject body = new JSONObject(); body.put("tableId", tableId); HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); - String res = HttpKits.post(String.format("%s/api/v1/datasource/upload/url", ProjectConstants.BASE_URI), headers(), entity); + String res = HttpKits.post(String.format("%s/api/v1/datasource/table/upload/url", ProjectConstants.BASE_URI), headers(), entity); JSONObject data = new JSONObject(res); return data.getString("data"); }