yashmayya commented on code in PR #17156: URL: https://github.com/apache/pinot/pull/17156#discussion_r2500506982
########## pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/ArrayHasAnyScalarFunction.java: ########## @@ -0,0 +1,269 @@ +/** + * 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.pinot.common.function.scalar.array; + +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.BooleanSupplier; +import javax.annotation.Nullable; +import org.apache.pinot.common.function.FunctionInfo; +import org.apache.pinot.common.function.PinotScalarFunction; +import org.apache.pinot.common.function.sql.PinotSqlFunction; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.spi.annotations.ScalarFunction; + + +@ScalarFunction(names = {"ARRAYHASANY"}) Review Comment: Hm I'm not so sure about this name considering we're essentially checking if the intersection of two arrays is non-empty, are there similar functions in any other DBs? ########## pinot-query-planner/src/main/java/org/apache/pinot/calcite/sql/fun/PinotOperatorTable.java: ########## @@ -289,6 +289,8 @@ public static PinotOperatorTable instance(boolean nullHandlingEnabled) { i -> i == 2)), new PinotSqlFunction("VECTOR_SIMILARITY", ReturnTypes.BOOLEAN, OperandTypes.family(List.of(SqlTypeFamily.ARRAY, SqlTypeFamily.ARRAY, SqlTypeFamily.INTEGER), i -> i == 2)), + new PinotSqlFunction("ARRAY_HAS_ANY", ReturnTypes.BOOLEAN, + OperandTypes.family(List.of(SqlTypeFamily.ARRAY, SqlTypeFamily.ARRAY), i -> i == 2)), Review Comment: There's only two parameters right? So the optional parameter check `i -> i == 2` doesn't really make sense? ########## pinot-query-planner/src/main/java/org/apache/pinot/calcite/sql/fun/PinotOperatorTable.java: ########## @@ -289,6 +289,8 @@ public static PinotOperatorTable instance(boolean nullHandlingEnabled) { i -> i == 2)), new PinotSqlFunction("VECTOR_SIMILARITY", ReturnTypes.BOOLEAN, OperandTypes.family(List.of(SqlTypeFamily.ARRAY, SqlTypeFamily.ARRAY, SqlTypeFamily.INTEGER), i -> i == 2)), + new PinotSqlFunction("ARRAY_HAS_ANY", ReturnTypes.BOOLEAN, + OperandTypes.family(List.of(SqlTypeFamily.ARRAY, SqlTypeFamily.ARRAY), i -> i == 2)), Review Comment: Also why are we adding an explicit entry here? We should be able to rely on the scalar function auto-registration by overriding the `toPinotSqlFunction` method and returning a non-null value there. ########## pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/ArrayHasAnyScalarFunction.java: ########## @@ -0,0 +1,269 @@ +/** + * 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.pinot.common.function.scalar.array; + +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.BooleanSupplier; +import javax.annotation.Nullable; +import org.apache.pinot.common.function.FunctionInfo; +import org.apache.pinot.common.function.PinotScalarFunction; +import org.apache.pinot.common.function.sql.PinotSqlFunction; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.spi.annotations.ScalarFunction; + + +@ScalarFunction(names = {"ARRAYHASANY"}) +public class ArrayHasAnyScalarFunction implements PinotScalarFunction { + + private static final Map<DataSchema.ColumnDataType, FunctionInfo> + TYPE_FUNCTION_INFO_MAP = new EnumMap<>(DataSchema.ColumnDataType.class); + + private static final float HASH_SET_LOAD_FACTOR = 0.75f; + + static { + try { + TYPE_FUNCTION_INFO_MAP.put(DataSchema.ColumnDataType.INT_ARRAY, + new FunctionInfo(ArrayHasAnyScalarFunction.class.getMethod("arrayHasAny", int[].class, int[].class), + ArrayHasAnyScalarFunction.class, false)); + TYPE_FUNCTION_INFO_MAP.put(DataSchema.ColumnDataType.LONG_ARRAY, + new FunctionInfo(ArrayHasAnyScalarFunction.class.getMethod("arrayHasAny", long[].class, long[].class), + ArrayHasAnyScalarFunction.class, false)); + TYPE_FUNCTION_INFO_MAP.put(DataSchema.ColumnDataType.FLOAT_ARRAY, + new FunctionInfo(ArrayHasAnyScalarFunction.class.getMethod("arrayHasAny", float[].class, float[].class), + ArrayHasAnyScalarFunction.class, false)); + TYPE_FUNCTION_INFO_MAP.put(DataSchema.ColumnDataType.DOUBLE_ARRAY, + new FunctionInfo(ArrayHasAnyScalarFunction.class.getMethod("arrayHasAny", double[].class, double[].class), + ArrayHasAnyScalarFunction.class, false)); + TYPE_FUNCTION_INFO_MAP.put(DataSchema.ColumnDataType.STRING_ARRAY, + new FunctionInfo(ArrayHasAnyScalarFunction.class.getMethod("arrayHasAny", String[].class, String[].class), + ArrayHasAnyScalarFunction.class, false)); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + + @Override + public String getName() { + return "ARRAYHASANY"; + } + + @Override + public Set<String> getNames() { + return Set.of("ARRAYHASANY"); + } + + @Nullable + @Override + public PinotSqlFunction toPinotSqlFunction() { + // Should already be registered in PinotOperatorTable by the transform function implementation + return null; + } Review Comment: There isn't any corresponding transform function though? -- 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]
