You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@linkis.apache.org by "ChengJie1053 (via GitHub)" <gi...@apache.org> on 2023/05/30 09:54:08 UTC

[GitHub] [linkis] ChengJie1053 opened a new pull request, #4589: Generate jdbc sql

ChengJie1053 opened a new pull request, #4589:
URL: https://github.com/apache/linkis/pull/4589

   Generate jdbc sql


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For additional commands, e-mail: notifications-help@linkis.apache.org


[GitHub] [linkis] peacewong merged pull request #4589: Generate jdbc sql

Posted by "peacewong (via GitHub)" <gi...@apache.org>.
peacewong merged PR #4589:
URL: https://github.com/apache/linkis/pull/4589


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For additional commands, e-mail: notifications-help@linkis.apache.org


[GitHub] [linkis] peacewong commented on a diff in pull request #4589: Generate jdbc sql

Posted by "peacewong (via GitHub)" <gi...@apache.org>.
peacewong commented on code in PR #4589:
URL: https://github.com/apache/linkis/pull/4589#discussion_r1211276814


##########
linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/AbstractSqlConnection.java:
##########
@@ -108,6 +116,65 @@ public List<String> getPrimaryKeys(String table) throws SQLException {
     }
   }
 
+  public GenerateSqlInfo queryJdbcSql(String database, String table) {
+    GenerateSqlInfo generateSqlInfo = new GenerateSqlInfo();
+    String ddl = generateJdbcDdlSql(database, table);
+    generateSqlInfo.setDdl(ddl);
+
+    String dml = String.format(SparkDdlSQlTemplate.DML_SQL_TEMPLATE, table);
+    generateSqlInfo.setDml(dml);
+
+    String columnStr = "*";
+    try {
+      List<MetaColumnInfo> columns = getColumns(database, table);
+      if (CollectionUtils.isNotEmpty(columns)) {
+        columnStr =
+            columns.stream().map(column -> column.getName()).collect(Collectors.joining(","));
+      }
+    } catch (Exception e) {
+      LOG.warn("Fail to get Sql columns(获取字段列表失败)");

Review Comment:
   need to print exception



##########
linkis-public-enhancements/linkis-datasource/linkis-metadata-query/server/src/main/java/org/apache/linkis/metadata/query/server/restful/MetadataQueryRestful.java:
##########
@@ -467,6 +467,62 @@ public Message getSparkSql(
     }
   }
 
+  @ApiOperation(value = "getJdbcSql", notes = "get jdbc sql", response = Message.class)
+  @ApiImplicitParams({
+    @ApiImplicitParam(name = "dataSourceName", required = true, dataType = "String"),
+    @ApiImplicitParam(name = "envId", required = false, dataType = "String"),
+    @ApiImplicitParam(name = "system", required = true, dataType = "String"),
+    @ApiImplicitParam(name = "database", required = true, dataType = "String"),
+    @ApiImplicitParam(name = "table", required = true, dataType = "String")
+  })
+  @RequestMapping(value = "/getJdbcSql", method = RequestMethod.GET)
+  public Message getJdbcSql(
+      @RequestParam("dataSourceName") String dataSourceName,
+      @RequestParam(value = "envId", required = false) String envId,
+      @RequestParam("database") String database,
+      @RequestParam("table") String table,
+      @RequestParam("system") String system,
+      HttpServletRequest request) {
+    try {
+      if (StringUtils.isBlank(system)) {
+        return Message.error("'system' is missing[缺少系统名]");
+      }
+      if (!MetadataUtils.nameRegexPattern.matcher(system).matches()) {
+        return Message.error("'system' is invalid[系统名错误]");
+      }
+      if (!MetadataUtils.nameRegexPattern.matcher(database).matches()) {
+        return Message.error("'database' is invalid[数据库名错误]");
+      }
+      if (!MetadataUtils.nameRegexPattern.matcher(table).matches()) {
+        return Message.error("'table' is invalid[表名错误]");
+      }
+      if (!MetadataUtils.nameRegexPattern.matcher(dataSourceName).matches()) {
+        return Message.error("'dataSourceName' is invalid[数据源错误]");
+      }
+
+      String userName =
+          ModuleUserUtils.getOperationUser(request, "getJdbcSql, dataSourceName:" + dataSourceName);
+
+      GenerateSqlInfo sparkSql =
+          metadataQueryService.getJdbcSqlByDsNameAndEnvId(
+              dataSourceName, database, table, system, userName, envId);
+      return Message.ok().data("jdbcSql", sparkSql);
+    } catch (Exception e) {
+      return errorToResponseMessage(

Review Comment:
   need to print log



##########
linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/PostgresqlMetaService.java:
##########
@@ -108,4 +109,13 @@ public List<MetaColumnInfo> queryColumns(
   public String querySqlConnectUrl(SqlConnection connection) {
     return connection.getSqlConnectUrl();
   }
+
+  @Override
+  public GenerateSqlInfo queryJdbcSql(SqlConnection connection, String database, String table) {
+    try {
+      return connection.queryJdbcSql(database, table);
+    } catch (Exception e) {
+      throw new RuntimeException("Fail to get jdbc sql (获取jdbcSql失败)", e);

Review Comment:
   Should to use LinkisRuntimeException



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For additional commands, e-mail: notifications-help@linkis.apache.org


[GitHub] [linkis] ChengJie1053 commented on a diff in pull request #4589: Generate jdbc sql

Posted by "ChengJie1053 (via GitHub)" <gi...@apache.org>.
ChengJie1053 commented on code in PR #4589:
URL: https://github.com/apache/linkis/pull/4589#discussion_r1211295969


##########
linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/PostgresqlMetaService.java:
##########
@@ -108,4 +109,13 @@ public List<MetaColumnInfo> queryColumns(
   public String querySqlConnectUrl(SqlConnection connection) {
     return connection.getSqlConnectUrl();
   }
+
+  @Override
+  public GenerateSqlInfo queryJdbcSql(SqlConnection connection, String database, String table) {
+    try {
+      return connection.queryJdbcSql(database, table);
+    } catch (Exception e) {
+      throw new RuntimeException("Fail to get jdbc sql (获取jdbcSql失败)", e);

Review Comment:
   Ok, thank you for reviewing the code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For additional commands, e-mail: notifications-help@linkis.apache.org