zhztheplayer commented on code in PR #8839:
URL: https://github.com/apache/incubator-gluten/pull/8839#discussion_r1978598709


##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.rexnode;
+
+import io.github.zhztheplayer.velox4j.expression.CallTypedExpr;
+import io.github.zhztheplayer.velox4j.expression.ConstantTypedExpr;
+import io.github.zhztheplayer.velox4j.expression.FieldAccessTypedExpr;
+import io.github.zhztheplayer.velox4j.expression.TypedExpr;
+import io.github.zhztheplayer.velox4j.type.BooleanType;
+import io.github.zhztheplayer.velox4j.type.IntegerType;
+import io.github.zhztheplayer.velox4j.type.Type;
+import io.github.zhztheplayer.velox4j.variant.BigIntValue;
+import io.github.zhztheplayer.velox4j.variant.BooleanValue;
+import io.github.zhztheplayer.velox4j.variant.DoubleValue;
+import io.github.zhztheplayer.velox4j.variant.IntegerValue;
+import io.github.zhztheplayer.velox4j.variant.SmallIntValue;
+import io.github.zhztheplayer.velox4j.variant.TimestampValue;
+import io.github.zhztheplayer.velox4j.variant.TinyIntValue;
+import io.github.zhztheplayer.velox4j.variant.VarBinaryValue;
+import io.github.zhztheplayer.velox4j.variant.VarCharValue;
+import io.github.zhztheplayer.velox4j.variant.Variant;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Convertor to convert RexNode to velox TypedExpr */
+public class RexNodeConverter {
+
+    public static TypedExpr toTypedExpr(RexNode rexNode) {
+        if (rexNode instanceof RexLiteral) {
+            RexLiteral literal = (RexLiteral) rexNode;
+            return new ConstantTypedExpr(
+                    toType(literal.getType()),
+                    toVariant(literal),
+                    null);

Review Comment:
   Could use `ConstantTypedExpr.create(toVariant(literal))`



##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecCalc.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.planner.plan.nodes.exec.stream;
+
+import io.github.zhztheplayer.velox4j.plan.ValuesNode;
+import org.apache.gluten.rexnode.RexNodeConverter;
+import org.apache.gluten.table.runtime.operators.GlutenCalOperator;
+
+import io.github.zhztheplayer.velox4j.plan.FilterNode;
+import io.github.zhztheplayer.velox4j.plan.PlanNode;
+import io.github.zhztheplayer.velox4j.plan.ProjectNode;
+import org.apache.calcite.rex.RexNode;
+import org.apache.flink.FlinkVersion;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeMetadata;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecEdge;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext;
+import org.apache.flink.table.planner.plan.nodes.exec.InputProperty;
+import org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecCalc;
+import org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil;
+import 
org.apache.flink.table.planner.plan.nodes.exec.utils.TransformationMetadata;
+import org.apache.flink.table.runtime.operators.TableStreamOperator;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.flink.table.types.logical.RowType;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+/** Gluten Stream {@link ExecNode} for Calc to use {@link GlutenCalOperator}. 
*/
+@ExecNodeMetadata(
+        name = "stream-exec-calc",
+        version = 1,
+        producedTransformations = CommonExecCalc.CALC_TRANSFORMATION,
+        minPlanVersion = FlinkVersion.v1_15,
+        minStateVersion = FlinkVersion.v1_15)
+public class StreamExecCalc extends CommonExecCalc implements 
StreamExecNode<RowData> {
+
+    public StreamExecCalc(
+            ReadableConfig tableConfig,
+            List<RexNode> projection,
+            @Nullable RexNode condition,
+            InputProperty inputProperty,
+            RowType outputType,
+            String description) {
+        this(
+                ExecNodeContext.newNodeId(),
+                ExecNodeContext.newContext(StreamExecCalc.class),
+                ExecNodeContext.newPersistedConfig(StreamExecCalc.class, 
tableConfig),
+                projection,
+                condition,
+                Collections.singletonList(inputProperty),
+                outputType,
+                description);
+    }
+
+    @JsonCreator
+    public StreamExecCalc(
+            @JsonProperty(FIELD_NAME_ID) int id,
+            @JsonProperty(FIELD_NAME_TYPE) ExecNodeContext context,
+            @JsonProperty(FIELD_NAME_CONFIGURATION) ReadableConfig 
persistedConfig,
+            @JsonProperty(FIELD_NAME_PROJECTION) List<RexNode> projection,
+            @JsonProperty(FIELD_NAME_CONDITION) @Nullable RexNode condition,
+            @JsonProperty(FIELD_NAME_INPUT_PROPERTIES) List<InputProperty> 
inputProperties,
+            @JsonProperty(FIELD_NAME_OUTPUT_TYPE) RowType outputType,
+            @JsonProperty(FIELD_NAME_DESCRIPTION) String description) {
+        super(
+                id,
+                context,
+                persistedConfig,
+                projection,
+                condition,
+                TableStreamOperator.class,
+                true, // retainHeader
+                inputProperties,
+                outputType,
+                description);
+    }
+
+    @Override
+    public Transformation<RowData> translateToPlanInternal(
+            PlannerBase planner, ExecNodeConfig config) {
+        final ExecEdge inputEdge = getInputEdges().get(0);
+        final Transformation<RowData> inputTransform =
+                (Transformation<RowData>) inputEdge.translateToPlan(planner);
+
+        // add a mock input as velox not allow the source is empty.
+        PlanNode mockInput = new ValuesNode(
+                String.valueOf(ExecNodeContext.newNodeId()),
+                "",
+                false,
+                1);

Review Comment:
   Adding a scan node so we can bind the split to it. E.g.,
   
   ```java
   final TableScanNode scanNode = new TableScanNode(
           "id-1",
           ...(type),
           new ExternalStreamTableHandle("connector-external-stream"),
           List.of()
       );
   ```



##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.rexnode;
+
+import io.github.zhztheplayer.velox4j.expression.CallTypedExpr;
+import io.github.zhztheplayer.velox4j.expression.ConstantTypedExpr;
+import io.github.zhztheplayer.velox4j.expression.FieldAccessTypedExpr;
+import io.github.zhztheplayer.velox4j.expression.TypedExpr;
+import io.github.zhztheplayer.velox4j.type.BooleanType;
+import io.github.zhztheplayer.velox4j.type.IntegerType;
+import io.github.zhztheplayer.velox4j.type.Type;
+import io.github.zhztheplayer.velox4j.variant.BigIntValue;
+import io.github.zhztheplayer.velox4j.variant.BooleanValue;
+import io.github.zhztheplayer.velox4j.variant.DoubleValue;
+import io.github.zhztheplayer.velox4j.variant.IntegerValue;
+import io.github.zhztheplayer.velox4j.variant.SmallIntValue;
+import io.github.zhztheplayer.velox4j.variant.TimestampValue;
+import io.github.zhztheplayer.velox4j.variant.TinyIntValue;
+import io.github.zhztheplayer.velox4j.variant.VarBinaryValue;
+import io.github.zhztheplayer.velox4j.variant.VarCharValue;
+import io.github.zhztheplayer.velox4j.variant.Variant;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Convertor to convert RexNode to velox TypedExpr */
+public class RexNodeConverter {
+
+    public static TypedExpr toTypedExpr(RexNode rexNode) {
+        if (rexNode instanceof RexLiteral) {
+            RexLiteral literal = (RexLiteral) rexNode;
+            return new ConstantTypedExpr(
+                    toType(literal.getType()),
+                    toVariant(literal),
+                    null);
+        } else if (rexNode instanceof RexCall) {
+            RexCall rexCall = (RexCall) rexNode;
+            List<TypedExpr> params = toTypedExpr(rexCall.getOperands());
+            Type nodeType = toType(rexCall.getType());
+            return new CallTypedExpr(
+                    nodeType,
+                    params,
+                    
FunctionMappings.toVeloxFunction(rexCall.getOperator().getName()));
+        } else if (rexNode instanceof RexInputRef) {
+            RexInputRef inputRef = (RexInputRef) rexNode;
+            return FieldAccessTypedExpr.create(
+                    toType(inputRef.getType()),
+                    String.valueOf(inputRef.getIndex()));
+        } else {
+            throw new RuntimeException("Unrecognized RexNode: " + rexNode);
+        }
+    }
+
+    public static List<TypedExpr> toTypedExpr(List<RexNode> rexNodes) {
+        return rexNodes.stream()
+                .map(rexNode -> toTypedExpr(rexNode))
+                .collect(Collectors.toList());
+    }
+
+    public static Type toType(RelDataType relDataType) {
+        switch (relDataType.getSqlTypeName()) {
+            case BOOLEAN:
+                return new BooleanType();
+            case INTEGER:
+                return new IntegerType();
+            default:
+                throw new RuntimeException("Unsupported type: " + 
relDataType.getSqlTypeName());
+        }
+    }
+
+    public static Variant toVariant(RexLiteral literal) {
+        switch (literal.getType().getSqlTypeName()) {
+            case BOOLEAN:
+                return new BooleanValue((boolean) literal.getValue());
+            case TINYINT:
+                return new 
TinyIntValue(Integer.valueOf(literal.getValue().toString()));
+            case SMALLINT:
+                return new 
SmallIntValue(Integer.valueOf(literal.getValue().toString()));
+            case INTEGER:
+                return new 
IntegerValue(Integer.valueOf(literal.getValue().toString()));
+            case BIGINT:
+                return new 
BigIntValue(Long.valueOf(literal.getValue().toString()));
+            case DOUBLE:
+                return new 
DoubleValue(Double.valueOf(literal.getValue().toString()));
+            case VARCHAR:
+                return new VarCharValue(literal.getValue().toString());
+            case BINARY:
+                return new VarBinaryValue(literal.getValue().toString());

Review Comment:
   Should we use `VarBinaryValue.create()` to pass a byte array in?



-- 
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]

Reply via email to