Skip to content
Merged
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 @@ -68,6 +68,7 @@
import io.trino.spi.security.Privilege;
import io.trino.spi.security.RoleGrant;
import io.trino.spi.security.TrinoPrincipal;
import io.trino.spi.session.PropertyMetadata;
import io.trino.spi.statistics.ComputedStatistics;
import io.trino.spi.transaction.IsolationLevel;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -124,6 +125,8 @@ public class MockConnector
private final Function<SchemaTableName, List<List<?>>> data;
private final Set<Procedure> procedures;
private final boolean allowMissingColumnsOnInsert;
private final Supplier<List<PropertyMetadata<?>>> schemaProperties;
private final Supplier<List<PropertyMetadata<?>>> tableProperties;

MockConnector(
Function<ConnectorSession, List<String>> listSchemaNames,
Expand All @@ -150,7 +153,9 @@ public class MockConnector
Optional<ConnectorAccessControl> accessControl,
Function<SchemaTableName, List<List<?>>> data,
Set<Procedure> procedures,
boolean allowMissingColumnsOnInsert)
boolean allowMissingColumnsOnInsert,
Supplier<List<PropertyMetadata<?>>> schemaProperties,
Comment thread
Praveen2112 marked this conversation as resolved.
Outdated
Supplier<List<PropertyMetadata<?>>> tableProperties)
{
this.listSchemaNames = requireNonNull(listSchemaNames, "listSchemaNames is null");
this.listTables = requireNonNull(listTables, "listTables is null");
Expand All @@ -177,6 +182,8 @@ public class MockConnector
this.data = requireNonNull(data, "data is null");
this.procedures = requireNonNull(procedures, "procedures is null");
this.allowMissingColumnsOnInsert = allowMissingColumnsOnInsert;
this.schemaProperties = requireNonNull(schemaProperties, "schemaProperties is null");
this.tableProperties = requireNonNull(tableProperties, "tableProperties is null");
}

@Override
Expand Down Expand Up @@ -234,6 +241,18 @@ public Set<Procedure> getProcedures()
return procedures;
}

@Override
public List<PropertyMetadata<?>> getSchemaProperties()
{
return schemaProperties.get();
}

@Override
public List<PropertyMetadata<?>> getTableProperties()
{
return tableProperties.get();
}

private class MockConnectorMetadata
implements ConnectorMetadata
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.trino.spi.procedure.Procedure;
import io.trino.spi.security.RoleGrant;
import io.trino.spi.security.ViewExpression;
import io.trino.spi.session.PropertyMetadata;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -94,6 +95,8 @@ public class MockConnectorFactory
private final Function<SchemaTableName, List<List<?>>> data;
private final Set<Procedure> procedures;
private final boolean allowMissingColumnsOnInsert;
private final Supplier<List<PropertyMetadata<?>>> schemaProperties;
private final Supplier<List<PropertyMetadata<?>>> tableProperties;

// access control
private final ListRoleGrants roleGrants;
Expand Down Expand Up @@ -123,6 +126,8 @@ private MockConnectorFactory(
Supplier<Iterable<EventListener>> eventListeners,
Function<SchemaTableName, List<List<?>>> data,
Set<Procedure> procedures,
Supplier<List<PropertyMetadata<?>>> schemaProperties,
Supplier<List<PropertyMetadata<?>>> tableProperties,
ListRoleGrants roleGrants,
Optional<ConnectorAccessControl> accessControl,
boolean allowMissingColumnsOnInsert)
Expand All @@ -148,6 +153,8 @@ private MockConnectorFactory(
this.getNewTableLayout = requireNonNull(getNewTableLayout, "getNewTableLayout is null");
this.getTableProperties = requireNonNull(getTableProperties, "getTableProperties is null");
this.eventListeners = requireNonNull(eventListeners, "eventListeners is null");
this.schemaProperties = requireNonNull(schemaProperties, "schemaProperties is null");
this.tableProperties = requireNonNull(tableProperties, "tableProperties is null");
this.roleGrants = requireNonNull(roleGrants, "roleGrants is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
this.data = requireNonNull(data, "data is null");
Expand Down Expand Up @@ -195,7 +202,9 @@ public Connector create(String catalogName, Map<String, String> config, Connecto
accessControl,
data,
procedures,
allowMissingColumnsOnInsert);
allowMissingColumnsOnInsert,
schemaProperties,
tableProperties);
}

