use of io.trino.sql.SqlEnvironmentConfig in project trino by trinodb.
the class TestQuerySessionSupplier method testDefaultCatalogAndSchema.
@Test
public void testDefaultCatalogAndSchema() {
// no session or defaults
Session session = createSession(ImmutableListMultimap.<String, String>builder().put(TRINO_HEADERS.requestUser(), "testUser").build(), new SqlEnvironmentConfig());
assertThat(session.getCatalog()).isEmpty();
assertThat(session.getSchema()).isEmpty();
// no session with default catalog
session = createSession(ImmutableListMultimap.<String, String>builder().put(TRINO_HEADERS.requestUser(), "testUser").build(), new SqlEnvironmentConfig().setDefaultCatalog("default-catalog"));
assertThat(session.getCatalog()).contains("default-catalog");
assertThat(session.getSchema()).isEmpty();
// no session with default catalog and schema
session = createSession(ImmutableListMultimap.<String, String>builder().put(TRINO_HEADERS.requestUser(), "testUser").build(), new SqlEnvironmentConfig().setDefaultCatalog("default-catalog").setDefaultSchema("default-schema"));
assertThat(session.getCatalog()).contains("default-catalog");
assertThat(session.getSchema()).contains("default-schema");
// only default schema
assertThatThrownBy(() -> createSessionSupplier(new SqlEnvironmentConfig().setDefaultSchema("schema"))).isInstanceOf(IllegalArgumentException.class).hasMessage("Default schema cannot be set if catalog is not set");
// both session and defaults set
session = createSession(ImmutableListMultimap.<String, String>builder().put(TRINO_HEADERS.requestUser(), "testUser").put(TRINO_HEADERS.requestCatalog(), "catalog").put(TRINO_HEADERS.requestSchema(), "schema").build(), new SqlEnvironmentConfig().setDefaultCatalog("default-catalog").setDefaultSchema("default-schema"));
assertThat(session.getCatalog()).contains("catalog");
assertThat(session.getSchema()).contains("schema");
// default schema not used when session catalog is set
session = createSession(ImmutableListMultimap.<String, String>builder().put(TRINO_HEADERS.requestUser(), "testUser").put(TRINO_HEADERS.requestCatalog(), "catalog").build(), new SqlEnvironmentConfig().setDefaultCatalog("default-catalog").setDefaultSchema("default-schema"));
assertThat(session.getCatalog()).contains("catalog");
assertThat(session.getSchema()).isEmpty();
}
use of io.trino.sql.SqlEnvironmentConfig in project trino by trinodb.
the class TestQuerySessionSupplier method testCreateSession.
@Test
public void testCreateSession() {
SessionContext context = SESSION_CONTEXT_FACTORY.createSessionContext(TEST_HEADERS, Optional.empty(), Optional.of("testRemote"), Optional.empty());
QuerySessionSupplier sessionSupplier = createSessionSupplier(new SqlEnvironmentConfig());
Session session = sessionSupplier.createSession(new QueryId("test_query_id"), context);
assertEquals(session.getQueryId(), new QueryId("test_query_id"));
assertEquals(session.getUser(), "testUser");
assertEquals(session.getSource().get(), "testSource");
assertEquals(session.getCatalog().get(), "testCatalog");
assertEquals(session.getSchema().get(), "testSchema");
assertEquals(session.getPath().getRawPath().get(), "testPath");
assertEquals(session.getLocale(), Locale.TAIWAN);
assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei"));
assertEquals(session.getRemoteUserAddress().get(), "testRemote");
assertEquals(session.getClientInfo().get(), "client-info");
assertEquals(session.getClientTags(), ImmutableSet.of("tag1", "tag2", "tag3"));
assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").buildOrThrow());
assertEquals(session.getPreparedStatements(), ImmutableMap.<String, String>builder().put("query1", "select * from foo").put("query2", "select * from bar").buildOrThrow());
}
use of io.trino.sql.SqlEnvironmentConfig in project trino by trinodb.
the class TestQuerySessionSupplier method testInvalidTimeZone.
@Test
public void testInvalidTimeZone() {
MultivaluedMap<String, String> headers = new GuavaMultivaluedMap<>(ImmutableListMultimap.<String, String>builder().put(TRINO_HEADERS.requestUser(), "testUser").put(TRINO_HEADERS.requestTimeZone(), "unknown_timezone").build());
SessionContext context = SESSION_CONTEXT_FACTORY.createSessionContext(headers, Optional.empty(), Optional.of("remoteAddress"), Optional.empty());
QuerySessionSupplier sessionSupplier = createSessionSupplier(new SqlEnvironmentConfig());
assertThatThrownBy(() -> sessionSupplier.createSession(new QueryId("test_query_id"), context)).isInstanceOf(TrinoException.class).hasMessage("Time zone not supported: unknown_timezone");
}
Aggregations