You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/09/23 10:28:35 UTC

[incubator-linkis] branch dev-1.3.1 updated: errorcode code optimization (#3514)

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.3.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.3.1 by this push:
     new 52c67a99f errorcode code optimization (#3514)
52c67a99f is described below

commit 52c67a99f504ba32308f2d071a0c9118532c59bd
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Fri Sep 23 18:28:28 2022 +0800

    errorcode code optimization (#3514)
---
 docs/errorcode/linkis-metadata-errorcode.md        |  9 +++
 .../errorcode/LinkisMetadataErrorCodeSummary.java  | 80 ++++++++++++++++++++++
 .../linkis/metadata/ddl/ImportDDLCreator.scala     | 11 +--
 .../linkis/metadata/ddl/ScalaDDLCreator.scala      |  3 +-
 .../exception/MdqIllegalParamException.scala       |  4 +-
 5 files changed, 100 insertions(+), 7 deletions(-)

diff --git a/docs/errorcode/linkis-metadata-errorcode.md b/docs/errorcode/linkis-metadata-errorcode.md
new file mode 100644
index 000000000..fdf74c99f
--- /dev/null
+++ b/docs/errorcode/linkis-metadata-errorcode.md
@@ -0,0 +1,9 @@
+##  linkis-metadata errorcode
+
+| 模块名(服务名) | 错误码  | 描述 | Exception Class|
+| -------- | -------- | ----- |-----|
+| linkis-metadata|57895| unrecognized import type(无法识别的导入类型)|LinkisMetadataErrorCodeSummary|
+| linkis-metadata|57895|import hive source is null(导入配置单元源为空)|LinkisMetadataErrorCodeSummary|
+| linkis-metadata|57895|Hive create table destination database or tablename is null(Hive 创建表目标数据库或表名为空)|LinkisMetadataErrorCodeSummary|
+| linkis-metadata|57895|hive create table source table name is null(hive 创建表源表名为空)|LinkisMetadataErrorCodeSummary|
+| linkis-metadata|57895|partition name or type is null(分区名称或类型为空)|LinkisMetadataErrorCodeSummary|
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/java/org/apache/linkis/metadata/errorcode/LinkisMetadataErrorCodeSummary.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/java/org/apache/linkis/metadata/errorcode/LinkisMetadataErrorCodeSummary.java
new file mode 100644
index 000000000..305abf66c
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/java/org/apache/linkis/metadata/errorcode/LinkisMetadataErrorCodeSummary.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.errorcode;
+
+public enum LinkisMetadataErrorCodeSummary {
+  UNRECOGNIZED_IMPORT_TYPE(
+      57895, "unrecognized import type(无法识别的导入类型)", "unrecognized import type(无法识别的导入类型)"),
+  IMPORT_HIVE_SOURCE_IS_NULL(
+      57895, "import hive source is null(导入配置单元源为空)", "import hive source is null(导入配置单元源为空)"),
+  HIVE_CREATE_IS_NULL(
+      57895,
+      "Hive create table destination database or tablename is null(Hive 创建表目标数据库或表名为空)",
+      "Hive create table destination database or tablename is null(Hive 创建表目标数据库或表名为空)"),
+  HIVE_CREATE__TABLE_IS_NULL(
+      57895,
+      "hive create table source table name is null(hive 创建表源表名为空)",
+      "hive create table source table name is null(hive 创建表源表名为空)"),
+  PARTITION_IS_NULL(
+      57895,
+      "partition name or type is null(分区名称或类型为空)",
+      "partition name or type is null(分区名称或类型为空)"),
+  EXPRESS_CODE(57895, "", "");
+
+  /** (errorCode)错误码 */
+  private int errorCode;
+  /** (errorDesc)错误描述 */
+  private String errorDesc;
+  /** Possible reasons for the error(错误可能出现的原因) */
+  private String comment;
+
+  LinkisMetadataErrorCodeSummary(int errorCode, String errorDesc, String comment) {
+    this.errorCode = errorCode;
+    this.errorDesc = errorDesc;
+    this.comment = comment;
+  }
+
+  public int getErrorCode() {
+    return errorCode;
+  }
+
+  public void setErrorCode(int errorCode) {
+    this.errorCode = errorCode;
+  }
+
+  public String getErrorDesc() {
+    return errorDesc;
+  }
+
+  public void setErrorDesc(String errorDesc) {
+    this.errorDesc = errorDesc;
+  }
+
+  public String getComment() {
+    return comment;
+  }
+
+  public void setComment(String comment) {
+    this.comment = comment;
+  }
+
+  @Override
+  public String toString() {
+    return "errorCode: " + this.errorCode + ", errorDesc:" + this.errorDesc;
+  }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ImportDDLCreator.scala b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ImportDDLCreator.scala
index 999226940..7e7d464b0 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ImportDDLCreator.scala
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ImportDDLCreator.scala
@@ -22,6 +22,7 @@ import org.apache.linkis.common.io.FsPath
 import org.apache.linkis.common.utils.{Logging, Utils}
 import org.apache.linkis.metadata.conf.MdqConfiguration
 import org.apache.linkis.metadata.domain.mdq.bo.{MdqTableBO, MdqTableFieldsInfoBO}
+import org.apache.linkis.metadata.errorcode.LinkisMetadataErrorCodeSummary._
 import org.apache.linkis.metadata.exception.MdqIllegalParamException
 import org.apache.linkis.storage.FSFactory
 import org.apache.linkis.storage.fs.FileSystem
@@ -74,13 +75,13 @@ object FileImportDDLHelper extends ImportHelper with Logging {
     val args = importInfo.getArgs
     val _source =
       if (StringUtils.isEmpty(importInfo.getSource)) {
-        throw MdqIllegalParamException("import hive source is null")
+        throw MdqIllegalParamException(IMPORT_HIVE_SOURCE_IS_NULL.getErrorDesc)
       } else {
         importInfo.getSource
       }
     val _destination =
       if (StringUtils.isEmpty(importInfo.getDestination)) {
-        throw MdqIllegalParamException("import hive source is null")
+        throw MdqIllegalParamException(IMPORT_HIVE_SOURCE_IS_NULL.getErrorDesc)
       } else {
         importInfo.getDestination
       }
@@ -173,17 +174,17 @@ object HiveImportDDLHelper extends ImportHelper with SQLConst with Logging {
     val destinationTable = mdqTableBO.getTableBaseInfo.getBase.getName
     if (StringUtils.isEmpty(destinationDatabase) || StringUtils.isEmpty(destinationTable)) {
       logger.error("Hive create table destination database or tablename is null")
-      throw MdqIllegalParamException("Hive create table destination database or tablename is null")
+      throw MdqIllegalParamException(HIVE_CREATE_IS_NULL.getErrorDesc)
     }
     val sourceDatabase =
       if (StringUtils.isEmpty(args.get(DATABASE))) {
-        throw MdqIllegalParamException("hive create table source database is null")
+        throw MdqIllegalParamException(HIVE_CREATE__TABLE_IS_NULL.getErrorDesc)
       } else {
         args.get(DATABASE)
       }
     val sourceTableName =
       if (StringUtils.isEmpty(args.get(TABLE))) {
-        throw MdqIllegalParamException("hive create table source table name is null")
+        throw MdqIllegalParamException(HIVE_CREATE__TABLE_IS_NULL.getErrorDesc)
       } else {
         args.get(TABLE)
       }
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ScalaDDLCreator.scala b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ScalaDDLCreator.scala
index 439826482..dd2bda957 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ScalaDDLCreator.scala
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/ddl/ScalaDDLCreator.scala
@@ -20,6 +20,7 @@ package org.apache.linkis.metadata.ddl
 import org.apache.linkis.common.utils.Logging
 import org.apache.linkis.metadata.conf.MdqConfiguration
 import org.apache.linkis.metadata.domain.mdq.bo.{MdqTableBO, MdqTableFieldsInfoBO}
+import org.apache.linkis.metadata.errorcode.LinkisMetadataErrorCodeSummary.PARTITION_IS_NULL
 import org.apache.linkis.metadata.exception.MdqIllegalParamException
 
 import org.apache.commons.lang3.StringUtils
@@ -60,7 +61,7 @@ object ScalaDDLCreator extends DDLCreator with SQLConst with Logging {
         val name = p.getName
         val _type = p.getType
         if (StringUtils.isEmpty(name) || StringUtils.isEmpty(_type)) {
-          throw MdqIllegalParamException("partition name or type is null")
+          throw MdqIllegalParamException(PARTITION_IS_NULL.getErrorDesc)
         }
         partitionArr += (name + SPACE + _type)
       }
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/exception/MdqIllegalParamException.scala b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/exception/MdqIllegalParamException.scala
index 8a1620d41..d22fb7451 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/exception/MdqIllegalParamException.scala
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata/src/main/scala/org/apache/linkis/metadata/exception/MdqIllegalParamException.scala
@@ -18,5 +18,7 @@
 package org.apache.linkis.metadata.exception
 
 import org.apache.linkis.common.exception.ErrorException
+import org.apache.linkis.metadata.errorcode.LinkisMetadataErrorCodeSummary.EXPRESS_CODE
 
-case class MdqIllegalParamException(errMsg: String) extends ErrorException(57895, errMsg)
+case class MdqIllegalParamException(errMsg: String)
+    extends ErrorException(EXPRESS_CODE.getErrorCode, errMsg)


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