use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testDescribeInput.
@Test
public void testDescribeInput() {
Session session = Session.builder(getSession()).addPreparedStatement("my_query", "select ? from nation where nationkey = ? and name < ?").build();
MaterializedResult actual = computeActual(session, "DESCRIBE INPUT my_query");
MaterializedResult expected = resultBuilder(session, BIGINT, VARCHAR).row(0, "unknown").row(1, "bigint").row(2, "varchar").build();
assertEqualsIgnoreOrder(actual, expected);
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testDescribeOutput.
@Test
public void testDescribeOutput() {
Session session = Session.builder(getSession()).addPreparedStatement("my_query", "SELECT * FROM nation").build();
MaterializedResult actual = computeActual(session, "DESCRIBE OUTPUT my_query");
MaterializedResult expected = resultBuilder(session, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BOOLEAN).row("nationkey", session.getCatalog().get(), session.getSchema().get(), "nation", "bigint", 8, false).row("name", session.getCatalog().get(), session.getSchema().get(), "nation", "varchar(25)", 0, false).row("regionkey", session.getCatalog().get(), session.getSchema().get(), "nation", "bigint", 8, false).row("comment", session.getCatalog().get(), session.getSchema().get(), "nation", "varchar(152)", 0, false).build();
assertEqualsIgnoreOrder(actual, expected);
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestDistributedQueries method testViewAccessControl.
@Test
public void testViewAccessControl() throws Exception {
skipTestUnless(supportsViews());
Session viewOwnerSession = TestingSession.testSessionBuilder().setIdentity(new Identity("test_view_access_owner", Optional.empty())).setCatalog(getSession().getCatalog().get()).setSchema(getSession().getSchema().get()).build();
// verify creation of view over a table requires special view creation privileges for the table
assertAccessDenied(viewOwnerSession, "CREATE VIEW test_view_access AS SELECT * FROM orders", "Cannot select from table .*.orders.*", privilege("orders", CREATE_VIEW_WITH_SELECT_TABLE));
// create the view
assertAccessAllowed(viewOwnerSession, "CREATE VIEW test_view_access AS SELECT * FROM orders", privilege("bogus", "bogus privilege to disable security", SELECT_TABLE));
// verify selecting from a view over a table requires the view owner to have special view creation privileges for the table
assertAccessDenied("SELECT * FROM test_view_access", "Cannot select from table .*.orders.*", privilege(viewOwnerSession.getUser(), "orders", CREATE_VIEW_WITH_SELECT_TABLE));
// verify selecting from a view over a table does not require the session user to have SELECT privileges on the underlying table
assertAccessAllowed("SELECT * FROM test_view_access", privilege(getSession().getUser(), "orders", CREATE_VIEW_WITH_SELECT_TABLE));
assertAccessAllowed("SELECT * FROM test_view_access", privilege(getSession().getUser(), "orders", SELECT_TABLE));
Session nestedViewOwnerSession = TestingSession.testSessionBuilder().setIdentity(new Identity("test_nested_view_access_owner", Optional.empty())).setCatalog(getSession().getCatalog().get()).setSchema(getSession().getSchema().get()).build();
// verify creation of view over a view requires special view creation privileges for the view
assertAccessDenied(nestedViewOwnerSession, "CREATE VIEW test_nested_view_access AS SELECT * FROM test_view_access", "Cannot select from view .*.test_view_access.*", privilege("test_view_access", CREATE_VIEW_WITH_SELECT_VIEW));
// create the nested view
assertAccessAllowed(nestedViewOwnerSession, "CREATE VIEW test_nested_view_access AS SELECT * FROM test_view_access", privilege("bogus", "bogus privilege to disable security", SELECT_TABLE));
// verify selecting from a view over a view requires the view owner of the outer view to have special view creation privileges for the inner view
assertAccessDenied("SELECT * FROM test_nested_view_access", "Cannot select from view .*.test_view_access.*", privilege(nestedViewOwnerSession.getUser(), "test_view_access", CREATE_VIEW_WITH_SELECT_VIEW));
// verify selecting from a view over a view does not require the session user to have SELECT privileges for the inner view
assertAccessAllowed("SELECT * FROM test_nested_view_access", privilege(getSession().getUser(), "test_view_access", CREATE_VIEW_WITH_SELECT_VIEW));
assertAccessAllowed("SELECT * FROM test_nested_view_access", privilege(getSession().getUser(), "test_view_access", SELECT_VIEW));
assertAccessAllowed(nestedViewOwnerSession, "DROP VIEW test_nested_view_access");
assertAccessAllowed(viewOwnerSession, "DROP VIEW test_view_access");
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testShowSession.
@Test
public void testShowSession() {
Session session = new Session(getSession().getQueryId(), Optional.empty(), getSession().isClientTransactionSupport(), getSession().getIdentity(), getSession().getSource(), getSession().getCatalog(), getSession().getSchema(), getSession().getTimeZoneKey(), getSession().getLocale(), getSession().getRemoteUserAddress(), getSession().getUserAgent(), getSession().getClientInfo(), getSession().getStartTime(), ImmutableMap.<String, String>builder().put("test_string", "foo string").put("test_long", "424242").build(), ImmutableMap.of(), ImmutableMap.of(TESTING_CATALOG, ImmutableMap.<String, String>builder().put("connector_string", "bar string").put("connector_long", "11").build()), getQueryRunner().getMetadata().getSessionPropertyManager(), getSession().getPreparedStatements());
MaterializedResult result = computeActual(session, "SHOW SESSION");
ImmutableMap<String, MaterializedRow> properties = Maps.uniqueIndex(result.getMaterializedRows(), input -> {
assertEquals(input.getFieldCount(), 5);
return (String) input.getField(0);
});
assertEquals(properties.get("test_string"), new MaterializedRow(1, "test_string", "foo string", "test default", "varchar", "test string property"));
assertEquals(properties.get("test_long"), new MaterializedRow(1, "test_long", "424242", "42", "bigint", "test long property"));
assertEquals(properties.get(TESTING_CATALOG + ".connector_string"), new MaterializedRow(1, TESTING_CATALOG + ".connector_string", "bar string", "connector default", "varchar", "connector string property"));
assertEquals(properties.get(TESTING_CATALOG + ".connector_long"), new MaterializedRow(1, TESTING_CATALOG + ".connector_long", "11", "33", "bigint", "connector long property"));
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testDescribeOutputShowTables.
@Test
public void testDescribeOutputShowTables() {
Session session = Session.builder(getSession()).addPreparedStatement("my_query", "SHOW TABLES").build();
MaterializedResult actual = computeActual(session, "DESCRIBE OUTPUT my_query");
MaterializedResult expected = resultBuilder(session, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BOOLEAN).row("Table", session.getCatalog().get(), "information_schema", "tables", "varchar", 0, true).build();
assertEqualsIgnoreOrder(actual, expected);
}
Aggregations