public static Builder builder()
Expand Down Expand Up @@ -291,6 +300,8 @@ public static final class Builder
private BiFunction<ConnectorSession, SchemaTableName, Optional<CatalogSchemaTableName>> redirectTable = (session, tableName) -> Optional.empty();
private Function<SchemaTableName, List<List<?>>> data = schemaTableName -> ImmutableList.of();
private Set<Procedure> procedures = ImmutableSet.of();
private Supplier<List<PropertyMetadata<?>>> schemaProperties = ImmutableList::of;
private Supplier<List<PropertyMetadata<?>>> tableProperties = ImmutableList::of;

// access control
private boolean provideAccessControl;
Expand Down Expand Up @@ -445,11 +456,22 @@ public Builder withData(Function<SchemaTableName, List<List<?>>> data)

public Builder withProcedures(Set<Procedure> procedures)
{
provideAccessControl = true;
this.procedures = procedures;
return this;
}

public Builder withSchemaProperties(Supplier<List<PropertyMetadata<?>>> schemaProperties)
{
this.schemaProperties = requireNonNull(schemaProperties, "schemaProperties is null");
return this;
}

public Builder withTableProperties(Supplier<List<PropertyMetadata<?>>> tableProperties)
{
this.tableProperties = requireNonNull(tableProperties, "tableProperties is null");
return this;
}

public Builder withListRoleGrants(ListRoleGrants roleGrants)
{
provideAccessControl = true;
Expand Down Expand Up @@ -521,6 +543,8 @@ public MockConnectorFactory build()
eventListeners,
data,
procedures,
schemaProperties,
tableProperties,
roleGrants,
accessControl,
allowMissingColumnsOnInsert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.trino.spi.connector.ConnectorMaterializedViewDefinition;
import io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.session.PropertyMetadata;
import io.trino.testing.AbstractTestQueryFramework;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;
Expand All @@ -35,6 +36,8 @@

import static io.trino.connector.MockConnectorEntities.TPCH_NATION_DATA;
import static io.trino.connector.MockConnectorEntities.TPCH_NATION_SCHEMA;
import static io.trino.spi.session.PropertyMetadata.booleanProperty;
import static io.trino.spi.session.PropertyMetadata.integerProperty;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -60,7 +63,12 @@ protected QueryRunner createQueryRunner()
}
return ImmutableList.of(new ColumnMetadata("nationkey", BIGINT));
})
.withGetTableHandle((session, tableName) -> new MockConnectorTableHandle(tableName))
.withGetTableHandle((session, tableName) -> {
if (tableName.equals(new SchemaTableName("default", "new_table"))) {
return null;
}
return new MockConnectorTableHandle(tableName);
})
.withGetMaterializedViews((session, schemaTablePrefix) -> ImmutableMap.of(
new SchemaTableName("default", "test_materialized_view"),
new ConnectorMaterializedViewDefinition(
Expand All @@ -79,6 +87,12 @@ protected QueryRunner createQueryRunner()
throw new UnsupportedOperationException();
})
.withProcedures(ImmutableSet.of(new TestProcedure().get()))
.withSchemaProperties(() -> ImmutableList.<PropertyMetadata<?>>builder()
.add(booleanProperty("boolean_schema_property", "description", false, false))
.build())
.withTableProperties(() -> ImmutableList.<PropertyMetadata<?>>builder()
.add(integerProperty("integer_table_property", "description", 0, false))
.build())
.build()));
queryRunner.createCatalog("mock", "mock");
return queryRunner;
Expand Down Expand Up @@ -180,4 +194,20 @@ public void testProcedure()
assertThatThrownBy(() -> assertUpdate("CALL mock.default.non_exist_procedure()"))
.hasMessage("Procedure not registered: default.non_exist_procedure");
}

@Test
public void testSchemaProperties()
{
assertUpdate("CREATE SCHEMA mock.test_schema WITH (boolean_schema_property = true)");
assertThatThrownBy(() -> assertUpdate("CREATE SCHEMA mock.test_schema WITH (unknown_property = true)"))
.hasMessage("Catalog 'mock' does not support schema property 'unknown_property'");
}

@Test
public void testTableProperties()
{
assertUpdate("CREATE TABLE mock.default.new_table (c int) WITH (integer_table_property = 1)");
assertThatThrownBy(() -> assertUpdate("CREATE TABLE mock.default.new_table (c int) WITH (unknown_property = 1)"))
.hasMessage("Catalog 'mock' does not support table property 'unknown_property'");
}
}