Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hive module errorcode optimization and documentation #3482

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/errorcode/linkis-engineplugin-hive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## linkis-engineplugin-hive errorcode


| 模块名(服务名) | 错误码 | 描述 | module |
|--------------------------|-------| ---- |--------------|
| linkis-engineplugin-hive | 26040 |failed to create hive executor(创建hive执行器失败)| hiveEngine |
| linkis-engineplugin-hive | 26041 |cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)| hiveEngine |
| linkis-engineplugin-hive | 26042 |cannot get the field schemas(无法获取字段模式)| hiveEngine |
| linkis-engineplugin-hive | 26043 |invalid value(无效值)| hiveEngine |

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.engineplugin.hive.errorcode;

import org.apache.linkis.common.errorcode.ErrorCodeUtils;

public enum HiveErrorCodeSummary {
/**
* 10000-10999 linkis-frame 11000-12999 linkis-commons 13000-14999 linkis-spring-cloud-services
* 15000-19999 linkis-public-enhancements 20000-24999 linkis-computation-governance 25000-25999
* linkis-extensions 26000-29999 linkis-engineconn-plugins
*/
CREATE_HIVE_EXECUTOR_ERROR(
26040,
"failed to create hive executor(创建hive执行器失败)",
"failed to create hive executor(创建hive执行器失败)",
"hiveEngine"),
HIVE_EXEC_JAR_ERROR(
26041,
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)",
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)",
"hiveEngine"),
GET_FIELD_SCHEMAS_ERROR(
26042,
"cannot get the field schemas(无法获取字段模式)",
"cannot get the field schemas(无法获取字段模式)",
"hiveEngine"),
INVALID_VALUE(26043, "invalid value(无效值)", "invalid value(无效值)", "hiveEngine");

private int errorCode;

private String errorDesc;

private String comment;

private String module;

HiveErrorCodeSummary(int errorCode, String errorDesc, String comment, String module) {
ErrorCodeUtils.validateErrorCode(errorCode, 26000, 29999);
this.errorCode = errorCode;
this.errorDesc = errorDesc;
this.comment = comment;
this.module = module;
}

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;
}

public String getModule() {
return module;
}

public void setModule(String module) {
this.module = module;
}

@Override
public String toString() {
return "errorCode: " + this.errorCode + ", errorDesc:" + this.errorDesc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.apache.linkis.engineconn.executor.entity.LabelExecutor
import org.apache.linkis.engineplugin.hive.common.HiveUtils
import org.apache.linkis.engineplugin.hive.conf.HiveEngineConfiguration
import org.apache.linkis.engineplugin.hive.entity.HiveSession
import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.CREATE_HIVE_EXECUTOR_ERROR
import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.HIVE_EXEC_JAR_ERROR
import org.apache.linkis.engineplugin.hive.exception.HiveSessionStartFailedException
import org.apache.linkis.engineplugin.hive.executor.HiveEngineConnExecutor
import org.apache.linkis.hadoop.common.utils.HDFSUtils
Expand Down Expand Up @@ -62,7 +64,10 @@ class HiveEngineConnFactory extends ComputationSingleExecutorEngineConnFactory w
hiveSession.baos
)
case _ =>
throw HiveSessionStartFailedException(40012, "Failed to create hive executor")
throw HiveSessionStartFailedException(
CREATE_HIVE_EXECUTOR_ERROR.getErrorCode,
CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc
)
}
}

