Skip to content

Commit

Permalink
remove CommonErrorCodeDeprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochen-zhou committed May 9, 2024
1 parent 0e91978 commit 8036acb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
import static org.apache.seatunnel.common.exception.CommonErrorCode.GET_CATALOG_TABLE_WITH_UNSUPPORTED_TYPE_ERROR;
import static org.apache.seatunnel.common.exception.CommonErrorCode.JSON_OPERATION_FAILED;
import static org.apache.seatunnel.common.exception.CommonErrorCode.SQL_TEMPLATE_HANDLED_ERROR;
import static org.apache.seatunnel.common.exception.CommonErrorCode.UNSUPPORTED_ARRAY_GENERIC_TYPE;
import static org.apache.seatunnel.common.exception.CommonErrorCode.UNSUPPORTED_DATA_TYPE;
import static org.apache.seatunnel.common.exception.CommonErrorCode.UNSUPPORTED_DATA_TYPE_SIMPLE;
import static org.apache.seatunnel.common.exception.CommonErrorCode.UNSUPPORTED_ENCODING;
import static org.apache.seatunnel.common.exception.CommonErrorCode.UNSUPPORTED_ROW_KIND;
import static org.apache.seatunnel.common.exception.CommonErrorCode.WRITE_SEATUNNEL_ROW_ERROR;

