KevinyhZou commented on code in PR #10189: URL: https://github.com/apache/incubator-gluten/pull/10189#discussion_r2206915508
########## gluten-flink/runtime/src/main/java/org/apache/flink/streaming/runtime/translators/OneInputTransformationTranslator.java: ########## @@ -0,0 +1,191 @@ +/* + * 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.streaming.runtime.translators; + +import org.apache.gluten.streaming.api.operators.GlutenOneInputOperatorFactory; +import org.apache.gluten.table.runtime.operators.GlutenSingleInputOperator; +import org.apache.gluten.util.LogicalTypeConverter; +import org.apache.gluten.util.PlanNodeIdGenerator; +import org.apache.gluten.util.ReflectUtils; + +import io.github.zhztheplayer.velox4j.connector.CommitStrategy; +import io.github.zhztheplayer.velox4j.connector.FileSystemInsertTableHandle; +import io.github.zhztheplayer.velox4j.plan.EmptyNode; +import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode; +import io.github.zhztheplayer.velox4j.plan.TableWriteNode; +import io.github.zhztheplayer.velox4j.type.BigIntType; +import io.github.zhztheplayer.velox4j.type.RowType; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.java.functions.KeySelector; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink.BulkFormatBuilder; +import org.apache.flink.streaming.api.graph.StreamConfig; +import org.apache.flink.streaming.api.graph.TransformationTranslator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.api.operators.SimpleOperatorFactory; +import org.apache.flink.streaming.api.operators.StreamOperatorFactory; +import org.apache.flink.streaming.api.transformations.OneInputTransformation; +import org.apache.flink.table.runtime.typeutils.InternalTypeInfo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * A {@link TransformationTranslator} for the {@link OneInputTransformation}. + * + * @param <IN> The type of the elements in the input {@code Transformation} of the transformation to + * translate. + * @param <OUT> The type of the elements that result from the provided {@code + * OneInputTransformation}. + */ +@Internal +public final class OneInputTransformationTranslator<IN, OUT> + extends AbstractOneInputTransformationTranslator<IN, OUT, OneInputTransformation<IN, OUT>> { + + private static final Logger LOG = LoggerFactory.getLogger(OneInputTransformationTranslator.class); + + @Override + public Collection<Integer> translateForBatchInternal( + final OneInputTransformation<IN, OUT> transformation, final Context context) { + KeySelector<IN, ?> keySelector = transformation.getStateKeySelector(); + Collection<Integer> ids = + translateInternal( + transformation, + transformation.getOperatorFactory(), + transformation.getInputType(), + keySelector, + transformation.getStateKeyType(), + context); + boolean isKeyed = keySelector != null; + if (isKeyed) { + BatchExecutionUtils.applyBatchExecutionSettings( + transformation.getId(), context, StreamConfig.InputRequirement.SORTED); + } + + return ids; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override + public Collection<Integer> translateForStreamingInternal( + final OneInputTransformation<IN, OUT> transformation, final Context context) { + StreamOperatorFactory<OUT> operatorFactory = transformation.getOperatorFactory(); + if (operatorFactory instanceof SimpleOperatorFactory) { + String operatorClazzName = transformation.getOperator().getClass().getSimpleName(); + if (operatorClazzName.equals("StreamingFileWriter")) { + OneInputStreamOperator<IN, OUT> operator = transformation.getOperator(); + Configuration configuration = + (Configuration) ReflectUtils.getObjectField(operator.getClass(), operator, "conf"); + List<Integer> partitionIndexes = new ArrayList<>(); + List<String> partitionKeys = new ArrayList<>(); Review Comment: fixed. ########## gluten-flink/runtime/src/main/java/org/apache/flink/streaming/runtime/translators/OneInputTransformationTranslator.java: ########## @@ -0,0 +1,191 @@ +/* + * 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.streaming.runtime.translators; + +import org.apache.gluten.streaming.api.operators.GlutenOneInputOperatorFactory; +import org.apache.gluten.table.runtime.operators.GlutenSingleInputOperator; +import org.apache.gluten.util.LogicalTypeConverter; +import org.apache.gluten.util.PlanNodeIdGenerator; +import org.apache.gluten.util.ReflectUtils; + +import io.github.zhztheplayer.velox4j.connector.CommitStrategy; +import io.github.zhztheplayer.velox4j.connector.FileSystemInsertTableHandle; +import io.github.zhztheplayer.velox4j.plan.EmptyNode; +import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode; +import io.github.zhztheplayer.velox4j.plan.TableWriteNode; +import io.github.zhztheplayer.velox4j.type.BigIntType; +import io.github.zhztheplayer.velox4j.type.RowType; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.java.functions.KeySelector; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink.BulkFormatBuilder; +import org.apache.flink.streaming.api.graph.StreamConfig; +import org.apache.flink.streaming.api.graph.TransformationTranslator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.api.operators.SimpleOperatorFactory; +import org.apache.flink.streaming.api.operators.StreamOperatorFactory; +import org.apache.flink.streaming.api.transformations.OneInputTransformation; +import org.apache.flink.table.runtime.typeutils.InternalTypeInfo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * A {@link TransformationTranslator} for the {@link OneInputTransformation}. + * + * @param <IN> The type of the elements in the input {@code Transformation} of the transformation to + * translate. + * @param <OUT> The type of the elements that result from the provided {@code + * OneInputTransformation}. + */ +@Internal +public final class OneInputTransformationTranslator<IN, OUT> + extends AbstractOneInputTransformationTranslator<IN, OUT, OneInputTransformation<IN, OUT>> { + + private static final Logger LOG = LoggerFactory.getLogger(OneInputTransformationTranslator.class); + + @Override + public Collection<Integer> translateForBatchInternal( + final OneInputTransformation<IN, OUT> transformation, final Context context) { + KeySelector<IN, ?> keySelector = transformation.getStateKeySelector(); + Collection<Integer> ids = + translateInternal( + transformation, + transformation.getOperatorFactory(), + transformation.getInputType(), + keySelector, + transformation.getStateKeyType(), + context); + boolean isKeyed = keySelector != null; + if (isKeyed) { + BatchExecutionUtils.applyBatchExecutionSettings( + transformation.getId(), context, StreamConfig.InputRequirement.SORTED); + } + + return ids; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override + public Collection<Integer> translateForStreamingInternal( + final OneInputTransformation<IN, OUT> transformation, final Context context) { + StreamOperatorFactory<OUT> operatorFactory = transformation.getOperatorFactory(); + if (operatorFactory instanceof SimpleOperatorFactory) { + String operatorClazzName = transformation.getOperator().getClass().getSimpleName(); + if (operatorClazzName.equals("StreamingFileWriter")) { + OneInputStreamOperator<IN, OUT> operator = transformation.getOperator(); + Configuration configuration = + (Configuration) ReflectUtils.getObjectField(operator.getClass(), operator, "conf"); + List<Integer> partitionIndexes = new ArrayList<>(); + List<String> partitionKeys = new ArrayList<>(); + try { + partitionKeys = + (List<String>) + ReflectUtils.getObjectField(operator.getClass(), operator, "partitionKeys"); + Class<?> streamingFileWriterClazz = + Class.forName("org.apache.flink.connector.file.table.stream.AbstractStreamingWriter"); + Object bucketsBuilder = + ReflectUtils.getObjectField(streamingFileWriterClazz, operator, "bucketsBuilder"); + if (bucketsBuilder instanceof BulkFormatBuilder) { + Object assigner = + ReflectUtils.getObjectField( + BulkFormatBuilder.class, bucketsBuilder, "bucketAssigner"); + Object partitionComputer = + ReflectUtils.getObjectField(assigner.getClass(), assigner, "computer"); + int[] partitionIndexArray = + (int[]) + ReflectUtils.getObjectField( + partitionComputer.getClass(), partitionComputer, "partitionIndexes"); + partitionIndexes = + Arrays.stream(partitionIndexArray).boxed().collect(Collectors.toList()); + } else { + throw new RuntimeException("Not support:" + bucketsBuilder.getClass().getName()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + org.apache.flink.table.types.logical.RowType inputType = + (org.apache.flink.table.types.logical.RowType) + ((InternalTypeInfo) transformation.getInputType()).toLogicalType(); + RowType inputDataColumns = (RowType) LogicalTypeConverter.toVLType(inputType); + RowType ignore = new RowType(List.of("num"), List.of(new BigIntType())); + Map<String, String> tableParams = configuration.toMap(); + tableParams.put("fs.file_name_prefix", UUID.randomUUID().toString()); + tableParams.put("fs.writer_task_id", String.valueOf(0)); + FileSystemInsertTableHandle insertTableHandle = Review Comment: fixed. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
