github-actions[bot] commented on code in PR #62698: URL: https://github.com/apache/doris/pull/62698#discussion_r3240244533
########## fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/udf/UdfVolatilityTest.java: ########## @@ -0,0 +1,106 @@ +// 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.doris.nereids.trees.expressions.functions.udf; + +import org.apache.doris.catalog.Function; +import org.apache.doris.catalog.Function.NullableMode; +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.catalog.FunctionVolatility; +import org.apache.doris.nereids.rules.rewrite.AddProjectForUniqueFunction; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.VolatileIdentity; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; +import org.apache.doris.nereids.types.IntegerType; +import org.apache.doris.nereids.util.ExpressionUtils; + +import com.google.common.collect.ImmutableList; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class UdfVolatilityTest { + + @Test + void testImmutablePythonUdfIsNotVolatileExpression() { + PythonUdf udf = pythonUdf(FunctionVolatility.IMMUTABLE, VolatileIdentity.NON_VOLATILE); + + Assertions.assertTrue(udf.isDeterministic()); + Assertions.assertFalse(udf.containsVolatileExpression()); + Assertions.assertEquals(PythonUdf.class, new PythonUdfBuilder(udf).functionClass()); + } + + @Test + void testVolatilePythonUdfUsesUniqueIdentity() { + PythonUdf first = pythonUdf(FunctionVolatility.VOLATILE, VolatileIdentity.newVolatileIdentity()); + PythonUdf second = pythonUdf(FunctionVolatility.VOLATILE, VolatileIdentity.newVolatileIdentity()); + + Assertions.assertFalse(first.isDeterministic()); + Assertions.assertTrue(first.containsVolatileExpression()); + Assertions.assertNotEquals(first, second); + + Expression ignoredFirst = ExpressionUtils.setIgnoreUniqueIdForUniqueFunc(first, true); + Expression ignoredSecond = ExpressionUtils.setIgnoreUniqueIdForUniqueFunc(second, true); + Assertions.assertEquals(ignoredFirst, ignoredSecond); + } + + @Test + void testVolatileAndImmutableUdfAreNotEqual() { + PythonUdf immutable = pythonUdf(FunctionVolatility.IMMUTABLE, VolatileIdentity.NON_VOLATILE); + PythonUdf volatileUdf = pythonUdf(FunctionVolatility.VOLATILE, VolatileIdentity.newVolatileIdentity()); + + Assertions.assertNotEquals(immutable, volatileUdf); + Assertions.assertNotEquals(volatileUdf, immutable); + } + + @Test + void testAddProjectForRepeatedVolatileUdf() { + PythonUdf udf = pythonUdf(FunctionVolatility.VOLATILE, VolatileIdentity.newVolatileIdentity()); + List<NamedExpression> aliases = new AddProjectForUniqueFunction() + .tryGenUniqueFunctionAlias(ImmutableList.of(udf, udf)); + + Assertions.assertEquals(1, aliases.size()); + Assertions.assertEquals(udf, aliases.get(0).child(0)); Review Comment: This assertion does not match the current implementation. `AddProjectForUniqueFunction.tryGenUniqueFunctionAlias()` still only counts `expr instanceof UniqueFunction`, so a `PythonUdf` is ignored and `aliases.size()` is `0`. This makes the newly added unit test fail on current head. Please either restore safe aliasing for volatile UDFs in the rule, or update/remove this test if the intended fix is to keep aliasing limited to built-in `UniqueFunction`s. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddProjectForUniqueFunction.java: ########## @@ -26,6 +26,7 @@ import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator; +import org.apache.doris.nereids.trees.expressions.VolatileExpression; import org.apache.doris.nereids.trees.expressions.functions.Function; Review Comment: `VolatileExpression` is imported but no longer used in this class. FE Checkstyle enables `UnusedImports`, so this stale import will fail style validation. ```suggestion ``` -- 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]