/**
Expand Down Expand Up @@ -87,6 +90,14 @@ public static SeaTunnelRuntimeException writeSeaTunnelRowFailed(
return new SeaTunnelRuntimeException(WRITE_SEATUNNEL_ROW_ERROR, params, cause);
}

public static SeaTunnelRuntimeException unsupportedDataType(
String identifier, String dataType) {
Map<String, String> params = new HashMap<>();
params.put("identifier", identifier);
params.put("dataType", dataType);
return new SeaTunnelRuntimeException(UNSUPPORTED_DATA_TYPE_SIMPLE, params);
}

public static SeaTunnelRuntimeException unsupportedDataType(
String identifier, String dataType, String field) {
Map<String, String> params = new HashMap<>();
Expand Down Expand Up @@ -199,4 +210,19 @@ public static SeaTunnelRuntimeException sqlTemplateHandledError(
params.put("optionName", optionName);
return new SeaTunnelRuntimeException(SQL_TEMPLATE_HANDLED_ERROR, params);
}

public static SeaTunnelRuntimeException unsupportedArrayGenericType(
String identifier, String dataType) {
Map<String, String> params = new HashMap<>();
params.put("identifier", identifier);
params.put("dataType", dataType);
return new SeaTunnelRuntimeException(UNSUPPORTED_ARRAY_GENERIC_TYPE, params);
}

public static SeaTunnelRuntimeException unsupportedRowKind(String identifier, String rowKind) {
Map<String, String> params = new HashMap<>();
params.put("identifier", identifier);
params.put("rowKind", rowKind);
return new SeaTunnelRuntimeException(UNSUPPORTED_ROW_KIND, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public enum CommonErrorCode implements SeaTunnelErrorCode {
"<connector> write SeaTunnelRow failed, the SeaTunnelRow value is '<seaTunnelRow>'."),
SQL_TEMPLATE_HANDLED_ERROR(
"COMMON-24",
"The table of <tableName> has no <keyName>, but the template \n <template> \n which has the place holder named <placeholder>. Please use the option named <optionName> to specify sql template");
"The table of <tableName> has no <keyName>, but the template \n <template> \n which has the place holder named <placeholder>. Please use the option named <optionName> to specify sql template"),
UNSUPPORTED_DATA_TYPE_SIMPLE("COMMON-25", "'<identifier>' unsupported data type '<dataType>'"),
UNSUPPORTED_ARRAY_GENERIC_TYPE(
"COMMON-26", "'<identifier>' array type not support genericType '<genericType>'"),
UNSUPPORTED_ROW_KIND("COMMON-27", "'<identifier>' unsupported rowKind type '<rowKind>'");

private final String code;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.exception.CommonError;
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
import org.apache.seatunnel.connectors.seatunnel.paimon.config.PaimonConfig;
import org.apache.seatunnel.connectors.seatunnel.paimon.exception.PaimonConnectorException;

import org.apache.paimon.data.BinaryArray;
Expand Down Expand Up @@ -120,10 +121,8 @@ public static Object convert(InternalArray array, SeaTunnelDataType<?> dataType)
}
return doubles;
default:
String errorMsg =
String.format("Array type not support this genericType [%s]", dataType);
throw new PaimonConnectorException(
CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE, errorMsg);
throw CommonError.unsupportedArrayGenericType(
PaimonConfig.CONNECTOR_IDENTITY, dataType.getSqlType().toString());
}
}

Expand Down Expand Up @@ -221,10 +220,8 @@ public static BinaryArray reconvert(Object array, SeaTunnelDataType<?> dataType)
}
break;
default:
String errorMsg =
String.format("Array type not support this genericType [%s]", dataType);
throw new PaimonConnectorException(
CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE, errorMsg);
throw CommonError.unsupportedArrayGenericType(
PaimonConfig.CONNECTOR_IDENTITY, dataType.getSqlType().toString());
}
binaryArrayWriter.complete();
return binaryArray;
Expand Down Expand Up @@ -439,9 +436,9 @@ public static InternalRow reconvert(
binaryWriter.writeRow(i, paimonRow, new InternalRowSerializer(paimonRowType));
break;
default:
throw new PaimonConnectorException(
CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,
"Unsupported data type " + seaTunnelRowType.getFieldType(i));
throw CommonError.unsupportedDataType(
PaimonConfig.CONNECTOR_IDENTITY,
seaTunnelRowType.getFieldType(i).getSqlType().toString());
}
}
return binaryRow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.seatunnel.connectors.seatunnel.paimon.utils;

import org.apache.seatunnel.api.table.type.RowKind;
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.connectors.seatunnel.paimon.exception.PaimonConnectorException;
import org.apache.seatunnel.common.exception.CommonError;
import org.apache.seatunnel.connectors.seatunnel.paimon.config.PaimonConfig;

import org.apache.paimon.data.InternalRow;

Expand All @@ -43,9 +43,8 @@ public static org.apache.paimon.types.RowKind convertSeaTunnelRowKind2PaimonRowK
case INSERT:
return org.apache.paimon.types.RowKind.INSERT;
default:
throw new PaimonConnectorException(
CommonErrorCode.UNSUPPORTED_DATA_TYPE,
"Unsupported rowKind type " + seaTunnelRowInd.shortString());
throw CommonError.unsupportedRowKind(
PaimonConfig.CONNECTOR_IDENTITY, seaTunnelRowInd.shortString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
import org.apache.seatunnel.connectors.seatunnel.paimon.exception.PaimonConnectorException;
import org.apache.seatunnel.common.exception.CommonError;
import org.apache.seatunnel.connectors.seatunnel.paimon.config.PaimonConfig;

import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.types.ArrayType;
Expand Down Expand Up @@ -175,11 +174,8 @@ public static Column convert(BasicTypeDefine<DataType> typeDefine) {
seaTunnelDataType = paimonToSeaTunnelTypeVisitor.visit((RowType) dataType);
break;
default:
String errorMsg =
String.format(
"Paimon dataType not support this genericType [%s]",
dataType.asSQLString());
throw new PaimonConnectorException(CommonErrorCode.UNSUPPORTED_DATA_TYPE, errorMsg);
throw CommonError.unsupportedDataType(
PaimonConfig.CONNECTOR_IDENTITY, dataType.asSQLString());
}
return physicalColumnBuilder.dataType(seaTunnelDataType).build();
}
Expand Down Expand Up @@ -346,9 +342,8 @@ public DataType visit(SeaTunnelDataType<?> dataType) {
Arrays.stream(fieldTypes).map(this::visit).toArray(DataType[]::new);
return DataTypes.ROW(dataTypes);
default:
throw new PaimonConnectorException(
CommonErrorCode.UNSUPPORTED_DATA_TYPE,
"Unsupported data type: " + dataType.getSqlType());
throw CommonError.unsupportedDataType(
PaimonConfig.CONNECTOR_IDENTITY, dataType.getSqlType().toString());
}
}
}
Expand Down Expand Up @@ -462,12 +457,9 @@ public SeaTunnelDataType<?> visit(ArrayType arrayType) {
case DOUBLE:
return org.apache.seatunnel.api.table.type.ArrayType.DOUBLE_ARRAY_TYPE;
default:
String errorMsg =
String.format(
"Array type not support this genericType [%s]",
seaTunnelArrayType);
throw new PaimonConnectorException(
CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE, errorMsg);
throw CommonError.unsupportedArrayGenericType(
PaimonConfig.CONNECTOR_IDENTITY,
seaTunnelArrayType.getSqlType().toString());
}
}

Expand All @@ -490,9 +482,8 @@ public SeaTunnelDataType<?> visit(RowType rowType) {

@Override
protected SeaTunnelDataType defaultMethod(DataType dataType) {
throw new PaimonConnectorException(
CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,
"Unsupported data type: " + dataType);
throw CommonError.unsupportedDataType(
PaimonConfig.CONNECTOR_IDENTITY, dataType.getTypeRoot().name());
}
}
}

0 comments on commit 8036acb

Please sign in to comment.