Search in sources :

Example 6 with SqlParserOptions

use of com.facebook.presto.sql.parser.SqlParserOptions in project presto by prestodb.

the class TestHttpRequestSessionContext method testSessionContext.

@Test
public void testSessionContext() {
    HttpServletRequest request = new MockHttpServletRequest(ImmutableListMultimap.<String, String>builder().put(PRESTO_USER, "testUser").put(PRESTO_SOURCE, "testSource").put(PRESTO_CATALOG, "testCatalog").put(PRESTO_SCHEMA, "testSchema").put(PRESTO_LANGUAGE, "zh-TW").put(PRESTO_TIME_ZONE, "Asia/Taipei").put(PRESTO_CLIENT_INFO, "client-info").put(PRESTO_SESSION, QUERY_MAX_MEMORY + "=1GB").put(PRESTO_SESSION, JOIN_DISTRIBUTION_TYPE + "=partitioned," + HASH_PARTITION_COUNT + " = 43").put(PRESTO_PREPARED_STATEMENT, "query1=select * from foo,query2=select * from bar").put(PRESTO_ROLE, "foo_connector=ALL").put(PRESTO_ROLE, "bar_connector=NONE").put(PRESTO_ROLE, "foobar_connector=ROLE{role}").put(PRESTO_EXTRA_CREDENTIAL, "test.token.foo=bar").put(PRESTO_EXTRA_CREDENTIAL, "test.token.abc=xyz").put(PRESTO_SESSION_FUNCTION, format("%s=%s,%s=%s", urlEncode(SERIALIZED_SQL_FUNCTION_ID_ADD), urlEncode(SERIALIZED_SQL_FUNCTION_ADD), urlEncode(SERIALIZED_SQL_FUNCTION_ID_ADD_1_TO_INT_ARRAY), urlEncode(SERIALIZED_SQL_FUNCTION_ADD_1_to_INT_ARRAY))).build(), "testRemote");
    HttpRequestSessionContext context = new HttpRequestSessionContext(request, new SqlParserOptions());
    assertEquals(context.getSource(), "testSource");
    assertEquals(context.getCatalog(), "testCatalog");
    assertEquals(context.getSchema(), "testSchema");
    assertEquals(context.getIdentity(), new Identity("testUser", Optional.empty()));
    assertEquals(context.getClientInfo(), "client-info");
    assertEquals(context.getLanguage(), "zh-TW");
    assertEquals(context.getTimeZoneId(), "Asia/Taipei");
    assertEquals(context.getSystemProperties(), ImmutableMap.of(QUERY_MAX_MEMORY, "1GB", JOIN_DISTRIBUTION_TYPE, "partitioned", HASH_PARTITION_COUNT, "43"));
    assertEquals(context.getPreparedStatements(), ImmutableMap.of("query1", "select * from foo", "query2", "select * from bar"));
    assertEquals(context.getIdentity().getRoles(), ImmutableMap.of("foo_connector", new SelectedRole(SelectedRole.Type.ALL, Optional.empty()), "bar_connector", new SelectedRole(SelectedRole.Type.NONE, Optional.empty()), "foobar_connector", new SelectedRole(SelectedRole.Type.ROLE, Optional.of("role"))));
    assertEquals(context.getIdentity().getExtraCredentials(), ImmutableMap.of("test.token.foo", "bar", "test.token.abc", "xyz"));
    assertEquals(context.getSessionFunctions(), ImmutableMap.of(SQL_FUNCTION_ID_ADD, SQL_FUNCTION_ADD, SQL_FUNCTION_ID_ADD1_TO_INT_ARRAY, SQL_FUNCTION_ADD_1_TO_INT_ARRAY));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) SelectedRole(com.facebook.presto.spi.security.SelectedRole) Identity(com.facebook.presto.spi.security.Identity) Test(org.testng.annotations.Test)

Example 7 with SqlParserOptions

use of com.facebook.presto.sql.parser.SqlParserOptions in project presto by prestodb.

the class TestHttpRequestSessionContext method testExtraCredentials.

