Skip to content

Commit

Permalink
Fix failure when reading BigQuery views with Arrow
Browse files Browse the repository at this point in the history
The size of 'vectors' and 'columns' in BigQueryArrowToPageConverter
can be different when columns in predicates
don't exist in projection when materializing BigQuery views.
  • Loading branch information
ebyhr committed Apr 1, 2024
1 parent b4ad7f1 commit aca0365
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plugin/trino-bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@
<exclude>**/TestBigQueryMetadataCaching.java</exclude>
<exclude>**/TestBigQueryAvroTypeMapping.java</exclude>
<exclude>**/TestBigQueryArrowTypeMapping.java</exclude>
<exclude>**/TestBigQueryArrowSerialization.java</exclude>
<exclude>**/TestBigQueryMetadata.java</exclude>
<exclude>**/TestBigQueryInstanceCleaner.java</exclude>
<exclude>**/TestBigQueryCaseInsensitiveMapping.java</exclude>
Expand Down Expand Up @@ -590,6 +591,7 @@
<includes>
<include>**/TestBigQueryWithDifferentProjectIdConnectorSmokeTest.java</include>
<include>**/TestBigQueryWithProxyTest.java</include>
<include>**/TestBigQueryArrowSerialization.java</include>
<include>**/TestBigQueryArrowTypeMapping.java</include>
<include>**/TestBigQueryAvroTypeMapping.java</include>
<include>**/TestBigQueryMetadataCaching.java</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public BigQueryArrowToPageConverter(BigQueryTypeManager typeManager, BufferAlloc
.map(field -> field.createVector(allocator))
.collect(toImmutableList());
root = new VectorSchemaRoot(vectors);
verify(vectors.size() == columns.size(), "Vectors, columns size differ");
loader = new VectorLoader(root, INSTANCE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.bigquery;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.plugin.bigquery.BigQueryQueryRunner.BigQuerySqlExecutor;
import io.trino.testing.AbstractTestQueryFramework;
import io.trino.testing.QueryRunner;
import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Test;

import static io.trino.testing.TestingNames.randomNameSuffix;

public class TestBigQueryArrowSerialization
extends AbstractTestQueryFramework
{
private final BigQuerySqlExecutor bigQuerySqlExecutor;

public TestBigQueryArrowSerialization()
{
this.bigQuerySqlExecutor = new BigQuerySqlExecutor();
}

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
return BigQueryQueryRunner.createQueryRunner(
ImmutableMap.of(),
ImmutableMap.of("bigquery.experimental.arrow-serialization.enabled", "true"),
ImmutableList.of());
}

@Test
void testViewProjectionPredicates()
{
// Run query that columns in WHERE clause don't exist in projections.
// Columns in ReadSession.setRowRestriction in ReadSessionCreator must exist in selected fields.
String viewName = "test_projection_predicates_" + randomNameSuffix();

onBigQuery("CREATE VIEW test." + viewName + " AS SELECT 1 AS id, 'test' AS data");
try {
assertQuery("SELECT data FROM test." + viewName + " WHERE id = 1", "VALUES 'test'");
assertQuery("SELECT id FROM test." + viewName + " WHERE data = 'test'", "VALUES 1");
}
finally {
onBigQuery("DROP VIEW test." + viewName);
}
}

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

0 comments on commit aca0365

Please sign in to comment.