Skip to content

Commit a839d7b

Browse files
committed
fixes in tests
1 parent a2b9627 commit a839d7b

File tree

3 files changed

+139
-53
lines changed

3 files changed

+139
-53
lines changed

hive.properties

Whitespace-only changes.

src/main/java/com/caretdev/trino/plugin/iris/IRISClient.java

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,24 @@
3232
import io.trino.spi.TrinoException;
3333
import io.trino.spi.connector.*;
3434
import io.trino.spi.expression.ConnectorExpression;
35-
36-
import static com.google.common.base.Preconditions.checkArgument;
37-
import static com.google.common.base.Verify.verify;
38-
import static io.trino.plugin.jdbc.StandardColumnMappings.*;
39-
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
40-
4135
import io.trino.spi.statistics.TableStatistics;
4236
import io.trino.spi.type.*;
4337

44-
import javax.swing.text.html.Option;
4538
import java.sql.*;
4639
import java.util.*;
4740
import java.util.function.BiFunction;
4841
import java.util.stream.Stream;
4942

43+
import static com.google.common.base.Preconditions.checkArgument;
44+
import static com.google.common.base.Verify.verify;
45+
import static com.google.common.collect.Iterables.getOnlyElement;
5046
import static io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR;
5147
import static io.trino.plugin.jdbc.PredicatePushdownController.FULL_PUSHDOWN;
52-
48+
import static io.trino.plugin.jdbc.StandardColumnMappings.*;
49+
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
5350
import static io.trino.spi.type.BigintType.BIGINT;
5451
import static io.trino.spi.type.BooleanType.BOOLEAN;
5552
import static io.trino.spi.type.CharType.createCharType;
56-
import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone;
5753
import static io.trino.spi.type.DateType.DATE;
5854
import static io.trino.spi.type.DecimalType.createDecimalType;
5955
import static io.trino.spi.type.DoubleType.DOUBLE;
@@ -63,18 +59,15 @@
6359
import static io.trino.spi.type.TimeType.createTimeType;
6460
import static io.trino.spi.type.TimestampType.createTimestampType;
6561
import static io.trino.spi.type.Timestamps.PICOSECONDS_PER_DAY;
66-
import static io.trino.spi.type.Timestamps.round;
6762
import static io.trino.spi.type.TinyintType.TINYINT;
6863
import static io.trino.spi.type.VarbinaryType.VARBINARY;
6964
import static io.trino.spi.type.VarcharType.createUnboundedVarcharType;
7065
import static io.trino.spi.type.VarcharType.createVarcharType;
71-
7266
import static java.lang.Math.max;
7367
import static java.lang.String.format;
7468
import static java.lang.String.join;
7569
import static java.math.RoundingMode.UNNECESSARY;
7670
import static java.util.stream.Collectors.joining;
77-
import static com.google.common.collect.Iterables.getOnlyElement;
7871

