fsk119 commented on code in PR #26644:
URL: https://github.com/apache/flink/pull/26644#discussion_r2148955561


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/ml/SqlMLEvaluateTableFunction.java:
##########
@@ -0,0 +1,208 @@
+/*
+ * 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.functions.sql.ml;
+
+import org.apache.flink.table.planner.functions.utils.SqlValidatorUtils;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlCharStringLiteral;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.SqlOperandCountRanges;
+import org.apache.calcite.sql.type.SqlOperandMetadata;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.util.NlsString;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * SqlMLEvaluateTableFunction implements an operator for model evaluation.
+ *
+ * <p>It allows six parameters:
+ *
+ * <ol>
+ *   <li>a table name
+ *   <li>a model name
+ *   <li>a descriptor to provide label column names from the input table
+ *   <li>a descriptor to provide feature column names from the input table
+ *   <li>an optional task override string
+ *   <li>an optional config map
+ * </ol>
+ *
+ * <p>The function returns a MAP type containing evaluation metrics and 
results.
+ */
+public class SqlMLEvaluateTableFunction extends SqlMLTableFunction {
+
+    public static final String PARAM_LABEL = "LABEL";
+    public static final String PARAM_FEATURE = "FEATURE";
+    public static final String PARAM_TASK = "TASK";
+
+    public static final List<String> SUPPORTED_TASKS =
+            List.of("regression", "clustering", "classification", "embedding", 
"text_generation");
+
+    public SqlMLEvaluateTableFunction() {
+        super("ML_EVALUATE", new EvaluateOperandMetadata());
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * <p>Overrides because the first parameter of ML table-value function is 
an explicit TABLE
+     * parameter, which is not scalar.
+     */
+    @Override
+    public boolean argumentMustBeScalar(int ordinal) {
+        return ordinal != 0;
+    }
+
+    @Override
+    protected RelDataType inferRowType(SqlOperatorBinding opBinding) {
+        final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+        final RelDataType inputRowType = opBinding.getOperandType(0);
+
+        // Create a MAP type for evaluation results
+        RelDataType keyType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+        RelDataType valueType = typeFactory.createSqlType(SqlTypeName.DOUBLE);
+        RelDataType mapType = typeFactory.createMapType(keyType, valueType);
+
+        return typeFactory
+                .builder()
+                .kind(inputRowType.getStructKind())
+                .add("result", mapType)
+                .build();
+    }
+
+    private static class EvaluateOperandMetadata implements SqlOperandMetadata 
{
+        private static final List<String> PARAM_NAMES =
+                List.of(
+                        PARAM_INPUT,
+                        PARAM_MODEL,
+                        PARAM_LABEL,
+                        PARAM_FEATURE,
+                        PARAM_TASK,
+                        PARAM_CONFIG);
+        private static final List<String> MANDATORY_PARAM_NAMES =

Review Comment:
   BTW, we can implement the second one first and then use another PR to derive 
the task from model pojo object.



-- 
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-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to