zhztheplayer commented on code in PR #8839: URL: https://github.com/apache/incubator-gluten/pull/8839#discussion_r2037764672
########## gluten-flink/runtime/src/main/java/org/apache/gluten/table/runtime/operators/GlutenCalOperator.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.gluten.table.runtime.operators; + +import io.github.zhztheplayer.velox4j.connector.ExternalStream; +import io.github.zhztheplayer.velox4j.connector.ExternalStreamConnectorSplit; +import io.github.zhztheplayer.velox4j.iterator.DownIterator; +import io.github.zhztheplayer.velox4j.iterator.UpIterator; +import io.github.zhztheplayer.velox4j.query.BoundSplit; +import io.github.zhztheplayer.velox4j.serde.Serde; +import io.github.zhztheplayer.velox4j.type.RowType; +import org.apache.gluten.streaming.api.operators.GlutenOperator; +import org.apache.gluten.vectorized.VLVectorIterator; +import org.apache.gluten.vectorized.FlinkRowToVLVectorConvertor; + +import io.github.zhztheplayer.velox4j.Velox4j; +import io.github.zhztheplayer.velox4j.config.Config; +import io.github.zhztheplayer.velox4j.config.ConnectorConfig; +import io.github.zhztheplayer.velox4j.memory.AllocationListener; +import io.github.zhztheplayer.velox4j.memory.MemoryManager; +import io.github.zhztheplayer.velox4j.plan.PlanNode; +import io.github.zhztheplayer.velox4j.query.Query; +import io.github.zhztheplayer.velox4j.session.Session; +import org.apache.arrow.memory.BufferAllocator; +import org.apache.arrow.memory.RootAllocator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.runtime.operators.TableStreamOperator; + +import java.util.List; + +/** Calculate operator in gluten, which will call Velox to run. */ +public class GlutenCalOperator extends TableStreamOperator<RowData> + implements OneInputStreamOperator<RowData, RowData>, GlutenOperator { + + private final String glutenPlan; + private final String id; + private final String inputType; + private final String outputType; + + private StreamRecord outElement = null; + + private Session session; + private Query query; + private VLVectorIterator inputIterator; + BufferAllocator allocator; + + public GlutenCalOperator(String plan, String id, String inputType, String outputType) { + this.glutenPlan = plan; + this.id = id; + this.inputType = inputType; + this.outputType = outputType; + } + + @Override + public void open() throws Exception { + super.open(); + outElement = new StreamRecord(null); + session = Velox4j.newSession(MemoryManager.create(AllocationListener.NOOP)); Review Comment: Sessions should be closed otherwise memory will leak. MemoryManager should be closed as well. ``` final MemoryManager memoryManager = MemoryManager.create(AllocationListener.NOOP); final Session session = Velox4j.newSession(memoryManager); session.close(); memoryManager.close(); ``` ########## gluten-flink/runtime/src/main/java/org/apache/gluten/table/runtime/operators/GlutenSourceFunction.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.gluten.table.runtime.operators; + +import io.github.zhztheplayer.velox4j.connector.FuzzerConnectorSplit; +import io.github.zhztheplayer.velox4j.query.BoundSplit; +import org.apache.gluten.vectorized.FlinkRowToVLVectorConvertor; + +import io.github.zhztheplayer.velox4j.Velox4j; +import io.github.zhztheplayer.velox4j.config.Config; +import io.github.zhztheplayer.velox4j.config.ConnectorConfig; +import io.github.zhztheplayer.velox4j.iterator.UpIterator; +import io.github.zhztheplayer.velox4j.memory.AllocationListener; +import io.github.zhztheplayer.velox4j.memory.MemoryManager; +import io.github.zhztheplayer.velox4j.plan.PlanNode; +import io.github.zhztheplayer.velox4j.query.Query; +import io.github.zhztheplayer.velox4j.session.Session; +import io.github.zhztheplayer.velox4j.type.RowType; +import org.apache.arrow.memory.BufferAllocator; +import org.apache.arrow.memory.RootAllocator; +import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction; +import org.apache.flink.table.data.RowData; + +import java.util.List; + +/** Gluten legacy source function, call velox plan to execute. */ +public class GlutenSourceFunction extends RichParallelSourceFunction<RowData> { + + private final PlanNode planNode; + private final RowType outputType; + private final String id; + private volatile boolean isRunning = true; + + private Session session; + private Query query; + BufferAllocator allocator; + + public GlutenSourceFunction(PlanNode planNode, RowType outputType, String id) { + this.planNode = planNode; + this.outputType = outputType; + this.id = id; + } + + public PlanNode getPlanNode() { + return planNode; + } + + public RowType getOutputType() { return outputType; } + + public String getId() { return id; } + + @Override + public void run(SourceContext<RowData> sourceContext) throws Exception { + final List<BoundSplit> splits = List.of(new BoundSplit( + id, + -1, + new FuzzerConnectorSplit("connector-fuzzer", 1000))); + session = Velox4j.newSession(MemoryManager.create(AllocationListener.NOOP)); Review Comment: ditto -- 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]
