forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-20437][table-planner-blink] Move the utility methods in ExecNo…
…de into ExecNodeUtil
- Loading branch information
Showing
25 changed files
with
158 additions
and
105 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...link/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/utils/ExecNodeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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:https://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.planner.plan.nodes.exec.utils; | ||
|
||
import org.apache.flink.api.common.typeinfo.TypeInformation; | ||
import org.apache.flink.api.dag.Transformation; | ||
import org.apache.flink.core.memory.ManagedMemoryUseCase; | ||
import org.apache.flink.streaming.api.operators.StreamOperatorFactory; | ||
import org.apache.flink.streaming.api.transformations.OneInputTransformation; | ||
import org.apache.flink.streaming.api.transformations.TwoInputTransformation; | ||
import org.apache.flink.table.api.TableException; | ||
import org.apache.flink.table.planner.plan.nodes.exec.ExecNode; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* An Utility class that helps translating {@link ExecNode} to {@link Transformation}. | ||
*/ | ||
public class ExecNodeUtil { | ||
|
||
/** | ||
* Set memoryBytes to {@link Transformation#declareManagedMemoryUseCaseAtOperatorScope(ManagedMemoryUseCase, int)}. | ||
*/ | ||
public static <T> Transformation<T> setManagedMemoryWeight( | ||
Transformation<T> transformation, | ||
long memoryBytes) { | ||
// Using Bytes can easily overflow | ||
// Using KibiBytes to cast to int | ||
// Careful about zero | ||
if (memoryBytes > 0) { | ||
int memoryKibiBytes = (int) Math.max(1, (memoryBytes >> 10)); | ||
Optional<Integer> previousWeight = transformation.declareManagedMemoryUseCaseAtOperatorScope( | ||
ManagedMemoryUseCase.BATCH_OP, memoryKibiBytes); | ||
if (previousWeight.isPresent()) { | ||
throw new TableException("Managed memory weight has been set, this should not happen."); | ||
} | ||
} | ||
return transformation; | ||
} | ||
|
||
/** | ||
* Create a {@link OneInputTransformation} with memoryBytes. | ||
*/ | ||
public static <T> OneInputTransformation<T, T> createOneInputTransformation( | ||
Transformation<T> input, | ||
String name, | ||
StreamOperatorFactory<T> operatorFactory, | ||
TypeInformation<T> outputType, | ||
int parallelism, | ||
long memoryBytes) { | ||
OneInputTransformation<T, T> transformation = new OneInputTransformation<>( | ||
input, name, operatorFactory, outputType, parallelism); | ||
setManagedMemoryWeight(transformation, memoryBytes); | ||
return transformation; | ||
} | ||
|
||
/** | ||
* Create a {@link TwoInputTransformation} with memoryBytes. | ||
*/ | ||
public static <T> TwoInputTransformation<T, T, T> createTwoInputTransformation( | ||
Transformation<T> input1, | ||
Transformation<T> input2, | ||
String name, | ||
StreamOperatorFactory<T> operatorFactory, | ||
TypeInformation<T> outputType, | ||
int parallelism, | ||
long memoryBytes) { | ||
TwoInputTransformation<T, T, T> transformation = new TwoInputTransformation<>( | ||
input1, input2, name, operatorFactory, outputType, parallelism); | ||
setManagedMemoryWeight(transformation, memoryBytes); | ||
return transformation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.