7972
public class IRISClient
8073
extends BaseJdbcClient {
@@ -114,7 +107,7 @@ public IRISClient(
114107
.map("$like(value: varchar, pattern: varchar): boolean").to("value LIKE pattern")
115108
.map("$like(value: varchar, pattern: varchar, escape: varchar(1)): boolean").to("value LIKE pattern ESCAPE escape")
116109
.map("$not($is_null(value))").to("value IS NOT NULL")
117-
.map("$not(value: boolean)").to("NOT value")
110+
.map("$not(value: boolean)").to("value = 0")
118111
.map("$is_null(value)").to("value IS NULL")
119112
.map("$nullif(first, second)").to("NULLIF(first, second)")
120113
.build();
@@ -130,15 +123,6 @@ public IRISClient(
130123
.add(new ImplementSum(IRISClient::toTypeHandle))
131124
.add(new ImplementAvgFloatingPoint())
132125
.add(new ImplementAvgDecimal())
133-
// .add(new ImplementStddevSamp())
134-
// .add(new ImplementStddevPop())
135-
// .add(new ImplementVarianceSamp())
136-
// .add(new ImplementVariancePop())
137-
// .add(new ImplementCovarianceSamp())
138-
// .add(new ImplementCovariancePop())
139-
// .add(new ImplementCorr())
140-
// .add(new ImplementRegrIntercept())
141-
// .add(new ImplementRegrSlope())
142126
.build());
143127
}
144128

@@ -149,7 +133,6 @@ public boolean schemaExists(ConnectorSession session, String schema) {
149133
}
150134

151135

152-
153136
@Override
154137
protected void createSchema(ConnectorSession session, Connection connection, String remoteSchemaName) throws SQLException {
155138
assert true;
@@ -189,25 +172,66 @@ protected List<String> createTableSqls(RemoteTableName remoteTableName, List<Str
189172
return createTableSqlsBuilder.build();
190173
}
191174

175+
@Override
176+
protected String getColumnDefinitionSql(ConnectorSession session, ColumnMetadata column, String columnName) {
177+
StringBuilder sb = new StringBuilder()
178+
.append(quoted(columnName))
179+
.append(" ")
180+
.append(toWriteMapping(session, column.getType()).getDataType());
181+
if (!column.isNullable()) {
182+
sb.append(" NOT NULL");
183+
}
184+
if (column.getComment() != null) {
185+
sb.append(" %Description " + varcharLiteral(column.getComment()));
186+
}
187+
return sb.toString();
188+
}
189+
190+
@Override
191+
protected void renameTable(ConnectorSession session, Connection connection, String catalogName, String remoteSchemaName, String remoteTableName, String newRemoteSchemaName, String newRemoteTableName)
192+
throws SQLException
193+
{
194+
if (!remoteSchemaName.equals(newRemoteSchemaName)) {
195+
throw new TrinoException(NOT_SUPPORTED, "This connector does not support renaming tables across schemas");
196+
}
197+
execute(session, connection, format(
198+
"ALTER TABLE %s RENAME %s",
199+
quoted(catalogName, remoteSchemaName, remoteTableName),
200+
quoted(null, null, newRemoteTableName)));
201+
}
202+
192203
@Override
193204
public Collection<String> listSchemas(Connection connection) {
194205
ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder();
195-
schemaNames.addAll(super.listSchemas(connection).stream().filter(
196-
schema ->
197-
!schema.startsWith("%")
198-
&& !schema.startsWith("ens.")
199-
&& !schema.startsWith("enslib_")
200-
&& !schema.startsWith("hsfhir_")
201-
&& !schema.startsWith("hs_")
202-
).toList());
206+
schemaNames.addAll(super.listSchemas(connection));
207+
203208
if (schemaTableNameOverrideExist != null) {
204209
schemaNames.add(schemaTableNameOverrideExist);
205210
}
206-
// schemaNames.add("sqluser");
207-
// schemaNames.add("tpch");
211+
try {
212+
schemaNames.add(connection.getSchema().toLowerCase());
213+
} catch (SQLException e) {
214+
215+
}
208216
return schemaNames.build();
209217
}
210218

219+
protected boolean filterSchema(String schemaName) {
220+
schemaName = schemaName.toLowerCase();
221+
return !schemaName.startsWith("%")
222+
&& !schemaName.equalsIgnoreCase("information_schema")
223+
&& !schemaName.equalsIgnoreCase("ens")
224+
&& !schemaName.equalsIgnoreCase("ensportal")
225+
&& !schemaName.startsWith("ens_")
226+
&& !schemaName.startsWith("ensportal_")
227+
&& !schemaName.startsWith("enslib_")
228+
&& !schemaName.startsWith("hs_")
229+
&& !schemaName.startsWith("hsfhir_")
230+
&& !schemaName.startsWith("hsmod_")
231+
&& !schemaName.startsWith("schemamap_")
232+
;
233+
}
234+
211235
@Override
212236
public void renameSchema(ConnectorSession session, String schemaName, String newSchemaName) {
213237
throw new TrinoException(NOT_SUPPORTED, "This connector does not support renaming schemas");
@@ -341,6 +365,10 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
341365
return WriteMapping.objectMapping(dataType, longDecimalWriteFunction(decimalType));
342366
}
343367

368+
if (type instanceof CharType) {
369+
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
370+
}
371+
344372
if (type instanceof VarbinaryType) {
345373
return WriteMapping.sliceMapping("varbinary(max)", varbinaryWriteFunction());
346374
}
@@ -371,8 +399,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
371399
throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
372400
}
373401

374-
private static LongWriteFunction irisTimeWriteFunction(int precision)
375-
{
402+
private static LongWriteFunction irisTimeWriteFunction(int precision) {
376403
checkArgument(precision <= 12, "Unsupported precision: %s", precision);
377404

378405
return LongWriteFunction.of(Types.TIME, (statement, index, picosOfDay) -> {

src/test/java/com/caretdev/trino/plugin/iris/TestIRISConnectorTest.java

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package com.caretdev.trino.plugin.iris;
22

3-
import io.trino.Session;
43
import io.trino.plugin.jdbc.BaseJdbcConnectorTest;
5-
import io.trino.sql.planner.plan.TopNNode;
64
import io.trino.testing.QueryRunner;
75
import io.trino.testing.TestingConnectorBehavior;
8-
import io.trino.testing.TestingNames;
96
import io.trino.testing.sql.SqlExecutor;
7+
import org.intellij.lang.annotations.Language;
108
import org.testng.annotations.Test;
119

1210
import java.util.Map;
1311
import java.util.Optional;
12+
import java.util.OptionalInt;
1413

15-
import static com.caretdev.trino.plugin.iris.IRISQueryRunner.createIRISQueryRunner;
16-
import static io.trino.testing.TestingConnectorBehavior.*;
17-
import static org.assertj.core.api.Assertions.assertThat;
14+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
1815

1916
public class TestIRISConnectorTest extends BaseJdbcConnectorTest {
2017

@@ -32,14 +29,16 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) {
3229
SUPPORTS_AGGREGATION_PUSHDOWN_REGRESSION,
3330
SUPPORTS_ARRAY,
3431
SUPPORTS_COMMENT_ON_COLUMN,
35-
SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT,
36-
// SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT,
32+
// SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT,
33+
SUPPORTS_COMMENT_ON_TABLE,
3734
SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM,
3835
SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN,
3936
SUPPORTS_NEGATIVE_DATE,
4037
SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY,
4138
SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY,
4239
SUPPORTS_RENAME_SCHEMA,
40+
SUPPORTS_CREATE_SCHEMA,
41+
SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS,
4342
SUPPORTS_ROW_TYPE -> false;
4443
default -> super.hasBehavior(connectorBehavior);
4544
};
@@ -74,24 +73,35 @@ protected Optional<String> filterColumnNameTestData(String columnName) {
7473
}
7574

7675
@Override
77-
protected Optional<SetColumnTypeSetup> filterSetColumnTypesDataProvider(SetColumnTypeSetup setup)
78-
{
79-
switch ("%s -> %s".formatted(setup.sourceColumnType(), setup.newColumnType())) {
80-
case "varchar -> char(20)":
81-
return Optional.of(setup.asUnsupported());
76+
protected Optional<SetColumnTypeSetup> filterSetColumnTypesDataProvider(SetColumnTypeSetup setup) {
77+
switch (setup.newColumnType()) {
78+
case "decimal(38,3)": // -> decimal(22,3)
79+
case "varchar": // -> varchar(65535)
80+
case "char(20)": // -> varchar(20)
81+
case "timestamp(3)": // -> timestamp(3)
82+
case "timestamp(6)": // -> timestamp(3)
83+
return Optional.empty();
8284
}
83-
// return Optional.of(setup);
84-
return Optional.of(setup.asUnsupported());
85+
if (setup.sourceColumnType().startsWith("time(")) {
86+
// No milliseconds
87+
return Optional.of(setup.withNewValueLiteral("TIME '15:03:00'"));
88+
}
89+
return Optional.of(setup);
8590
}
8691

87-
@Test
92+
@Override
8893
public void testCreateTableAsSelectSchemaNotFound() {
8994
// not for IRIS
9095
}
9196

9297
@Override
93-
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup)
94-
{
98+
public void testCaseSensitiveDataMapping(DataMappingTestSetup dataMappingTestSetup) {
99+
100+
}
101+
102+
103+
@Override
104+
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup) {
95105
String typeName = dataMappingTestSetup.getTrinoTypeName();
96106
if (typeName.equals("time(3)") || typeName.equals("time(6)")
97107
|| typeName.equals("timestamp(3) with time zone")
@@ -102,4 +112,53 @@ protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMapp
102112
return Optional.of(dataMappingTestSetup);
103113
}
104114

115+
@Override
116+
protected OptionalInt maxSchemaNameLength() {
117+
return OptionalInt.of(128);
118+
}
119+
120+
@Override
121+
protected OptionalInt maxTableNameLength() {
122+
return OptionalInt.of(512);
123+
}
124+
125+
@Override
126+
public void testCreateTableWithLongColumnName() {
127+
// IRIS does not have fixed max length
128+
}
129+
130+
@Override
131+
public void testCreateTableWithLongTableName() {
132+
// IRIS does not have fixed max length
133+
}
134+
135+
@Override
136+
public void testRenameTableToLongTableName() {
137+
// IRIS does not have fixed max length
138+
}
139+
140+
@Override
141+
@Language("RegExp")
142+
protected String errorMessageForInsertNegativeDate(String date) {
143+
return ".*SQLCODE: <-104>:<Field validation failed in INSERT>.*\n.* < MIN .*";
144+
}
145+
146+
147+
@Test
148+
public void testRenameSchema() {
149+
150+
}
151+
152+
@Override
153+
public void testCreateTableSchemaNotFound() {
154+
assertThatThrownBy(super::testCreateTableSchemaNotFound)
155+
.hasMessageContaining("Expected query to fail: CREATE TABLE test_schema_");
156+
157+
}
158+
159+
@Override
160+
public void testCreateSchema() {
161+
assertThatThrownBy(super::testCreateTableSchemaNotFound)
162+
.hasMessageContaining("Expected query to fail: CREATE TABLE test_schema_");
163+
}
105164
}

0 commit comments

Comments
 (0)