Skip to content

Commit a25b824

Browse files
committed
Addressed pr review comments
1 parent 946d9b0 commit a25b824

File tree

14 files changed

+154
-81
lines changed

14 files changed

+154
-81
lines changed

core/trino-server/src/main/provisio/trino.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@
284284
</artifact>
285285
</artifactSet>
286286

287+
<artifactSet to="plugin/teradata">
288+
<artifact id="${project.groupId}:trino-teradata:zip:${project.version}">
289+
<unpack />
290+
</artifact>
291+
</artifactSet>
292+
287293
<artifactSet to="plugin/teradata-functions">
288294
<artifact id="${project.groupId}:trino-teradata-functions:zip:${project.version}">
289295
<unpack />

docs/src/main/sphinx/connector/teradata.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To connect to Teradata, you need:
1919
## Configuration
2020

2121
To configure the Teradata connector, create a catalog properties file in
22-
`etc/catalog` named, for example, `teradata.properties`, to mount the Teradata
22+
`etc/catalog` named, for example, `example.properties`, to mount the Teradata
2323
connector as the `teradata` catalog. Create the file with the following
2424
contents, replacing the connection properties as appropriate for your setup:
2525

@@ -51,7 +51,7 @@ your data source, you can enable TLS between your cluster and the data
5151
source by appending parameters to the JDBC connection string set in the
5252
connection-url catalog configuration property.
5353

54-
For example, to specify SSLMODE:
54+
For example, to specify `SSLMODE`:
5555

5656
```properties
5757
connection-url=jdbc:teradata://example.teradata.com/SSLMODE=REQUIRED
@@ -136,6 +136,43 @@ this table:
136136

137137
No other types are supported.
138138

139+
### Trino type to Teradata type mapping
140+
141+
The connector maps Trino types to the corresponding Teradata types following
142+
this table:
143+
144+
:::{list-table} Trino type to Teradata type mapping
145+
:widths: 40, 40, 20
146+
:header-rows: 1
147+
148+
* - Trino type
149+
- Teradata type
150+
- Notes
151+
* - `TINYINT`
152+
- `SMALLINT`
153+
-
154+
* - `SMALLINT`
155+
- `SMALLINT`
156+
-
157+
* - `INTEGER`
158+
- `INTEGER`
159+
-
160+
* - `BIGINT`
161+
- `BIGINT`
162+
-
163+
* - `REAL`
164+
- `FLOAT`
165+
-
166+
* - `DOUBLE`
167+
- `DOUBLE`
168+
-
169+
* - `DATE`
170+
- `DATE`
171+
-
172+
::::
173+
174+
No other types are supported.
175+
139176
```{include} jdbc-type-mapping.fragment
140177
```
141178

@@ -144,28 +181,28 @@ No other types are supported.
144181
The Teradata connector provides a schema for every Teradata database. You can
145182
see the available Teradata databases by running SHOW SCHEMAS:
146183

147-
```
184+
```sql
148185
SHOW SCHEMAS FROM teradata;
149186
```
150187

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

154-
```
191+
```sql
155192
SHOW TABLES FROM teradata.sales;
156193
```
157194

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

161-
```
198+
```sql
162199
DESCRIBE teradata.sales.orders;
163200
SHOW COLUMNS FROM teradata.sales.orders;
164201
```
165202

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

168-
```
205+
```sql
169206
SELECT * FROM teradata.sales.orders;
170207
```
171208

plugin/trino-teradata/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ Once the environment variables are set, run the integration tests with:
3737

3838
⚠️ **Note:** Run the following command from the Trino parent directory.
3939

40-
```
40+
```
4141
./mvnw clean install -pl :trino-teradata
4242
```

plugin/trino-teradata/src/main/java/io/trino/plugin/teradata/TeradataClient.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -113,40 +113,6 @@ public TeradataClient(
113113
this.teradataJDBCCaseSensitivity = teradataConfig.getTeradataCaseSensitivity();
114114
}
115115

