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
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public boolean isFinished()
public Page getNextPage()
{
checkState(pageBuilder.isEmpty(), "PageBuilder is not empty at the beginning of a new page");
if (!responses.hasNext()) {
return null;
}
ReadRowsResponse response = responses.next();
Iterable<GenericRecord> records = parse(response);
for (GenericRecord record : records) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.testing.MaterializedResult.resultBuilder;
import static io.trino.testing.assertions.Assert.assertEquals;
import static io.trino.testing.assertions.Assert.assertEventually;
import static io.trino.testing.sql.TestTable.randomTableSuffix;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -424,6 +425,38 @@ public void testColumnPositionMismatch()
}
}

@Test
public void testSelectTableWithRowAccessPolicyFilterAll()
{
String policyName = "test_policy" + randomTableSuffix();
try (TestTable table = new TestTable(this::onBigQuery, "test.test_row_access_policy", "AS SELECT 1 col")) {
assertQuery("SELECT * FROM " + table.getName(), "VALUES 1");

// Use assertEventually because there's delay until new row access policies become effective
onBigQuery("CREATE ROW ACCESS POLICY " + policyName + " ON " + table.getName() + " FILTER USING (true)");
assertEventually(() -> assertQueryReturnsEmptyResult("SELECT * FROM " + table.getName()));

onBigQuery("DROP ALL ROW ACCESS POLICIES ON " + table.getName());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be in a finally block (in addition to in the test) to avoid leaking policies when assertion fails?

Or do policies go away as tables get dropped?

Copy link
Copy Markdown
Member Author

@ebyhr ebyhr Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find the official docs about it, but policies go away when dropping tables as far as I confirmed.

assertEventually(() -> assertQuery("SELECT * FROM " + table.getName(), "VALUES 1"));
}
}

@Test
public void testSelectTableWithRowAccessPolicyFilterPartialRow()
{
String policyName = "test_policy" + randomTableSuffix();
try (TestTable table = new TestTable(this::onBigQuery, "test.test_row_access_policy", "AS (SELECT 1 col UNION ALL SELECT 2 col)")) {
assertQuery("SELECT * FROM " + table.getName(), "VALUES (1), (2)");

// Use assertEventually because there's delay until new row access policies become effective
onBigQuery("CREATE ROW ACCESS POLICY " + policyName + " ON " + table.getName() + " GRANT TO (\"allAuthenticatedUsers\") FILTER USING (col = 1)");
assertEventually(() -> assertQuery("SELECT * FROM " + table.getName(), "VALUES 1"));

onBigQuery("DROP ALL ROW ACCESS POLICIES ON " + table.getName());
assertEventually(() -> assertQuery("SELECT * FROM " + table.getName(), "VALUES (1), (2)"));
}
}

@Test
public void testViewDefinitionSystemTable()
{
Expand Down