Expand All @@ -77,8 +82,8 @@ class HiveEngineConnFactory extends ComputationSingleExecutorEngineConnFactory w
.jarOfClass(classOf[Driver])
.getOrElse(
throw HiveSessionStartFailedException(
40012,
"cannot find hive-exec.jar, start session failed!"
HIVE_EXEC_JAR_ERROR.getErrorCode,
HIVE_EXEC_JAR_ERROR.getErrorDesc
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,8 @@ package org.apache.linkis.engineplugin.hive.exception

import org.apache.linkis.common.exception.ErrorException

case class NotSupportedHiveTypeException(errCode: Int, desc: String)
extends ErrorException(errCode, desc) {}

case class HadoopConfSetFailedException(errCode: Int, desc: String)
extends ErrorException(errCode, desc) {}

case class HiveSessionStartFailedException(erroCode: Int, desc: String)
extends ErrorException(erroCode, desc) {}
extends ErrorException(erroCode, desc)

/**
* @param erroCode
* 41004
* @param desc
* hive query fail
*/
case class HiveQueryFailedException(erroCode: Int, desc: String)
extends ErrorException(erroCode, desc) {}
extends ErrorException(erroCode, desc)
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.apache.linkis.engineconn.core.EngineConnObject
import org.apache.linkis.engineconn.executor.entity.ResourceFetchExecutor
import org.apache.linkis.engineplugin.hive.conf.{Counters, HiveEngineConfiguration}
import org.apache.linkis.engineplugin.hive.cs.CSHiveHelper
import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.GET_FIELD_SCHEMAS_ERROR
import org.apache.linkis.engineplugin.hive.exception.HiveQueryFailedException
import org.apache.linkis.engineplugin.hive.progress.HiveProgressHelper
import org.apache.linkis.governance.common.paser.SQLCodeParser
Expand Down Expand Up @@ -234,7 +235,11 @@ class HiveEngineConnExecutor(
val fieldSchemas =
if (hiveResponse.getSchema != null) hiveResponse.getSchema.getFieldSchemas
else if (driver.getSchema != null) driver.getSchema.getFieldSchemas
else throw HiveQueryFailedException(41005, "cannot get the field schemas.")
else
throw HiveQueryFailedException(
GET_FIELD_SCHEMAS_ERROR.getErrorCode,
GET_FIELD_SCHEMAS_ERROR.getErrorDesc
)

LOG.debug("fieldSchemas are " + fieldSchemas)
if (fieldSchemas == null || isNoResultSql(realCode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.apache.linkis.common.utils.{Logging, Utils}
import org.apache.linkis.engineconn.common.creation.EngineCreationContext
import org.apache.linkis.engineconn.computation.executor.execute.EngineExecutionContext
import org.apache.linkis.engineconn.computation.executor.hook.ComputationExecutorHook
import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.INVALID_VALUE
import org.apache.linkis.engineplugin.hive.exception.HiveQueryFailedException

import org.apache.commons.lang3.StringUtils
Expand Down Expand Up @@ -78,8 +79,8 @@ class HiveAddMetaTableNameHook extends ComputationExecutorHook with Logging {
engineExecutionContext.setEnableResultsetMetaWithTableName(boolValue)
} { case e: IllegalArgumentException =>
throw HiveQueryFailedException(
41006,
s"Invalid value : ${value} in param [${mather.group()}]"
INVALID_VALUE.getErrorCode,
INVALID_VALUE.getErrorDesc.concat(s" : ${value} in param [${mather.group()}]")
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* 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.common.errorcode;

import org.junit.jupiter.api.Test;

import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.CREATE_HIVE_EXECUTOR_ERROR;
import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.GET_FIELD_SCHEMAS_ERROR;
import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.HIVE_EXEC_JAR_ERROR;
import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.INVALID_VALUE;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class HiveErrorCodeSummaryTest {
@Test
void testGetErrorCode() {
assertEquals(26040, CREATE_HIVE_EXECUTOR_ERROR.getErrorCode());
assertEquals(26041, HIVE_EXEC_JAR_ERROR.getErrorCode());
assertEquals(26042, GET_FIELD_SCHEMAS_ERROR.getErrorCode());
assertEquals(26043, INVALID_VALUE.getErrorCode());
}

@Test
void testSetErrorCode() {
CREATE_HIVE_EXECUTOR_ERROR.setErrorCode(1);
assertEquals(1, CREATE_HIVE_EXECUTOR_ERROR.getErrorCode());
CREATE_HIVE_EXECUTOR_ERROR.setErrorCode(26040);
assertEquals(26040, CREATE_HIVE_EXECUTOR_ERROR.getErrorCode());

HIVE_EXEC_JAR_ERROR.setErrorCode(1);
assertEquals(1, HIVE_EXEC_JAR_ERROR.getErrorCode());
HIVE_EXEC_JAR_ERROR.setErrorCode(26041);
assertEquals(26041, HIVE_EXEC_JAR_ERROR.getErrorCode());

GET_FIELD_SCHEMAS_ERROR.setErrorCode(1);
assertEquals(1, GET_FIELD_SCHEMAS_ERROR.getErrorCode());
GET_FIELD_SCHEMAS_ERROR.setErrorCode(26042);
assertEquals(26042, GET_FIELD_SCHEMAS_ERROR.getErrorCode());

INVALID_VALUE.setErrorCode(1);
assertEquals(1, INVALID_VALUE.getErrorCode());
INVALID_VALUE.setErrorCode(26043);
assertEquals(26043, INVALID_VALUE.getErrorCode());
}

@Test
void testGetErrorDesc() {
assertEquals(
"failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc());
assertEquals(
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)",
HIVE_EXEC_JAR_ERROR.getErrorDesc());
assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getErrorDesc());
assertEquals("invalid value(无效值)", INVALID_VALUE.getErrorDesc());
}

@Test
void testSetErrorDesc() {
CREATE_HIVE_EXECUTOR_ERROR.setErrorDesc("test");
assertEquals("test", CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc());
CREATE_HIVE_EXECUTOR_ERROR.setErrorDesc("failed to create hive executor(创建hive执行器失败)");
assertEquals(
"failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc());

HIVE_EXEC_JAR_ERROR.setErrorDesc("test");
assertEquals("test", HIVE_EXEC_JAR_ERROR.getErrorDesc());
HIVE_EXEC_JAR_ERROR.setErrorDesc(
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)");
assertEquals(
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)",
HIVE_EXEC_JAR_ERROR.getErrorDesc());

GET_FIELD_SCHEMAS_ERROR.setErrorDesc("test");
assertEquals("test", GET_FIELD_SCHEMAS_ERROR.getErrorDesc());
GET_FIELD_SCHEMAS_ERROR.setErrorDesc("cannot get the field schemas(无法获取字段模式)");
assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getErrorDesc());

INVALID_VALUE.setErrorDesc("test");
assertEquals("test", INVALID_VALUE.getErrorDesc());
INVALID_VALUE.setErrorDesc("invalid value(无效值)");
assertEquals("invalid value(无效值)", INVALID_VALUE.getErrorDesc());
}

@Test
void testGetComment() {
assertEquals(
"failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getComment());
assertEquals(
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)",
HIVE_EXEC_JAR_ERROR.getComment());
assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getComment());
assertEquals("invalid value(无效值)", INVALID_VALUE.getComment());
}

@Test
void testSetComment() {
CREATE_HIVE_EXECUTOR_ERROR.setComment("test");
assertEquals("test", CREATE_HIVE_EXECUTOR_ERROR.getComment());
CREATE_HIVE_EXECUTOR_ERROR.setComment("failed to create hive executor(创建hive执行器失败)");
assertEquals(
"failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getComment());

HIVE_EXEC_JAR_ERROR.setComment("test");
assertEquals("test", HIVE_EXEC_JAR_ERROR.getComment());
HIVE_EXEC_JAR_ERROR.setComment(
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)");
assertEquals(
"cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)",
HIVE_EXEC_JAR_ERROR.getComment());

GET_FIELD_SCHEMAS_ERROR.setComment("test");
assertEquals("test", GET_FIELD_SCHEMAS_ERROR.getComment());
GET_FIELD_SCHEMAS_ERROR.setComment("cannot get the field schemas(无法获取字段模式)");
assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getComment());

INVALID_VALUE.setComment("test");
assertEquals("test", INVALID_VALUE.getComment());
INVALID_VALUE.setComment("invalid value(无效值)");
assertEquals("invalid value(无效值)", INVALID_VALUE.getComment());
}

@Test
void testGetModule() {
assertEquals("hiveEngine", CREATE_HIVE_EXECUTOR_ERROR.getModule());
assertEquals("hiveEngine", HIVE_EXEC_JAR_ERROR.getModule());
assertEquals("hiveEngine", GET_FIELD_SCHEMAS_ERROR.getModule());
assertEquals("hiveEngine", INVALID_VALUE.getModule());
}

@Test
void testSetModule() {
CREATE_HIVE_EXECUTOR_ERROR.setModule("test");
assertEquals("test", CREATE_HIVE_EXECUTOR_ERROR.getModule());
CREATE_HIVE_EXECUTOR_ERROR.setModule("hiveEngine");
assertEquals("hiveEngine", CREATE_HIVE_EXECUTOR_ERROR.getModule());

HIVE_EXEC_JAR_ERROR.setModule("test");
assertEquals("test", HIVE_EXEC_JAR_ERROR.getModule());
HIVE_EXEC_JAR_ERROR.setModule("hiveEngine");
assertEquals("hiveEngine", HIVE_EXEC_JAR_ERROR.getModule());

GET_FIELD_SCHEMAS_ERROR.setModule("test");
assertEquals("test", GET_FIELD_SCHEMAS_ERROR.getModule());
GET_FIELD_SCHEMAS_ERROR.setModule("hiveEngine");
assertEquals("hiveEngine", GET_FIELD_SCHEMAS_ERROR.getModule());

INVALID_VALUE.setModule("test");
assertEquals("test", INVALID_VALUE.getModule());
INVALID_VALUE.setModule("hiveEngine");
assertEquals("hiveEngine", INVALID_VALUE.getModule());
}
}