Skip to content

Commit

Permalink
fixes in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Dec 12, 2023
1 parent a2b9627 commit a839d7b
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 53 deletions.
Empty file removed hive.properties
Empty file.
97 changes: 62 additions & 35 deletions src/main/java/com/caretdev/trino/plugin/iris/IRISClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,24 @@
import io.trino.spi.TrinoException;
import io.trino.spi.connector.*;
import io.trino.spi.expression.ConnectorExpression;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static io.trino.plugin.jdbc.StandardColumnMappings.*;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;

import io.trino.spi.statistics.TableStatistics;
import io.trino.spi.type.*;

import javax.swing.text.html.Option;
import java.sql.*;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Stream;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static com.google.common.collect.Iterables.getOnlyElement;
import static io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR;
import static io.trino.plugin.jdbc.PredicatePushdownController.FULL_PUSHDOWN;

import static io.trino.plugin.jdbc.StandardColumnMappings.*;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.BooleanType.BOOLEAN;
import static io.trino.spi.type.CharType.createCharType;
import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone;
import static io.trino.spi.type.DateType.DATE;
import static io.trino.spi.type.DecimalType.createDecimalType;
import static io.trino.spi.type.DoubleType.DOUBLE;
Expand All @@ -63,18 +59,15 @@
import static io.trino.spi.type.TimeType.createTimeType;
import static io.trino.spi.type.TimestampType.createTimestampType;
import static io.trino.spi.type.Timestamps.PICOSECONDS_PER_DAY;
import static io.trino.spi.type.Timestamps.round;
import static io.trino.spi.type.TinyintType.TINYINT;
import static io.trino.spi.type.VarbinaryType.VARBINARY;
import static io.trino.spi.type.VarcharType.createUnboundedVarcharType;
import static io.trino.spi.type.VarcharType.createVarcharType;

import static java.lang.Math.max;
import static java.lang.String.format;
import static java.lang.String.join;
import static java.math.RoundingMode.UNNECESSARY;
import static java.util.stream.Collectors.joining;
import static com.google.common.collect.Iterables.getOnlyElement;

public class IRISClient
extends BaseJdbcClient {
Expand Down Expand Up @@ -114,7 +107,7 @@ public IRISClient(
.map("$like(value: varchar, pattern: varchar): boolean").to("value LIKE pattern")
.map("$like(value: varchar, pattern: varchar, escape: varchar(1)): boolean").to("value LIKE pattern ESCAPE escape")
.map("$not($is_null(value))").to("value IS NOT NULL")
.map("$not(value: boolean)").to("NOT value")
.map("$not(value: boolean)").to("value = 0")
.map("$is_null(value)").to("value IS NULL")
.map("$nullif(first, second)").to("NULLIF(first, second)")
.build();
Expand All @@ -130,15 +123,6 @@ public IRISClient(
.add(new ImplementSum(IRISClient::toTypeHandle))
.add(new ImplementAvgFloatingPoint())
.add(new ImplementAvgDecimal())
// .add(new ImplementStddevSamp())
// .add(new ImplementStddevPop())
// .add(new ImplementVarianceSamp())
// .add(new ImplementVariancePop())
// .add(new ImplementCovarianceSamp())
// .add(new ImplementCovariancePop())
// .add(new ImplementCorr())
// .add(new ImplementRegrIntercept())
// .add(new ImplementRegrSlope())
.build());
}

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



@Override
protected void createSchema(ConnectorSession session, Connection connection, String remoteSchemaName) throws SQLException {
assert true;
Expand Down Expand Up @@ -189,25 +172,66 @@ protected List<String> createTableSqls(RemoteTableName remoteTableName, List<Str
return createTableSqlsBuilder.build();
}

@Override
protected String getColumnDefinitionSql(ConnectorSession session, ColumnMetadata column, String columnName) {
StringBuilder sb = new StringBuilder()
.append(quoted(columnName))
.append(" ")
.append(toWriteMapping(session, column.getType()).getDataType());
if (!column.isNullable()) {
sb.append(" NOT NULL");
}
if (column.getComment() != null) {
sb.append(" %Description " + varcharLiteral(column.getComment()));
}
return sb.toString();
}

@Override
protected void renameTable(ConnectorSession session, Connection connection, String catalogName, String remoteSchemaName, String remoteTableName, String newRemoteSchemaName, String newRemoteTableName)
throws SQLException
{
if (!remoteSchemaName.equals(newRemoteSchemaName)) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support renaming tables across schemas");
}
execute(session, connection, format(
"ALTER TABLE %s RENAME %s",
quoted(catalogName, remoteSchemaName, remoteTableName),
quoted(null, null, newRemoteTableName)));
}

@Override
public Collection<String> listSchemas(Connection connection) {
ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder();
schemaNames.addAll(super.listSchemas(connection).stream().filter(
schema ->
!schema.startsWith("%")
&& !schema.startsWith("ens.")
&& !schema.startsWith("enslib_")
&& !schema.startsWith("hsfhir_")
&& !schema.startsWith("hs_")
).toList());
schemaNames.addAll(super.listSchemas(connection));

if (schemaTableNameOverrideExist != null) {
schemaNames.add(schemaTableNameOverrideExist);
}
// schemaNames.add("sqluser");
// schemaNames.add("tpch");
try {
schemaNames.add(connection.getSchema().toLowerCase());
} catch (SQLException e) {

}
return schemaNames.build();
}

protected boolean filterSchema(String schemaName) {
schemaName = schemaName.toLowerCase();
return !schemaName.startsWith("%")
&& !schemaName.equalsIgnoreCase("information_schema")
&& !schemaName.equalsIgnoreCase("ens")
&& !schemaName.equalsIgnoreCase("ensportal")
&& !schemaName.startsWith("ens_")
&& !schemaName.startsWith("ensportal_")
&& !schemaName.startsWith("enslib_")
&& !schemaName.startsWith("hs_")
&& !schemaName.startsWith("hsfhir_")
&& !schemaName.startsWith("hsmod_")
&& !schemaName.startsWith("schemamap_")
;
}

@Override
public void renameSchema(ConnectorSession session, String schemaName, String newSchemaName) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support renaming schemas");
Expand Down Expand Up @@ -341,6 +365,10 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
return WriteMapping.objectMapping(dataType, longDecimalWriteFunction(decimalType));
}

