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
97cf1a0
commit 1da5169
Showing
2 changed files
with
65 additions
and
100 deletions.
There are no files selected for viewing
141 changes: 51 additions & 90 deletions
141
src/test/java/com/exasol/adapter/dialects/postgresql/PostgreSQLScalarFunctionsIT.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,137 +1,98 @@ | ||
package com.exasol.adapter.dialects.postgresql; | ||
|
||
import java.sql.*; | ||
import java.sql.Date; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.*; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import com.exasol.adapter.commontests.scalarfunction.*; | ||
import com.exasol.adapter.commontests.scalarfunction.ScalarFunctionsTestBase; | ||
import com.exasol.adapter.commontests.scalarfunction.TestSetup; | ||
import com.exasol.adapter.commontests.scalarfunction.virtualschematestsetup.*; | ||
import com.exasol.adapter.commontests.scalarfunction.virtualschematestsetup.request.Column; | ||
import com.exasol.adapter.commontests.scalarfunction.virtualschematestsetup.request.TableRequest; | ||
import com.exasol.adapter.metadata.DataType; | ||
import com.exasol.closeafterall.CloseAfterAll; | ||
import com.exasol.closeafterall.CloseAfterAllExtension; | ||
import com.exasol.dbbuilder.dialects.Schema; | ||
import com.exasol.dbbuilder.dialects.Table; | ||
import com.exasol.dbbuilder.dialects.exasol.VirtualSchema; | ||
import com.exasol.dbbuilder.dialects.postgres.PostgreSqlObjectFactory; | ||
|
||
@ExtendWith({ CloseAfterAllExtension.class }) | ||
class PostgreSQLScalarFunctionsIT extends ScalarFunctionsTestBase { | ||
@CloseAfterAll | ||
private static final PostgresVirtualSchemaIntegrationTestSetup SETUP = new PostgresVirtualSchemaIntegrationTestSetup(); | ||
|
||
@Override | ||
protected Set<String> getDialectSpecificExcludes() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
} | ||
protected TestSetup getTestSetup() { | ||
final PostgreSqlObjectFactory postgresFactory = SETUP.getPostgresFactory(); | ||
return new TestSetup() { | ||
|
||
@Override | ||
protected SingleTableVirtualSchemaTestSetup createVirtualSchemaTableWithExamplesForAllDataTypes() { | ||
return new PostgreSQLSingleTableVirtualSchemaTestSetup() { | ||
@Override | ||
protected Table createTable() { | ||
return this.getPostgresqlSchema().createTableBuilder(getUniqueIdentifier())// | ||
.column("floating_point", "real")// | ||
.column("number", "integer")// | ||
.column("boolean", "boolean")// | ||
.column("string", "VARCHAR(2)")// | ||
.column("date", "DATE")// | ||
.column("timestamp", "TIMESTAMP").build() | ||
.insert(0.5, 2, true, "a", new Date(1000), new Timestamp(1001)); | ||
public VirtualSchemaTestSetupProvider getVirtualSchemaTestSetupProvider() { | ||
return (final CreateVirtualSchemaTestSetupRequest request) -> { | ||
final Schema postgresSchema = postgresFactory.createSchema(getUniqueIdentifier()); | ||
for (final TableRequest tableRequest : request.getTableRequests()) { | ||
final Table.Builder tableBuilder = postgresSchema.createTableBuilder(tableRequest.getName()); | ||
for (final Column column : tableRequest.getColumns()) { | ||
tableBuilder.column(column.getName(), column.getType()); | ||
} | ||
final Table table = tableBuilder.build(); | ||
for (final List<Object> row : tableRequest.getRows()) { | ||
table.insert(row.toArray()); | ||
} | ||
} | ||
|
||
final VirtualSchema virtualSchema = SETUP.createVirtualSchema(postgresSchema.getName(), | ||
Map.of("IGNORE_ERRORS", "POSTGRESQL_UPPERCASE_TABLES")); | ||
|
||
return new PostgreSQLSingleTableVirtualSchemaTestSetup(virtualSchema, postgresSchema); | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected SingleRowSingleTableVirtualSchemaTestSetup<Timestamp> createDateVirtualSchemaTable() { | ||
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); | ||
return createTestTable("timestamp"); | ||
} | ||
|
||
@Override | ||
protected SingleRowSingleTableVirtualSchemaTestSetup<Integer> createIntegerVirtualSchemaTable() { | ||
return createTestTable("integer"); | ||
} | ||
|
||
@Override | ||
protected SingleRowSingleTableVirtualSchemaTestSetup<Double> createDoubleVirtualSchemaTable() { | ||
return createTestTable("real"); | ||
} | ||
@Override | ||
public String getExternalTypeFor(final DataType exasolType) { | ||
return exasolType.toString(); | ||
} | ||
|
||
@Override | ||
protected SingleRowSingleTableVirtualSchemaTestSetup<Boolean> createBooleanVirtualSchemaTable() { | ||
return createTestTable("boolean"); | ||
} | ||
@Override | ||
public Set<String> getDialectSpecificExcludes() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
private <T> SingleRowSingleTableVirtualSchemaTestSetup<T> createTestTable(final String type) { | ||
return new SingleRowPostgreSQLSingleTableVirtualSchemaTestSetup<>() { | ||
@Override | ||
protected Table createTable() { | ||
return this.getPostgresqlSchema().createTableBuilder(getUniqueIdentifier())// | ||
.column("my_column", type).build(); | ||
public Connection createExasolConnection() throws SQLException { | ||
return SETUP.getExasolContainer().createConnection(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected Connection createExasolConnection() throws SQLException { | ||
return SETUP.getExasolContainer().createConnection(); | ||
} | ||
|
||
@Override | ||
protected SingleRowSingleTableVirtualSchemaTestSetup<String> createStringVirtualSchemaTable() { | ||
return createTestTable("VARCHAR(500)"); | ||
} | ||
|
||
private static abstract class PostgreSQLSingleTableVirtualSchemaTestSetup | ||
implements SingleTableVirtualSchemaTestSetup { | ||
private static class PostgreSQLSingleTableVirtualSchemaTestSetup implements VirtualSchemaTestSetup { | ||
private final VirtualSchema virtualSchema; | ||
private final Table table; | ||
private final Schema postgresqlSchema; | ||
|
||
public PostgreSQLSingleTableVirtualSchemaTestSetup() { | ||
this.postgresqlSchema = SETUP.getPostgresFactory().createSchema(getUniqueIdentifier()); | ||
this.table = createTable(); | ||
this.virtualSchema = SETUP.createVirtualSchema(this.postgresqlSchema.getName(), Map.of()); | ||
private PostgreSQLSingleTableVirtualSchemaTestSetup(final VirtualSchema virtualSchema, | ||
final Schema postgresqlSchema) { | ||
this.virtualSchema = virtualSchema; | ||
this.postgresqlSchema = postgresqlSchema; | ||
} | ||
|
||
protected abstract Table createTable(); | ||
|
||
@Override | ||
public String getFullyQualifiedName() { | ||
return this.virtualSchema.getFullyQualifiedName() + "." + this.table.getName(); | ||
return this.virtualSchema.getFullyQualifiedName(); | ||
} | ||
|
||
@Override | ||
public void drop() { | ||
public void close() { | ||
this.virtualSchema.drop(); | ||
this.table.drop(); | ||
this.postgresqlSchema.drop(); | ||
} | ||
|
||
public Schema getPostgresqlSchema() { | ||
return this.postgresqlSchema; | ||
} | ||
|
||
public Table getTable() { | ||
return this.table; | ||
} | ||
} | ||
|
||
private static abstract class SingleRowPostgreSQLSingleTableVirtualSchemaTestSetup<T> extends | ||
PostgreSQLSingleTableVirtualSchemaTestSetup implements SingleRowSingleTableVirtualSchemaTestSetup<T> { | ||
|
||
@Override | ||
public void truncateTable() throws SQLException { | ||
SETUP.getPostgresqlStatement().executeUpdate("TRUNCATE TABLE " + this.getTable().getFullyQualifiedName()); | ||
} | ||
|
||
@Override | ||
public void insertValue(final T value) { | ||
getTable().insert(value); | ||
} | ||
@BeforeAll | ||
static void beforeAll() { | ||
} | ||
|
||
} |
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