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

Minor JDBC Connector tests fixes #8361

Merged
merged 4 commits into from
Jun 24, 2021
Merged
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
Expand Up @@ -32,7 +32,6 @@
import io.trino.sql.query.QueryAssertions.QueryAssert;
import io.trino.testing.BaseConnectorTest;
import io.trino.testing.MaterializedResult;
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.sql.SqlExecutor;
import io.trino.testing.sql.TestTable;
import io.trino.testing.sql.TestView;
Expand Down Expand Up @@ -65,6 +64,7 @@
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_STDDEV;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CANCELLATION;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN;
Expand All @@ -87,29 +87,14 @@ public abstract class BaseJdbcConnectorTest
{
private final ExecutorService executor = newCachedThreadPool(daemonThreadsNamed(getClass().getName()));

protected abstract SqlExecutor onRemoteDatabase();
Copy link
Member

Choose a reason for hiding this comment

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

OTOH it's a helper, so i belongs at the bottom


@AfterClass(alwaysRun = true)
public void afterClass()
{
executor.shutdownNow();
}

@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_CREATE_VIEW:
// Not supported by JdbcMetadata
return false;

case SUPPORTS_DELETE:
// Not supported by JdbcMetadata
return false;

default:
return super.hasBehavior(connectorBehavior);
}
}

@Test
public void testInsertInPresenceOfNotSupportedColumn()
{
Expand Down Expand Up @@ -343,6 +328,10 @@ public void testStddevAggregationPushdown()
{
String schemaName = getSession().getSchema().orElseThrow();
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_STDDEV)) {
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
}

try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_stddev_pushdown", ImmutableList.of())) {
assertThat(query("SELECT stddev_pop(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
assertThat(query("SELECT stddev(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
Expand Down Expand Up @@ -390,6 +379,10 @@ public void testVarianceAggregationPushdown()
{
String schemaName = getSession().getSchema().orElseThrow();
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE)) {
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
}

try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_variance_pushdown", ImmutableList.of())) {
assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
Expand Down Expand Up @@ -430,6 +423,10 @@ public void testCovarianceAggregationPushdown()
{
String schemaName = getSession().getSchema().orElseThrow();
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_COVARIANCE)) {
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
}

try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_covariance_pushdown", ImmutableList.of())) {
assertThat(query("SELECT covar_pop(t_double, u_double), covar_pop(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
assertThat(query("SELECT covar_samp(t_double, u_double), covar_samp(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
Expand Down Expand Up @@ -463,6 +460,10 @@ public void testCorrAggregationPushdown()
{
String schemaName = getSession().getSchema().orElseThrow();
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_CORRELATION)) {
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
}

try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_corr_pushdown", ImmutableList.of())) {
assertThat(query("SELECT corr(t_double, u_double), corr(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
return;
Expand Down Expand Up @@ -492,6 +493,10 @@ public void testRegrAggregationPushdown()
{
String schemaName = getSession().getSchema().orElseThrow();
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_REGRESSION)) {
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
}

try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_regr_pushdown", ImmutableList.of())) {
assertThat(query("SELECT regr_intercept(t_double, u_double), regr_intercept(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
assertThat(query("SELECT regr_slope(t_double, u_double), regr_slope(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
Expand Down Expand Up @@ -1141,6 +1146,4 @@ protected TestView createSleepingView(Duration minimalSleepDuration)
{
throw new UnsupportedOperationException();
}

protected abstract SqlExecutor onRemoteDatabase();
}
7 changes: 7 additions & 0 deletions plugin/trino-druid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
</dependency>

<!-- for testing -->
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-base-jdbc</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-main</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*/
package io.trino.plugin.druid;

import io.trino.Session;
import io.trino.plugin.jdbc.JdbcMetadataConfig;
import io.trino.plugin.jdbc.BaseJdbcConnectorTest;
import io.trino.plugin.jdbc.JdbcTableHandle;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.SchemaTableName;
Expand All @@ -23,15 +22,14 @@
import io.trino.sql.planner.plan.JoinNode;
import io.trino.sql.planner.plan.TableScanNode;
import io.trino.sql.planner.plan.TopNNode;
import io.trino.testing.BaseConnectorTest;
import io.trino.testing.MaterializedResult;
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.assertions.Assert;
import io.trino.testing.sql.SqlExecutor;
import org.intellij.lang.annotations.Language;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import static com.google.common.base.Verify.verify;
import static io.trino.plugin.druid.DruidQueryRunner.copyAndIngestTpchData;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.sql.planner.assertions.PlanMatchPattern.anyTree;
Expand All @@ -40,7 +38,7 @@
import static org.assertj.core.api.Assertions.assertThat;

public abstract class BaseDruidConnectorTest
extends BaseConnectorTest
extends BaseJdbcConnectorTest
{
protected static final String SELECT_FROM_ORDERS = "SELECT " +
"orderdate, " +
Expand Down Expand Up @@ -138,12 +136,19 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_COMMENT_ON_COLUMN:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_TOPN_PUSHDOWN:
case SUPPORTS_AGGREGATION_PUSHDOWN:
return false;
default:
return super.hasBehavior(connectorBehavior);
}
}

@Override
protected SqlExecutor onRemoteDatabase()
{
return druidServer::execute;
}

@Test
@Override
public void testDescribeTable()
Expand Down Expand Up @@ -342,13 +347,4 @@ public void testLimitPushDown()
"LIMIT 30"))
.isNotFullyPushedDown(joinOverTableScans);
}

protected Session joinPushdownEnabled(Session session)
{
// If join pushdown gets enabled by default, tests should use default session
verify(!new JdbcMetadataConfig().isJoinPushdownEnabled());
return Session.builder(session)
.setCatalogSessionProperty(session.getCatalog().orElseThrow(), "join_pushdown_enabled", "true")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
Expand Down Expand Up @@ -207,6 +211,17 @@ public String getJdbcUrl()
return getJdbcUrl(broker.getMappedPort(DRUID_BROKER_PORT));
}

public void execute(String sql)
{
try (Connection connection = DriverManager.getConnection(getJdbcUrl());
Statement statement = connection.createStatement()) {
statement.execute(sql);
}
catch (SQLException e) {
throw new RuntimeException(e);
}
}

public int getCoordinatorOverlordPort()
{
return coordinator.getMappedPort(DRUID_COORDINATOR_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ public void testDelete()
String tableName = "test_delete_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM region", 5);

// delete half the table, then delete the rest
assertUpdate("DELETE FROM " + tableName + " WHERE regionkey = 2", 1);
assertThat(query("SELECT regionkey FROM " + tableName))
.skippingTypesCheck()
.matches("VALUES 1, 3, 4, 5");
.matches("VALUES 0, 1, 3, 4");

assertUpdate("DROP TABLE " + tableName);
}
Expand Down