Skip to content

Commit 0fdb594

Browse files
author
yixuanyxzhu
committed
[test](function) Add FE unit tests for ST_NumGeometries, ST_NumPoints, ST_Geometries functions
1 parent d3ad3cd commit 0fdb594

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with 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,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.nereids.trees.expressions.functions.scalar;
19+
20+
import org.apache.doris.catalog.FunctionSignature;
21+
import org.apache.doris.nereids.trees.expressions.Expression;
22+
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
23+
import org.apache.doris.nereids.types.ArrayType;
24+
import org.apache.doris.nereids.types.BigIntType;
25+
import org.apache.doris.nereids.types.VarcharType;
26+
27+
import com.google.common.collect.ImmutableList;
28+
import org.junit.jupiter.api.Assertions;
29+
import org.junit.jupiter.api.Test;
30+
31+
import java.util.List;
32+
33+
/**
34+
* Unit tests for ST_NumGeometries, ST_NumPoints, and ST_Geometries scalar functions.
35+
*/
36+
public class StGeoComponentFunctionsTest {
37+
38+
@Test
39+
public void testStNumGeometriesBasicProperties() {
40+
Expression arg = new VarcharLiteral("test");
41+
StNumGeometries func = new StNumGeometries(arg);
42+
43+
Assertions.assertEquals("st_numgeometries", func.getName());
44+
Assertions.assertEquals(1, func.arity());
45+
Assertions.assertTrue(func.nullable());
46+
47+
List<FunctionSignature> signatures = func.getSignatures();
48+
Assertions.assertEquals(1, signatures.size());
49+
Assertions.assertEquals(BigIntType.INSTANCE, signatures.get(0).returnType);
50+
Assertions.assertEquals(VarcharType.SYSTEM_DEFAULT, signatures.get(0).getArgType(0));
51+
}
52+
53+
@Test
54+
public void testStNumGeometriesWithChildren() {
55+
Expression arg = new VarcharLiteral("test");
56+
StNumGeometries func = new StNumGeometries(arg);
57+
58+
Expression newArg = new VarcharLiteral("new_test");
59+
StNumGeometries newFunc = func.withChildren(ImmutableList.of(newArg));
60+
61+
Assertions.assertNotSame(func, newFunc);
62+
Assertions.assertEquals("st_numgeometries", newFunc.getName());
63+
Assertions.assertEquals(1, newFunc.arity());
64+
}
65+
66+
@Test
67+
public void testStNumPointsBasicProperties() {
68+
Expression arg = new VarcharLiteral("test");
69+
StNumPoints func = new StNumPoints(arg);
70+
71+
Assertions.assertEquals("st_numpoints", func.getName());
72+
Assertions.assertEquals(1, func.arity());
73+
Assertions.assertTrue(func.nullable());
74+
75+
List<FunctionSignature> signatures = func.getSignatures();
76+
Assertions.assertEquals(1, signatures.size());
77+
Assertions.assertEquals(BigIntType.INSTANCE, signatures.get(0).returnType);
78+
Assertions.assertEquals(VarcharType.SYSTEM_DEFAULT, signatures.get(0).getArgType(0));
79+
}
80+
81+
@Test
82+
public void testStNumPointsWithChildren() {
83+
Expression arg = new VarcharLiteral("test");
84+
StNumPoints func = new StNumPoints(arg);
85+
86+
Expression newArg = new VarcharLiteral("new_test");
87+
StNumPoints newFunc = func.withChildren(ImmutableList.of(newArg));
88+
89+
Assertions.assertNotSame(func, newFunc);
90+
Assertions.assertEquals("st_numpoints", newFunc.getName());
91+
Assertions.assertEquals(1, newFunc.arity());
92+
}
93+
94+
@Test
95+
public void testStGeometriesBasicProperties() {
96+
Expression arg = new VarcharLiteral("test");
97+
StGeometries func = new StGeometries(arg);
98+
99+
Assertions.assertEquals("st_geometries", func.getName());
100+
Assertions.assertEquals(1, func.arity());
101+
Assertions.assertTrue(func.nullable());
102+
103+
List<FunctionSignature> signatures = func.getSignatures();
104+
Assertions.assertEquals(1, signatures.size());
105+
Assertions.assertTrue(signatures.get(0).returnType instanceof ArrayType);
106+
Assertions.assertEquals(VarcharType.SYSTEM_DEFAULT, signatures.get(0).getArgType(0));
107+
}
108+
109+
@Test
110+
public void testStGeometriesWithChildren() {
111+
Expression arg = new VarcharLiteral("test");
112+
StGeometries func = new StGeometries(arg);
113+
114+
Expression newArg = new VarcharLiteral("new_test");
115+
StGeometries newFunc = func.withChildren(ImmutableList.of(newArg));
116+
117+
Assertions.assertNotSame(func, newFunc);
118+
Assertions.assertEquals("st_geometries", newFunc.getName());
119+
Assertions.assertEquals(1, newFunc.arity());
120+
}
121+
122+
@Test
123+
public void testStGeometriesReturnType() {
124+
Expression arg = new VarcharLiteral("test");
125+
StGeometries func = new StGeometries(arg);
126+
127+
List<FunctionSignature> signatures = func.getSignatures();
128+
FunctionSignature sig = signatures.get(0);
129+
130+
// Return type should be Array<Varchar>
131+
Assertions.assertTrue(sig.returnType instanceof ArrayType);
132+
ArrayType arrayType = (ArrayType) sig.returnType;
133+
Assertions.assertTrue(arrayType.getItemType() instanceof VarcharType);
134+
}
135+
}

0 commit comments

Comments
 (0)