@Test
public void testExtraCredentials() {
    HttpServletRequest request = new MockHttpServletRequest(ImmutableListMultimap.<String, String>builder().put(PRESTO_USER, "testUser").put(PRESTO_SOURCE, "testSource").put(PRESTO_CATALOG, "testCatalog").put(PRESTO_SCHEMA, "testSchema").put(PRESTO_LANGUAGE, "zh-TW").put(PRESTO_TIME_ZONE, "Asia/Taipei").put(PRESTO_CLIENT_INFO, "client-info").put(PRESTO_SESSION, QUERY_MAX_MEMORY + "=1GB").put(PRESTO_SESSION, JOIN_DISTRIBUTION_TYPE + "=partitioned," + HASH_PARTITION_COUNT + " = 43").put(PRESTO_PREPARED_STATEMENT, "query1=select * from foo,query2=select * from bar").put(PRESTO_ROLE, "foo_connector=ALL").put(PRESTO_ROLE, "bar_connector=NONE").put(PRESTO_ROLE, "foobar_connector=ROLE{role}").put(PRESTO_EXTRA_CREDENTIAL, "test.token.key1=" + urlEncode("bar=ab===,d")).put(PRESTO_EXTRA_CREDENTIAL, "test.token.key2=bar=ab===").put(PRESTO_EXTRA_CREDENTIAL, "test.json=" + urlEncode("{\"a\" : \"b\", \"c\" : \"d=\"}") + ", test.token.key3 = abc=cd").put(PRESTO_EXTRA_CREDENTIAL, "test.token.abc=xyz").build(), "testRemote");
    HttpRequestSessionContext context = new HttpRequestSessionContext(request, new SqlParserOptions());
    assertEquals(context.getIdentity().getExtraCredentials(), ImmutableMap.builder().put("test.token.key1", "bar=ab===,d").put("test.token.key2", "bar=ab===").put("test.token.key3", "abc=cd").put("test.json", "{\"a\" : \"b\", \"c\" : \"d=\"}").put("test.token.abc", "xyz").build());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) Test(org.testng.annotations.Test)

Example 8 with SqlParserOptions

use of com.facebook.presto.sql.parser.SqlParserOptions in project presto by prestodb.

the class TestQuerySessionSupplier method testInvalidTimeZone.

@Test(expectedExceptions = TimeZoneNotSupportedException.class)
public void testInvalidTimeZone() {
    HttpServletRequest request = new MockHttpServletRequest(ImmutableListMultimap.<String, String>builder().put(PRESTO_USER, "testUser").put(PRESTO_TIME_ZONE, "unknown_timezone").build(), "testRemote");
    HttpRequestSessionContext context = new HttpRequestSessionContext(request, new SqlParserOptions());
    QuerySessionSupplier sessionSupplier = new QuerySessionSupplier(createTestTransactionManager(), new AllowAllAccessControl(), new SessionPropertyManager(), new SqlEnvironmentConfig());
    sessionSupplier.createSession(new QueryId("test_query_id"), context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) SqlEnvironmentConfig(com.facebook.presto.sql.SqlEnvironmentConfig) Test(org.testng.annotations.Test)

Example 9 with SqlParserOptions

use of com.facebook.presto.sql.parser.SqlParserOptions in project presto by prestodb.

the class TestJdbcWarnings method setupServer.

@BeforeClass
public void setupServer() throws Exception {
    server = new TestingPrestoServer(true, ImmutableMap.<String, String>builder().put("testing-warning-collector.add-warnings", "true").put("testing-warning-collector.preloaded-warnings", String.valueOf(PRELOADED_WARNINGS)).build(), null, null, new SqlParserOptions(), ImmutableList.of());
    server.installPlugin(new TpchPlugin());
    server.createCatalog("tpch", "tpch");
    server.installPlugin(new BlackHolePlugin());
    server.createCatalog("blackhole", "blackhole");
    waitForNodeRefresh(server);
}
Also used : SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) BlackHolePlugin(com.facebook.presto.plugin.blackhole.BlackHolePlugin) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) BeforeClass(org.testng.annotations.BeforeClass)

Example 10 with SqlParserOptions

use of com.facebook.presto.sql.parser.SqlParserOptions in project presto by prestodb.

the class TpchQueryRunner method createQueryRunner.

public static DistributedQueryRunner createQueryRunner(Map<String, String> extraProperties, Map<String, String> coordinatorProperties) throws Exception {
    Session session = testSessionBuilder().setSource("test").setCatalog("tpch").setSchema("tiny").build();
    DistributedQueryRunner queryRunner = new DistributedQueryRunner(session, 4, extraProperties, coordinatorProperties, new SqlParserOptions());
    try {
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.createCatalog("tpch", "tpch");
        return queryRunner;
    } catch (Exception e) {
        queryRunner.close();
        throw e;
    }
}
Also used : SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) Session(com.facebook.presto.Session)

Aggregations

SqlParserOptions (com.facebook.presto.sql.parser.SqlParserOptions)18 Test (org.testng.annotations.Test)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 SqlParser (com.facebook.presto.sql.parser.SqlParser)5 CatalogManager (com.facebook.presto.metadata.CatalogManager)4 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)4 SqlEnvironmentConfig (com.facebook.presto.sql.SqlEnvironmentConfig)4 TpchPlugin (com.facebook.presto.tpch.TpchPlugin)4 JsonBinder.jsonBinder (com.facebook.airlift.json.JsonBinder.jsonBinder)3 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)3 NodeSchedulerConfig (com.facebook.presto.execution.scheduler.NodeSchedulerConfig)3 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)3 HandleJsonModule (com.facebook.presto.metadata.HandleJsonModule)3 StaticCatalogStore (com.facebook.presto.metadata.StaticCatalogStore)3 StaticFunctionNamespaceStore (com.facebook.presto.metadata.StaticFunctionNamespaceStore)3 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)3 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)2 AbstractConfigurationAwareModule (com.facebook.airlift.configuration.AbstractConfigurationAwareModule)2