Skip to content

Commit f2281e5

Browse files
春栖春栖
authored andcommitted
fix empty generated expression script
1 parent 1d48d38 commit f2281e5

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/operators/transform/TransformExpressionCompiler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,17 @@ public static TransformExpressionEvaluator compileExpression(
7676
// Result type
7777
scriptEvaluator.setReturnType(key.getReturnClass());
7878

79+
String fullScript = key.getFullScript();
7980
if (LOG.isDebugEnabled()) {
80-
LOG.debug("Going to evaluate script: {}", key.getFullScript());
81+
LOG.debug("Going to evaluate script: {}", fullScript);
8182
LOG.debug(" - Argument names: {}", argumentNames);
8283
LOG.debug(" - Argument types: {}", argumentClasses);
8384
LOG.debug(" - Returns: {}", key.getReturnClass());
8485
}
8586

8687
try {
8788
// Compile
88-
scriptEvaluator.cook(key.getFullScript());
89+
scriptEvaluator.cook(fullScript);
8990
} catch (CompileException e) {
9091
throw new InvalidProgramException(
9192
String.format(

flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/operators/transform/TransformExpressionKey.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public String getCompiledScript() {
7878
}
7979

8080
public String getFullScript() {
81+
validateGeneratedExpression();
8182
return JaninoCompiler.loadSystemFunction(getCompiledScript());
8283
}
8384

@@ -97,6 +98,13 @@ public Map<String, String> getColumnNameMap() {
9798
return Collections.unmodifiableMap(columnNameMap);
9899
}
99100

101+
private void validateGeneratedExpression() {
102+
if (generatedExpression.getResultTerm().trim().isEmpty()) {
103+
throw new IllegalArgumentException(
104+
"Generated expression result term must not be empty.");
105+
}
106+
}
107+
100108
public static TransformExpressionKey of(
101109
@Nullable String originalExpression,
102110
String compiledExpression,

flink-cdc-runtime/src/test/java/org/apache/flink/cdc/runtime/parser/JaninoCompilerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.flink.cdc.common.types.variant.BinaryVariantInternalBuilder;
2525
import org.apache.flink.cdc.common.types.variant.Variant;
2626
import org.apache.flink.cdc.common.types.variant.VariantTypeException;
27+
import org.apache.flink.cdc.runtime.operators.transform.TransformExpressionKey;
2728

2829
import org.assertj.core.api.Assertions;
2930
import org.codehaus.commons.compiler.CompileException;
@@ -339,6 +340,22 @@ void testGeneratedLogicalExpressionCompilesWithJanino() throws Exception {
339340
.isNull();
340341
}
341342

343+
@Test
344+
void testTransformExpressionKeyRejectsEmptyResultTermForFullScript() {
345+
TransformExpressionKey key =
346+
TransformExpressionKey.of(
347+
null,
348+
GeneratedExpression.fromExpression("", Boolean.class),
349+
Collections.emptyList(),
350+
Collections.emptyList(),
351+
Collections.emptyMap());
352+
353+
Assertions.assertThatCode(key::toString).doesNotThrowAnyException();
354+
Assertions.assertThatThrownBy(key::getFullScript)
355+
.isExactlyInstanceOf(IllegalArgumentException.class)
356+
.hasMessage("Generated expression result term must not be empty.");
357+
}
358+
342359
@Test
343360
void testLargeNumericLiterals() {
344361
// Test parsing integer literals

0 commit comments

Comments
 (0)