Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 14 additions & 41 deletions docs/src/main/sphinx/connector/teradata.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ data between different systems like Teradata and Hive, or between different Tera

To connect to Teradata, you need:

- Teradata Database
- Teradata database.
- Network access from the Trino coordinator and workers to Teradata. Port
1025 is the default port
1025 is the default port.

## Configuration

To configure the Teradata connector, create a catalog properties file in
`etc/catalog` named, for example, `example.properties`, to mount the Teradata
connector as the `teradata` catalog. Create the file with the following
contents, replacing the connection properties as appropriate for your setup:
The connector can query a database on a Teradata server. Create a catalog
properties file that specifies the Teradata connector by setting the
`connector.name` to `teradata`.

For example, to access a database as the `example` catalog, create the file
`etc/catalog/example.properties`. Replace the connection properties as
appropriate for your setup:

```properties
connector.name=teradata
Expand Down Expand Up @@ -65,11 +68,11 @@ Teradata [JDBC documentation](https://teradata-docs.s3.amazonaws.com/doc/connect

### Multiple Teradata databases

You can have as many catalogs as you need, so if you have additional Teradata
databases, simply add another properties file to etc/catalog with a different
name, making sure it ends in .properties.
For example, if you name the property file sales.properties, Trino creates a
catalog named sales using the configured connector.
You can configure as many catalogs as you need, so if you have additional Teradata
databases, simply add another properties file to `etc/catalog` with a different
name.
For example, if you name the catalog file `sales.properties`, Trino creates a
catalog named `sales` using the configured connector.

## Type mapping

Expand Down Expand Up @@ -176,36 +179,6 @@ No other types are supported.
```{include} jdbc-type-mapping.fragment
```

## Querying Teradata

The Teradata connector provides a schema for every Teradata database. You can
see the available Teradata databases by running SHOW SCHEMAS:

```sql
SHOW SCHEMAS FROM teradata;
```

If you have a Teradata database named sales, you can view the tables in this
database by running SHOW TABLES:

```sql
SHOW TABLES FROM teradata.sales;
```

You can see a list of the columns in the orders table in the sales database
using either of the following:

```sql
DESCRIBE teradata.sales.orders;
SHOW COLUMNS FROM teradata.sales.orders;
```

Finally, you can access the orders table in the sales database:

```sql
SELECT * FROM teradata.sales.orders;
```

## SQL support

The connector provides read access to data and metadata in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static DatabaseConfig create(String envName)
String hostName = null;

if (isEnvSet("CLEARSCAPE_TOKEN")) {
userName = TeradataTestConstants.ENV_CLEARSCAPE_USERNAME;
userName = TeradataTestConstants.CLEARSCAPE_USERNAME;
password = requireEnv("CLEARSCAPE_PASSWORD");
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ public DistributedQueryRunner build()
return super.build();
}

public static void main(String[] args)
static void main()
throws Exception
{
Logging logger = Logging.initialize();
logger.setLevel("io.trino.plugin.teradata", Level.DEBUG);
logger.setLevel("io.trino", Level.INFO);
TestingTeradataServer server = new TestingTeradataServer("TeradataQueryRunner", false);
QueryRunner queryRunner = builder(server).addCoordinatorProperty("http-server.http.port", "8080").setInitialTables(TpchTable.getTables()).build();
QueryRunner queryRunner = builder(server)
.addCoordinatorProperty("http-server.http.port", "8080")
.setInitialTables(TpchTable.getTables())
.build();

Logger log = Logger.get(TeradataQueryRunner.class);
log.info("======== SERVER STARTED ========");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
*/
package io.trino.plugin.teradata.integration;

public interface TeradataTestConstants
public final class TeradataTestConstants
{
String ENV_CLEARSCAPE_URL = "https://api.clearscape.teradata.com";
String ENV_CLEARSCAPE_USERNAME = "demo_user";
public static final String CLEARSCAPE_URL = "https://api.clearscape.teradata.com";
public static final String CLEARSCAPE_USERNAME = "demo_user";

private TeradataTestConstants() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.teradata.integration;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class TestTeradataClassLoading
{
@Test
void testPluginClassLoadable()
throws Exception
{
Class<?> pluginClass = Class.forName("io.trino.plugin.teradata.TeradataPlugin");
Object pluginInstance = pluginClass.getDeclaredConstructor().newInstance();
assertThat(pluginInstance).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,11 @@

private TestingTeradataServer database;

private static void verifyResultOrFailure(AssertProvider<QueryAssertions.QueryAssert> queryAssertProvider, Consumer<QueryAssertions.QueryAssert> verifyResults,
Consumer<TrinoExceptionAssert> verifyFailure)
{
requireNonNull(verifyResults, "verifyResults is null");
requireNonNull(verifyFailure, "verifyFailure is null");
QueryAssertions.QueryAssert queryAssert = assertThat(queryAssertProvider);
verifyResults.accept(queryAssert);
}

@Override
protected SqlExecutor onRemoteDatabase()
{
return database;
}

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
database = closeAfterClass(new TestingTeradataServer(generateUniqueEnvName(getClass()), true));

Check failure on line 56 in plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/integration/TestTeradataConnectorTest.java

View workflow job for this annotation

GitHub Actions / test (plugin/trino-teradata, clearscape-tests)

TestTeradataConnectorTest.

Failed to initialize ClearScape environment: testteradataconnectortest-18223k52xvykn

Check failure on line 56 in plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/integration/TestTeradataConnectorTest.java

View workflow job for this annotation

GitHub Actions / test (plugin/trino-teradata, run-only-long-tests)

TestTeradataConnectorTest.

Failed to initialize ClearScape environment: testteradataconnectortest-14b6t6ve64uks
// Register this specific instance for this test class
return TeradataQueryRunner.builder(database).setInitialTables(REQUIRED_TPCH_TABLES).build();
}
Expand Down Expand Up @@ -551,4 +536,19 @@
{
super.testCaseSensitiveDataMapping();
}

private static void verifyResultOrFailure(AssertProvider<QueryAssertions.QueryAssert> queryAssertProvider, Consumer<QueryAssertions.QueryAssert> verifyResults,
Consumer<TrinoExceptionAssert> verifyFailure)
{
requireNonNull(verifyResults, "verifyResults is null");
requireNonNull(verifyFailure, "verifyFailure is null");
QueryAssertions.QueryAssert queryAssert = assertThat(queryAssertProvider);
verifyResults.accept(queryAssert);
}

@Override
protected SqlExecutor onRemoteDatabase()
{
return database;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void testByteint()
.addRoundTrip("byteint", "127", TINYINT, "CAST(127 AS TINYINT)")
.addRoundTrip("byteint", "-128", TINYINT, "CAST(-128 AS TINYINT)")
.addRoundTrip("byteint", "null", TINYINT, "CAST(null AS TINYINT)")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("byteint"));
.execute(getQueryRunner(), teradataCreateAndInsert("byteint"));
}

@Test
Expand All @@ -75,7 +75,7 @@ void testSmallint()
.addRoundTrip("smallint", "32767", SMALLINT, "CAST(32767 AS SMALLINT)")
.addRoundTrip("smallint", "-32768", SMALLINT, "CAST(-32768 AS SMALLINT)")
.addRoundTrip("smallint", "null", SMALLINT, "CAST(null AS SMALLINT)")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("smallint"));
.execute(getQueryRunner(), teradataCreateAndInsert("smallint"));
}

@Test
Expand All @@ -86,7 +86,7 @@ void testInteger()
.addRoundTrip("integer", "2147483647", INTEGER, "2147483647")
.addRoundTrip("integer", "-2147483648", INTEGER, "-2147483648")
.addRoundTrip("integer", "NULL", INTEGER, "CAST(NULL AS INTEGER)")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("integer"));
.execute(getQueryRunner(), teradataCreateAndInsert("integer"));
}

@Test
Expand All @@ -97,7 +97,7 @@ void testBigint()
.addRoundTrip("bigint", "9223372036854775807", BIGINT, "9223372036854775807")
.addRoundTrip("bigint", "-9223372036854775808", BIGINT, "-9223372036854775808")
.addRoundTrip("bigint", "NULL", BIGINT, "CAST(NULL AS BIGINT)")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("bigint"));
.execute(getQueryRunner(), teradataCreateAndInsert("bigint"));
}

@Test
Expand All @@ -116,7 +116,7 @@ void testFloat()
.addRoundTrip("float", "NULL", DOUBLE, "CAST(NULL AS DOUBLE)")
.addRoundTrip("real", "NULL", DOUBLE, "CAST(NULL AS DOUBLE)")
.addRoundTrip("double precision", "NULL", DOUBLE, "CAST(NULL AS DOUBLE)")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("float"));
.execute(getQueryRunner(), teradataCreateAndInsert("float"));
}

@Test
Expand Down Expand Up @@ -150,7 +150,7 @@ void testDecimal()
.addRoundTrip("decimal(38, 0)", "-12345678901234567890123456789012345678", createDecimalType(38, 0), "CAST('-12345678901234567890123456789012345678' AS decimal(38, 0))")
.addRoundTrip("numeric(38, 0)", "-12345678901234567890123456789012345678", createDecimalType(38, 0), "CAST('-12345678901234567890123456789012345678' AS decimal(38, 0))")
.addRoundTrip("decimal(1, 0)", "null", createDecimalType(1, 0), "CAST(null AS decimal(1, 0))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("decimal"));
.execute(getQueryRunner(), teradataCreateAndInsert("decimal"));
}

@Test
Expand All @@ -163,7 +163,7 @@ void testNumber()
.addRoundTrip("number(38,2)", "123456789012345678901234567890123456.78", createDecimalType(38, 2), "CAST('123456789012345678901234567890123456.78' AS decimal(38, 2))")
.addRoundTrip("numeric(38)", "12345678901234567890123456789012345678", createDecimalType(38, 0), "CAST('12345678901234567890123456789012345678' AS decimal(38, 0))")
.addRoundTrip("numeric(3)", "null", createDecimalType(3, 0), "CAST(null AS decimal(3, 0))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("number"));
.execute(getQueryRunner(), teradataCreateAndInsert("number"));
}

@Test
Expand All @@ -183,20 +183,20 @@ void testChar()
.addRoundTrip("char(3)", "'A C'", createCharType(3), "CAST('A C' AS char(3))")
.addRoundTrip("char(3)", "' BC'", createCharType(3), "CAST(' BC' AS char(3))")
.addRoundTrip("char(3)", "null", createCharType(3), "CAST(null AS char(3))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("char"));
.execute(getQueryRunner(), teradataCreateAndInsert("char"));
String tmode = database.getTMode();
if (tmode.equals("TERA")) {
// truncation
create()
.addRoundTrip("char(3)", "'ABCD'", createCharType(3), "CAST('ABCD' AS char(3))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("chart"));
.execute(getQueryRunner(), teradataCreateAndInsert("chart"));
}
else {
// Error on truncation
assertThatThrownBy(() ->
create()
.addRoundTrip("char(3)", "'ABCD'", createCharType(3), "CAST('ABCD' AS char(3))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("chart")))
.execute(getQueryRunner(), teradataCreateAndInsert("chart")))
.isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(SQLException.class)
.cause()
Expand All @@ -205,7 +205,7 @@ void testChar()
// max-size
create()
.addRoundTrip("char(64000)", "'max'", createCharType(64000), "CAST('max' AS char(64000))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("charl"));
.execute(getQueryRunner(), teradataCreateAndInsert("charl"));
}

@Test
Expand All @@ -226,20 +226,20 @@ void testVarchar()
.addRoundTrip("varchar(32)", "'A C'", createVarcharType(32), "CAST('A C' AS varchar(32))")
.addRoundTrip("varchar(32)", "' BC'", createVarcharType(32), "CAST(' BC' AS varchar(32))")
.addRoundTrip("varchar(32)", "null", createVarcharType(32), "CAST(null AS varchar(32))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("varchar"));
.execute(getQueryRunner(), teradataCreateAndInsert("varchar"));
String teraMode = database.getTMode();
if (teraMode.equals("TERA")) {
// truncation
create()
.addRoundTrip("varchar(3)", "'ABCD'", createVarcharType(3), "CAST('ABCD' AS varchar(3))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("varchart"));
.execute(getQueryRunner(), teradataCreateAndInsert("varchart"));
}
else {
// Error on truncation
assertThatThrownBy(() ->
create()
.addRoundTrip("varchar(3)", "'ABCD'", createVarcharType(3), "CAST('ABCD' AS varchar(3))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("varchart")))
.execute(getQueryRunner(), teradataCreateAndInsert("varchart")))
.isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(SQLException.class)
.cause()
Expand All @@ -248,7 +248,7 @@ void testVarchar()
// max-size
create()
.addRoundTrip("long varchar", "'max'", createVarcharType(64000), "CAST('max' AS varchar(64000))")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("varcharl"));
.execute(getQueryRunner(), teradataCreateAndInsert("varcharl"));
}

@Test
Expand All @@ -271,10 +271,10 @@ void testDate()
.addRoundTrip("date", "DATE '2024-02-29'", DATE, "DATE '2024-02-29'")
.addRoundTrip("date", "DATE '9999-12-30'", DATE, "DATE '9999-12-30'")
.addRoundTrip("date", "NULL", DATE, "CAST(NULL AS DATE)")
.execute(getQueryRunner(), teradataJDBCCreateAndInsert("date"));
.execute(getQueryRunner(), teradataCreateAndInsert("date"));
}

private DataSetup teradataJDBCCreateAndInsert(String tableNamePrefix)
private DataSetup teradataCreateAndInsert(String tableNamePrefix)
{
String prefix = format("%s.%s", database.getDatabaseName(), tableNamePrefix);
return new CreateAndInsertDataSetup(database, prefix);
Expand Down
Loading
Loading