|
36 | 36 | import org.apache.seatunnel.connectors.seatunnel.file.sink.commit.FileCommitInfo;
|
37 | 37 | import org.apache.seatunnel.connectors.seatunnel.file.sink.config.FileSinkConfig;
|
38 | 38 | import org.apache.seatunnel.connectors.seatunnel.file.sink.state.FileSinkState;
|
39 |
| -import org.apache.seatunnel.connectors.seatunnel.file.sink.util.FileSystemUtils; |
40 | 39 | import org.apache.seatunnel.connectors.seatunnel.file.sink.writer.WriteStrategy;
|
41 | 40 | import org.apache.seatunnel.connectors.seatunnel.file.sink.writer.WriteStrategyFactory;
|
42 | 41 | import org.apache.seatunnel.connectors.seatunnel.hive.commit.HiveSinkAggregatedCommitter;
|
@@ -71,31 +70,31 @@ public class HiveSink
|
71 | 70 | implements SeaTunnelSink<
|
72 | 71 | SeaTunnelRow, FileSinkState, FileCommitInfo, FileAggregatedCommitInfo>,
|
73 | 72 | SupportMultiTableSink {
|
74 |
| - private final Table tableInformation; |
| 73 | + |
| 74 | + // Since Table might contain some unserializable fields, we need to make it transient |
| 75 | + // And use getTableInformation to get the Table object |
| 76 | + private transient Table tableInformation; |
75 | 77 | private final CatalogTable catalogTable;
|
76 | 78 | private final ReadonlyConfig readonlyConfig;
|
77 | 79 | private final HiveHadoopConfig hiveHadoopConfig;
|
78 |
| - private final FileSystemUtils fileSystemUtils; |
79 | 80 | private final FileSinkConfig fileSinkConfig;
|
80 | 81 | private final WriteStrategy writeStrategy;
|
81 | 82 | private String jobId;
|
82 | 83 |
|
83 | 84 | public HiveSink(ReadonlyConfig readonlyConfig, CatalogTable catalogTable) {
|
84 | 85 | this.readonlyConfig = readonlyConfig;
|
85 | 86 | this.catalogTable = catalogTable;
|
86 |
| - this.tableInformation = HiveTableUtils.getTableInfo(readonlyConfig); |
87 |
| - this.hiveHadoopConfig = parseHiveHadoopConfig(readonlyConfig, tableInformation); |
88 |
| - this.fileSinkConfig = |
89 |
| - generateFileSinkConfig(readonlyConfig, tableInformation, catalogTable); |
| 87 | + this.tableInformation = getTableInformation(); |
| 88 | + this.hiveHadoopConfig = parseHiveHadoopConfig(readonlyConfig); |
| 89 | + this.fileSinkConfig = generateFileSinkConfig(readonlyConfig, catalogTable); |
90 | 90 | this.writeStrategy =
|
91 | 91 | WriteStrategyFactory.of(fileSinkConfig.getFileFormat(), fileSinkConfig);
|
92 |
| - this.fileSystemUtils = new FileSystemUtils(hiveHadoopConfig); |
93 | 92 | this.writeStrategy.setSeaTunnelRowTypeInfo(catalogTable.getSeaTunnelRowType());
|
94 |
| - this.writeStrategy.setFileSystemUtils(fileSystemUtils); |
95 | 93 | }
|
96 | 94 |
|
97 | 95 | private FileSinkConfig generateFileSinkConfig(
|
98 |
| - ReadonlyConfig readonlyConfig, Table tableInformation, CatalogTable catalogTable) { |
| 96 | + ReadonlyConfig readonlyConfig, CatalogTable catalogTable) { |
| 97 | + Table tableInformation = getTableInformation(); |
99 | 98 | Config pluginConfig = readonlyConfig.toConfig();
|
100 | 99 | List<String> sinkFields =
|
101 | 100 | tableInformation.getSd().getCols().stream()
|
@@ -171,7 +170,8 @@ public String getPluginName() {
|
171 | 170 | public Optional<SinkAggregatedCommitter<FileCommitInfo, FileAggregatedCommitInfo>>
|
172 | 171 | createAggregatedCommitter() {
|
173 | 172 | return Optional.of(
|
174 |
| - new HiveSinkAggregatedCommitter(readonlyConfig, tableInformation, fileSystemUtils)); |
| 173 | + new HiveSinkAggregatedCommitter( |
| 174 | + readonlyConfig, getTableInformation(), hiveHadoopConfig)); |
175 | 175 | }
|
176 | 176 |
|
177 | 177 | @Override
|
@@ -206,8 +206,8 @@ public Optional<Serializer<FileSinkState>> getWriterStateSerializer() {
|
206 | 206 | return Optional.of(new DefaultSerializer<>());
|
207 | 207 | }
|
208 | 208 |
|
209 |
| - private HiveHadoopConfig parseHiveHadoopConfig(ReadonlyConfig readonlyConfig, Table table) { |
210 |
| - String hdfsLocation = tableInformation.getSd().getLocation(); |
| 209 | + private HiveHadoopConfig parseHiveHadoopConfig(ReadonlyConfig readonlyConfig) { |
| 210 | + String hdfsLocation = getTableInformation().getSd().getLocation(); |
211 | 211 | HiveHadoopConfig hiveHadoopConfig;
|
212 | 212 | try {
|
213 | 213 | URI uri = new URI(hdfsLocation);
|
@@ -235,6 +235,16 @@ private HiveHadoopConfig parseHiveHadoopConfig(ReadonlyConfig readonlyConfig, Ta
|
235 | 235 | readonlyConfig
|
236 | 236 | .getOptional(HiveSourceOptions.KERBEROS_KEYTAB_PATH)
|
237 | 237 | .ifPresent(hiveHadoopConfig::setKerberosKeytabPath);
|
| 238 | + readonlyConfig |
| 239 | + .getOptional(HiveSourceOptions.REMOTE_USER) |
| 240 | + .ifPresent(hiveHadoopConfig::setRemoteUser); |
238 | 241 | return hiveHadoopConfig;
|
239 | 242 | }
|
| 243 | + |
| 244 | + private Table getTableInformation() { |
| 245 | + if (tableInformation == null) { |
| 246 | + tableInformation = HiveTableUtils.getTableInfo(readonlyConfig); |
| 247 | + } |
| 248 | + return tableInformation; |
| 249 | + } |
240 | 250 | }
|
0 commit comments