use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class TestCachingJdbcClient method testDifferentIdentityKeys.
@Test
public void testDifferentIdentityKeys() {
CachingJdbcClient cachingJdbcClient = new CachingJdbcClient(database.getJdbcClient(), SESSION_PROPERTIES_PROVIDERS, new ExtraCredentialsBasedIdentityCacheMapping(new ExtraCredentialConfig().setUserCredentialName("user").setPasswordCredentialName("password")), FOREVER, true, 10000);
ConnectorSession alice = createUserSession("alice");
ConnectorSession bob = createUserSession("bob");
JdbcTableHandle table = createTable(new SchemaTableName(schema, "table"));
assertTableNamesCache(cachingJdbcClient).loads(2).misses(2).afterRunning(() -> {
assertThat(cachingJdbcClient.getTableNames(alice, Optional.empty())).contains(table.getRequiredNamedRelation().getSchemaTableName());
assertThat(cachingJdbcClient.getTableNames(bob, Optional.empty())).contains(table.getRequiredNamedRelation().getSchemaTableName());
});
assertTableNamesCache(cachingJdbcClient).hits(2).afterRunning(() -> {
assertThat(cachingJdbcClient.getTableNames(alice, Optional.empty())).contains(table.getRequiredNamedRelation().getSchemaTableName());
assertThat(cachingJdbcClient.getTableNames(bob, Optional.empty())).contains(table.getRequiredNamedRelation().getSchemaTableName());
});
// Drop tables by not using caching jdbc client
jdbcClient.dropTable(SESSION, table);
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class TestCachingJdbcClient method testColumnsCacheInvalidationOnTableDrop.
@Test
public void testColumnsCacheInvalidationOnTableDrop() {
ConnectorSession firstSession = createSession("first");
ConnectorSession secondSession = createSession("second");
JdbcTableHandle firstTable = createTable(new SchemaTableName(schema, "first_table"));
JdbcTableHandle secondTable = createTable(new SchemaTableName(schema, "second_table"));
JdbcColumnHandle firstColumn = addColumn(firstTable, "first_column");
JdbcColumnHandle secondColumn = addColumn(secondTable, "second_column");
// Load columns for both tables into cache and assert cache loads (sessions x tables)
assertColumnCacheStats(cachingJdbcClient).loads(4).misses(4).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, firstTable)).contains(firstColumn);
assertThat(cachingJdbcClient.getColumns(firstSession, secondTable)).contains(secondColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, firstTable)).contains(firstColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, secondTable)).contains(secondColumn);
});
// Load columns from cache
assertColumnCacheStats(cachingJdbcClient).hits(2).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, firstTable)).contains(firstColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, secondTable)).contains(secondColumn);
});
// Rename column
cachingJdbcClient.renameColumn(firstSession, firstTable, firstColumn, "another_column");
assertColumnCacheStats(cachingJdbcClient).loads(1).misses(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(secondSession, firstTable)).doesNotContain(firstColumn).containsAll(jdbcClient.getColumns(SESSION, firstTable));
});
// Drop columns and caches for first table
cachingJdbcClient.dropTable(secondSession, firstTable);
assertColumnCacheStats(cachingJdbcClient).loads(2).misses(2).afterRunning(() -> {
assertThatThrownBy(() -> cachingJdbcClient.getColumns(firstSession, firstTable)).isInstanceOf(TableNotFoundException.class);
assertThatThrownBy(() -> cachingJdbcClient.getColumns(secondSession, firstTable)).isInstanceOf(TableNotFoundException.class);
});
// Check if second table is still cached
assertColumnCacheStats(cachingJdbcClient).hits(2).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, secondTable)).contains(secondColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, secondTable)).contains(secondColumn);
});
cachingJdbcClient.dropTable(secondSession, secondTable);
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class TestCachingJdbcClient method testTruncateTable.
@Test
public void testTruncateTable() {
CachingJdbcClient cachingJdbcClient = cachingStatisticsAwareJdbcClient(FOREVER, true, 10000);
ConnectorSession session = createSession("table");
JdbcTableHandle table = createTable(new SchemaTableName(schema, "table"));
// load
assertStatisticsCacheStats(cachingJdbcClient).loads(1).misses(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getTableStatistics(session, table, TupleDomain.all())).isEqualTo(NON_EMPTY_STATS);
});
// read from cache
assertStatisticsCacheStats(cachingJdbcClient).hits(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getTableStatistics(session, table, TupleDomain.all())).isEqualTo(NON_EMPTY_STATS);
});
// invalidate
cachingJdbcClient.truncateTable(SESSION, table);
// load again
assertStatisticsCacheStats(cachingJdbcClient).loads(1).misses(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getTableStatistics(session, table, TupleDomain.all())).isEqualTo(NON_EMPTY_STATS);
});
// read from cache
assertStatisticsCacheStats(cachingJdbcClient).hits(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getTableStatistics(session, table, TupleDomain.all())).isEqualTo(NON_EMPTY_STATS);
});
// cleanup
this.jdbcClient.dropTable(SESSION, table);
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class TestCachingJdbcClient method testColumnsNotCachedWhenCacheDisabled.
@Test
public void testColumnsNotCachedWhenCacheDisabled() {
CachingJdbcClient cachingJdbcClient = createCachingJdbcClient(ZERO, true, 10000);
ConnectorSession firstSession = createSession("first");
ConnectorSession secondSession = createSession("second");
JdbcTableHandle firstTable = createTable(new SchemaTableName(schema, "first_table"));
JdbcTableHandle secondTable = createTable(new SchemaTableName(schema, "second_table"));
JdbcColumnHandle firstColumn = addColumn(firstTable, "first_column");
JdbcColumnHandle secondColumn = addColumn(secondTable, "second_column");
assertColumnCacheStats(cachingJdbcClient).loads(4).misses(4).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, firstTable)).containsExactly(firstColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, firstTable)).containsExactly(firstColumn);
assertThat(cachingJdbcClient.getColumns(firstSession, secondTable)).containsExactly(secondColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, secondTable)).containsExactly(secondColumn);
});
assertColumnCacheStats(cachingJdbcClient).loads(4).misses(4).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, firstTable)).containsExactly(firstColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, firstTable)).containsExactly(firstColumn);
assertThat(cachingJdbcClient.getColumns(firstSession, secondTable)).containsExactly(secondColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, secondTable)).containsExactly(secondColumn);
});
// Drop tables by not using caching jdbc client
jdbcClient.dropTable(SESSION, firstTable);
jdbcClient.dropTable(SESSION, secondTable);
// Columns are loaded bypassing a cache
assertColumnCacheStats(cachingJdbcClient).loads(2).misses(2).afterRunning(() -> {
assertThatThrownBy(() -> cachingJdbcClient.getColumns(firstSession, firstTable)).isInstanceOf(TableNotFoundException.class);
assertThatThrownBy(() -> cachingJdbcClient.getColumns(firstSession, secondTable)).isInstanceOf(TableNotFoundException.class);
});
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class TestCachingJdbcClient method testColumnsCachedPerSession.
@Test
public void testColumnsCachedPerSession() {
ConnectorSession firstSession = createSession("first");
ConnectorSession secondSession = createSession("second");
JdbcTableHandle table = getAnyTable(schema);
JdbcColumnHandle phantomColumn = addColumn(table);
// Load columns in first session scope
assertColumnCacheStats(cachingJdbcClient).loads(1).misses(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, table)).contains(phantomColumn);
});
// Load columns in second session scope
assertColumnCacheStats(cachingJdbcClient).loads(1).misses(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(secondSession, table)).contains(phantomColumn);
});
// Check that columns are cached
assertColumnCacheStats(cachingJdbcClient).hits(1).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(secondSession, table)).contains(phantomColumn);
});
// Drop first column and invalidate cache for all sessions
cachingJdbcClient.dropColumn(firstSession, table, phantomColumn);
assertThat(jdbcClient.getColumns(firstSession, table)).doesNotContain(phantomColumn);
// Load columns into cache in both sessions scope
assertColumnCacheStats(cachingJdbcClient).loads(2).misses(2).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, table)).doesNotContain(phantomColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, table)).doesNotContain(phantomColumn);
});
// Read columns from cache
assertColumnCacheStats(cachingJdbcClient).hits(2).afterRunning(() -> {
assertThat(cachingJdbcClient.getColumns(firstSession, table)).doesNotContain(phantomColumn);
assertThat(cachingJdbcClient.getColumns(secondSession, table)).doesNotContain(phantomColumn);
});
}
Aggregations