116-
private static ColumnMapping charColumnMapping(int charLength, boolean isCaseSensitive)
117-
{
118-
if (charLength > CharType.MAX_LENGTH) {
119-
return varcharColumnMapping(charLength, isCaseSensitive);
120-
}
121-
CharType charType = createCharType(charLength);
122-
return ColumnMapping.sliceMapping(
123-
charType,
124-
charReadFunction(charType),
125-
charWriteFunction(),
126-
isCaseSensitive ? TERADATA_STRING_PUSHDOWN : CASE_INSENSITIVE_CHARACTER_PUSHDOWN);
127-
}
128-
129-
private static ColumnMapping varcharColumnMapping(int varcharLength, boolean isCaseSensitive)
130-
{
131-
VarcharType varcharType = varcharLength <= VarcharType.MAX_LENGTH
132-
? createVarcharType(varcharLength)
133-
: createUnboundedVarcharType();
134-
return ColumnMapping.sliceMapping(
135-
varcharType,
136-
varcharReadFunction(varcharType),
137-
varcharWriteFunction(),
138-
isCaseSensitive ? TERADATA_STRING_PUSHDOWN : CASE_INSENSITIVE_CHARACTER_PUSHDOWN);
139-
}
140-
141-
private boolean deriveCaseSensitivity(CaseSensitivity caseSensitivity)
142-
{
143-
return switch (teradataJDBCCaseSensitivity) {
144-
case CASE_INSENSITIVE -> false;
145-
case CASE_SENSITIVE -> true;
146-
default -> caseSensitivity != null;
147-
};
148-
}
149-
150116
@Override
151117
protected void createSchema(ConnectorSession session, Connection connection, String remoteSchemaName)
152118
{
@@ -340,7 +306,7 @@ public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connect
340306
return Optional.empty();
341307
}
342308

343-
private Optional<ColumnMapping> numberMapping(JdbcTypeHandle typeHandle)
309+
private static Optional<ColumnMapping> numberMapping(JdbcTypeHandle typeHandle)
344310
{
345311
int precision = typeHandle.requiredColumnSize();
346312
int scale = typeHandle.requiredDecimalDigits();
@@ -351,6 +317,40 @@ private Optional<ColumnMapping> numberMapping(JdbcTypeHandle typeHandle)
351317
return Optional.of(decimalColumnMapping(createDecimalType(precision, scale)));
352318
}
353319

320+
private static ColumnMapping charColumnMapping(int charLength, boolean isCaseSensitive)
321+
{
322+
if (charLength > CharType.MAX_LENGTH) {
323+
return varcharColumnMapping(charLength, isCaseSensitive);
324+
}
325+
CharType charType = createCharType(charLength);
326+
return ColumnMapping.sliceMapping(
327+
charType,
328+
charReadFunction(charType),
329+
charWriteFunction(),
330+
isCaseSensitive ? TERADATA_STRING_PUSHDOWN : CASE_INSENSITIVE_CHARACTER_PUSHDOWN);
331+
}
332+
333+
private static ColumnMapping varcharColumnMapping(int varcharLength, boolean isCaseSensitive)
334+
{
335+
VarcharType varcharType = varcharLength <= VarcharType.MAX_LENGTH
336+
? createVarcharType(varcharLength)
337+
: createUnboundedVarcharType();
338+
return ColumnMapping.sliceMapping(
339+
varcharType,
340+
varcharReadFunction(varcharType),
341+
varcharWriteFunction(),
342+
isCaseSensitive ? TERADATA_STRING_PUSHDOWN : CASE_INSENSITIVE_CHARACTER_PUSHDOWN);
343+
}
344+
345+
private boolean deriveCaseSensitivity(CaseSensitivity caseSensitivity)
346+
{
347+
return switch (teradataJDBCCaseSensitivity) {
348+
case CASE_INSENSITIVE -> false;
349+
case CASE_SENSITIVE -> true;
350+
default -> caseSensitivity != null;
351+
};
352+
}
353+
354354
@Override
355355
public WriteMapping toWriteMapping(ConnectorSession session, Type type)
356356
{

plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/TestTeradataPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import io.trino.plugin.jdbc.JdbcConnectorFactory;
1717
import io.trino.spi.connector.ConnectorFactory;
1818
import io.trino.testing.TestingConnectorContext;
19-
import org.junit.jupiter.api.Assertions;
2019
import org.junit.jupiter.api.Test;
2120

2221
import java.util.Map;
@@ -31,7 +30,6 @@ public void testCreateConnector()
3130
{
3231
TeradataPlugin plugin = new TeradataPlugin();
3332
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
34-
Assertions.assertNotNull(factory);
3533
assertThat(factory).isInstanceOf(JdbcConnectorFactory.class);
3634
factory.create("test",
3735
Map.of(

plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/integration/TeradataQueryRunner.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.trino.testing.DistributedQueryRunner;
2626
import io.trino.testing.QueryRunner;
2727
import io.trino.tpch.TpchTable;
28-
import org.assertj.core.api.ObjectAssert;
2928
import org.intellij.lang.annotations.Language;
3029

3130
import java.util.List;
@@ -45,20 +44,6 @@ public static Builder builder(TestingTeradataServer server)
4544
return new Builder(server);
4645
}
4746

48-
public static void main(String[] args)
49-
throws Exception
50-
{
51-
Logging logger = Logging.initialize();
52-
logger.setLevel("io.trino.plugin.teradata", Level.DEBUG);
53-
logger.setLevel("io.trino", Level.INFO);
54-
TestingTeradataServer server = new TestingTeradataServer("TeradataQueryRunner", false);
55-
QueryRunner queryRunner = builder(server).addCoordinatorProperty("http-server.http.port", "8080").setInitialTables(TpchTable.getTables()).build();
56-
57-
Logger log = Logger.get(TeradataQueryRunner.class);
58-
log.info("======== SERVER STARTED ========");
59-
log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl());
60-
}
61-
6247
public static class Builder
6348
extends DistributedQueryRunner.Builder<Builder>
6449
{
@@ -75,8 +60,8 @@ public void copyTable(QueryRunner queryRunner, QualifiedObjectName table, Sessio
7560
{
7661
@Language("SQL") String sql = String.format("CREATE TABLE %s AS SELECT * FROM %s", table.objectName(), table);
7762
queryRunner.execute(session, sql);
78-
((ObjectAssert) assertThat(queryRunner.execute(session, "SELECT count(*) FROM " + table.objectName()).getOnlyValue()).as("Table is not loaded properly: %s", new Object[] {
79-
table.objectName()})).isEqualTo(queryRunner.execute(session, "SELECT count(*) FROM " + table).getOnlyValue());
63+
assertThat(queryRunner.execute(session, "SELECT count(*) FROM " + table.objectName()).getOnlyValue()).as("Table is not loaded properly: %s", new Object[] {
64+
table.objectName()}).isEqualTo(queryRunner.execute(session, "SELECT count(*) FROM " + table).getOnlyValue());
8065
}
8166

8267
public void copyTpchTables(QueryRunner queryRunner, String sourceCatalog, String sourceSchema, Session session, Iterable<TpchTable<?>> tables)
@@ -121,5 +106,19 @@ public DistributedQueryRunner build()
121106
});
122107
return super.build();
123108
}
109+
110+
public static void main(String[] args)
111+
throws Exception
112+
{
113+
Logging logger = Logging.initialize();
114+
logger.setLevel("io.trino.plugin.teradata", Level.DEBUG);
115+
logger.setLevel("io.trino", Level.INFO);
116+
TestingTeradataServer server = new TestingTeradataServer("TeradataQueryRunner", false);
117+
QueryRunner queryRunner = builder(server).addCoordinatorProperty("http-server.http.port", "8080").setInitialTables(TpchTable.getTables()).build();
118+
119+
Logger log = Logger.get(TeradataQueryRunner.class);
120+
log.info("======== SERVER STARTED ========");
121+
log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl());
122+
}
124123
}
125124
}

plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/integration/TestTeradataTypeMapping.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static io.trino.spi.type.TinyintType.TINYINT;
3434
import static io.trino.spi.type.VarcharType.createVarcharType;
3535
import static io.trino.testing.datatype.SqlDataTypeTest.create;
36+
import static java.lang.String.format;
3637
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
3738

3839
final class TestTeradataTypeMapping
@@ -275,7 +276,7 @@ void testDate()
275276

276277
private DataSetup teradataJDBCCreateAndInsert(String tableNamePrefix)
277278
{
278-
String prefix = String.format("%s.%s", database.getDatabaseName(), tableNamePrefix);
279+
String prefix = format("%s.%s", database.getDatabaseName(), tableNamePrefix);
279280
return new CreateAndInsertDataSetup(database, prefix);
280281
}
281282
}

plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/integration/clearscape/BaseException.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@
1616
public class BaseException
1717
extends RuntimeException
1818
{
19-
private final int statusCode;
19+
protected final int statusCode;
2020

2121
public BaseException(int statusCode, String body)
2222
{
2323
super(body);
2424
this.statusCode = statusCode;
2525
}
26-
27-
public int getStatusCode()
28-
{
29-
return statusCode;
30-
}
3126
}

plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/integration/clearscape/CreateEnvironmentRequest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@
1313
*/
1414
package io.trino.plugin.teradata.integration.clearscape;
1515

16+
import static java.util.Objects.requireNonNull;
17+
1618
public record CreateEnvironmentRequest(
1719
String name,
1820
String region,
19-
String password
20-
) {}
21+
String password)
22+
{
23+
public CreateEnvironmentRequest
24+
{
25+
requireNonNull(name, "name should not be null");
26+
requireNonNull(region, "region should not be null");
27+
requireNonNull(password, "password should not be null");
28+
}
29+
}

plugin/trino-teradata/src/test/java/io/trino/plugin/teradata/integration/clearscape/DeleteEnvironmentRequest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
*/
1414
package io.trino.plugin.teradata.integration.clearscape;
1515

16+
import static java.util.Objects.requireNonNull;
17+
1618
public record DeleteEnvironmentRequest(
17-
String name
18-
) {}
19+
String name)
20+
{
21+
public DeleteEnvironmentRequest
22+
{
23+
requireNonNull(name, "name should not be null");
24+
}
25+
}

0 commit comments

Comments
 (0)