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
6 changes: 6 additions & 0 deletions plugin/trino-bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.function.Function;
import java.util.stream.Stream;

import static com.google.cloud.bigquery.TableDefinition.Type.MATERIALIZED_VIEW;
import static com.google.cloud.bigquery.TableDefinition.Type.TABLE;
import static com.google.cloud.bigquery.TableDefinition.Type.VIEW;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -176,7 +177,7 @@ public List<SchemaTableName> listTables(ConnectorSession session, Optional<Strin
ImmutableList.Builder<SchemaTableName> tableNames = ImmutableList.builder();
for (String remoteSchemaName : remoteSchemaNames) {
try {
Iterable<Table> tables = client.listTables(DatasetId.of(projectId, remoteSchemaName), TABLE, VIEW);
Iterable<Table> tables = client.listTables(DatasetId.of(projectId, remoteSchemaName), TABLE, VIEW, MATERIALIZED_VIEW);
for (Table table : tables) {
// filter ambiguous tables
client.toRemoteTable(projectId, remoteSchemaName, table.getTableId().getTable().toLowerCase(ENGLISH), tables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.Optional;

import static com.google.cloud.bigquery.TableDefinition.Type.MATERIALIZED_VIEW;
import static com.google.cloud.bigquery.TableDefinition.Type.TABLE;
import static com.google.cloud.bigquery.TableDefinition.Type.VIEW;
import static com.google.common.collect.ImmutableList.toImmutableList;
Expand Down Expand Up @@ -115,6 +116,10 @@ private List<BigQuerySplit> readFromBigQuery(ConnectorSession session, TableDefi
.map(column -> ((BigQueryColumnHandle) column).getName())
.collect(toImmutableList());

if (type == MATERIALIZED_VIEW) {
// Storage API doesn't support reading materialized views
return ImmutableList.of(BigQuerySplit.forViewStream(columns, filter));
}
if (skipViewMaterialization && type == VIEW) {
return ImmutableList.of(BigQuerySplit.forViewStream(columns, filter));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.List;
import java.util.Optional;

import static com.google.cloud.bigquery.TableDefinition.Type.TABLE;
import static com.google.cloud.bigquery.TableDefinition.Type.VIEW;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -96,10 +98,10 @@ private TableInfo getActualTable(
{
TableDefinition tableDefinition = remoteTable.getDefinition();
TableDefinition.Type tableType = tableDefinition.getType();
if (TableDefinition.Type.TABLE == tableType) {
if (tableType == TABLE) {
return remoteTable;
}
if (TableDefinition.Type.VIEW == tableType) {
if (tableType == VIEW) {
if (!viewEnabled) {
throw new TrinoException(NOT_SUPPORTED, format(
"Views are not enabled. You can enable views by setting '%s' to true. Notice additional cost may occur.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.trino.plugin.tpch.TpchPlugin;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.sql.SqlExecutor;
import org.intellij.lang.annotations.Language;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -107,12 +108,12 @@ public BigQuerySqlExecutor()
}

@Override
public void execute(String sql)
public void execute(@Language("SQL") String sql)
{
executeQuery(sql);
}

public TableResult executeQuery(String sql)
public TableResult executeQuery(@Language("SQL") String sql)
{
try {
return bigQuery.query(QueryJobConfiguration.of(sql));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.sql.TestTable;
import io.trino.testing.sql.TestView;
import org.intellij.lang.annotations.Language;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -582,7 +583,26 @@ public void testSymbolAliasing()
assertUpdate("DROP TABLE " + tableName);
}

private void onBigQuery(String sql)
@Test
public void testBigQueryMaterializedView()
{
String materializedView = "test_materialized_view" + randomTableSuffix();
try {
onBigQuery("CREATE MATERIALIZED VIEW test." + materializedView + " AS SELECT count(1) AS cnt FROM tpch.region");
assertQuery("SELECT table_type FROM information_schema.tables WHERE table_schema = 'test' AND table_name = '" + materializedView + "'", "VALUES 'BASE TABLE'");

assertQuery("DESCRIBE test." + materializedView, "VALUES ('cnt', 'bigint', '', '')");
assertQuery("SELECT * FROM test." + materializedView, "VALUES 5");

assertUpdate("DROP TABLE test." + materializedView);
assertQueryReturnsEmptyResult("SELECT * FROM information_schema.tables WHERE table_schema = 'test' AND table_name = '" + materializedView + "'");
}
finally {
onBigQuery("DROP MATERIALIZED VIEW IF EXISTS test." + materializedView);
}
}

private void onBigQuery(@Language("SQL") String sql)
{
bigQuerySqlExecutor.execute(sql);
}
Expand Down