|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.seatunnel.transform.sql.zeta; |
| 19 | + |
| 20 | +import org.apache.seatunnel.transform.sql.zeta.functions.StringFunction; |
| 21 | + |
| 22 | +import org.junit.jupiter.api.Assertions; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Collections; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +public class ConcatWsFunctionTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testConcatWs() { |
| 33 | + Assertions.assertEquals("", StringFunction.concatWs(genArgs(";", new String[] {}))); |
| 34 | + Assertions.assertEquals("", StringFunction.concatWs(genArgs(null, new String[] {}))); |
| 35 | + Assertions.assertEquals( |
| 36 | + "a;b", StringFunction.concatWs(genArgs(";", new String[] {"a", "b"}))); |
| 37 | + Assertions.assertEquals( |
| 38 | + "a;b", StringFunction.concatWs(genArgs(";", new String[] {"a", null, "b"}))); |
| 39 | + Assertions.assertEquals( |
| 40 | + "ab", |
| 41 | + StringFunction.concatWs(genArgs("", new String[] {null, "a", null, "b", null}))); |
| 42 | + Assertions.assertEquals( |
| 43 | + "ab", StringFunction.concatWs(genArgs(null, new String[] {"a", "b", null}))); |
| 44 | + Assertions.assertEquals( |
| 45 | + "a;b;c", StringFunction.concatWs(genArgs(";", new String[] {"a", "b"}, "c"))); |
| 46 | + Assertions.assertEquals( |
| 47 | + "a;b", StringFunction.concatWs(genArgs(";", new String[] {"a", "b"}, null))); |
| 48 | + Assertions.assertEquals( |
| 49 | + "a;b;1;2", |
| 50 | + StringFunction.concatWs( |
| 51 | + genArgs(";", new String[] {"a", "b"}, new String[] {"1", "2"}))); |
| 52 | + } |
| 53 | + |
| 54 | + public List<Object> genArgs(String separator, String[] arr) { |
| 55 | + List<Object> list = new ArrayList<>(); |
| 56 | + list.add(separator); |
| 57 | + list.add(arr); |
| 58 | + return list; |
| 59 | + } |
| 60 | + |
| 61 | + public List<Object> genArgs(String separator, Object... arr) { |
| 62 | + List<Object> list = new ArrayList<>(); |
| 63 | + list.add(separator); |
| 64 | + Collections.addAll(list, arr); |
| 65 | + return list; |
| 66 | + } |
| 67 | +} |
0 commit comments