-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca20cc4
commit 42245c6
Showing
3 changed files
with
120 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...schema-jdbc-adapter/src/test/java/com/exasol/adapter/dialects/impl/DB2SqlDialectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.exasol.adapter.dialects.impl; | ||
|
||
import static com.exasol.adapter.capabilities.AggregateFunctionCapability.*; | ||
import static com.exasol.adapter.capabilities.LiteralCapability.*; | ||
import static com.exasol.adapter.capabilities.MainCapability.*; | ||
import static com.exasol.adapter.capabilities.PredicateCapability.*; | ||
import static com.exasol.adapter.capabilities.ScalarFunctionCapability.*; | ||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.exasol.adapter.capabilities.Capabilities; | ||
import com.exasol.adapter.dialects.SqlDialect; | ||
|
||
class DB2SqlDialectTest { | ||
SqlDialect dialect; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
this.dialect = new DB2SqlDialect(null); | ||
} | ||
|
||
@Test | ||
void testGetCapabilities() { | ||
final Capabilities capabilities = this.dialect.getCapabilities(); | ||
assertAll(() -> assertThat(capabilities.getMainCapabilities(), | ||
containsInAnyOrder(SELECTLIST_PROJECTION, SELECTLIST_EXPRESSIONS, FILTER_EXPRESSIONS, | ||
AGGREGATE_SINGLE_GROUP, AGGREGATE_GROUP_BY_COLUMN, AGGREGATE_GROUP_BY_EXPRESSION, | ||
AGGREGATE_GROUP_BY_TUPLE, AGGREGATE_HAVING, ORDER_BY_COLUMN, ORDER_BY_EXPRESSION, LIMIT)), | ||
() -> assertThat(capabilities.getLiteralCapabilities(), | ||
containsInAnyOrder(NULL, DATE, TIMESTAMP, TIMESTAMP_UTC, DOUBLE, EXACTNUMERIC, STRING, | ||
INTERVAL)), | ||
() -> assertThat(capabilities.getPredicateCapabilities(), | ||
containsInAnyOrder(AND, OR, NOT, EQUAL, NOTEQUAL, LESS, LESSEQUAL, LIKE, LIKE_ESCAPE, BETWEEN, | ||
IN_CONSTLIST, IS_NULL, IS_NOT_NULL)), | ||
() -> assertThat(capabilities.getAggregateFunctionCapabilities(), | ||
containsInAnyOrder(COUNT, COUNT_STAR, COUNT_DISTINCT, GROUP_CONCAT, GROUP_CONCAT_SEPARATOR, | ||
GROUP_CONCAT_ORDER_BY, SUM, SUM_DISTINCT, MIN, MAX, AVG, AVG_DISTINCT, MEDIAN, | ||
FIRST_VALUE, LAST_VALUE, STDDEV, STDDEV_POP, STDDEV_SAMP, VARIANCE, VARIANCE_DISTINCT, | ||
VAR_POP, VAR_SAMP)), | ||
() -> assertThat(capabilities.getScalarFunctionCapabilities(), | ||
containsInAnyOrder(CEIL, DIV, FLOOR, SIGN, ADD, SUB, MULT, FLOAT_DIV, NEG, ABS, ACOS, ASIN, | ||
ATAN, ATAN2, COS, COSH, COT, DEGREES, EXP, GREATEST, LEAST, LN, LOG, MOD, POWER, | ||
RADIANS, SIN, SINH, SQRT, TAN, TANH, ASCII, CHR, INSTR, LENGTH, LOCATE, LOWER, LPAD, | ||
LTRIM, REPEAT, REPLACE, RIGHT, RPAD, RTRIM, SOUNDEX, SUBSTR, TRANSLATE, TRIM, UPPER, | ||
ADD_DAYS, ADD_HOURS, ADD_MINUTES, ADD_MONTHS, ADD_SECONDS, ADD_WEEKS, ADD_YEARS, | ||
CURRENT_DATE, CURRENT_TIMESTAMP, LOCALTIMESTAMP, SYSDATE, SYSTIMESTAMP, CAST, TO_CHAR, | ||
TO_DATE, TO_NUMBER, TO_TIMESTAMP, CASE, CURRENT_SCHEMA, CURRENT_USER, NULLIFZERO, | ||
ZEROIFNULL))); | ||
} | ||
} |
93 changes: 48 additions & 45 deletions
93
...ema-jdbc-adapter/src/test/java/com/exasol/adapter/dialects/impl/ExasolSqlDialectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,60 @@ | ||
package com.exasol.adapter.dialects.impl; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import com.exasol.adapter.AdapterException; | ||
import com.exasol.adapter.capabilities.Capabilities; | ||
import com.exasol.adapter.capabilities.PredicateCapability; | ||
import com.exasol.adapter.dialects.SqlDialect; | ||
import com.exasol.adapter.dialects.SqlGenerationContext; | ||
import com.exasol.adapter.dialects.SqlGenerationVisitor; | ||
import com.exasol.adapter.capabilities.*; | ||
import com.exasol.adapter.dialects.*; | ||
import com.exasol.adapter.sql.SqlNode; | ||
import org.junit.Test; | ||
import utils.SqlTestUtil; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ExasolSqlDialectTest { | ||
import utils.SqlTestUtil; | ||
|
||
@Test | ||
public void testApplyQuoteIfNeeded() { | ||
ExasolSqlDialect dialect = new ExasolSqlDialect(DialectTestData.getExasolDialectContext()); | ||
// Regular Identifiers | ||
assertEquals("\"A1\"", dialect.applyQuoteIfNeeded("A1")); | ||
assertEquals("\"A_1\"", dialect.applyQuoteIfNeeded("A_1")); | ||
assertEquals("\"A\"", dialect.applyQuoteIfNeeded("A")); | ||
|
||
// Irregular Identifiers | ||
assertEquals("\"A_a_1\"", dialect.applyQuoteIfNeeded("A_a_1")); | ||
assertEquals("\"1\"", dialect.applyQuoteIfNeeded("1")); | ||
assertEquals("\"1a\"", dialect.applyQuoteIfNeeded("1a")); | ||
assertEquals("\"a\"\"b\"", dialect.applyQuoteIfNeeded("a\"b")); | ||
class ExasolSqlDialectTest { | ||
@CsvSource({ "A1, \"A1\"", // | ||
"A_1, \"A_1\"", // | ||
"A,\"A\"", // | ||
"A_a_1, \"A_a_1\"", // | ||
"1, \"1\"", // | ||
"1a, \"1a\", \"1a\"", // | ||
"'a\"b', \"a\"\"b\"" }) | ||
@ParameterizedTest | ||
void testApplyQuoteIfNeeded(final String identifier, final String expectedQuotingResult) { | ||
final ExasolSqlDialect dialect = new ExasolSqlDialect(DialectTestData.getExasolDialectContext()); | ||
assertThat(dialect.applyQuoteIfNeeded(identifier), equalTo(expectedQuotingResult)); | ||
} | ||
|
||
@Test | ||
public void testCapabilities() { | ||
// Test if EXASOL dialect really has all capabilities | ||
ExasolSqlDialect dialect = new ExasolSqlDialect(DialectTestData.getExasolDialectContext()); | ||
Capabilities caps = dialect.getCapabilities(); | ||
assertEquals(PredicateCapability.values().length, caps.getPredicateCapabilities().size()); | ||
void testExasolSqlDialectSupportsAllCapabilities() { | ||
final ExasolSqlDialect dialect = new ExasolSqlDialect(DialectTestData.getExasolDialectContext()); | ||
final Capabilities capabilities = dialect.getCapabilities(); | ||
assertAll(() -> assertThat(capabilities.getMainCapabilities(), containsInAnyOrder(MainCapability.values())), | ||
() -> assertThat(capabilities.getLiteralCapabilities(), containsInAnyOrder(LiteralCapability.values())), | ||
() -> assertThat(capabilities.getPredicateCapabilities(), | ||
containsInAnyOrder(PredicateCapability.values())), | ||
() -> assertThat(capabilities.getScalarFunctionCapabilities(), | ||
containsInAnyOrder(ScalarFunctionCapability.values())), | ||
() -> assertThat(capabilities.getAggregateFunctionCapabilities(), | ||
containsInAnyOrder(AggregateFunctionCapability.values()))); | ||
} | ||
|
||
@Test | ||
public void testSqlGenerator() throws AdapterException { | ||
SqlNode node = DialectTestData.getTestSqlNode(); | ||
String schemaName = "SCHEMA"; | ||
String expectedSql = "SELECT \"USER_ID\", COUNT(\"URL\") FROM \"" + schemaName + "\".\"CLICKS\"" + | ||
" WHERE 1 < \"USER_ID\"" + | ||
" GROUP BY \"USER_ID\"" + | ||
" HAVING 1 < COUNT(\"URL\")" + | ||
" ORDER BY \"USER_ID\"" + | ||
" LIMIT 10"; | ||
SqlGenerationContext context = new SqlGenerationContext("", schemaName, false, false); | ||
SqlDialect dialect = new ExasolSqlDialect(DialectTestData.getExasolDialectContext()); | ||
SqlGenerationVisitor generator = dialect.getSqlGenerationVisitor(context); | ||
String actualSql = node.accept(generator); | ||
assertEquals(SqlTestUtil.normalizeSql(expectedSql), SqlTestUtil.normalizeSql(actualSql)); | ||
void testSqlGenerator() throws AdapterException { | ||
final SqlNode node = DialectTestData.getTestSqlNode(); | ||
final String schemaName = "SCHEMA"; | ||
final String expectedSql = "SELECT \"USER_ID\", COUNT(\"URL\") FROM \"" + schemaName + "\".\"CLICKS\"" | ||
+ " WHERE 1 < \"USER_ID\"" + " GROUP BY \"USER_ID\"" + " HAVING 1 < COUNT(\"URL\")" | ||
+ " ORDER BY \"USER_ID\"" + " LIMIT 10"; | ||
final SqlGenerationContext context = new SqlGenerationContext("", schemaName, false, false); | ||
final SqlDialect dialect = new ExasolSqlDialect(DialectTestData.getExasolDialectContext()); | ||
final SqlGenerationVisitor generator = dialect.getSqlGenerationVisitor(context); | ||
final String actualSql = node.accept(generator); | ||
assertThat(SqlTestUtil.normalizeSql(actualSql), equalTo(SqlTestUtil.normalizeSql(expectedSql))); | ||
} | ||
|
||
} | ||
} |