|
18 | 18 | import io.airlift.units.Duration; |
19 | 19 | import io.trino.spi.connector.ConnectorOutputTableHandle; |
20 | 20 | import io.trino.spi.connector.ConnectorTableMetadata; |
| 21 | +import io.trino.spi.connector.ConnectorViewDefinition; |
21 | 22 | import io.trino.spi.connector.SchemaTableName; |
22 | 23 | import io.trino.spi.security.TrinoPrincipal; |
23 | 24 | import org.junit.jupiter.api.Test; |
|
29 | 30 | import static io.trino.spi.StandardErrorCode.NOT_FOUND; |
30 | 31 | import static io.trino.spi.connector.RetryMode.NO_RETRIES; |
31 | 32 | import static io.trino.spi.security.PrincipalType.USER; |
| 33 | +import static io.trino.spi.type.BigintType.BIGINT; |
32 | 34 | import static io.trino.testing.TestingConnectorSession.SESSION; |
33 | 35 | import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; |
| 36 | +import static java.util.Map.entry; |
34 | 37 | import static java.util.concurrent.TimeUnit.SECONDS; |
35 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
36 | 39 |
|
@@ -84,6 +87,44 @@ void testCreateTableInNotExistSchema() |
84 | 87 | .hasMessage("Schema schema1 not found"); |
85 | 88 | } |
86 | 89 |
|
| 90 | + @Test |
| 91 | + void testGetView() |
| 92 | + { |
| 93 | + ConnectorViewDefinition viewDefinition = createViewDefinition(); |
| 94 | + Map<SchemaTableName, ConnectorViewDefinition> views = ImmutableMap.<SchemaTableName, ConnectorViewDefinition>builder() |
| 95 | + .put(new SchemaTableName("default", "test_view"), viewDefinition) |
| 96 | + .put(new SchemaTableName("default", "test_view2"), viewDefinition) |
| 97 | + .put(new SchemaTableName("default2", "test_view2"), viewDefinition) |
| 98 | + .buildOrThrow(); |
| 99 | + |
| 100 | + for (Map.Entry<SchemaTableName, ConnectorViewDefinition> entry : views.entrySet()) { |
| 101 | + metadata.createView(SESSION, entry.getKey(), entry.getValue(), ImmutableMap.of(), false); |
| 102 | + } |
| 103 | + |
| 104 | + assertThat(metadata.listViews(SESSION, Optional.empty())) |
| 105 | + .containsExactlyElementsOf(views.keySet()); |
| 106 | + assertThat(metadata.listViews(SESSION, Optional.of("default"))) |
| 107 | + .containsExactly(new SchemaTableName("default", "test_view"), new SchemaTableName("default", "test_view2")); |
| 108 | + |
| 109 | + assertThat(metadata.getViews(SESSION, Optional.empty())) |
| 110 | + .containsExactlyEntriesOf(views); |
| 111 | + assertThat(metadata.getViews(SESSION, Optional.of("default2"))) |
| 112 | + .containsExactly(entry(new SchemaTableName("default2", "test_view2"), viewDefinition)); |
| 113 | + } |
| 114 | + |
| 115 | + private static ConnectorViewDefinition createViewDefinition() |
| 116 | + { |
| 117 | + return new ConnectorViewDefinition( |
| 118 | + "SELECT * FROM test_table", |
| 119 | + Optional.of("blackhole"), |
| 120 | + Optional.of("default"), |
| 121 | + ImmutableList.of(new ConnectorViewDefinition.ViewColumn("col1", BIGINT.getTypeId(), Optional.empty())), |
| 122 | + Optional.empty(), |
| 123 | + Optional.empty(), |
| 124 | + true, |
| 125 | + ImmutableList.of()); |
| 126 | + } |
| 127 | + |
87 | 128 | private void assertThatNoTableIsCreated() |
88 | 129 | { |
89 | 130 | assertThat(metadata.listTables(SESSION, Optional.empty())).isEmpty(); |
|
0 commit comments