Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated test for queries with caching #6986

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.jdbc;

import com.google.common.collect.ImmutableMap;
import io.trino.testing.AbstractTestDistributedQueries;
import io.trino.testing.QueryRunner;
import io.trino.testing.sql.JdbcSqlExecutor;
import io.trino.testing.sql.TestTable;
import io.trino.tpch.TpchTable;
import org.testng.SkipException;

import java.util.Map;
import java.util.Optional;
import java.util.Properties;

import static io.trino.plugin.jdbc.H2QueryRunner.createH2QueryRunner;

public class TestJdbcCachingQueries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestJdbcDistributedQueriesWithMetadataCaching?

I understand that other tests like io.trino.plugin.postgresql.TestPostgreSqlDistributedQueries can use caching if they like. It is irrelevant for for them, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test connectors with default settings as much as possible, but other than that -- yes

TestJdbcDistributedQueriesWithMetadataCaching

i don't want to encode the promise that all "AbstractTestDistributedQueries" are gonna always be included here

// TODO define shorter tests set that exercises various read and write scenarios (a.k.a. "a smoke test")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GH issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but this feels more like your idea, so feel free to create one :)

extends AbstractTestDistributedQueries
{
private Map<String, String> properties;

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
properties = ImmutableMap.<String, String>builder()
.putAll(TestingH2JdbcModule.createProperties())
.put("metadata.cache-ttl", "10m")
.put("metadata.cache-missing", "true")
.put("allow-drop-table", "true")
.build();
return createH2QueryRunner(TpchTable.getTables(), properties);
}

@Override
protected boolean supportsDelete()
{
return false;
}

@Override
protected boolean supportsViews()
{
return false;
}

@Override
protected boolean supportsArrays()
{
return false;
}

@Override
protected boolean supportsCommentOnTable()
{
return false;
}

@Override
protected boolean supportsCommentOnColumn()
{
return false;
}

@Override
public void testLargeIn(int valuesCount)
{
throw new SkipException("This test should pass with H2, but takes too long (currently over a mninute) and is not that important");
}

@Override
protected TestTable createTableWithDefaultColumns()
{
return new TestTable(
getSqlExecutor(),
"tpch.table",
"(col_required BIGINT NOT NULL," +
"col_nullable BIGINT," +
"col_default BIGINT DEFAULT 43," +
"col_nonnull_default BIGINT NOT NULL DEFAULT 42," +
"col_required2 BIGINT NOT NULL)");
}

@Override
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup)
{
String typeBaseName = dataMappingTestSetup.getTrinoTypeName().replaceAll("\\([^()]*\\)", "");
switch (typeBaseName) {
case "boolean":
case "decimal":
case "char":
case "varbinary":
case "time":
case "timestamp":
case "timestamp with time zone":
return Optional.of(dataMappingTestSetup.asUnsupported());
}

return Optional.of(dataMappingTestSetup);
}

private JdbcSqlExecutor getSqlExecutor()
{
return new JdbcSqlExecutor(properties.get("connection-url"), new Properties());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,105 @@
*/
package io.trino.plugin.jdbc;

import io.trino.testing.AbstractTestQueries;
import com.google.common.collect.ImmutableMap;
import io.trino.testing.AbstractTestDistributedQueries;
import io.trino.testing.QueryRunner;
import io.trino.testing.sql.JdbcSqlExecutor;
import io.trino.testing.sql.TestTable;
import io.trino.tpch.TpchTable;
import org.testng.SkipException;

import java.util.Map;
import java.util.Optional;
import java.util.Properties;

import static io.trino.plugin.jdbc.H2QueryRunner.createH2QueryRunner;

public class TestJdbcDistributedQueries
extends AbstractTestQueries
extends AbstractTestDistributedQueries
{
private Map<String, String> properties;

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
return createH2QueryRunner(TpchTable.getTables());
properties = ImmutableMap.<String, String>builder()
.putAll(TestingH2JdbcModule.createProperties())
.put("allow-drop-table", "true")
.build();
return createH2QueryRunner(TpchTable.getTables(), properties);
}

@Override
protected boolean supportsDelete()
{
return false;
}

@Override
protected boolean supportsViews()
{
return false;
}

@Override
protected boolean supportsArrays()
{
return false;
}

@Override
protected boolean supportsCommentOnTable()
{
return false;
}

@Override
protected boolean supportsCommentOnColumn()
{
return false;
}

@Override
public void testLargeIn(int valuesCount)
{
throw new SkipException("This test should pass with H2, but takes too long (currently over a mninute) and is not that important");
}

@Override
protected TestTable createTableWithDefaultColumns()
{
return new TestTable(
getSqlExecutor(),
"tpch.table",
"(col_required BIGINT NOT NULL," +
"col_nullable BIGINT," +
"col_default BIGINT DEFAULT 43," +
"col_nonnull_default BIGINT NOT NULL DEFAULT 42," +
"col_required2 BIGINT NOT NULL)");
}

@Override
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup)
{
String typeBaseName = dataMappingTestSetup.getTrinoTypeName().replaceAll("\\([^()]*\\)", "");
switch (typeBaseName) {
case "boolean":
case "decimal":
case "char":
case "varbinary":
case "time":
case "timestamp":
case "timestamp with time zone":
return Optional.of(dataMappingTestSetup.asUnsupported());
}

return Optional.of(dataMappingTestSetup);
}

private JdbcSqlExecutor getSqlExecutor()
{
return new JdbcSqlExecutor(properties.get("connection-url"), new Properties());
}
}