This is an automated email from the ASF dual-hosted git repository.
gaojun2048 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new 12c0fb91d [Improve][Connector-V2][Hive] Unified exceptions for hive
source & sink connector (#3541)
12c0fb91d is described below
commit 12c0fb91d2f195e07abeab48a9e408659d46e485
Author: Tyrantlucifer <[email protected]>
AuthorDate: Thu Nov 24 16:20:37 2022 +0800
[Improve][Connector-V2][Hive] Unified exceptions for hive source & sink
connector (#3541)
---
.../connector-v2/Error-Quick-Reference-Manual.md | 9 +++++
.../hive/exception/HiveConnectorErrorCode.java | 44 ++++++++++++++++++++++
.../hive/exception/HiveConnectorException.java | 35 +++++++++++++++++
.../connectors/seatunnel/hive/sink/HiveSink.java | 15 ++++++--
.../seatunnel/hive/source/HiveSource.java | 15 ++++++--
.../seatunnel/hive/utils/HiveMetaStoreProxy.java | 7 +++-
6 files changed, 117 insertions(+), 8 deletions(-)
diff --git a/docs/en/connector-v2/Error-Quick-Reference-Manual.md
b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
index 99d7027c3..f5aac0371 100644
--- a/docs/en/connector-v2/Error-Quick-Reference-Manual.md
+++ b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
@@ -75,3 +75,12 @@ This document records some common error codes and
corresponding solutions of Sea
| SOCKET-01 | Cannot connect to socket server | When
the user encounters this error code, it means that the connection address may
not match, please check |
| SOCKET-02 | Failed to send message to socket server | When
the user encounters this error code, it means that there is a problem sending
data and retry is not enabled, please check |
| SOCKET-03 | Unable to write; interrupted while doing another attempt | When
the user encounters this error code, it means that the data writing is
interrupted abnormally, please check |
+
+
+## Hive Connector Error Codes
+
+| code | description |
solution
|
+|---------|---------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
+| HIVE-01 | Get name node host from table location failed |
When users encounter this error code, it means that the metastore inforamtion
has some problems, please check it |
+| HIVE-02 | Initialize hive metastore client failed |
When users encounter this error code, it means that connect to hive metastore
service failed, please check it whether is work |
+| HIVE-03 | Get hive table information from hive metastore service failed |
When users encounter this error code, it means that hive metastore service has
some problems, please check it whether is work |
diff --git
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/exception/HiveConnectorErrorCode.java
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/exception/HiveConnectorErrorCode.java
new file mode 100644
index 000000000..e4d68a75f
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/exception/HiveConnectorErrorCode.java
@@ -0,0 +1,44 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.hive.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+
+public enum HiveConnectorErrorCode implements SeaTunnelErrorCode {
+ GET_HDFS_NAMENODE_HOST_FAILED("HIVE-01", "Get name node host from table
location failed"),
+ INITIALIZE_HIVE_METASTORE_CLIENT_FAILED("HIVE-02", "Initialize hive
metastore client failed"),
+ GET_HIVE_TABLE_INFORMATION_FAILED("HIVE-03", "Get hive table information
from hive metastore service failed");
+
+ private final String code;
+ private final String description;
+
+ HiveConnectorErrorCode(String code, String description) {
+ this.code = code;
+ this.description = description;
+ }
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+}
diff --git
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/exception/HiveConnectorException.java
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/exception/HiveConnectorException.java
new file mode 100644
index 000000000..af8fcf19b
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/exception/HiveConnectorException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.hive.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class HiveConnectorException extends SeaTunnelRuntimeException {
+ public HiveConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
String errorMessage) {
+ super(seaTunnelErrorCode, errorMessage);
+ }
+
+ public HiveConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
String errorMessage, Throwable cause) {
+ super(seaTunnelErrorCode, errorMessage, cause);
+ }
+
+ public HiveConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
Throwable cause) {
+ super(seaTunnelErrorCode, cause);
+ }
+}
diff --git
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/sink/HiveSink.java
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/sink/HiveSink.java
index 080a1b49e..ac94e56e9 100644
---
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/sink/HiveSink.java
+++
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/sink/HiveSink.java
@@ -30,11 +30,13 @@ import static
org.apache.seatunnel.connectors.seatunnel.hive.config.HiveConfig.P
import static
org.apache.seatunnel.connectors.seatunnel.hive.config.HiveConfig.TEXT_OUTPUT_FORMAT_CLASSNAME;
import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
import org.apache.seatunnel.api.sink.SeaTunnelSink;
import org.apache.seatunnel.api.sink.SinkAggregatedCommitter;
import org.apache.seatunnel.common.config.CheckConfigUtil;
import org.apache.seatunnel.common.config.CheckResult;
import org.apache.seatunnel.common.constants.PluginType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.connectors.seatunnel.file.config.FileFormat;
import org.apache.seatunnel.connectors.seatunnel.file.config.HadoopConf;
import
org.apache.seatunnel.connectors.seatunnel.file.hdfs.sink.BaseHdfsFileSink;
@@ -42,6 +44,8 @@ import
org.apache.seatunnel.connectors.seatunnel.file.sink.commit.FileAggregated
import
org.apache.seatunnel.connectors.seatunnel.file.sink.commit.FileCommitInfo;
import
org.apache.seatunnel.connectors.seatunnel.hive.commit.HiveSinkAggregatedCommitter;
import org.apache.seatunnel.connectors.seatunnel.hive.config.HiveConfig;
+import
org.apache.seatunnel.connectors.seatunnel.hive.exception.HiveConnectorErrorCode;
+import
org.apache.seatunnel.connectors.seatunnel.hive.exception.HiveConnectorException;
import org.apache.seatunnel.shade.com.typesafe.config.Config;
import org.apache.seatunnel.shade.com.typesafe.config.ConfigValueFactory;
@@ -75,7 +79,9 @@ public class HiveSink extends BaseHdfsFileSink {
CheckResult result = CheckConfigUtil.checkAllExists(pluginConfig,
HiveConfig.METASTORE_URI.key(),
HiveConfig.TABLE_NAME.key());
if (!result.isSuccess()) {
- throw new PrepareFailException(getPluginName(), PluginType.SINK,
result.getMsg());
+ throw new
HiveConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+ String.format("PluginName: %s, PluginType: %s, Message:
%s",
+ getPluginName(), PluginType.SINK,
result.getMsg()));
}
Pair<String[], Table> tableInfo =
HiveConfig.getTableInfo(pluginConfig);
dbName = tableInfo.getLeft()[0];
@@ -99,7 +105,8 @@ public class HiveSink extends BaseHdfsFileSink {
} else if (ORC_OUTPUT_FORMAT_CLASSNAME.equals(outputFormat)) {
pluginConfig = pluginConfig.withValue(FILE_FORMAT.key(),
ConfigValueFactory.fromAnyRef(FileFormat.ORC.toString()));
} else {
- throw new RuntimeException("Only support [text parquet orc] file
now");
+ throw new HiveConnectorException(CommonErrorCode.ILLEGAL_ARGUMENT,
+ "Hive connector only support [text parquet orc] table
now");
}
pluginConfig = pluginConfig
.withValue(IS_PARTITION_FIELD_WRITE_IN_FILE.key(),
ConfigValueFactory.fromAnyRef(false))
@@ -114,7 +121,9 @@ public class HiveSink extends BaseHdfsFileSink {
pluginConfig = pluginConfig.withValue(FILE_PATH.key(),
ConfigValueFactory.fromAnyRef(path));
hadoopConf = new HadoopConf(hdfsLocation.replace(path, ""));
} catch (URISyntaxException e) {
- throw new RuntimeException("Get hdfs cluster address failed,
please check.", e);
+ String errorMsg = String.format("Get hdfs namenode host from table
location [%s] failed," +
+ "please check it", hdfsLocation);
+ throw new
HiveConnectorException(HiveConnectorErrorCode.GET_HDFS_NAMENODE_HOST_FAILED,
errorMsg, e);
}
this.pluginConfig = pluginConfig;
}
diff --git
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/source/HiveSource.java
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/source/HiveSource.java
index b0091bb29..ab6090bb9 100644
---
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/source/HiveSource.java
+++
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/source/HiveSource.java
@@ -23,14 +23,18 @@ import static
org.apache.seatunnel.connectors.seatunnel.hive.config.HiveConfig.T
import static
org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY;
import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
import org.apache.seatunnel.api.source.SeaTunnelSource;
import org.apache.seatunnel.common.config.CheckConfigUtil;
import org.apache.seatunnel.common.config.CheckResult;
import org.apache.seatunnel.common.constants.PluginType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.connectors.seatunnel.file.config.BaseSourceConfig;
import org.apache.seatunnel.connectors.seatunnel.file.config.FileFormat;
import
org.apache.seatunnel.connectors.seatunnel.file.hdfs.source.BaseHdfsFileSource;
import org.apache.seatunnel.connectors.seatunnel.hive.config.HiveConfig;
+import
org.apache.seatunnel.connectors.seatunnel.hive.exception.HiveConnectorErrorCode;
+import
org.apache.seatunnel.connectors.seatunnel.hive.exception.HiveConnectorException;
import org.apache.seatunnel.shade.com.typesafe.config.Config;
import org.apache.seatunnel.shade.com.typesafe.config.ConfigValueFactory;
@@ -56,7 +60,9 @@ public class HiveSource extends BaseHdfsFileSource {
CheckResult result = CheckConfigUtil.checkAllExists(pluginConfig,
HiveConfig.METASTORE_URI.key(),
HiveConfig.TABLE_NAME.key());
if (!result.isSuccess()) {
- throw new PrepareFailException(getPluginName(), PluginType.SOURCE,
result.getMsg());
+ throw new
HiveConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+ String.format("PluginName: %s, PluginType: %s, Message:
%s",
+ getPluginName(), PluginType.SOURCE,
result.getMsg()));
}
Pair<String[], Table> tableInfo =
HiveConfig.getTableInfo(pluginConfig);
tableInformation = tableInfo.getRight();
@@ -71,7 +77,8 @@ public class HiveSource extends BaseHdfsFileSource {
pluginConfig =
pluginConfig.withValue(BaseSourceConfig.FILE_TYPE.key(),
ConfigValueFactory.fromAnyRef(FileFormat.ORC.toString()));
} else {
- throw new RuntimeException("Only support [text parquet orc] file
now");
+ throw new HiveConnectorException(CommonErrorCode.ILLEGAL_ARGUMENT,
+ "Hive connector only support [text parquet orc] table
now");
}
String hdfsLocation = tableInformation.getSd().getLocation();
try {
@@ -81,7 +88,9 @@ public class HiveSource extends BaseHdfsFileSource {
pluginConfig =
pluginConfig.withValue(BaseSourceConfig.FILE_PATH.key(),
ConfigValueFactory.fromAnyRef(path))
.withValue(FS_DEFAULT_NAME_KEY,
ConfigValueFactory.fromAnyRef(defaultFs));
} catch (URISyntaxException e) {
- throw new RuntimeException("Get hdfs cluster address failed,
please check.", e);
+ String errorMsg = String.format("Get hdfs namenode host from table
location [%s] failed," +
+ "please check it", hdfsLocation);
+ throw new
HiveConnectorException(HiveConnectorErrorCode.GET_HDFS_NAMENODE_HOST_FAILED,
errorMsg, e);
}
super.prepare(pluginConfig);
}
diff --git
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxy.java
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxy.java
index ee08e305e..0d8194488 100644
---
a/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxy.java
+++
b/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxy.java
@@ -18,6 +18,8 @@
package org.apache.seatunnel.connectors.seatunnel.hive.utils;
import org.apache.seatunnel.connectors.seatunnel.hive.config.HiveConfig;
+import
org.apache.seatunnel.connectors.seatunnel.hive.exception.HiveConnectorErrorCode;
+import
org.apache.seatunnel.connectors.seatunnel.hive.exception.HiveConnectorException;
import org.apache.seatunnel.shade.com.typesafe.config.Config;
@@ -41,7 +43,8 @@ public class HiveMetaStoreProxy {
try {
hiveMetaStoreClient = new HiveMetaStoreClient(hiveConf);
} catch (MetaException e) {
- throw new RuntimeException(e);
+ String errorMsg = String.format("Using this hive uris [%s] to
initialize hive metastore client instance failed", uris);
+ throw new
HiveConnectorException(HiveConnectorErrorCode.INITIALIZE_HIVE_METASTORE_CLIENT_FAILED,
errorMsg, e);
}
}
@@ -62,7 +65,7 @@ public class HiveMetaStoreProxy {
return hiveMetaStoreClient.getTable(dbName, tableName);
} catch (TException e) {
String errorMsg = String.format("Get table [%s.%s] information
failed", dbName, tableName);
- throw new RuntimeException(errorMsg, e);
+ throw new
HiveConnectorException(HiveConnectorErrorCode.GET_HIVE_TABLE_INFORMATION_FAILED,
errorMsg, e);
}
}