You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "CosmosNi (via GitHub)" <gi...@apache.org> on 2026/02/13 05:41:54 UTC
[PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
CosmosNi opened a new pull request, #10489:
URL: https://github.com/apache/seatunnel/pull/10489
#10460
<!--
Thank you for contributing to SeaTunnel! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
## Contribution Checklist
- Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
- Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
- Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
-->
### Purpose of this pull request
<!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
If no, write 'No'.
If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
-->
### Check list
* [ ] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] If necessary, please update `incompatible-changes.md` to describe the incompatibility caused by this PR.
* [ ] If you are contributing the connector code, please check that the following files are updated:
1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
Posted by "DanielCarter-stack (via GitHub)" <gi...@apache.org>.
DanielCarter-stack commented on PR #10489:
URL: https://github.com/apache/seatunnel/pull/10489#issuecomment-3895119958
<!-- code-pr-reviewer -->
<!-- cpr:pr_reply_v2_parts {"group": "apache/seatunnel#10489", "part": 1, "total": 1} -->
### Issue 1: UDF state not restored after Checkpoint
**Location**: `seatunnel-e2e/seatunnel-transforms-v2-e2e/seatunnel-transforms-v2-udf/src/main/java/org/apache/seatunnel/e2e/transform/udf/EncryptUDF.java:32`
```java
private transient CryptoClient client;
@Override
public void open() {
this.client = new CryptoClient();
}
@Override
public Object evaluateWithContext(List<Object> args, ZetaUDFContext context) {
if (client == null) { // Triggered after Checkpoint recovery
throw new IllegalStateException("open() was not called before evaluateWithContext()");
}
// ...
}
```
**Related Context**:
- Parent class/interface: `ZetaUDF.java:70-73`
- Caller: `ZetaSQLEngine.java:108-120` (`openUDFs`)
- Caller: `ZetaSQLFunction.java:668-670` (`evaluateWithContext`)
**Problem Description**:
When SeaTunnel Task restores from Checkpoint:
1. `SQLTransform.sqlEngine` field is `transient`, and is `null` during restoration
2. `transformRow()` calling `tryOpen()` will re-initialize `sqlEngine`
3. But if Checkpoint occurs after `open()`, the UDF instance in `udfList` is deserialized during restoration
4. The UDF instance's `transient` field (such as `client`) becomes `null`
5. The next call to `evaluateWithContext()` will throw `IllegalStateException`
**Potential Risks**:
- In production environment when Task recovers from failure, all UDFs using `transient` resources will fail
- Impacts SeaTunnel's high availability feature
- Error message is not user-friendly (`open() was not called`)
**Impact Scope**:
- Direct impact: All UDF implementations using `transient` field
- Indirect impact: Data processing jobs dependent on UDFs
- Affected area: SQL Transform (single Transform)
**Severity**: **MAJOR**
**Improvement Suggestions**:
**Solution 1: Let UDF implement `CheckpointListener`**
```java
// ZetaUDF.java
public interface ZetaUDF extends Serializable, CheckpointListener {
// ...
default void notifyCheckpointComplete(long checkpointId) {}
default void notifyCheckpointRestore(long checkpointId) {}
}
```
**Solution 2: Re-initialize at `SQLTransform` level**
```java
// SQLTransform.java
@Override
public void open() {
if (sqlEngine == null) {
sqlEngine = SQLEngineFactory.getSQLEngine(engineType);
// ...
}
// Reinitialize UDF each time reopened
sqlEngine.reopenUDFs(); // This method needs to be added
}
```
**Solution 3: Document UDF state management limitations**
Explicitly state in documentation:
- UDFs should not store state in `transient` fields
- For state management, external state backends should be used
**Rationale**:
- Checkpoint/Restore is a core feature of distributed computing frameworks
- Current implementation silently fails after restoration
- Users cannot work around through code (unless avoiding use of `transient`)
---
### Issue 2: ZetaUDFContext lacks null safety checks
**Location**: `seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaUDFContext.java:108-110`
```java
public Object[] getAllFields() {
return allFields;
}
```
**Related Context**:
- Caller 1: `ZetaSQLFunction.java:247-252` (`updateUDFContext`)
- Caller 2: UDF implementations (user code)
**Problem Description**:
`getAllFields()` returns a direct reference to the internal array, posing risks:
1. UDF implementations may modify array contents
2. If `fields` parameter is `null`, returns `EMPTY_FIELDS` (although it's final, the semantics are unclear)
3. No JavaDoc explains whether the return value is mutable
**Potential Risks**:
- UDF accidentally modifies context array
- Multiple calls return different content (violates immutability expectations)
- State inconsistency in concurrent scenarios
**Impact Scope**:
- Direct impact: UDFs using `context.getAllFields()`
- Indirect impact: UDFs dependent on `getAllFields()` immutability
- Affected area: SQL Transform (single Transform)
**Severity**: **MINOR**
**Improvement Suggestions**:
```java
// ZetaUDFContext.java
@Nullable
public Object[] getAllFields() {
return allFields == EMPTY_FIELDS ? null : allFields.clone();
}
/**
* Get all fields of the current row.
* Note: The returned array is a copy and modifying it will not affect the context.
*
* @return a copy of all fields, or null if the row has no fields
*/
@Nullable
public Object[] getAllFields() {
return allFields.length == 0 ? null : Arrays.copyOf(allFields, allFields.length);
}
```
**Rationale**:
- Defensive copy prevents accidental modification
- Clear JavaDoc explains behavior
- Returning `null` is more Java-conventional than `EMPTY_FIELDS`
---
### Issue 3: EncryptUDF unnecessary throw UnsupportedOperationException
**Location**: `seatunnel-e2e/seatunnel-transforms-v2-e2e/seatunnel-transforms-v2-udf/src/main/java/org/apache/seatunnel/e2e/transform/udf/EncryptUDF.java:55-57`
```java
@Override
public Object evaluate(List<Object> args) {
throw new UnsupportedOperationException("ENCRYPT should be called with context");
}
```
**Related Context**:
- Interface definition: `ZetaUDF.java:47`
- Caller: `ZetaSQLFunction.java:666-673`
**Problem Description**:
Although this UDF sets `requiresContext() = true`, it still implements `evaluate()` and throws exception:
1. Caller will call `evaluate()` when `udfContext == null`
2. Exception message is not user-friendly
3. Violates the principle that "interface default implementations should be callable"
**Potential Risks**:
- Throws confusing exceptions in edge cases (`udfContext == null`)
- If code paths bypass `requiresContext()` check, it will cause runtime errors
- Inconsistent with interface default implementation (`return evaluate(args)`)
**Impact Scope**:
- Direct impact: `EncryptUDF` (example code)
- Indirect impact: User UDFs imitating this pattern
- Affected area: SQL Transform (single Transform)
**Severity**: **MINOR**
**Improvement Suggestions**:
```java
// EncryptUDF.java
@Override
public Object evaluate(List<Object> args) {
// Fallback to context-less evaluation if needed
Object value = args.get(0);
if (value == null) {
return null;
}
// Simplified implementation: no tableId-related encryption
return "ENC(-1):" + value;
}
@Override
public Object evaluateWithContext(List<Object> args, ZetaUDFContext context) {
if (client == null) {
throw new IllegalStateException("open() was not called before evaluateWithContext()");
}
Object value = args.get(0);
if (value == null) {
return null;
}
String tableId = context.getRawTableId();
return client.encrypt(value, tableId);
}
```
**Rationale**:
- Provides reasonable fallback behavior
- Maintains interface consistency
- Better user experience (still works in edge cases)
---
### Issue 4: Missing unit tests covering core logic
**Location**: `seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaUDFContext.java:61-83`
**Related Context**:
- Test directory: `seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/`
**Problem Description**:
The newly added `ZetaUDFContext` in this PR lacks unit tests, not covering:
1. Accessing `getDatabase()/getSchema()/getTable()` when `tableId = null`
2. Exception handling for `tableId = "invalid"` format
3. Storage and re-throwing of `tablePathParseException`
4. Short-circuit logic for multiple calls to `resolveTablePathIfNeeded()`
**Potential Risks**:
- Behavior in edge cases is unverified
- Refactoring may introduce regressions
- Code reviewers cannot understand expected behavior through tests
**Impact Scope**:
- Direct impact: Maintainability of `ZetaUDFContext`
- Indirect impact: Future developers modifying this class
- Affected area: SQL Transform (single Transform)
**Severity**: **MINOR**
**Improvement Suggestions**:
Add unit test `ZetaUDFContextTest.java`:
```java
public class ZetaUDFContextTest {
@Test
public void testNullTableId() {
ZetaUDFContext context = new ZetaUDFContext();
SeaTunnelRow row = new SeaTunnelRow(new Object[0]);
row.setTableId(null);
context.update(row.getFields(), row);
assertNull(context.getRawTableId());
assertNull(context.getDatabase()); // Should return null, not throw exception
assertNull(context.getSchema());
assertNull(context.getTable());
assertEquals(RowKind.INSERT, context.getRowKind());
}
@Test
public void testInvalidTableIdFormat() {
ZetaUDFContext context = new ZetaUDFContext();
SeaTunnelRow row = new SeaTunnelRow(new Object[0]);
row.setTableId("invalid.format.with.too.many.parts");
context.update(row.getFields(), row);
// First access should throw exception
assertThrows(IllegalArgumentException.class, () -> context.getDatabase());
// Subsequent access should rethrow same exception
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> context.getTable());
assertTrue(ex.getMessage().contains("Cannot get split"));
}
@Test
public void testValidTableIdFormats() {
// Test "db", "db.table", "db.schema.table" formats
// ...
}
@Test
public void testTablePathResolutionLazy() {
ZetaUDFContext context = new ZetaUDFContext();
SeaTunnelRow row = new SeaTunnelRow(new Object[0]);
row.setTableId("db.table");
context.update(row.getFields(), row);
// tablePathResolved should be false before getDatabase() is accessed
// ...
}
}
```
**Rationale**:
- Unit tests are insurance for code quality
- Verifies edge cases and exception handling
- Provides documentation for future maintenance
- Apache top-level projects should have adequate test coverage
---
### Issue 5: closeUDFs may swallow exceptions during openUDFs failure rollback
**Location**: `seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLEngine.java:114-120`
```java
try {
udf.open();
} catch (Exception e) {
closeUDFs(i - 1); // Try to close already opened UDF
throw new TransformException(
CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION,
String.format("Open udf %s failed: %s", udf.functionName(), e.getMessage()));
}
```
**Related Context**:
- Caller: `ZetaSQLEngine.java:98` (`init()` method)
- Related method: `ZetaSQLEngine.java:351-359` (`closeUDFs`)
**Problem Description**:
When `udf.open()` throws an exception:
1. Calls `closeUDFs(i - 1)` to close previously opened UDFs in reverse order
2. `close()` exceptions inside `closeUDFs` are swallowed (only logs `warn`)
3. If `close()` of multiple UDFs also fails, only the last exception will be retained in `TransformException`
4. Other `close()` failure exceptions will be swallowed
**Potential Risks**:
- Resource cleanup failures are silently swallowed
- Users cannot diagnose why resources are not released
- May lead to file handle/connection leaks
**Impact Scope**:
- Direct impact: Error diagnosis when `open()` fails
- Indirect impact: Resource management and troubleshooting
- Affected area: SQL Transform (single Transform)
**Severity**: **MINOR**
**Improvement Suggestions**:
```java
// ZetaSQLEngine.java
private void openUDFs() {
List<Exception> closeErrors = new ArrayList<>();
for (int i = 0; i < udfList.size(); i++) {
ZetaUDF udf = udfList.get(i);
try {
udf.open();
} catch (Exception e) {
// Collect all exceptions when closing
closeUDFs(i - 1, closeErrors);
// Build detailed error message
String errorMsg = String.format(
"Open udf %s failed: %s. UDFs [%s] were closed, with %d close errors",
udf.functionName(),
e.getMessage(),
describeUdfRange(0, i - 1),
closeErrors.size());
throw new TransformException(
CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION, errorMsg);
}
}
}
private void closeUDFs(int lastIndex, List<Exception> errors) {
for (int i = lastIndex; i >= 0; i--) {
try {
udfList.get(i).close();
} catch (Exception e) {
log.error("Close udf {} failed during rollback",
udfList.get(i).functionName(), e);
if (errors != null) {
errors.add(e);
}
}
}
}
private String describeUdfRange(int start, int end) {
return udfList.subList(start, end + 1).stream()
.map(ZetaUDF::functionName)
.collect(Collectors.joining(", "));
}
```
**Rationale**:
- Preserve all exception information for diagnosis
- Detailed error messages help users understand what happened
- Use `log.error` instead of `log.warn` (error rather than warning)
- `closeUDFs` maintains backward compatibility (`errors` parameter can be `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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on code in PR #10489:
URL: https://github.com/apache/seatunnel/pull/10489#discussion_r2883973576
##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaUDFContext.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.seatunnel.transform.sql.zeta;
+
+import org.apache.seatunnel.api.table.catalog.TablePath;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+
+import javax.annotation.Nullable;
+
+/** Runtime context for zeta udf execution. */
+public class ZetaUDFContext {
+ private static final Object[] EMPTY_FIELDS = new Object[0];
+
+ @Nullable private String rawTableId;
+ private boolean tableIdIsNull;
+ @Nullable private String database;
+ @Nullable private String schema;
+ @Nullable private String table;
+ @Nullable private IllegalArgumentException tablePathParseException;
+ private boolean tablePathResolved;
+ private RowKind rowKind = RowKind.INSERT;
+ private Object[] allFields = EMPTY_FIELDS;
+
+ public ZetaUDFContext update(SeaTunnelRow row) {
+ return update(row.getFields(), row);
+ }
+
+ public ZetaUDFContext update(Object[] fields, SeaTunnelRow row) {
+ this.allFields = fields == null ? EMPTY_FIELDS : fields;
+ this.rowKind = row.getRowKind();
+ updateTableId(row.getTableId());
+ return this;
+ }
+
+ private void updateTableId(String tableId) {
+ this.rawTableId = tableId;
Review Comment:
```suggestion
if (Objects.equals(this.rawTableId, tableId)) { return;
}
this.rawTableId = tableId;
```
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
Posted by "CosmosNi (via GitHub)" <gi...@apache.org>.
CosmosNi commented on PR #10489:
URL: https://github.com/apache/seatunnel/pull/10489#issuecomment-4010728977
> 好工作。 @CosmosNi请解决评论问题@DanielCarter-stack `### Issue 1: UDF state not restored after Checkpoint` 这是合并前的问题
UDF state is not lost. Since sqlEngine is transient, it becomes null after checkpoint restore. The tryOpen() method detects this and creates a new SQLEngine instance via open(), which calls init() → loadUDFs() → openUDFs(), properly reinitializing all transient resources like CryptoClient.
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on PR #10489:
URL: https://github.com/apache/seatunnel/pull/10489#issuecomment-3900314011
Good job.
This enables more complex UDFs that need to maintain state or adapt behavior based on the input row context.
And I found some issues need to be addressed:
### Finding 1 — Opening all discovered UDFs at init time
- Severity: **High**
- Description:
- Engine calls `open()` for every UDF discovered via SPI, regardless of whether it is referenced in the SQL.
- References:
- ZetaSQLEngine.init -> openUDFs(): seatunnel-transforms-v2/.../ZetaSQLEngine.java#L91-L99
- openUDFs implementation: seatunnel-transforms-v2/.../ZetaSQLEngine.java#L108-L125
- Risk:
- Startup latency grows with number/complexity of UDFs
- Job can fail due to unrelated UDF initialization failures
- In cluster mode, this amplifies by parallelism (multiple JVMs)
- Best improvement:
- Only `open()` UDFs that are actually referenced by the parsed SQL AST (collect function names from the statement).
- Alternative: lazy-open the UDF on first use, with a per-UDF open state (and thread-safety / idempotency).
### Finding 2 — Open failure drops exception cause
- Severity: **Medium**
- Description:
- On `udf.open()` failure, the thrown exception includes only `e.getMessage()`.
- Reference:
- seatunnel-transforms-v2/.../ZetaSQLEngine.java#L111-L121
- Risk:
- Production troubleshooting becomes difficult (no stack trace / root cause)
- Best improvement:
- Preserve the cause when throwing `TransformException` (or log the full exception with stack trace before throwing).
### Finding 3 — Mutable fields array exposed via context
- Severity: **Low to Medium**
- Description:
- `getAllFields()` returns the original `Object[]`.
- References:
- seatunnel-transforms-v2/.../ZetaUDFContext.java#L44-L50
- seatunnel-transforms-v2/.../ZetaUDFContext.java#L108-L110
- Risk:
- A buggy UDF could mutate the array and affect later expressions / outputs.
- Best improvement:
- Document `allFields` as read-only, or provide safer APIs (`getField(int)`), or return a defensive copy (performance tradeoff).
### Finding 4 — Test coverage relies on E2E only, Please add UT for this PR
- Severity: **Medium**
- Description:
- E2E exists, but unit tests are missing for key branching and lifecycle semantics.
- Reference: seatunnel-e2e/.../ExampleUdfIT.java#L47-L52
- Risk:
- Slower feedback loops; regressions harder to pinpoint.
- Best improvement:
- Add unit tests in `seatunnel-transforms-v2` to validate routing and lifecycle behavior.
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on code in PR #10489:
URL: https://github.com/apache/seatunnel/pull/10489#discussion_r2883973576
##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaUDFContext.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.seatunnel.transform.sql.zeta;
+
+import org.apache.seatunnel.api.table.catalog.TablePath;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+
+import javax.annotation.Nullable;
+
+/** Runtime context for zeta udf execution. */
+public class ZetaUDFContext {
+ private static final Object[] EMPTY_FIELDS = new Object[0];
+
+ @Nullable private String rawTableId;
+ private boolean tableIdIsNull;
+ @Nullable private String database;
+ @Nullable private String schema;
+ @Nullable private String table;
+ @Nullable private IllegalArgumentException tablePathParseException;
+ private boolean tablePathResolved;
+ private RowKind rowKind = RowKind.INSERT;
+ private Object[] allFields = EMPTY_FIELDS;
+
+ public ZetaUDFContext update(SeaTunnelRow row) {
+ return update(row.getFields(), row);
+ }
+
+ public ZetaUDFContext update(Object[] fields, SeaTunnelRow row) {
+ this.allFields = fields == null ? EMPTY_FIELDS : fields;
+ this.rowKind = row.getRowKind();
+ updateTableId(row.getTableId());
+ return this;
+ }
+
+ private void updateTableId(String tableId) {
+ this.rawTableId = tableId;
Review Comment:
```suggestion
if (Objects.equals(this.rawTableId, tableId)) {
return;
}
this.rawTableId = tableId;
```
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on code in PR #10489:
URL: https://github.com/apache/seatunnel/pull/10489#discussion_r2883952400
##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLEngine.java:
##########
@@ -84,15 +87,37 @@ public void init(
this.inputRowType = inputRowType;
this.sql = sql;
- List<ZetaUDF> udfList = new ArrayList<>();
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- ServiceLoader.load(ZetaUDF.class, classLoader).forEach(udfList::add);
+ udfList = loadUDFs();
+ udfContext = new ZetaUDFContext();
this.zetaSQLType = new ZetaSQLType(inputRowType, udfList);
- this.zetaSQLFunction = new ZetaSQLFunction(inputRowType, zetaSQLType, udfList);
+ this.zetaSQLFunction = new ZetaSQLFunction(inputRowType, zetaSQLType, udfList, udfContext);
this.zetaSQLFilter = new ZetaSQLFilter(zetaSQLFunction, zetaSQLType);
parseSQL();
+ openUDFs();
+ }
+
+ protected List<ZetaUDF> loadUDFs() {
+ List<ZetaUDF> loadedUdfs = new ArrayList<>();
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ServiceLoader.load(ZetaUDF.class, classLoader).forEach(loadedUdfs::add);
+ return loadedUdfs;
+ }
+
+ private void openUDFs() {
+ for (int i = 0; i < udfList.size(); i++) {
+ ZetaUDF udf = udfList.get(i);
+ try {
+ udf.open();
+ } catch (Exception e) {
+ closeUDFs(i - 1);
Review Comment:
```suggestion
closeUDFs(i - 1);
log.error("Open udf {} failed", udf.functionName(), e);
```
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Transform] Add Zeta SQL UDF context and lifecycle hooks with e2e/docs updates [seatunnel]
Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on PR #10489:
URL: https://github.com/apache/seatunnel/pull/10489#issuecomment-3997789126
Good job.
@CosmosNi please solve the review from @DanielCarter-stack `### Issue 1: UDF state not restored after Checkpoint`
This is a problem before merged
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org