-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
c8e5f5f
commit 6555aa8
Showing
3 changed files
with
141 additions
and
18 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
104 changes: 104 additions & 0 deletions
104
plugin/trino-spanner/src/test/java/io/trino/plugin/spanner/TestSpannerDataTypesMapping.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,104 @@ | ||
package io.trino.plugin.spanner; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.trino.Session; | ||
import io.trino.spi.type.BigintType; | ||
import io.trino.testing.AbstractTestQueryFramework; | ||
import io.trino.testing.QueryRunner; | ||
import io.trino.testing.datatype.CreateAndInsertDataSetup; | ||
import io.trino.testing.datatype.CreateAsSelectDataSetup; | ||
import io.trino.testing.datatype.DataSetup; | ||
import io.trino.testing.datatype.SqlDataTypeTest; | ||
import io.trino.testing.sql.JdbcSqlExecutor; | ||
import io.trino.testing.sql.TemporaryRelation; | ||
import io.trino.testing.sql.TrinoSqlExecutor; | ||
import io.trino.tpch.TpchTable; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Properties; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import static io.trino.spi.type.BooleanType.BOOLEAN; | ||
|
||
public class TestSpannerDataTypesMapping | ||
extends AbstractTestQueryFramework | ||
{ | ||
protected TestingSpannerInstance spannerInstance; | ||
|
||
@Override | ||
protected QueryRunner createQueryRunner() | ||
throws Exception | ||
{ | ||
spannerInstance = closeAfterClass(new TestingSpannerInstance()); | ||
return SpannerQueryRunner.createSpannerQueryRunner( | ||
spannerInstance, | ||
ImmutableMap.of("http-server.http.port", "8080"), | ||
ImmutableMap.of(), | ||
TpchTable.getTables(), false); | ||
} | ||
|
||
@Test | ||
public void testBoolean() | ||
{ | ||
SqlDataTypeTest.create() | ||
.addRoundTrip("bool", "true", BOOLEAN) | ||
.addRoundTrip("bool", "false", BOOLEAN) | ||
.addRoundTrip("bool", "NULL", BOOLEAN, "CAST(NULL AS BOOLEAN)") | ||
.addRoundTrip("int64", "1", BigintType.BIGINT, "CAST(1 as BIGINT)") | ||
.execute(getQueryRunner(), spannerCreateAndInsert("test_boolean")) | ||
.execute(getQueryRunner(), trinoCreateAsSelect("test_boolean")) | ||
.execute(getQueryRunner(), trinoCreateAndInsert("test_boolean")); | ||
} | ||
|
||
private DataSetup spannerCreateAndInsert(String tableNamePrefix) | ||
{ | ||
JdbcSqlExecutor jdbcSqlExecutor = new JdbcSqlExecutor(spannerInstance.getJdbcUrl(), new Properties()); | ||
return inputs -> { | ||
|
||
String primaryKey = String.format("col_%s", inputs.size() - 1); | ||
|
||
jdbcSqlExecutor.execute("CREATE TABLE %s (%s) PRIMARY KEY (%s)" | ||
.formatted( | ||
tableNamePrefix, | ||
IntStream.range(0, inputs.size()) | ||
.mapToObj(f -> String.format("col_%s %s", f, inputs.get(f).getDeclaredType().get())) | ||
.collect(Collectors.joining(", ")), | ||
primaryKey)); | ||
return new TemporaryRelation() | ||
{ | ||
@Override | ||
public String getName() | ||
{ | ||
return tableNamePrefix; | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
|
||
} | ||
}; | ||
}; | ||
} | ||
|
||
private DataSetup trinoCreateAsSelect(String tableNamePrefix) | ||
{ | ||
return trinoCreateAsSelect(getSession(), tableNamePrefix); | ||
} | ||
|
||
private DataSetup trinoCreateAsSelect(Session session, String tableNamePrefix) | ||
{ | ||
return new CreateAsSelectDataSetup(new TrinoSqlExecutor(getQueryRunner(), session), tableNamePrefix); | ||
} | ||
|
||
private DataSetup trinoCreateAndInsert(String tableNamePrefix) | ||
{ | ||
return trinoCreateAndInsert(getSession(), tableNamePrefix); | ||
} | ||
|
||
private DataSetup trinoCreateAndInsert(Session session, String tableNamePrefix) | ||
{ | ||
return new CreateAndInsertDataSetup(new TrinoSqlExecutor(getQueryRunner(), session), tableNamePrefix); | ||
} | ||
} |
17 changes: 14 additions & 3 deletions
17
plugin/trino-spanner/src/test/java/io/trino/plugin/spanner/TestSpannerPlugin.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,22 +1,33 @@ | ||
package io.trino.plugin.spanner; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.trino.plugin.spanner.SpannerPlugin; | ||
import io.trino.spi.Plugin; | ||
import io.trino.spi.connector.ConnectorFactory; | ||
import io.trino.testing.TestingConnectorContext; | ||
import org.testcontainers.utility.DockerImageName; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import static com.google.common.collect.Iterables.getOnlyElement; | ||
|
||
public class TestSpannerPlugin | ||
{ | ||
@Test | ||
public void testCreateConnector() | ||
throws Exception | ||
{ | ||
Plugin plugin = new SpannerPlugin(); | ||
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories()); | ||
factory.create("test", ImmutableMap.of("connection-url", "jdbc:cloudspanner://0.0.0.0:9010/projects/spanner-project/instances/spanner-instance/databases/spanner-database;autoConfigEmulator=true"), new TestingConnectorContext()).shutdown(); | ||
TestingSpannerInstance instance = new TestingSpannerInstance(); | ||
factory.create("test", ImmutableMap.of( | ||
"spanner.credentials.file", "credentials.json", | ||
"spanner.instanceId", instance.getInstanceId() | ||
, "spanner.projectId", instance.getProjectId() | ||
, "spanner.database", instance.getDatabaseId() | ||
, "spanner.emulated", "true" | ||
, "spanner.emulated.host", instance.getHost() | ||
), | ||
new TestingConnectorContext()).shutdown(); | ||
instance.close(); | ||
} | ||
} |