Skip to content

Commit a8dcdfe

Browse files
[AMORO-4455][flink] Preserve projection and watermark in LogDynamicSource (#4507)
[AMORO-4455][flink] Preserve projection and watermark in LogDynamicSource (#4507)
1 parent 1852efe commit a8dcdfe

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

‎amoro-format-mixed/amoro-mixed-flink/amoro-mixed-flink-common/src/main/java/org/apache/amoro/flink/table/LogDynamicSource.java‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,17 @@ public boolean isBounded() {
182182

183183
@Override
184184
public DynamicTableSource copy() {
185-
return new LogDynamicSource(
186-
this.properties,
187-
this.schema,
188-
this.tableOptions,
189-
this.mixedTable,
190-
this.logRetractionEnable,
191-
this.consumerChangelogMode);
185+
LogDynamicSource copy =
186+
new LogDynamicSource(
187+
this.properties,
188+
this.schema,
189+
this.tableOptions,
190+
this.mixedTable,
191+
this.logRetractionEnable,
192+
this.consumerChangelogMode);
193+
copy.watermarkStrategy = this.watermarkStrategy;
194+
copy.projectedFields = this.projectedFields;
195+
return copy;
192196
}
193197

194198
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.amoro.flink.table;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.mockito.Mockito.mock;
23+
import static org.mockito.Mockito.when;
24+
25+
import org.apache.amoro.table.MixedTable;
26+
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
27+
import org.apache.flink.configuration.Configuration;
28+
import org.apache.flink.table.data.RowData;
29+
import org.apache.iceberg.Schema;
30+
import org.apache.iceberg.types.Types;
31+
import org.junit.Test;
32+
33+
import java.util.Collections;
34+
import java.util.Properties;
35+
36+
public class TestLogDynamicSource {
37+
38+
@Test
39+
public void testCopyPreservesProjectionAndWatermark() {
40+
MixedTable mixedTable = mock(MixedTable.class);
41+
when(mixedTable.properties()).thenReturn(Collections.emptyMap());
42+
when(mixedTable.name()).thenReturn("test_table");
43+
44+
Schema schema =
45+
new Schema(
46+
Types.NestedField.required(1, "id", Types.IntegerType.get()),
47+
Types.NestedField.optional(2, "name", Types.StringType.get()));
48+
49+
LogDynamicSource source =
50+
new LogDynamicSource(new Properties(), schema, new Configuration(), mixedTable);
51+
52+
WatermarkStrategy<RowData> watermarkStrategy = WatermarkStrategy.noWatermarks();
53+
source.applyWatermark(watermarkStrategy);
54+
source.applyProjection(new int[][] {{1}});
55+
56+
LogDynamicSource copy = (LogDynamicSource) source.copy();
57+
58+
assertThat(copy.watermarkStrategy).isSameAs(watermarkStrategy);
59+
assertThat(copy.projectedFields).containsExactly(1);
60+
}
61+
}

0 commit comments

Comments
 (0)