Skip to content

Commit c52042f

Browse files
committed
[fix-32052]metadatasqlserver]解决部分库权限不足导致所有整个任务失败的问题
1 parent 6781e85 commit c52042f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

flinkx-metadata-sqlserver/flinkx-metadata-sqlserver-reader/src/main/java/com/dtstack/flinkx/metadatasqlserver/inputformat/MetadatasqlserverInputFormat.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
import com.dtstack.flinkx.constants.ConstantValue;
2222
import com.dtstack.flinkx.metadata.MetaDataCons;
2323
import com.dtstack.flinkx.metadata.inputformat.BaseMetadataInputFormat;
24+
import com.dtstack.flinkx.metadata.inputformat.MetadataInputSplit;
2425
import com.dtstack.flinkx.metadatasqlserver.constants.SqlServerMetadataCons;
2526
import com.dtstack.flinkx.util.ExceptionUtil;
27+
import org.apache.commons.collections.CollectionUtils;
2628
import org.apache.commons.lang.StringUtils;
2729
import org.apache.commons.lang3.tuple.Pair;
30+
import org.apache.flink.core.io.InputSplit;
2831
import org.apache.flink.types.Row;
2932

3033
import java.io.IOException;
@@ -52,6 +55,34 @@ public class MetadatasqlserverInputFormat extends BaseMetadataInputFormat {
5255

5356
protected String table;
5457

58+
/**
59+
* 在use database失败时,不影响下一个任务
60+
* @param inputSplit 分片
61+
* @throws IOException 异常
62+
*/
63+
@Override
64+
protected void openInternal(InputSplit inputSplit) throws IOException {
65+
LOG.info("inputSplit = {}", inputSplit);
66+
try {
67+
connection.set(getConnection());
68+
statement.set(connection.get().createStatement());
69+
currentDb.set(((MetadataInputSplit) inputSplit).getDbName());
70+
tableList = ((MetadataInputSplit) inputSplit).getTableList();
71+
switchDatabase(currentDb.get());
72+
if (CollectionUtils.isEmpty(tableList)) {
73+
tableList = showTables();
74+
queryTable = true;
75+
}
76+
} catch (ClassNotFoundException e) {
77+
LOG.error("could not find suitable driver, e={}", ExceptionUtil.getErrorMessage(e));
78+
throw new IOException(e);
79+
} catch (SQLException e){
80+
LOG.error("获取table列表异常, dbUrl = {}, username = {}, inputSplit = {}, e = {}", dbUrl, username, inputSplit, ExceptionUtil.getErrorMessage(e));
81+
tableList = new LinkedList<>();
82+
}
83+
tableIterator.set(tableList.iterator());
84+
}
85+
5586
@Override
5687
protected List<Object> showTables() throws SQLException {
5788
List<Object> tableNameList = new LinkedList<>();

0 commit comments

Comments
 (0)