yzeng1618 commented on code in PR #10145: URL: https://github.com/apache/seatunnel/pull/10145#discussion_r2622124147
########## seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/udf/DesEncryptTest.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.seatunnel.transform.sql.zeta.functions.udf; + +import org.apache.seatunnel.api.table.type.BasicType; +import org.apache.seatunnel.api.table.type.SeaTunnelDataType; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +public class DesEncryptTest { + + @Test + public void testFunctionNameAndResultType() { + DesEncrypt udf = new DesEncrypt(); + Assertions.assertEquals("DES_ENCRYPT", udf.functionName()); + + List<SeaTunnelDataType<?>> argTypes = + Arrays.asList(BasicType.STRING_TYPE, BasicType.STRING_TYPE); + Assertions.assertEquals(BasicType.STRING_TYPE, udf.resultType(argTypes)); + } + + @Test + public void testEvaluateEncryptsWithValidArguments() { + DesEncrypt udf = new DesEncrypt(); + String password = "password123"; + String plain = "hello-udf"; + + List<Object> args = Arrays.asList(password, plain); + Object result = udf.evaluate(args); + Assertions.assertTrue(result instanceof String); + + String decrypted = DESUtil.decrypt(password, (String) result); + Assertions.assertEquals(plain, decrypted); + } + + @Test + public void testEvaluateReturnsNullWhenPasswordOrDataIsNull() { + DesEncrypt udf = new DesEncrypt(); + Review Comment: Handled. ########## seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/udf/DESUtilTest.java: ########## @@ -0,0 +1,55 @@ +/* + * 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.seatunnel.transform.sql.zeta.functions.udf; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class DESUtilTest { + + @Test + public void testEncryptDecryptRoundTrip() { + String password = "password123"; + String data = "hello-world"; + + String encrypted = DESUtil.encrypt(password, data); + Assertions.assertNotNull(encrypted); + Assertions.assertNotEquals(data, encrypted); + + String decrypted = DESUtil.decrypt(password, encrypted); + Assertions.assertEquals(data, decrypted); + } + + @Test + public void testEncryptAndDecryptNullData() { + String password = "password123"; + Review Comment: Handled. ########## seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/StringFunction.java: ########## @@ -479,7 +480,7 @@ private static int makeRegexpFlags(String stringFlags, boolean ignoreGlobalFlag) CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION, Review Comment: Handled. ########## seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/ArrayFunctionTest.java: ########## @@ -72,4 +81,140 @@ void testNestedArrayEvaluateWithSQLEngine() { Assertions.assertEquals(3, ((Number) inner2[0]).intValue()); Assertions.assertEquals(4, ((Number) inner2[1]).intValue()); } + + // ------------------ arrayMax / arrayMin ------------------ + + @Test + void testArrayMaxAndMinWithIntegers() { + Object[] values = new Object[] {1, 3, 2}; + Object max = ArrayFunction.arrayMax(java.util.Collections.singletonList((Object) values)); + Object min = ArrayFunction.arrayMin(java.util.Collections.singletonList((Object) values)); + + Assertions.assertEquals(3, max); + Assertions.assertEquals(1, min); + } + + @Test + void testArrayMaxAndMinWithStrings() { + Object[] values = new Object[] {"a", "c", "b"}; + Object max = ArrayFunction.arrayMax(java.util.Collections.singletonList((Object) values)); + Object min = ArrayFunction.arrayMin(java.util.Collections.singletonList((Object) values)); + + Assertions.assertEquals("c", max); + Assertions.assertEquals("a", min); + } + + @Test + void testArrayMaxAndMinWithEmptyOrNullArray() { + Object[] empty = new Object[] {}; + Assertions.assertNull( + ArrayFunction.arrayMax(java.util.Collections.singletonList((Object) empty))); + Assertions.assertNull( + ArrayFunction.arrayMin(java.util.Collections.singletonList((Object) empty))); + Review Comment: Handled. -- 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]
