Skip to content

Commit c15ee6f

Browse files
#139: added name aliases for aggregate ST_ functions (#140)
* #139: added name aliases for aggregate ST_ functions
1 parent d910941 commit c15ee6f

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.exasol</groupId>
66
<artifactId>virtual-schema-common-java</artifactId>
7-
<version>10.0.0</version>
7+
<version>10.0.1</version>
88
<name>Common module of Exasol Virtual Schemas Adapters</name>
99
<description>This is one of the modules of Virtual Schemas Adapters. The libraries provided by this project are the foundation of the adapter development, i.e. adapters must be implemented on top of them.</description>
1010
<url>https://github.com/exasol/virtual-schema-common-java</url>
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.exasol.adapter.sql;
22

33
/**
4-
* List of all aggregation functions supported by EXASOL
4+
* List of all aggregation functions supported by EXASOL.
55
*/
66
public enum AggregateFunction {
77
COUNT, SUM, MIN, MAX, AVG, MEDIAN, FIRST_VALUE, LAST_VALUE, STDDEV, STDDEV_POP, STDDEV_SAMP, VARIANCE, VAR_POP,
8-
VAR_SAMP, GROUP_CONCAT(false), APPROXIMATE_COUNT_DISTINCT, GEO_INTERSECTION_AGGREGATE, GEO_UNION_AGGREGATE, MUL;
8+
VAR_SAMP, GROUP_CONCAT(false, "GROUP_CONCAT"), APPROXIMATE_COUNT_DISTINCT,
9+
GEO_INTERSECTION_AGGREGATE(true, "ST_INTERSECTION"), GEO_UNION_AGGREGATE(true, "ST_UNION"), MUL;
910

10-
private final boolean isSimple;
11+
private final boolean simple;
12+
private String realFunctionName;
1113

1214
/**
1315
* True if the function is simple, i.e. is handled by {@link SqlFunctionAggregate}, and false if it has it's own
@@ -16,14 +18,24 @@ public enum AggregateFunction {
1618
* @return <code>true</code> if the function is simple
1719
*/
1820
public boolean isSimple() {
19-
return this.isSimple;
21+
return this.simple;
2022
}
2123

2224
AggregateFunction() {
23-
this.isSimple = true;
25+
this.simple = true;
2426
}
2527

26-
AggregateFunction(final boolean isSimple) {
27-
this.isSimple = isSimple;
28+
AggregateFunction(final boolean simple, final String realFunctionName) {
29+
this.simple = simple;
30+
this.realFunctionName = realFunctionName;
2831
}
29-
}
32+
33+
@Override
34+
public String toString() {
35+
if (realFunctionName != null && !realFunctionName.isBlank()) {
36+
return realFunctionName;
37+
} else {
38+
return name();
39+
}
40+
}
41+
}

src/main/java/com/exasol/adapter/sql/SqlFunctionAggregate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public AggregateFunction getFunction() {
4343
}
4444

4545
public String getFunctionName() {
46-
return function.name();
46+
return function.toString();
4747
}
4848

4949
public boolean hasDistinct() {

src/test/java/com/exasol/adapter/sql/AggregateFunctionTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.exasol.adapter.sql;
22

3-
import org.junit.jupiter.api.Test;
4-
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.equalTo;
55
import static org.junit.jupiter.api.Assertions.assertFalse;
66
import static org.junit.jupiter.api.Assertions.assertTrue;
77

8+
import org.junit.jupiter.api.Test;
9+
810
class AggregateFunctionTest {
911
@Test
1012
void testIsSimpleFalse() {
@@ -15,4 +17,14 @@ void testIsSimpleFalse() {
1517
void testIsSimpleTrue() {
1618
assertTrue(AggregateFunction.COUNT.isSimple());
1719
}
20+
21+
@Test
22+
void testToStringWithSpecialName() {
23+
assertThat(AggregateFunction.GEO_INTERSECTION_AGGREGATE.toString(), equalTo("ST_INTERSECTION"));
24+
}
25+
26+
@Test
27+
void testToString() {
28+
assertThat(AggregateFunction.AVG.toString(), equalTo("AVG"));
29+
}
1830
}

0 commit comments

Comments
 (0)