You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "luoyuxia (via GitHub)" <gi...@apache.org> on 2023/06/29 11:56:31 UTC
[GitHub] [flink] luoyuxia opened a new pull request, #22904: [FLINK-32352][table] Support type inference for procedure
luoyuxia opened a new pull request, #22904:
URL: https://github.com/apache/flink/pull/22904
<!--
*Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. 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.*
*Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- 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. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
*(For example: This pull request makes task deployment go through the blob server, rather than through RPC. That way we avoid re-transferring them on each deployment (during recovery).)*
## Brief change log
*(for example:)*
- *The TaskInfo is stored in the blob store on job creation time as a persistent artifact*
- *Deployments RPC transmits only the blob storage reference*
- *TaskManagers retrieve the TaskInfo from the blob cache*
## Verifying this change
Please make sure both new and modified tests in this PR follows the conventions defined in our code quality guide: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
*(Please pick either of the following options)*
This change is a trivial rework / code cleanup without any test coverage.
*(or)*
This change is already covered by existing tests, such as *(please describe tests)*.
*(or)*
This change added tests and can be verified as follows:
*(example:)*
- *Added integration tests for end-to-end deployment with large payloads (100MB)*
- *Extended integration test for recovery after master (JobManager) failure*
- *Added test that validates that TaskInfo is transferred only once across recoveries*
- *Manually verified the change by running a 4 node cluster with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.*
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (yes / no)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / no)
- The serializers: (yes / no / don't know)
- The runtime per-record code paths (performance sensitive): (yes / no / don't know)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
- The S3 file system connector: (yes / no / don't know)
## Documentation
- Does this pull request introduce a new feature? (yes / no)
- If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] LadyForest commented on a diff in pull request #22904: [FLINK-32352][table] Support type inference for procedure
Posted by "LadyForest (via GitHub)" <gi...@apache.org>.
LadyForest commented on code in PR #22904:
URL: https://github.com/apache/flink/pull/22904#discussion_r1247340442
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/procedures/ProcedureDefinition.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.flink.table.procedures;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.catalog.DataTypeFactory;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.functions.FunctionKind;
+import org.apache.flink.table.types.extraction.TypeInferenceExtractor;
+import org.apache.flink.table.types.inference.TypeInference;
+
+/**
+ * Definition of a procedure. We consider procedure as a kind of function, so make it implement
+ * {@link FunctionDefinition}.
+ */
+@Internal
+public class ProcedureDefinition implements FunctionDefinition {
+
+ // the name for the methods to be involved in the procedure
Review Comment:
```suggestion
/** the name for the methods to be involved in the procedure. */
```
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java:
##########
@@ -143,6 +145,27 @@ public static TypeInference forAsyncTableFunction(
return extractTypeInference(mappingExtractor);
}
+ public static TypeInference forProcedure(
+ DataTypeFactory typeFactory, Class<? extends Procedure> procedure) {
+ final ProcedureMappingExtractor mappingExtractor =
+ new ProcedureMappingExtractor(
+ typeFactory,
+ procedure,
+ ProcedureDefinition.PROCEDURE_CALL,
+ ProcedureMappingExtractor.createParameterSignatureExtraction(1),
+ ProcedureMappingExtractor.createReturnTypeResultExtraction(),
+ ProcedureMappingExtractor.createParameterAndReturnTypeVerification());
+ try {
+ return extractTypeInferenceOrError(mappingExtractor);
+ } catch (Throwable t) {
+ throw extractionError(
+ t,
+ "Could not extract a valid type inference for procedure class '%s'. "
+ + "Please check for implementation mistakes and/or provide a corresponding hint.",
+ mappingExtractor.getFunctionClass().getName());
+ }
+ }
Review Comment:
This snippet looks very similar to `extractTypeInference`.
Can we extract a common method here? like
`private static TypeInference extractTypeInference(BaseMappingExtractor mappingExtractor)`
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java:
##########
@@ -143,6 +145,27 @@ public static TypeInference forAsyncTableFunction(
return extractTypeInference(mappingExtractor);
}
+ public static TypeInference forProcedure(
Review Comment:
Nit: add Javadoc
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] LadyForest commented on a diff in pull request #22904: [FLINK-32481][table] Support type inference for procedure
Posted by "LadyForest (via GitHub)" <gi...@apache.org>.
LadyForest commented on code in PR #22904:
URL: https://github.com/apache/flink/pull/22904#discussion_r1259336884
##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/extraction/TypeInferenceExtractorTest.java:
##########
@@ -577,6 +839,18 @@ static TestSpec forTableAggregateFunction(
new DataTypeFactoryMock(), function));
}
+ static TestSpec forProcedure(Class<? extends Procedure> procedure) {
+ return forProcedure(null, procedure);
+ }
+
+ static TestSpec forProcedure(String description, Class<? extends Procedure> procedure) {
Review Comment:
Nit: add `@Nullable` annotation
##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/extraction/TypeInferenceExtractorTest.java:
##########
@@ -927,4 +1201,238 @@ private static class DataTypeHintOnScalarFunction extends ScalarFunction {
return null;
}
}
+
+ @ProcedureHint(
+ input = {@DataTypeHint("INT"), @DataTypeHint("STRING")},
+ argumentNames = {"i", "s"},
+ output = @DataTypeHint("BOOLEAN"))
+ private static class FullProcedureHint implements Procedure {
+ public Boolean[] call(Object procedureContext, Integer i, String s) {
+ return null;
+ }
+ }
+
+ private static class ComplexProcedureHint implements Procedure {
+ @ProcedureHint(
+ input = {@DataTypeHint("ARRAY<INT>"), @DataTypeHint(inputGroup = InputGroup.ANY)},
+ argumentNames = {"myInt", "myAny"},
+ output = @DataTypeHint("BOOLEAN"),
+ isVarArgs = true)
+ public Boolean[] call(Object procedureContext, Object... o) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(input = @DataTypeHint("INT"), output = @DataTypeHint("INT"))
+ @ProcedureHint(input = @DataTypeHint("BIGINT"), output = @DataTypeHint("BIGINT"))
+ private static class FullProcedureHints implements Procedure {
+ public Number[] call(Object procedureContext, Number n) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(output = @DataTypeHint("INT"))
+ private static class GlobalOutputProcedureHint implements Procedure {
+ @ProcedureHint(input = @DataTypeHint("INT"))
+ public Integer[] call(Object procedureContext, Integer n) {
+ return null;
+ }
+
+ @ProcedureHint(input = @DataTypeHint("STRING"))
+ public Integer[] call(Object procedureContext, String n) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(output = @DataTypeHint("INT"))
+ private static class InvalidSingleOutputProcedureHint implements Procedure {
+ @ProcedureHint(output = @DataTypeHint("TINYINT"))
+ public Integer call(Object procedureContext, Number n) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(input = @DataTypeHint("INT"), output = @DataTypeHint("INT"))
+ private static class SplitFullProcedureHints implements Procedure {
+ @ProcedureHint(input = @DataTypeHint("BIGINT"), output = @DataTypeHint("BIGINT"))
+ public Number[] call(Object procedureContext, Number n) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(input = @DataTypeHint("INT"), output = @DataTypeHint("INT"))
+ private static class InvalidFullOutputProcedureHint implements Procedure {
+ @ProcedureHint(input = @DataTypeHint("INT"), output = @DataTypeHint("BIGINT"))
+ public Number[] call(Object procedureContext, Integer i) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(input = @DataTypeHint("INT"), argumentNames = "a", output = @DataTypeHint("INT"))
+ private static class InvalidFullOutputProcedureWithArgNamesHint implements Procedure {
+ @ProcedureHint(
+ input = @DataTypeHint("INT"),
+ argumentNames = "b",
+ output = @DataTypeHint("BIGINT"))
+ public Number[] call(Object procedureContext, Integer i) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(input = @DataTypeHint("INT"))
+ private static class InvalidLocalOutputProcedureHint implements Procedure {
+ @ProcedureHint(output = @DataTypeHint("INT"))
+ public Integer[] call(Object procedureContext, Integer n) {
+ return null;
+ }
+
+ @ProcedureHint(output = @DataTypeHint("STRING"))
+ public Integer[] call(Object procedureContext, String n) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(
+ input = {@DataTypeHint("INT"), @DataTypeHint()},
+ output = @DataTypeHint("BOOLEAN"))
+ private static class IncompleteProcedureHint implements Procedure {
+ public Boolean[] call(Object procedureContext, Integer i1, Integer i2) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(input = @DataTypeHint("INT"))
+ @ProcedureHint(input = @DataTypeHint("BIGINT"))
+ private static class GlobalInputProcedureHints implements Procedure {
+ @ProcedureHint(output = @DataTypeHint("INT"))
+ public Integer[] call(Object procedureContext, Number n) {
+ return null;
+ }
+ }
+
+ private static class ZeroArgProcedure implements Procedure {
+ public Integer[] call(Object procedureContext) {
+ return null;
+ }
+ }
+
+ private static class MixedArgProcedure implements Procedure {
+ public Integer[] call(Object procedureContext, int i, Double d) {
+ return null;
+ }
+ }
+
+ private static class OverloadedProcedure implements Procedure {
+ public Integer[] call(Object procedureContext, int i, Double d) {
+ return null;
+ }
+
+ public long[] call(Object procedureContext, String s) {
+ return null;
+ }
+ }
+
+ private static class VarArgProcedure implements Procedure {
+ public String[] call(Object procedureContext, int i, int... more) {
+ return null;
+ }
+ }
+
+ private static class VarArgWithByteProcedure implements Procedure {
+ public String[] call(Object procedureContext, byte... bytes) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(output = @DataTypeHint("INT"))
+ private static class ExtractWithOutputHintProcedure implements Procedure {
+ public Object[] call(Object procedureContext, Integer i) {
+ return null;
+ }
+ }
+
+ @ProcedureHint(
+ input = {@DataTypeHint("INT"), @DataTypeHint("BOOLEAN")},
+ argumentNames = {"i", "b"})
+ private static class ExtractWithInputHintProcedure implements Procedure {
+ public double[] call(Object procedureContext, Object... o) {
+ return new double[] {0.0};
+ }
+ }
+
+ @ProcedureHint(output = @DataTypeHint("STRING"))
+ private static class InvalidMethodProcedure implements Procedure {
+ public Long[] call(Object procedureContext, int[] i) {
+ return null;
+ }
+ }
+
+ private static class NamedArgumentsProcedure implements Procedure {
+ public Integer[] call(Object procedureContext, int n) {
+ return null;
+ }
+
+ public Integer[] call(Object procedureContext, long n) {
+ return null;
+ }
+
+ public Integer[] call(Object procedureContext, @DataTypeHint("DECIMAL(10, 2)") Object n) {
+ return null;
+ }
+ }
+
+ private static class InputGroupProcedure implements Procedure {
+ public String[] call(
+ Object procedureContext, @DataTypeHint(inputGroup = InputGroup.ANY) Object o) {
+ return null;
+ }
+ }
+
+ private static class VarArgInputGroupProcedure implements Procedure {
+ public String[] call(
+ Object procedureContext, @DataTypeHint(inputGroup = InputGroup.ANY) Object... o) {
+ return null;
+ }
+ }
+
+ // extracted order is f(INT) || f(BIGINT) due to method signature sorting
+ private static class OrderedProcedure implements Procedure {
+ public Long[] call(Object procedureContext, Long l) {
+ return null;
+ }
+
+ public Integer[] call(Object procedureContext, Integer i) {
+ return null;
+ }
+ }
+
+ // extracted order is f(BIGINT) || f(INT)
+ @ProcedureHint(input = @DataTypeHint("BIGINT"), output = @DataTypeHint("BIGINT"))
+ @ProcedureHint(input = @DataTypeHint("INT"), output = @DataTypeHint("INT"))
+ private static class OrderedProcedure2 implements Procedure {
+ public Number[] call(Object procedureContext, Number n) {
+ return null;
+ }
+ }
+
+ // extracted order is f(BIGINT) || f(INT)
+ private static class OrderedProcedure3 implements Procedure {
+ @ProcedureHint(input = @DataTypeHint("BIGINT"), output = @DataTypeHint("BIGINT"))
+ @ProcedureHint(input = @DataTypeHint("INT"), output = @DataTypeHint("INT"))
+ public Number[] call(Object procedureContext, Number n) {
+ return null;
+ }
+ }
+
+ private static class DataTypeHintOnProcedure implements Procedure {
+ public @DataTypeHint("ROW<i INT>") RowData[] call(Object procedureContext) {
+ return null;
+ }
+ }
+
+ private static class MissMethodProcedure implements Procedure {
Review Comment:
Nit: `MissingMethodPrecedure`
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java:
##########
@@ -133,10 +149,19 @@ private static class DefaultAnnotationHelper {
// no implementation
}
+ @ProcedureHint
Review Comment:
Maybe we can simplify the changes like
```java
Index: flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java (revision 0dae399acf5aaf04cdc3cfddada4a7b38d7f2395)
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java (date 1689241074609)
@@ -26,6 +26,7 @@
import javax.annotation.Nullable;
+import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Function;
@@ -42,8 +43,6 @@
@Internal
final class FunctionTemplate {
- private static final FunctionHint DEFAULT_ANNOTATION = getDefaultAnnotation();
-
private final @Nullable FunctionSignatureTemplate signatureTemplate;
private final @Nullable FunctionResultTemplate accumulatorTemplate;
@@ -144,35 +143,27 @@
// --------------------------------------------------------------------------------------------
+ @ProcedureHint
@FunctionHint
private static class DefaultAnnotationHelper {
// no implementation
}
- @ProcedureHint
- private static class DefaultProcedureAnnotationHelper {
- // no implementation
- }
-
- private static FunctionHint getDefaultAnnotation() {
- return DefaultAnnotationHelper.class.getAnnotation(FunctionHint.class);
- }
-
- private static ProcedureHint getDefaultProcedureHintAnnotation() {
- return DefaultProcedureAnnotationHelper.class.getAnnotation(ProcedureHint.class);
+ private static <H extends Annotation> H getDefaultAnnotation(Class<H> hClass) {
+ return DefaultAnnotationHelper.class.getAnnotation(hClass);
}
private static <T> T defaultAsNull(FunctionHint hint, Function<FunctionHint, T> accessor) {
- final T defaultValue = accessor.apply(DEFAULT_ANNOTATION);
- final T actualValue = accessor.apply(hint);
- if (Objects.deepEquals(defaultValue, actualValue)) {
- return null;
- }
- return actualValue;
+ return defaultAsNull(hint, getDefaultAnnotation(FunctionHint.class), accessor);
}
private static <T> T defaultAsNull(ProcedureHint hint, Function<ProcedureHint, T> accessor) {
- final T defaultValue = accessor.apply(getDefaultProcedureHintAnnotation());
+ return defaultAsNull(hint, getDefaultAnnotation(ProcedureHint.class), accessor);
+ }
+
+ private static <T, H extends Annotation> T defaultAsNull(
+ H hint, H defaultHint, Function<H, T> accessor) {
+ final T defaultValue = accessor.apply(defaultHint);
final T actualValue = accessor.apply(hint);
if (Objects.deepEquals(defaultValue, actualValue)) {
return null;
```
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java:
##########
@@ -69,6 +85,21 @@ static Set<FunctionTemplate> asFunctionTemplates(
.collect(Collectors.toCollection(LinkedHashSet::new));
}
+ /** Converts {@link ProcedureHint}s to {@link FunctionTemplate}. */
+ static Set<FunctionTemplate> asFunctionTemplatesForProcedure(
+ DataTypeFactory typeFactory, Set<ProcedureHint> hints) {
+ return hints.stream()
+ .map(
+ hint -> {
+ try {
+ return FunctionTemplate.fromAnnotation(typeFactory, hint);
+ } catch (Throwable t) {
+ throw extractionError(t, "Error in function hint annotation.");
Review Comment:
Nit: Error in procedure hint annotation
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java:
##########
@@ -0,0 +1,433 @@
+/*
+ * 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.flink.table.types.extraction;
+
+import org.apache.flink.table.annotation.DataTypeHint;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.DataTypeFactory;
+import org.apache.flink.table.functions.UserDefinedFunction;
+import org.apache.flink.table.procedures.Procedure;
+import org.apache.flink.table.types.CollectionDataType;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+import static org.apache.flink.table.types.extraction.ExtractionUtils.createMethodSignatureString;
+import static org.apache.flink.table.types.extraction.ExtractionUtils.extractionError;
+import static org.apache.flink.table.types.extraction.TemplateUtils.findInputOnlyTemplates;
+import static org.apache.flink.table.types.extraction.TemplateUtils.findResultMappingTemplates;
+import static org.apache.flink.table.types.extraction.TemplateUtils.findResultOnlyTemplate;
+import static org.apache.flink.table.types.extraction.TemplateUtils.findResultOnlyTemplates;
+
+/**
+ * Base utility for extracting function/procedure mappings from signature to result, e.g. from (INT,
+ * STRING) to BOOLEAN.
+ *
+ * <p>It can not only be used for {@link UserDefinedFunction}, but also for {@link Procedure} which
+ * is almost same to {@link UserDefinedFunction} with regarding to extracting the mapping from
Review Comment:
Nit: either use `is almost same to {@link UserDefinedFunction} with regard to extracting ...` or `is almost same to {@link UserDefinedFunction} regarding extracting ...`
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java:
##########
@@ -146,6 +171,15 @@ private static <T> T defaultAsNull(FunctionHint hint, Function<FunctionHint, T>
return actualValue;
}
+ private static <T> T defaultAsNull(ProcedureHint hint, Function<ProcedureHint, T> accessor) {
+ final T defaultValue = accessor.apply(getDefaultProcedureHintAnnotation());
+ final T actualValue = accessor.apply(hint);
+ if (Objects.deepEquals(defaultValue, actualValue)) {
+ return null;
+ }
+ return actualValue;
+ }
+
Review Comment:
Nit: What about
```java
private static <T> T defaultAsNull(FunctionHint hint, Function<FunctionHint, T> accessor) {
return defaultAsNull(hint, DEFAULT_ANNOTATION, accessor);
}
private static <T> T defaultAsNull(ProcedureHint hint, Function<ProcedureHint, T> accessor) {
return defaultAsNull(hint, getDefaultProcedureHintAnnotation(), accessor);
}
private static <T, H> T defaultAsNull(H hint, H defaultHint, Function<H, T> accessor) {
final T defaultValue = accessor.apply(defaultHint);
final T actualValue = accessor.apply(hint);
if (Objects.deepEquals(defaultValue, actualValue)) {
return null;
}
return actualValue;
}
``
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #22904: [FLINK-32352][table] Support type inference for procedure
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #22904:
URL: https://github.com/apache/flink/pull/22904#issuecomment-1613030959
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "19a186cec0b290ad0b5b6e5dea7b20d97c3bd92b",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "19a186cec0b290ad0b5b6e5dea7b20d97c3bd92b",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 19a186cec0b290ad0b5b6e5dea7b20d97c3bd92b UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on a diff in pull request #22904: [FLINK-32352][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #22904:
URL: https://github.com/apache/flink/pull/22904#discussion_r1250482173
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java:
##########
@@ -143,6 +145,27 @@ public static TypeInference forAsyncTableFunction(
return extractTypeInference(mappingExtractor);
}
+ public static TypeInference forProcedure(
+ DataTypeFactory typeFactory, Class<? extends Procedure> procedure) {
+ final ProcedureMappingExtractor mappingExtractor =
+ new ProcedureMappingExtractor(
+ typeFactory,
+ procedure,
+ ProcedureDefinition.PROCEDURE_CALL,
+ ProcedureMappingExtractor.createParameterSignatureExtraction(1),
+ ProcedureMappingExtractor.createReturnTypeResultExtraction(),
+ ProcedureMappingExtractor.createParameterAndReturnTypeVerification());
+ try {
+ return extractTypeInferenceOrError(mappingExtractor);
+ } catch (Throwable t) {
+ throw extractionError(
+ t,
+ "Could not extract a valid type inference for procedure class '%s'. "
+ + "Please check for implementation mistakes and/or provide a corresponding hint.",
+ mappingExtractor.getFunctionClass().getName());
+ }
+ }
Review Comment:
Good suggestion.
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on a diff in pull request #22904: [FLINK-32352][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #22904:
URL: https://github.com/apache/flink/pull/22904#discussion_r1250497777
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java:
##########
@@ -143,6 +145,27 @@ public static TypeInference forAsyncTableFunction(
return extractTypeInference(mappingExtractor);
}
+ public static TypeInference forProcedure(
+ DataTypeFactory typeFactory, Class<? extends Procedure> procedure) {
+ final ProcedureMappingExtractor mappingExtractor =
+ new ProcedureMappingExtractor(
+ typeFactory,
+ procedure,
+ ProcedureDefinition.PROCEDURE_CALL,
+ ProcedureMappingExtractor.createParameterSignatureExtraction(1),
+ ProcedureMappingExtractor.createReturnTypeResultExtraction(),
+ ProcedureMappingExtractor.createParameterAndReturnTypeVerification());
+ try {
+ return extractTypeInferenceOrError(mappingExtractor);
+ } catch (Throwable t) {
+ throw extractionError(
+ t,
+ "Could not extract a valid type inference for procedure class '%s'. "
+ + "Please check for implementation mistakes and/or provide a corresponding hint.",
+ mappingExtractor.getFunctionClass().getName());
+ }
+ }
Review Comment:
Good suggestion. But it may be not as so good to extract a common method considering we also want to throw the exception that it's an error in type inference for procedure or function. If a common method is extracted, we may need to use if/else or another flag to mark it which I think is not as so good.
But I would like to extract this snippet to a method to follow the style of type inference for function.
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] LadyForest commented on a diff in pull request #22904: [FLINK-32481][table] Support type inference for procedure
Posted by "LadyForest (via GitHub)" <gi...@apache.org>.
LadyForest commented on code in PR #22904:
URL: https://github.com/apache/flink/pull/22904#discussion_r1262153293
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java:
##########
@@ -146,6 +171,15 @@ private static <T> T defaultAsNull(FunctionHint hint, Function<FunctionHint, T>
return actualValue;
}
+ private static <T> T defaultAsNull(ProcedureHint hint, Function<ProcedureHint, T> accessor) {
+ final T defaultValue = accessor.apply(getDefaultProcedureHintAnnotation());
+ final T actualValue = accessor.apply(hint);
+ if (Objects.deepEquals(defaultValue, actualValue)) {
+ return null;
+ }
+ return actualValue;
+ }
+
Review Comment:
Nit: What about
```java
private static <T> T defaultAsNull(FunctionHint hint, Function<FunctionHint, T> accessor) {
return defaultAsNull(hint, DEFAULT_ANNOTATION, accessor);
}
private static <T> T defaultAsNull(ProcedureHint hint, Function<ProcedureHint, T> accessor) {
return defaultAsNull(hint, getDefaultProcedureHintAnnotation(), accessor);
}
private static <T, H> T defaultAsNull(H hint, H defaultHint, Function<H, T> accessor) {
final T defaultValue = accessor.apply(defaultHint);
final T actualValue = accessor.apply(hint);
if (Objects.deepEquals(defaultValue, actualValue)) {
return null;
}
return actualValue;
}
``
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on pull request #22904: [FLINK-32481][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #22904:
URL: https://github.com/apache/flink/pull/22904#issuecomment-1633962951
@LadyForest Thanks for your reviewing. I have addressed your comment in this [commit](https://github.com/apache/flink/pull/22904/commits/35a62a159cd1fa45aaa250218f013cd43d8d31d1).
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on a diff in pull request #22904: [FLINK-32481][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #22904:
URL: https://github.com/apache/flink/pull/22904#discussion_r1262339392
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java:
##########
@@ -133,10 +149,19 @@ private static class DefaultAnnotationHelper {
// no implementation
}
+ @ProcedureHint
Review Comment:
Thanks for the sugeestion. I like it.
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on a diff in pull request #22904: [FLINK-32352][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #22904:
URL: https://github.com/apache/flink/pull/22904#discussion_r1250482173
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java:
##########
@@ -143,6 +145,27 @@ public static TypeInference forAsyncTableFunction(
return extractTypeInference(mappingExtractor);
}
+ public static TypeInference forProcedure(
+ DataTypeFactory typeFactory, Class<? extends Procedure> procedure) {
+ final ProcedureMappingExtractor mappingExtractor =
+ new ProcedureMappingExtractor(
+ typeFactory,
+ procedure,
+ ProcedureDefinition.PROCEDURE_CALL,
+ ProcedureMappingExtractor.createParameterSignatureExtraction(1),
+ ProcedureMappingExtractor.createReturnTypeResultExtraction(),
+ ProcedureMappingExtractor.createParameterAndReturnTypeVerification());
+ try {
+ return extractTypeInferenceOrError(mappingExtractor);
+ } catch (Throwable t) {
+ throw extractionError(
+ t,
+ "Could not extract a valid type inference for procedure class '%s'. "
+ + "Please check for implementation mistakes and/or provide a corresponding hint.",
+ mappingExtractor.getFunctionClass().getName());
+ }
+ }
Review Comment:
Good suggestion.
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on pull request #22904: [FLINK-32352][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #22904:
URL: https://github.com/apache/flink/pull/22904#issuecomment-1613979655
@flinkbot run azure
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on pull request #22904: [FLINK-32481][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #22904:
URL: https://github.com/apache/flink/pull/22904#issuecomment-1635130068
@LadyForest Thanks for reviewing. Merging...
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia merged pull request #22904: [FLINK-32481][table] Support type inference for procedure
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia merged PR #22904:
URL: https://github.com/apache/flink/pull/22904
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org