if (type instanceof CharType) {
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
}

if (type instanceof VarbinaryType) {
return WriteMapping.sliceMapping("varbinary(max)", varbinaryWriteFunction());
}
Expand Down Expand Up @@ -371,8 +399,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}

private static LongWriteFunction irisTimeWriteFunction(int precision)
{
private static LongWriteFunction irisTimeWriteFunction(int precision) {
checkArgument(precision <= 12, "Unsupported precision: %s", precision);

return LongWriteFunction.of(Types.TIME, (statement, index, picosOfDay) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.caretdev.trino.plugin.iris;

import io.trino.Session;
import io.trino.plugin.jdbc.BaseJdbcConnectorTest;
import io.trino.sql.planner.plan.TopNNode;
import io.trino.testing.QueryRunner;
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.TestingNames;
import io.trino.testing.sql.SqlExecutor;
import org.intellij.lang.annotations.Language;
import org.testng.annotations.Test;

import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;

import static com.caretdev.trino.plugin.iris.IRISQueryRunner.createIRISQueryRunner;
import static io.trino.testing.TestingConnectorBehavior.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

public class TestIRISConnectorTest extends BaseJdbcConnectorTest {

Expand All @@ -32,14 +29,16 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) {
SUPPORTS_AGGREGATION_PUSHDOWN_REGRESSION,
SUPPORTS_ARRAY,
SUPPORTS_COMMENT_ON_COLUMN,
SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT,
// SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT,
// SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT,
SUPPORTS_COMMENT_ON_TABLE,
SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM,
SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN,
SUPPORTS_NEGATIVE_DATE,
SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY,
SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY,
SUPPORTS_RENAME_SCHEMA,
SUPPORTS_CREATE_SCHEMA,
SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS,
SUPPORTS_ROW_TYPE -> false;
default -> super.hasBehavior(connectorBehavior);
};
Expand Down Expand Up @@ -74,24 +73,35 @@ protected Optional<String> filterColumnNameTestData(String columnName) {
}

@Override
protected Optional<SetColumnTypeSetup> filterSetColumnTypesDataProvider(SetColumnTypeSetup setup)
{
switch ("%s -> %s".formatted(setup.sourceColumnType(), setup.newColumnType())) {
case "varchar -> char(20)":
return Optional.of(setup.asUnsupported());
protected Optional<SetColumnTypeSetup> filterSetColumnTypesDataProvider(SetColumnTypeSetup setup) {
switch (setup.newColumnType()) {
case "decimal(38,3)": // -> decimal(22,3)
case "varchar": // -> varchar(65535)
case "char(20)": // -> varchar(20)
case "timestamp(3)": // -> timestamp(3)
case "timestamp(6)": // -> timestamp(3)
return Optional.empty();
}
// return Optional.of(setup);
return Optional.of(setup.asUnsupported());
if (setup.sourceColumnType().startsWith("time(")) {
// No milliseconds
return Optional.of(setup.withNewValueLiteral("TIME '15:03:00'"));
}
return Optional.of(setup);
}

@Test
@Override
public void testCreateTableAsSelectSchemaNotFound() {
// not for IRIS
}

@Override
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup)
{
public void testCaseSensitiveDataMapping(DataMappingTestSetup dataMappingTestSetup) {

}


@Override
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup) {
String typeName = dataMappingTestSetup.getTrinoTypeName();
if (typeName.equals("time(3)") || typeName.equals("time(6)")
|| typeName.equals("timestamp(3) with time zone")
Expand All @@ -102,4 +112,53 @@ protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMapp
return Optional.of(dataMappingTestSetup);
}

@Override
protected OptionalInt maxSchemaNameLength() {
return OptionalInt.of(128);
}

@Override
protected OptionalInt maxTableNameLength() {
return OptionalInt.of(512);
}

@Override
public void testCreateTableWithLongColumnName() {
// IRIS does not have fixed max length
}

@Override
public void testCreateTableWithLongTableName() {
// IRIS does not have fixed max length
}

@Override
public void testRenameTableToLongTableName() {
// IRIS does not have fixed max length
}

@Override
@Language("RegExp")
protected String errorMessageForInsertNegativeDate(String date) {
return ".*SQLCODE: <-104>:<Field validation failed in INSERT>.*\n.* < MIN .*";
}


@Test
public void testRenameSchema() {

}

@Override
public void testCreateTableSchemaNotFound() {
assertThatThrownBy(super::testCreateTableSchemaNotFound)
.hasMessageContaining("Expected query to fail: CREATE TABLE test_schema_");

}

@Override
public void testCreateSchema() {
assertThatThrownBy(super::testCreateTableSchemaNotFound)
.hasMessageContaining("Expected query to fail: CREATE TABLE test_schema_");
}
}

0 comments on commit a839d7b

Please sign in to comment.