Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for materialized view column comments #18016

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions plugin/trino-blackhole/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-testing-services</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-tpch</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.trino.spi.connector.ColumnMetadata;
import io.trino.spi.connector.ConnectorAnalyzeMetadata;
import io.trino.spi.connector.ConnectorInsertTableHandle;
import io.trino.spi.connector.ConnectorMaterializedViewDefinition;
ebyhr marked this conversation as resolved.
Show resolved Hide resolved
vlad-lyutenko marked this conversation as resolved.
Show resolved Hide resolved
import io.trino.spi.connector.ConnectorMergeTableHandle;
import io.trino.spi.connector.ConnectorMetadata;
import io.trino.spi.connector.ConnectorOutputMetadata;
Expand All @@ -33,6 +34,7 @@
import io.trino.spi.connector.ConnectorTableLayout;
import io.trino.spi.connector.ConnectorTableMetadata;
import io.trino.spi.connector.ConnectorViewDefinition;
import io.trino.spi.connector.MaterializedViewFreshness;
import io.trino.spi.connector.RetryMode;
import io.trino.spi.connector.RowChangeParadigm;
import io.trino.spi.connector.SchemaNotFoundException;
Expand Down Expand Up @@ -71,6 +73,7 @@
import static io.trino.plugin.blackhole.BlackHolePageSourceProvider.isNumericType;
import static io.trino.spi.StandardErrorCode.ALREADY_EXISTS;
import static io.trino.spi.StandardErrorCode.INVALID_TABLE_PROPERTY;
import static io.trino.spi.connector.MaterializedViewFreshness.Freshness.STALE;
import static io.trino.spi.connector.RetryMode.NO_RETRIES;
import static io.trino.spi.connector.RowChangeParadigm.DELETE_ROW_AND_INSERT_ROW;
import static io.trino.spi.type.BigintType.BIGINT;
Expand All @@ -86,6 +89,7 @@ public class BlackHoleMetadata
private final List<String> schemas = new ArrayList<>();
private final Map<SchemaTableName, BlackHoleTableHandle> tables = new ConcurrentHashMap<>();
private final Map<SchemaTableName, ConnectorViewDefinition> views = new ConcurrentHashMap<>();
private final Map<SchemaTableName, ConnectorMaterializedViewDefinition> materializedViews = new ConcurrentHashMap<>();

public BlackHoleMetadata()
{
Expand Down Expand Up @@ -147,6 +151,7 @@ public List<SchemaTableName> listTables(ConnectorSession session, Optional<Strin
.map(BlackHoleTableHandle::toSchemaTableName)
.collect(toList()))
.addAll(listViews(session, schemaName))
.addAll(listMaterializedViews(session, schemaName))
.build().asList();
}

Expand Down Expand Up @@ -408,4 +413,46 @@ public void setViewColumnComment(ConnectorSession session, SchemaTableName viewN
view.getOwner(),
view.isRunAsInvoker()));
}

@Override
public boolean delegateMaterializedViewRefreshToConnector(ConnectorSession session, SchemaTableName viewName)
{
return false;
}

@Override
public void dropMaterializedView(ConnectorSession session, SchemaTableName viewName)
{
materializedViews.remove(viewName);
}

@Override
public void createMaterializedView(ConnectorSession session, SchemaTableName viewName, ConnectorMaterializedViewDefinition definition, boolean replace, boolean ignoreExisting)
{
materializedViews.put(viewName, definition);
vlad-lyutenko marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public Optional<ConnectorMaterializedViewDefinition> getMaterializedView(ConnectorSession session, SchemaTableName viewName)
{
return Optional.ofNullable(materializedViews.get(viewName));
}

@Override
public Map<SchemaTableName, ConnectorMaterializedViewDefinition> getMaterializedViews(ConnectorSession session, Optional<String> schemaName)
{
return ImmutableMap.copyOf(materializedViews);
}
vlad-lyutenko marked this conversation as resolved.
Show resolved Hide resolved

@Override
public MaterializedViewFreshness getMaterializedViewFreshness(ConnectorSession session, SchemaTableName name)
{
return new MaterializedViewFreshness(STALE, Optional.empty());
}

@Override
vlad-lyutenko marked this conversation as resolved.
Show resolved Hide resolved
public List<SchemaTableName> listMaterializedViews(ConnectorSession session, Optional<String> schemaName)
{
return ImmutableList.copyOf(materializedViews.keySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
import static io.trino.plugin.blackhole.BlackHoleConnector.ROWS_PER_PAGE_PROPERTY;
import static io.trino.plugin.blackhole.BlackHoleConnector.SPLIT_COUNT_PROPERTY;
import static io.trino.plugin.blackhole.BlackHoleQueryRunner.createQueryRunner;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertEquals;

Expand Down Expand Up @@ -174,6 +176,26 @@ public void dataGenerationUsage()
assertThatQueryDoesNotReturnValues("DROP TABLE nation");
}

@Test
public void testMaterializedView()
{
String viewName = "test_materialized_view_" + randomNameSuffix();
queryRunner.execute("CREATE MATERIALIZED VIEW " + viewName + " AS SELECT * FROM tpch.tiny.nation");

try {
// reading
MaterializedResult rows = queryRunner.execute("SELECT * FROM " + viewName);
assertEquals(rows.getRowCount(), 25);
vlad-lyutenko marked this conversation as resolved.
Show resolved Hide resolved

// listing
assertThat(queryRunner.execute("SHOW TABLES").getOnlyColumnAsSet())
.contains(viewName);
}
finally {
assertThatQueryDoesNotReturnValues("DROP MATERIALIZED VIEW " + viewName);
}
}

@Test
public void fieldLength()
{
Expand Down