lihaosky commented on code in PR #27039:
URL: https://github.com/apache/flink/pull/27039#discussion_r2434234973


##########
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -2614,6 +2618,27 @@ private SqlNode registerFrom(
                         scopes.put(node, getSelectScope(call1.operand(0)));
                         return newNode;
                     }
+
+                    // Related to CALCITE-4077
+                    // ----- FLINK MODIFICATION BEGIN -----
+                    FlinkSqlCallBinding binding =
+                            new FlinkSqlCallBinding(this, getEmptyScope(), 
call1);
+                    if (op instanceof SqlVectorSearchTableFunction
+                            && binding.operand(0)
+                                    .isA(
+                                            new HashSet<>(
+                                                    
Collections.singletonList(SqlKind.SELECT)))) {
+                        boolean queryColumnIsNotLiteral =
+                                binding.operand(2).getKind() != 
SqlKind.LITERAL;
+                        if (!queryColumnIsNotLiteral && !lateral) {
+                            throw new ValidationException(
+                                    "The query column is not literal, please 
use LATERAL TABLE to run VECTOR_SEARCH.");
+                        }
+                        SqlValidatorScope scope = getSelectScope((SqlSelect) 
binding.operand(0));

Review Comment:
   nit: looks there's no need to cast based on line 2618?



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/ml/SqlVectorSearchTableFunction.java:
##########
@@ -0,0 +1,239 @@
+/*
+ * 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.api.ValidationException;
+import org.apache.flink.table.planner.functions.utils.SqlValidatorUtils;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.utils.LogicalTypeCasts;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlIdentifier;
+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.SqlTableFunction;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.sql.type.SqlOperandCountRanges;
+import org.apache.calcite.sql.type.SqlOperandMetadata;
+import org.apache.calcite.sql.type.SqlReturnTypeInference;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.validate.SqlNameMatcher;
+import org.apache.calcite.util.Util;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import static 
org.apache.flink.table.planner.calcite.FlinkTypeFactory.toLogicalType;
+
+/**
+ * {@link SqlVectorSearchTableFunction} implements an operator for search.
+ *
+ * <p>It allows four parameters:
+ *
+ * <ol>
+ *   <li>a table
+ *   <li>a descriptor to provide a column name from the input table
+ *   <li>a query column from the left table
+ *   <li>a literal value for top k
+ * </ol>
+ */
+public class SqlVectorSearchTableFunction extends SqlFunction implements 
SqlTableFunction {
+
+    private static final String PARAM_SEARCH_TABLE = "SEARCH_TABLE";
+    private static final String PARAM_COLUMN_TO_SEARCH = "COLUMN_TO_SEARCH";
+    private static final String PARAM_COLUMN_TO_QUERY = "COLUMN_TO_QUERY";
+    private static final String PARAM_TOP_K = "TOP_K";

Review Comment:
   Missing the optional config param from FLIP?



##########
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -2614,6 +2618,27 @@ private SqlNode registerFrom(
                         scopes.put(node, getSelectScope(call1.operand(0)));
                         return newNode;
                     }
+
+                    // Related to CALCITE-4077
+                    // ----- FLINK MODIFICATION BEGIN -----
+                    FlinkSqlCallBinding binding =
+                            new FlinkSqlCallBinding(this, getEmptyScope(), 
call1);
+                    if (op instanceof SqlVectorSearchTableFunction
+                            && binding.operand(0)
+                                    .isA(
+                                            new HashSet<>(
+                                                    
Collections.singletonList(SqlKind.SELECT)))) {
+                        boolean queryColumnIsNotLiteral =
+                                binding.operand(2).getKind() != 
SqlKind.LITERAL;
+                        if (!queryColumnIsNotLiteral && !lateral) {

Review Comment:
   Isn't `lateral` always needed? What's the syntax for literal?



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

Reply via email to