mxm commented on code in PR #15780: URL: https://github.com/apache/iceberg/pull/15780#discussion_r3009601696
########## flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/DynamicRecordWithDefaults.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.iceberg.flink.sink.dynamic; + +import org.apache.flink.annotation.Internal; +import org.apache.iceberg.DistributionMode; +import org.apache.iceberg.flink.FlinkWriteConf; +import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; + +/** + * DynamicRecord extension that provides overrides from FlinkWriteConf when the base record doesn't + * have fields set. + */ +@Internal +class DynamicRecordWithDefaults extends DynamicRecord { + + private final FlinkWriteConf flinkWriteConf; + + DynamicRecordWithDefaults(DynamicRecord source, FlinkWriteConf flinkWriteConf) { + super( + source.tableIdentifier(), + source.branch(), + source.schema(), + source.rowData(), + source.spec(), + source.distributionMode(), + source.writeParallelism()); Review Comment: Could we just resolve the adjusted arguments here? We wouldn't have to overwrite all the methods then. Seems cleaner to me. ########## flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/DynamicRecordProcessor.java: ########## @@ -111,7 +121,9 @@ public void processElement(T element, Context ctx, Collector<DynamicRecordIntern } @Override - public void collect(DynamicRecord data) { + public void collect(DynamicRecord inputData) { + DynamicRecordWithDefaults data = new DynamicRecordWithDefaults(inputData, flinkWriteConf); Review Comment: I don't like that we are creating another copy `DynamicRecord` here (`DynamicRecordWithDefaults`). Only a couple lines later, we also create `DynamicRecordInternal`. Could we simply resolve the parts of DynamicRecord which can be overridden? Only a subset of the values are actually overridable. ########## flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/DynamicIcebergSink.java: ########## @@ -302,7 +300,9 @@ public Builder<T> toBranch(String branch) { } public Builder<T> immediateTableUpdate(boolean newImmediateUpdate) { - this.immediateUpdate = newImmediateUpdate; + writeOptions.put( + FlinkDynamicSinkOptions.IMMEDIATE_TABLE_UPDATE.key(), + Boolean.toString(newImmediateUpdate)); Review Comment: Thinking about it again, it's probably ok. ########## flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/DynamicRecordWithDefaults.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.iceberg.flink.sink.dynamic; + +import org.apache.flink.annotation.Internal; +import org.apache.iceberg.DistributionMode; +import org.apache.iceberg.flink.FlinkWriteConf; +import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; + +/** + * DynamicRecord extension that provides overrides from FlinkWriteConf when the base record doesn't + * have fields set. + */ +@Internal +class DynamicRecordWithDefaults extends DynamicRecord { + + private final FlinkWriteConf flinkWriteConf; + + DynamicRecordWithDefaults(DynamicRecord source, FlinkWriteConf flinkWriteConf) { + super( + source.tableIdentifier(), + source.branch(), + source.schema(), + source.rowData(), + source.spec(), + source.distributionMode(), + source.writeParallelism()); + setUpsertMode(source.upsertMode()); + setEqualityFields(source.equalityFields()); + this.flinkWriteConf = flinkWriteConf; + } + + @Override + public String branch() { + return MoreObjects.firstNonNull(super.branch(), flinkWriteConf.branch()); + } + + @Override + public DistributionMode distributionMode() { + return MoreObjects.firstNonNull(super.distributionMode(), flinkWriteConf.distributionMode()); + } + + @Override + public int writeParallelism() { + if (super.writeParallelism() != Integer.MAX_VALUE) { + return super.writeParallelism(); + } Review Comment: True, the user supplies this value via the constructor. I initially thought that we were calling the non-existing empty constructor. Regardless, I'm not sure about this change. The docs state, that `Integer.MAX_VALUE` means to use the max write parallelism, but we cap it on the writeParallelism supplied by the FlinkWriteConf, that does not seem right. I think the only way to address this is to use a value like `0` to trigger loading from FlinkWriteConf. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
