junmuz commented on code in PR #9822:
URL: https://github.com/apache/paimon/pull/9822#discussion_r4039483545


##########
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/LookupChangelogEventMetadataITCase.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.paimon.flink;
+
+import org.apache.paimon.utils.BlockingIterator;
+
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** End-to-end tests for lookup changelog event metadata. */
+public class LookupChangelogEventMetadataITCase extends CatalogITCaseBase {
+
+    @Test
+    public void testEventMetadataCanBeReadAsWriteTime() throws Exception {
+        sql(
+                "CREATE TABLE source_table ("
+                        + "id INT PRIMARY KEY NOT ENFORCED, "
+                        + "data INT, "
+                        + "event_ts BIGINT, "
+                        + "writetime BIGINT METADATA FROM 
'paimon.event.event_ts' VIRTUAL"
+                        + ") WITH ("
+                        + "'bucket'='1', "
+                        + "'changelog-producer'='lookup', "
+                        + "'sequence.field'='event_ts', "
+                        + 
"'changelog-producer.expose-field-as-metadata'='event_ts')");
+
+        // The metadata column models a Cassandra sink column populated from 
WRITETIME. The
+        // physical event_ts column remains available to normal Flink 
operators, while writetime
+        // carries the incoming event value even on an UPDATE_BEFORE 
retraction.
+        BlockingIterator<Row, Row> iterator =
+                streamSqlBlockIter("SELECT id, data, event_ts, writetime FROM 
source_table");
+
+        sql("INSERT INTO source_table VALUES (1, 10, 50)");
+        assertThat(iterator.collect(1)).containsExactly(Row.of(1, 10, 50L, 
50L));
+
+        sql("INSERT INTO source_table VALUES (1, 20, 100)");
+        assertThat(iterator.collect(2))
+                .containsExactly(
+                        Row.ofKind(RowKind.UPDATE_BEFORE, 1, 10, 50L, 100L),
+                        Row.ofKind(RowKind.UPDATE_AFTER, 1, 20, 100L, 100L));
+
+        iterator.close();
+    }
+
+    @Test
+    public void testPhysicalFilterStillSeesBeforeImage() throws Exception {
+        sql(
+                "CREATE TABLE filtered_source ("
+                        + "id INT PRIMARY KEY NOT ENFORCED, "
+                        + "data INT, "
+                        + "event_ts BIGINT, "
+                        + "writetime BIGINT METADATA FROM 
'paimon.event.event_ts' VIRTUAL"

Review Comment:
   What happens if the table is created from Flink and read from Spark?



-- 
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]

Reply via email to