Skip to content

Commit d1599f8

Browse files
authored
[Improve][Connector-V2] Support read orc with schema config to cast type (#6531)
1 parent 2599d3b commit d1599f8

File tree

7 files changed

+334
-39
lines changed

7 files changed

+334
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.api.table.type;
19+
20+
public class TypeUtil {
21+
22+
/** Check if the data type can be converted to another data type. */
23+
public static boolean canConvert(SeaTunnelDataType<?> from, SeaTunnelDataType<?> to) {
24+
// any type can be converted to string
25+
if (from == to || to.getSqlType() == SqlType.STRING) {
26+
return true;
27+
}
28+
if (from.getSqlType() == SqlType.TINYINT) {
29+
return to.getSqlType() == SqlType.SMALLINT
30+
|| to.getSqlType() == SqlType.INT
31+
|| to.getSqlType() == SqlType.BIGINT;
32+
}
33+
if (from.getSqlType() == SqlType.SMALLINT) {
34+
return to.getSqlType() == SqlType.INT || to.getSqlType() == SqlType.BIGINT;
35+
}
36+
if (from.getSqlType() == SqlType.INT) {
37+
return to.getSqlType() == SqlType.BIGINT;
38+
}
39+
if (from.getSqlType() == SqlType.FLOAT) {
40+
return to.getSqlType() == SqlType.DOUBLE;
41+
}
42+
return false;
43+
}
44+
}

Diff for: seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/config/BaseFileSourceConfig.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ private List<String> parseFilePaths(ReadonlyConfig readonlyConfig) {
8080

8181
private CatalogTable parseCatalogTable(ReadonlyConfig readonlyConfig) {
8282
final CatalogTable catalogTable;
83-
if (readonlyConfig.getOptional(TableSchemaOptions.SCHEMA).isPresent()) {
83+
boolean configSchema = readonlyConfig.getOptional(TableSchemaOptions.SCHEMA).isPresent();
84+
if (configSchema) {
8485
catalogTable = CatalogTableUtil.buildWithConfig(getPluginName(), readonlyConfig);
8586
} else {
8687
catalogTable = CatalogTableUtil.buildSimpleTextTable();
@@ -99,7 +100,10 @@ private CatalogTable parseCatalogTable(ReadonlyConfig readonlyConfig) {
99100
case ORC:
100101
case PARQUET:
101102
return newCatalogTable(
102-
catalogTable, readStrategy.getSeaTunnelRowTypeInfo(filePaths.get(0)));
103+
catalogTable,
104+
readStrategy.getSeaTunnelRowTypeInfoWithUserConfigRowType(
105+
filePaths.get(0),
106+
configSchema ? catalogTable.getSeaTunnelRowType() : null));
103107
default:
104108
throw new FileConnectorException(
105109
FileConnectorErrorCode.FORMAT_NOT_SUPPORT,

0 commit comments

Comments
 (0)