Source:
public void testCurrentUserInView() { if (!getSession().getCatalog().isPresent() || !getSession().getSchema().isPresent()) { throw new SkipException("Session catalog and schema must be set"); } String testAccountsUnqualifiedName = "test_accounts"; String testAccountsViewUnqualifiedName = "test_accounts_view"; String testAccountsViewFullyQualifiedName = format("%s.%s.%s", getSession().getCatalog().get(), getSession().getSchema().get(), testAccountsViewUnqualifiedName); assertUpdate(format("CREATE TABLE %s AS SELECT user_name, account_name" + " FROM (VALUES ('user1', 'account1'), ('user2', 'account2'))" + " t (user_name, account_name)", testAccountsUnqualifiedName), 2); assertUpdate(format("CREATE VIEW %s AS SELECT account_name FROM test_accounts WHERE user_name = CURRENT_USER", testAccountsViewUnqualifiedName)); assertUpdate(format("GRANT SELECT ON %s TO user1", testAccountsViewFullyQualifiedName)); assertUpdate(format("GRANT SELECT ON %s TO user2", testAccountsViewFullyQualifiedName)); Session user1 = testSessionBuilder() .setCatalog(getSession().getCatalog().get()) .setSchema(getSession().getSchema().get()) .setIdentity(new Identity("user1", getSession().getIdentity().getPrincipal())) .build(); Session user2 = testSessionBuilder() .setCatalog(getSession().getCatalog().get()) .setSchema(getSession().getSchema().get()) .setIdentity(new Identity("user2", getSession().getIdentity().getPrincipal())) .build(); assertQuery(user1, "SELECT account_name FROM test_accounts_view", "VALUES 'account1'"); assertQuery(user2, "SELECT account_name FROM test_accounts_view", "VALUES 'account2'"); assertUpdate("DROP VIEW test_accounts_view"); assertUpdate("DROP TABLE test_accounts"); }

Target:
public void testCurrentUserInView() { checkState(getSession().getCatalog().isPresent(), "catalog is not set"); checkState(getSession().getSchema().isPresent(), "schema is not set"); String testAccountsUnqualifiedName = "test_accounts"; String testAccountsViewUnqualifiedName = "test_accounts_view"; String testAccountsViewFullyQualifiedName = format("%s.%s.%s", getSession().getCatalog().get(), getSession().getSchema().get(), testAccountsViewUnqualifiedName); assertUpdate(format("CREATE TABLE %s AS SELECT user_name, account_name" + " FROM (VALUES ('user1', 'account1'), ('user2', 'account2'))" + " t (user_name, account_name)", testAccountsUnqualifiedName), 2); assertUpdate(format("CREATE VIEW %s AS SELECT account_name FROM test_accounts WHERE user_name = CURRENT_USER", testAccountsViewUnqualifiedName)); assertUpdate(format("GRANT SELECT ON %s TO user1", testAccountsViewFullyQualifiedName)); assertUpdate(format("GRANT SELECT ON %s TO user2", testAccountsViewFullyQualifiedName)); Session user1 = testSessionBuilder() .setCatalog(getSession().getCatalog().get()) .setSchema(getSession().getSchema().get()) .setIdentity(new Identity("user1", getSession().getIdentity().getPrincipal())) .build(); Session user2 = testSessionBuilder() .setCatalog(getSession().getCatalog().get()) .setSchema(getSession().getSchema().get()) .setIdentity(new Identity("user2", getSession().getIdentity().getPrincipal())) .build(); assertQuery(user1, "SELECT account_name FROM test_accounts_view", "VALUES 'account1'"); assertQuery(user2, "SELECT account_name FROM test_accounts_view", "VALUES 'account2'"); assertUpdate("DROP VIEW test_accounts_view"); assertUpdate("DROP TABLE test_accounts"); }