Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.net.InetAddresses;
import io.airlift.slice.Slice;
import io.trino.spi.TrinoException;
import io.trino.spi.block.Block;
import io.trino.spi.block.RowBlockBuilder;
import io.trino.spi.block.SingleRowBlockWriter;
Expand Down Expand Up @@ -70,6 +71,7 @@
import static io.airlift.slice.Slices.wrappedBuffer;
import static io.trino.plugin.cassandra.util.CassandraCqlUtils.quoteStringLiteral;
import static io.trino.plugin.cassandra.util.CassandraCqlUtils.quoteStringLiteralForJson;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone;
import static io.trino.spi.type.DateTimeEncoding.unpackMillisUtc;
import static io.trino.spi.type.TypeUtils.writeNativeValue;
Expand Down Expand Up @@ -662,7 +664,7 @@ public static CassandraType toCassandraType(Type type, ProtocolVersion protocolV
if (type.equals(UuidType.UUID)) {
return CassandraTypes.UUID;
}
throw new IllegalArgumentException("unsupported type: " + type);
throw new TrinoException(NOT_SUPPORTED, "Unsupported type: " + type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

case SUPPORTS_ADD_COLUMN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

case SUPPORTS_NEGATIVE_DATE:
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_NOT_NULL_CONSTRAINT:
case SUPPORTS_TOPN_PUSHDOWN:
return false;

case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

case SUPPORTS_NEGATIVE_DATE:
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

case SUPPORTS_CREATE_SCHEMA:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
// Arrays are supported conditionally. Check the defaults.
return new PostgreSqlConfig().getArrayMapping() != PostgreSqlConfig.ArrayMapping.DISABLED;

case SUPPORTS_ROW_TYPE:
return false;

case SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS:
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,6 @@ private static StorageType toStorageType(Type type)
if (isMapType(type)) {
return mapOf(toStorageType(type.getTypeParameters().get(0)), toStorageType(type.getTypeParameters().get(1)));
}
throw new TrinoException(NOT_SUPPORTED, "No storage type for type: " + type);
throw new TrinoException(NOT_SUPPORTED, "Unsupported type: " + type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_NOT_NULL_CONSTRAINT:
case SUPPORTS_TOPN_PUSHDOWN:
return false;

case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

case SUPPORTS_RENAME_SCHEMA:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

case SUPPORTS_NEGATIVE_DATE:
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_TABLE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_ROW_LEVEL_DELETE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_ROW_TYPE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_TOPN_PUSHDOWN;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_TRUNCATE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_UPDATE;
Expand Down Expand Up @@ -2855,11 +2856,8 @@ private void testDataMapping(DataMappingTestSetup dataMappingTestSetup)
assertUpdate(createTable, 3);
};
if (dataMappingTestSetup.isUnsupportedType()) {
String typeNameBase = trinoTypeName.replaceFirst("\\(.*", "");
String expectedMessagePart = format("(%1$s.*not (yet )?supported)|((?i)unsupported.*%1$s)|((?i)not supported.*%1$s)", Pattern.quote(typeNameBase));
assertThatThrownBy(setup::run)
.hasMessageFindingMatch(expectedMessagePart)
.satisfies(e -> assertThat(getTrinoExceptionCause(e)).hasMessageFindingMatch(expectedMessagePart));
.satisfies(exception -> verifyUnsupportedTypeException(exception, trinoTypeName));
return;
}
setup.run();
Expand Down Expand Up @@ -2958,6 +2956,69 @@ private List<DataMappingTestSetup> testCaseSensitiveDataMappingData()
.build();
}

/**
* A regression test for row (struct) dereference pushdown edge case, with duplicate expressions.
* See https://github.com/trinodb/trino/issues/11559 and https://github.com/trinodb/trino/issues/11560.
*/
@Test
public void testPotentialDuplicateDereferencePushdown()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE_WITH_DATA));

String tableName = "test_dup_deref_" + randomTableSuffix();
String createTable = "CREATE TABLE " + tableName + " AS SELECT CAST(ROW('abc', 1) AS row(a varchar, b bigint)) r";
if (!hasBehavior(SUPPORTS_ROW_TYPE)) {
try {
assertUpdate(createTable);
}
catch (Exception expected) {
verifyUnsupportedTypeException(expected, "row(a varchar, b bigint)");
return;
}
assertUpdate("DROP TABLE " + tableName);
fail("Expected create table failure");
}

assertUpdate(createTable, 1);
try {
assertThat(query("SELECT r, r.b + 2 FROM " + tableName))
.matches("SELECT CAST(ROW('abc', 1) AS ROW(a varchar, b bigint)), BIGINT '3'");

assertThat(query("SELECT r[1], r[2], r.b + 2 FROM " + tableName))
.matches("VALUES (VARCHAR 'abc', BIGINT '1', BIGINT '3')");

assertThat(query("SELECT r[2], r.b + 2 FROM " + tableName))
.matches("VALUES (BIGINT '1', BIGINT '3')");

assertThat(query("SELECT r.b, r.b + 2 FROM " + tableName))
.matches("VALUES (BIGINT '1', BIGINT '3')");

assertThat(query("SELECT r, r.a LIKE '%c' FROM " + tableName))
.matches("SELECT CAST(ROW('abc', 1) AS ROW(a varchar, b bigint)), true");

assertThat(query("SELECT r[1], r[2], r.a LIKE '%c' FROM " + tableName))
.matches("VALUES (VARCHAR 'abc', BIGINT '1', true)");

assertThat(query("SELECT r[1], r.a LIKE '%c' FROM " + tableName))
.matches("VALUES (VARCHAR 'abc', true)");

assertThat(query("SELECT r.a, r.a LIKE '%c' FROM " + tableName))
.matches("VALUES (VARCHAR 'abc', true)");
}
finally {
assertUpdate("DROP TABLE " + tableName);
}
}

private void verifyUnsupportedTypeException(Throwable exception, String trinoTypeName)
{
String typeNameBase = trinoTypeName.replaceFirst("\\(.*", "");
String expectedMessagePart = format("(%1$s.*not (yet )?supported)|((?i)unsupported.*%1$s)|((?i)not supported.*%1$s)", Pattern.quote(typeNameBase));
assertThat(exception)
.hasMessageFindingMatch(expectedMessagePart)
.satisfies(e -> assertThat(getTrinoExceptionCause(e)).hasMessageFindingMatch(expectedMessagePart));
}

@Test(dataProvider = "testColumnNameDataProvider")
public void testMaterializedViewColumnName(String columnName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public enum TestingConnectorBehavior
SUPPORTS_TRUNCATE(false),

SUPPORTS_ARRAY,
SUPPORTS_ROW_TYPE,
SUPPORTS_NEGATIVE_DATE,

SUPPORTS_CANCELLATION(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_ARRAY:
return false;

case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down