You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "Shawn-Hx (via GitHub)" <gi...@apache.org> on 2026/06/02 12:51:43 UTC

[PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Shawn-Hx opened a new pull request, #3420:
URL: https://github.com/apache/fluss/pull/3420

   <!--
   *Thank you very much for contributing to Fluss - we are happy that you want to help us improve Fluss. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GitHub issue](https://github.com/apache/fluss/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no issue.
   
     - Name the pull request in the format "[component] Title of the pull request", where *[component]* should be replaced by the name of the component being changed. Typically, this corresponds to the component label assigned to the issue (e.g., [kv], [log], [client], [flink]). Skip *[component]* if you are unsure about which is the best component.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
   
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes.
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
   
     - **Generative AI disclosure:** Indicate whether generative AI tools were used in authoring this PR. If yes, specify the tool below.
       - [ ] No generative AI tools used
       - [ ] Yes (please specify the tool below)
   
   **(The sections below can be removed for hotfixes or typos)**
   -->
   
   <!--
   Generated-by: [Tool Name and Version] following [the guidelines](https://github.com/apache/fluss/blob/main/AGENTS.md)
   -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close #3419 
   
   <!-- What is the purpose of the change -->
   
   This PR supports reporting watermarks to Paimon snapshots during lake tiering.
   
   ### Brief change log
   
   <!-- Please describe the changes made in this pull request and explain how they address the issue -->
   
   - Introduced watermark extraction for Fluss rows in the lake tiering pipeline.
   - Added watermark propagation through lake write results and tiering commit.
   - Aggregated watermarks across tiered buckets before committing to the lake.
   - Reported the aggregated watermark to Paimon snapshots when committing.
   - Updated serializers and tests to support nullable and negative watermark values.
   - Added coverage for watermark extraction, commit aggregation, and Paimon snapshot watermark reporting.
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   Add tests in:
   - PaimonWriteResultSerializerTest
   - PaimonTieringTest
   - TieringCommitOperatorTest
   - SimpleWatermarkExtractorTest
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   This change extends the lake tiering API to carry watermark information through write results and committers.
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   No user-facing documentation needs to be added.


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "github-actions[bot] (via GitHub) via issues" <is...@fluss.apache.org>.
github-actions[bot] commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-6874642606

   This PR has been marked as stale because it has had no activity for 60 days. It will be closed in 10 days unless it receives a new comment, commit or other update.


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "beryllw (via GitHub)" <gi...@apache.org>.
beryllw commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-4912052496

   Thanks @Shawn-Hx for driving this. LTGM!
   From the #3314  (partition mark-done) side, this PR looks quite helpful as a prerequisite.For mark-done, the parts that seem most relevant are the WatermarkExtractor / SimpleWatermarkExtractor and the writer-side propagation, which let the watermark reach the tiering commit side. I plan to build on the watermark extraction/propagation here for the watermark-based mark-done in #3314. 
   Thanks again!
   


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "beryllw (via GitHub)" <gi...@apache.org>.
beryllw commented on code in PR #3420:
URL: https://github.com/apache/fluss/pull/3420#discussion_r3541159486


##########
fluss-lake/fluss-lake-paimon/src/main/java/org/apache/fluss/lake/paimon/tiering/PaimonWriteResultSerializer.java:
##########
@@ -38,21 +42,58 @@ public int getVersion() {
 
     @Override
     public byte[] serialize(PaimonWriteResult paimonWriteResult) throws IOException {
-        CommitMessage commitMessage = paimonWriteResult.commitMessage();
-        return messageSer.serialize(commitMessage);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        DataOutputViewStreamWrapper view = new DataOutputViewStreamWrapper(out);
+
+        Long watermark = paimonWriteResult.getWatermark();
+        if (watermark == null) {
+            view.writeBoolean(false);
+        } else {
+            view.writeBoolean(true);
+            view.writeLong(watermark);
+        }
+
+        byte[] messageBytes = messageSer.serialize(paimonWriteResult.commitMessage());
+        view.writeInt(messageBytes.length);
+        view.write(messageBytes);
+
+        return out.toByteArray();
     }
 
     @Override
     public PaimonWriteResult deserialize(int version, byte[] serialized) throws IOException {
-        if (version != CURRENT_VERSION) {
-            throw new UnsupportedOperationException(
-                    "Expecting PaimonWriteResult version to be "
-                            + CURRENT_VERSION
-                            + ", but found "
-                            + version
-                            + ".");
+        switch (version) {
+            case 1:
+                {
+                    CommitMessage commitMessage =
+                            messageSer.deserialize(messageSer.getVersion(), serialized);
+                    return new PaimonWriteResult(commitMessage, null);
+                }
+            case 2:
+                {
+                    DataInputView view = new DataInputDeserializer(serialized);
+
+                    Long watermark = null;
+                    boolean watermarkNonNull = view.readBoolean();
+                    if (watermarkNonNull) {
+                        watermark = view.readLong();
+                    }
+
+                    int len = view.readInt();
+                    byte[] messageBytes = new byte[len];
+                    view.read(messageBytes);

Review Comment:
   Might be slightly safer to use view.readFully(messageBytes) here — read(byte[]) doesn't guarantee filling the whole array (and its return value is unused). Not an issue today since messageBytes is the last field, just a nit for consistency with TableBucketWriteResultSerializer.



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "github-actions[bot] (via GitHub) via issues" <is...@fluss.apache.org>.
github-actions[bot] commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-7126395733

   This PR was closed because it has been stale for 10 days with no activity.


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "github-actions[bot] (via GitHub) via issues" <is...@fluss.apache.org>.
github-actions[bot] closed pull request #3420: [lake/tiering] Support reporting watermark to Paimon snapshot
URL: https://github.com/apache/fluss/pull/3420


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "Shawn-Hx (via GitHub)" <gi...@apache.org>.
Shawn-Hx commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-4795342138

   > Thanks for working on this.
   > 
   > I have one high-level question about the motivation/use case: if Fluss implements #3314, would that satisfy the requirement this PR is trying to address?
   > 
   > My understanding is that #3314 would provide a partition-level "mark done" / readiness signal for Paimon lake tiering, while this PR reports an event-time watermark into Paimon snapshots. If the main goal is to let downstream batch jobs know when a partition is ready to process, #3314 may be the more direct mechanism and this PR might not be necessary. But if the requirement is specifically to expose event-time progress through Paimon snapshot watermarks, then this PR still seems to cover a different need.
   > 
   > Could you clarify the intended downstream use case here?
   
   Yes, the main purpose of this PR is to determine whether a partition is done based on the watermark. Paimon’s PartitionMarkDone mechanism supports the watermark-based mode. I’m not sure whether the solution proposed in #3314 takes the watermark into consideration. If we need to determine whether a partition is done based on the watermark, the tiering job must be able to get the watermark. So I think this PR is a prerequisite for #3314.


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "Shawn-Hx (via GitHub)" <gi...@apache.org>.
Shawn-Hx commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-4912550159

   > One more thought — watermark extraction uses a shared WatermarkExtractor and applies to all lakes, so it feels more like a tiering-layer concern than a per-lake writer one. Since TieringSplitReader already builds the extractor and sees every record, could we compute the watermark there and carry it in TableBucketWriteResult (next to maxTimestamp), instead of each LakeWriter doing it via LakeWriteResult? That would keep the logic in one place and avoid pushing the extends LakeWriteResult bound across the lake API. @luoyuxia what do you think about moving watermark computation up to the tiering layer?
   
   Calculating watermark in LakeWriter for each lake format involves considering that some lake formats do not support reporting watermark information. In such cases, the overhead of calculating watermark during tiering process can be omitted.


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "Shawn-Hx (via GitHub)" <gi...@apache.org>.
Shawn-Hx commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-5265945188

   Hi @luoyuxia @beryllw, could you take a look at this PR when you have a moment?


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "beryllw (via GitHub)" <gi...@apache.org>.
beryllw commented on code in PR #3420:
URL: https://github.com/apache/fluss/pull/3420#discussion_r3541073576


##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/tiering/source/watermark/SimpleWatermarkExtractorTest.java:
##########
@@ -0,0 +1,371 @@
+/*
+ * 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.fluss.flink.tiering.source.watermark;
+
+import org.apache.fluss.config.Configuration;
+import org.apache.fluss.lake.batch.ArrowRecordBatch;
+import org.apache.fluss.metadata.Schema;
+import org.apache.fluss.metadata.TableInfo;
+import org.apache.fluss.metadata.TablePath;
+import org.apache.fluss.record.ArrowBatchData;
+import org.apache.fluss.row.GenericRow;
+import org.apache.fluss.row.TimestampLtz;
+import org.apache.fluss.row.TimestampNtz;
+import org.apache.fluss.types.DataTypes;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.TimeStampMilliVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link SimpleWatermarkExtractor}. */
+class SimpleWatermarkExtractorTest {
+
+    @Test
+    void testCreateWithNoWatermarkConfig() {
+        TableInfo tableInfo = createTableInfoWithoutWatermark();
+        assertThat(SimpleWatermarkExtractor.create(tableInfo)).isNull();
+    }
+
+    @Test
+    void testCreateWithSimpleColumn() {
+        TableInfo tableInfo = createTableInfoWithWatermark("`ts`", "TIMESTAMP(3)");
+        SimpleWatermarkExtractor extractor = SimpleWatermarkExtractor.create(tableInfo);
+        assertThat(extractor).isNotNull();
+
+        GenericRow row = GenericRow.of(1, TimestampNtz.fromMillis(1000L));
+        assertThat(extractor.currentWatermark(row)).isEqualTo(1000L);
+    }
+
+    @Test
+    void testCreateWithSimpleColumnWithoutBackticks() {
+        TableInfo tableInfo = createTableInfoWithWatermark("ts", "TIMESTAMP(3)");
+        SimpleWatermarkExtractor extractor = SimpleWatermarkExtractor.create(tableInfo);
+        assertThat(extractor).isNotNull();
+
+        GenericRow row = GenericRow.of(1, TimestampNtz.fromMillis(2000L));
+        assertThat(extractor.currentWatermark(row)).isEqualTo(2000L);
+    }
+
+    @Test
+    void testCreateWithColumnMinusInterval() {

Review Comment:
   Nice and thorough coverage here 👍. Just a small non-blocking suggestion: testCreateWithColumnMinusInterval / Decimal / Minute / Hour / Day share the exact same structure and differ only in the expression and expected value. Following the existing testCreateWithTimestampPrecision in this file, they could be folded into a single @ParameterizedTest with @CsvSource — that way adding new cases (e.g. lowercase units or non-backtick columns) is just one more row, and the intent reads more clearly. The Arrow-batch tests are fine to keep separate given the variable rows/nulls. 
   
   ```
   @ParameterizedTest
   @CsvSource({
       // expr, inputMillis, expectedWatermarkMillis
       "`ts`,                           1000,      1000",
       "ts,                             2000,      2000",
       "`ts` - INTERVAL '5' SECOND,     10000,     5000",
       "`ts` - INTERVAL '0.001' SECOND, 1000,      999",
       "`ts` - INTERVAL '2' MINUTE,     200000,    80000",
       "`ts` - INTERVAL '1' HOUR,       7200000,   3600000",
       "`ts` - INTERVAL '1' DAY,        172800000, 86400000",
   })
   void testNtzWatermarkExtraction(String expr, long inputMillis, long expectedMillis) {
   ```



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "beryllw (via GitHub)" <gi...@apache.org>.
beryllw commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-4912334761

   One more thought — watermark extraction uses a shared WatermarkExtractor and applies to all lakes, so it feels more like a tiering-layer concern than a per-lake writer one. Since TieringSplitReader already builds the extractor and sees every record, could we compute the watermark there and carry it in TableBucketWriteResult (next to maxTimestamp), instead of each LakeWriter doing it via LakeWriteResult? That would keep the logic in one place and avoid pushing the extends LakeWriteResult bound across the lake API.
   @luoyuxia  what do you think about moving watermark computation up to the tiering layer?


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-4797391268

   > > Thanks for working on this.
   > > I have one high-level question about the motivation/use case: if Fluss implements #3314, would that satisfy the requirement this PR is trying to address?
   > > My understanding is that #3314 would provide a partition-level "mark done" / readiness signal for Paimon lake tiering, while this PR reports an event-time watermark into Paimon snapshots. If the main goal is to let downstream batch jobs know when a partition is ready to process, #3314 may be the more direct mechanism and this PR might not be necessary. But if the requirement is specifically to expose event-time progress through Paimon snapshot watermarks, then this PR still seems to cover a different need.
   > > Could you clarify the intended downstream use case here?
   > 
   > Yes, the main purpose of this PR is to determine whether a partition is done based on the watermark. Paimon’s PartitionMarkDone mechanism supports the watermark-based mode. I’m not sure whether the solution proposed in #3314 takes the watermark into consideration. If we need to determine whether a partition is done based on the watermark, the tiering job must be able to get the watermark. So I think this PR is a prerequisite for #3314.
   
   Thanks. The issue is expected to take the watermark into consideration. And I agree on the pr or some similar thing is a prerequisite for #3314. But I think may be we need to limit the scope of the pr to avoid over implementation since seems write watermark is not needed.  @beryllw Could you please have to look to determine which part for watermark is needed in you design for #3314 


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-4788253240

   Thanks for working on this.
   
   I have one high-level question about the motivation/use case: if Fluss implements https://github.com/apache/fluss/issues/3314, would that satisfy the requirement this PR is trying to address?
   
   My understanding is that #3314 would provide a partition-level "mark done" / readiness signal for Paimon lake tiering, while this PR reports an event-time watermark into Paimon snapshots. If the main goal is to let downstream batch jobs know when a partition is ready to process, #3314 may be the more direct mechanism and this PR might not be necessary. But if the requirement is specifically to expose event-time progress through Paimon snapshot watermarks, then this PR still seems to cover a different need.
   
   Could you clarify the intended downstream use case here?


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "beryllw (via GitHub)" <gi...@apache.org>.
beryllw commented on code in PR #3420:
URL: https://github.com/apache/fluss/pull/3420#discussion_r3541102128


##########
fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/tiering/committer/TieringCommitOperator.java:
##########
@@ -232,14 +233,35 @@ private CommitResult commitWriteResults(
 
             Map<TableBucket, Long> logEndOffsets = new HashMap<>();
             Map<TableBucket, Long> logMaxTieredTimestamps = new HashMap<>();
+            Long watermark = null;
             for (TableBucketWriteResult<WriteResult> writeResult : nonEmptyResults) {
                 TableBucket tableBucket = writeResult.tableBucket();
                 logEndOffsets.put(tableBucket, writeResult.logEndOffset());
                 logMaxTieredTimestamps.put(tableBucket, writeResult.maxTimestamp());
+                Long writeResultWatermark = writeResult.writeResult().getWatermark();
+                if (writeResultWatermark == null) {
+                    continue;
+                }
+                watermark =

Review Comment:
   nit: Consider adding a brief comment explaining why it's safe for the aggregated watermark to be lower than previously committed — Paimon's FileStoreCommitImpl#tryCommitOnce guarantees snapshot watermark monotonicity via Math.max(current, latestSnapshot.watermark()), so it will never regress. This would save future readers from needing to trace into Paimon source to verify correctness.
   https://github.com/apache/paimon/blob/5b797ef63fba5e98bf4fd285fb5a34877c91ee81/paimon-core/src/main/java/org/apache/paimon/operation/FileStoreCommitImpl.java#L1020-L1026



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "beryllw (via GitHub)" <gi...@apache.org>.
beryllw commented on code in PR #3420:
URL: https://github.com/apache/fluss/pull/3420#discussion_r3541168187


##########
fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/tiering/source/watermark/SimpleWatermarkExtractor.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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.fluss.flink.tiering.source.watermark;
+
+import org.apache.fluss.lake.batch.ArrowRecordBatch;
+import org.apache.fluss.lake.batch.RecordBatch;
+import org.apache.fluss.lake.watermark.WatermarkExtractor;
+import org.apache.fluss.metadata.TableInfo;
+import org.apache.fluss.record.ArrowBatchData;
+import org.apache.fluss.row.InternalRow;
+import org.apache.fluss.types.RowType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Extracts epoch-millis watermark values from {@link InternalRow} by parsing Flink watermark
+ * definitions stored in table properties. Only two expression formats are supported:
+ *
+ * <ul>
+ *   <li>{@code WATERMARK FOR ts AS ts} — direct column reference, zero delay
+ *   <li>{@code WATERMARK FOR ts AS ts - INTERVAL '5' SECOND} — column minus interval delay
+ * </ul>
+ *
+ * <p>The rowtime column must be a physical column (computed columns are not supported). Returns
+ * {@code null} from {@link #create(TableInfo)} if the watermark configuration cannot be parsed.
+ */
+public class SimpleWatermarkExtractor implements WatermarkExtractor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleWatermarkExtractor.class);
+
+    private static final String WATERMARK_PROPERTY_PREFIX = "schema.watermark.";
+    private static final String WATERMARK_ROWTIME_SUFFIX = ".rowtime";
+    private static final String WATERMARK_STRATEGY_EXPR_SUFFIX = ".strategy.expr";
+    private static final String WATERMARK_STRATEGY_DATA_TYPE_SUFFIX = ".strategy.data-type";
+
+    private static final Pattern WATERMARK_EXPR_SIMPLE_COLUMN_PATTERN =
+            Pattern.compile("(`\\w+`|\\w+)");
+    private static final Pattern WATERMARK_EXPR_COLUMN_MINUS_INTERVAL_PATTERN =
+            Pattern.compile(
+                    "(`\\w+`|\\w+)\\s+-\\s+INTERVAL\\s+'(\\d+\\.?\\d*)'\\s+(SECOND|MINUTE|HOUR|DAY)",
+                    Pattern.CASE_INSENSITIVE);
+    private static final Pattern TIMESTAMP_TYPE_PATTERN =
+            Pattern.compile("TIMESTAMP(?:_LTZ)?\\((\\d+)\\)", Pattern.CASE_INSENSITIVE);
+
+    private final int fieldIndex;
+    private final int precision;
+    private final boolean isTimestampLtz;
+    private final long delayMillis;
+
+    private SimpleWatermarkExtractor(
+            int fieldIndex, int precision, boolean isTimestampLtz, long delayMillis) {
+        this.fieldIndex = fieldIndex;
+        this.precision = precision;
+        this.isTimestampLtz = isTimestampLtz;
+        this.delayMillis = delayMillis;
+    }
+
+    /**
+     * Creates a {@link SimpleWatermarkExtractor} from the table's properties. Returns null if no
+     * watermark configuration is found or the watermark configuration cannot be parsed.
+     */
+    @Nullable
+    public static SimpleWatermarkExtractor create(TableInfo tableInfo) {
+        Map<String, String> props = tableInfo.getCustomProperties().toMap();
+        RowType rowType = tableInfo.getRowType();
+
+        boolean isWatermarkDefined = false;
+        String rowtimeColumn = null;
+        String watermarkIndex = null;
+
+        for (Map.Entry<String, String> entry : props.entrySet()) {
+            String key = entry.getKey();
+            if (key.startsWith(WATERMARK_PROPERTY_PREFIX)

Review Comment:
   ```
   long count = props.keySet().stream()
       .filter(k -> k.startsWith(WATERMARK_PROPERTY_PREFIX) 
                 && k.endsWith(WATERMARK_ROWTIME_SUFFIX))
       .count();
   if (count > 1) {
       LOG.warn("More than 1 watermark definition...");
       return null;
   }
   ```



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3420:
URL: https://github.com/apache/fluss/pull/3420#discussion_r3378985526


##########
fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/tiering/source/watermark/SimpleWatermarkExtractor.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.fluss.flink.tiering.source.watermark;
+
+import org.apache.fluss.lake.watermark.WatermarkExtractor;
+import org.apache.fluss.metadata.TableInfo;
+import org.apache.fluss.row.InternalRow;
+import org.apache.fluss.types.RowType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Extracts epoch-millis watermark values from {@link InternalRow} by parsing Flink watermark
+ * definitions stored in table properties. Only two expression formats are supported:
+ *
+ * <ul>
+ *   <li>{@code WATERMARK FOR ts AS ts} — direct column reference, zero delay
+ *   <li>{@code WATERMARK FOR ts AS ts - INTERVAL '5' SECOND} — column minus interval delay
+ * </ul>
+ *
+ * <p>The rowtime column must be a physical column (computed columns are not supported). Returns
+ * {@code null} from {@link #create(TableInfo)} if the watermark configuration cannot be parsed.
+ */
+public class SimpleWatermarkExtractor implements WatermarkExtractor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleWatermarkExtractor.class);
+
+    private static final String WATERMARK_PROPERTY_PREFIX = "schema.watermark.";
+    private static final String WATERMARK_ROWTIME_SUFFIX = ".rowtime";
+    private static final String WATERMARK_STRATEGY_EXPR_SUFFIX = ".strategy.expr";
+    private static final String WATERMARK_STRATEGY_DATA_TYPE_SUFFIX = ".strategy.data-type";
+
+    private static final Pattern WATERMARK_EXPR_SIMPLE_COLUMN_PATTERN =
+            Pattern.compile("(`\\w+`|\\w+)");
+    private static final Pattern WATERMARK_EXPR_COLUMN_MINUS_INTERVAL_PATTERN =
+            Pattern.compile(
+                    "(`\\w+`|\\w+)\\s+-\\s+INTERVAL\\s+'(\\d+\\.?\\d*)'\\s+(SECOND|MINUTE|HOUR|DAY)",
+                    Pattern.CASE_INSENSITIVE);
+    private static final Pattern TIMESTAMP_TYPE_PATTERN =
+            Pattern.compile("TIMESTAMP(?:_LTZ)?\\((\\d+)\\)", Pattern.CASE_INSENSITIVE);
+
+    private final int fieldIndex;
+    private final int precision;
+    private final boolean isTimestampLtz;
+    private final long delayMillis;
+
+    private SimpleWatermarkExtractor(
+            int fieldIndex, int precision, boolean isTimestampLtz, long delayMillis) {
+        this.fieldIndex = fieldIndex;
+        this.precision = precision;
+        this.isTimestampLtz = isTimestampLtz;
+        this.delayMillis = delayMillis;
+    }
+
+    /**
+     * Creates a {@link SimpleWatermarkExtractor} from the table's properties. Returns null if no
+     * watermark configuration is found or the watermark configuration cannot be parsed.
+     */
+    @Nullable
+    public static SimpleWatermarkExtractor create(TableInfo tableInfo) {
+        Map<String, String> props = tableInfo.getCustomProperties().toMap();
+        RowType rowType = tableInfo.getRowType();
+
+        boolean isWatermarkDefined = false;
+        String rowtimeColumn = null;
+        String watermarkIndex = null;
+
+        for (Map.Entry<String, String> entry : props.entrySet()) {
+            String key = entry.getKey();
+            if (key.startsWith(WATERMARK_PROPERTY_PREFIX)
+                    && key.endsWith(WATERMARK_ROWTIME_SUFFIX)) {
+                isWatermarkDefined = true;
+                rowtimeColumn = entry.getValue();
+                watermarkIndex =
+                        key.substring(
+                                WATERMARK_PROPERTY_PREFIX.length(),
+                                key.length() - WATERMARK_ROWTIME_SUFFIX.length());
+                if (!String.valueOf(0).equals(watermarkIndex)) {
+                    LOG.warn(
+                            "There are more than 1 watermark definition for {}, which is not supported for watermark extraction.",
+                            tableInfo.getTablePath());
+                    return null;
+                }
+                break;
+            }
+        }
+
+        if (!isWatermarkDefined) {
+            return null;
+        }
+
+        int fieldIndex = rowType.getFieldIndex(rowtimeColumn);
+        if (fieldIndex < 0) {
+            LOG.warn(
+                    "Watermark rowtime column '{}' not found in row type for {}, "
+                            + "computed column is not supported for watermark extraction.",
+                    tableInfo.getTablePath(),
+                    rowtimeColumn);

Review Comment:
   The LOG.warn placeholder arguments are swapped here. As written, the log will print the table path where the rowtime column name should be, and vice versa, which makes the warning misleading when watermark config cannot be applied.



##########
fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/tiering/committer/TieringCommitOperator.java:
##########
@@ -232,14 +233,35 @@ private CommitResult commitWriteResults(
 
             Map<TableBucket, Long> logEndOffsets = new HashMap<>();
             Map<TableBucket, Long> logMaxTieredTimestamps = new HashMap<>();
+            Long watermark = null;
             for (TableBucketWriteResult<WriteResult> writeResult : nonEmptyResults) {
                 TableBucket tableBucket = writeResult.tableBucket();
                 logEndOffsets.put(tableBucket, writeResult.logEndOffset());
                 logMaxTieredTimestamps.put(tableBucket, writeResult.maxTimestamp());
+                Long writeResultWatermark = writeResult.writeResult().getWatermark();
+                if (writeResultWatermark == null) {
+                    continue;
+                }
+                watermark =
+                        watermark == null
+                                ? writeResultWatermark
+                                : Math.min(watermark, writeResultWatermark);
+            }
+
+            if (nonEmptyResults.size() < committableWriteResults.size()) {
+                // Empty results means some splits has not been processed, possibly caused by force
+                // completion. Do not update watermark here.
+                if (watermark != null) {

Review Comment:
   Grammar in the comment: "some splits has" should be "some splits have" (and "force completion" reads more naturally as "forced completion").



##########
fluss-common/src/main/java/org/apache/fluss/lake/committer/LakeCommitter.java:
##########
@@ -34,22 +35,36 @@
  * @since 0.7
  */
 @PublicEvolving
-public interface LakeCommitter<WriteResult, CommittableT> extends AutoCloseable {
+public interface LakeCommitter<WriteResult extends LakeWriteResult, CommittableT>
+        extends AutoCloseable {
 
     /**
      * The property key used to store the file path of lake table bucket offsets in snapshot
      * properties.
      */
     String FLUSS_LAKE_SNAP_BUCKET_OFFSET_PROPERTY = "fluss-offsets";
 
+    /**
+     * Converts a list of write results to a committable object with watermark.
+     *
+     * @param writeResults the list of write results
+     * @param watermark watermark to be committed
+     * @return the committable object
+     * @throws IOException if an I/O error occurs
+     */
+    CommittableT toCommittable(List<WriteResult> writeResults, @Nullable Long watermark)
+            throws IOException;
+
     /**
      * Converts a list of write results to a committable object.
      *
      * @param writeResults the list of write results
      * @return the committable object
      * @throws IOException if an I/O error occurs
      */
-    CommittableT toCommittable(List<WriteResult> writeResults) throws IOException;
+    default CommittableT toCommittable(List<WriteResult> writeResults) throws IOException {
+        return toCommittable(writeResults, null);
+    }

Review Comment:
   This change adds a new abstract method to a `@PublicEvolving` interface, which is a source-breaking change for any external LakeCommitter implementations (they must now implement the new overload). Consider instead making the new watermark overload a default method delegating to the existing toCommittable(List<WriteResult>) so existing implementations keep compiling and watermark support remains opt-in.



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [lake/tiering] Support reporting watermark to Paimon snapshot [fluss]

Posted by "Shawn-Hx (via GitHub)" <gi...@apache.org>.
Shawn-Hx commented on PR #3420:
URL: https://github.com/apache/fluss/pull/3420#issuecomment-4901701106

   Hi @beryllw , could you please take a look? I'm willing to commit if there are any modifications needed.


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org