Search in sources :

Example 1 with ViewColumn

use of io.trino.spi.connector.ConnectorViewDefinition.ViewColumn in project trino by trinodb.

the class AbstractTestHive method doCreateView.

private void doCreateView(SchemaTableName viewName, boolean replace) {
    String viewData = "test data";
    ConnectorViewDefinition definition = new ConnectorViewDefinition(viewData, Optional.empty(), Optional.empty(), ImmutableList.of(new ViewColumn("test", BIGINT.getTypeId())), Optional.empty(), Optional.empty(), true);
    try (Transaction transaction = newTransaction()) {
        transaction.getMetadata().createView(newSession(), viewName, definition, replace);
        transaction.commit();
    }
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        assertThat(metadata.getView(newSession(), viewName)).map(ConnectorViewDefinition::getOriginalSql).contains(viewData);
        Map<SchemaTableName, ConnectorViewDefinition> views = metadata.getViews(newSession(), Optional.of(viewName.getSchemaName()));
        assertEquals(views.size(), 1);
        assertEquals(views.get(viewName).getOriginalSql(), definition.getOriginalSql());
        assertTrue(metadata.listViews(newSession(), Optional.of(viewName.getSchemaName())).contains(viewName));
    }
}
Also used : ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition)

Example 2 with ViewColumn

use of io.trino.spi.connector.ConnectorViewDefinition.ViewColumn in project trino by trinodb.

the class TestConnectorViewDefinition method assertBaseView.

private static void assertBaseView(ConnectorViewDefinition view) {
    assertEquals(view.getOriginalSql(), "SELECT 42 x");
    assertEquals(view.getColumns().size(), 1);
    ViewColumn column = getOnlyElement(view.getColumns());
    assertEquals(column.getName(), "x");
    assertEquals(column.getType(), BIGINT.getTypeId());
    assertRoundTrip(view);
}
Also used : ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn)

Aggregations

ViewColumn (io.trino.spi.connector.ConnectorViewDefinition.ViewColumn)2 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)1 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)1 ConnectorViewDefinition (io.trino.spi.connector.ConnectorViewDefinition)1 SchemaTableName (io.trino.spi.connector.SchemaTableName)1