|
21 | 21 | import org.apache.flink.annotation.Internal;
|
22 | 22 | import org.apache.flink.api.common.typeinfo.TypeInformation;
|
23 | 23 | import org.apache.flink.api.common.typeutils.CompositeType;
|
24 |
| -import org.apache.flink.table.api.DataTypes; |
25 | 24 | import org.apache.flink.table.api.TableException;
|
26 | 25 | import org.apache.flink.table.api.ValidationException;
|
27 | 26 | import org.apache.flink.table.catalog.DataTypeFactory;
|
|
51 | 50 | import org.apache.flink.table.types.inference.TypeStrategies;
|
52 | 51 | import org.apache.flink.table.types.logical.LogicalType;
|
53 | 52 | import org.apache.flink.table.types.utils.DataTypeUtils;
|
54 |
| -import org.apache.flink.util.Preconditions; |
55 | 53 |
|
56 | 54 | import javax.annotation.Nullable;
|
57 | 55 |
|
|
68 | 66 |
|
69 | 67 | import static java.util.Collections.singletonList;
|
70 | 68 | import static org.apache.flink.table.expressions.ApiExpressionUtils.isFunction;
|
| 69 | +import static org.apache.flink.table.expressions.ApiExpressionUtils.unresolvedCall; |
71 | 70 | import static org.apache.flink.table.expressions.ApiExpressionUtils.valueLiteral;
|
72 | 71 | import static org.apache.flink.table.types.logical.utils.LogicalTypeCasts.supportsAvoidingCast;
|
73 | 72 | import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.hasLegacyTypes;
|
@@ -302,8 +301,18 @@ private UnresolvedCallExpression executeAssignment(
|
302 | 301 | declaredArgs.forEach(
|
303 | 302 | declaredArg -> {
|
304 | 303 | if (declaredArg.isOptional()) {
|
| 304 | + // All optional arguments have a type. |
| 305 | + // This is checked in StaticArgument. |
| 306 | + final DataType dataType = |
| 307 | + declaredArg |
| 308 | + .getDataType() |
| 309 | + .orElseThrow(IllegalStateException::new); |
305 | 310 | namedArgs.putIfAbsent(
|
306 |
| - declaredArg.getName(), valueLiteral(null, DataTypes.NULL())); |
| 311 | + declaredArg.getName(), |
| 312 | + CallExpression.permanent( |
| 313 | + BuiltInFunctionDefinitions.DEFAULT, |
| 314 | + List.of(), |
| 315 | + dataType)); |
307 | 316 | }
|
308 | 317 | });
|
309 | 318 |
|
@@ -490,32 +499,32 @@ public boolean isArgumentLiteral(int pos) {
|
490 | 499 |
|
491 | 500 | @Override
|
492 | 501 | public boolean isArgumentNull(int pos) {
|
493 |
| - Preconditions.checkArgument( |
494 |
| - isArgumentLiteral(pos), "Argument at position %s is not a literal.", pos); |
495 | 502 | final ResolvedExpression arg = getArgument(pos);
|
496 |
| - // special case for type literals in Table API only |
497 |
| - if (arg instanceof TypeLiteralExpression) { |
498 |
| - return false; |
| 503 | + if (isFunction(arg, BuiltInFunctionDefinitions.DEFAULT)) { |
| 504 | + return true; |
| 505 | + } |
| 506 | + if (arg instanceof ValueLiteralExpression) { |
| 507 | + final ValueLiteralExpression literal = (ValueLiteralExpression) arg; |
| 508 | + return literal.isNull(); |
499 | 509 | }
|
500 |
| - final ValueLiteralExpression literal = (ValueLiteralExpression) getArgument(pos); |
501 |
| - return literal.isNull(); |
| 510 | + return false; |
502 | 511 | }
|
503 | 512 |
|
504 | 513 | @Override
|
505 | 514 | @SuppressWarnings("unchecked")
|
506 | 515 | public <T> Optional<T> getArgumentValue(int pos, Class<T> clazz) {
|
507 |
| - Preconditions.checkArgument( |
508 |
| - isArgumentLiteral(pos), "Argument at position %s is not a literal.", pos); |
509 | 516 | final ResolvedExpression arg = getArgument(pos);
|
510 |
| - // special case for type literals in Table API only |
511 | 517 | if (arg instanceof TypeLiteralExpression) {
|
512 | 518 | if (!DataType.class.isAssignableFrom(clazz)) {
|
513 | 519 | return Optional.empty();
|
514 | 520 | }
|
515 | 521 | return Optional.of((T) arg.getOutputDataType());
|
516 | 522 | }
|
517 |
| - final ValueLiteralExpression literal = (ValueLiteralExpression) getArgument(pos); |
518 |
| - return literal.getValueAs(clazz); |
| 523 | + if (arg instanceof ValueLiteralExpression) { |
| 524 | + final ValueLiteralExpression literal = (ValueLiteralExpression) arg; |
| 525 | + return literal.getValueAs(clazz); |
| 526 | + } |
| 527 | + return Optional.empty(); |
519 | 528 | }
|
520 | 529 |
|
521 | 530 | @Override
|
|
0 commit comments