Skip to content

Commit

Permalink
Migrate redundant connector test to smoke test in Hudi
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Jul 24, 2023
1 parent 565375b commit c3a9278
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.hudi;

import io.trino.testing.BaseConnectorSmokeTest;
import io.trino.testing.TestingConnectorBehavior;

import static org.assertj.core.api.Assertions.assertThat;

public abstract class BaseHudiConnectorSmokeTest
extends BaseConnectorSmokeTest
{
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_INSERT:
case SUPPORTS_DELETE:
case SUPPORTS_UPDATE:
case SUPPORTS_MERGE:
return false;

case SUPPORTS_CREATE_SCHEMA:
return false;

case SUPPORTS_CREATE_TABLE:
case SUPPORTS_RENAME_TABLE:
return false;

case SUPPORTS_CREATE_VIEW:
case SUPPORTS_CREATE_MATERIALIZED_VIEW:
return false;

case SUPPORTS_COMMENT_ON_COLUMN:
return false;

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

@Override
public void testShowCreateTable()
{
// Override because Hudi connector contains 'location' table property
String schema = getSession().getSchema().orElseThrow();
assertThat((String) computeScalar("SHOW CREATE TABLE region"))
.matches("\\QCREATE TABLE hudi." + schema + ".region (\n" +
" regionkey bigint,\n" +
" name varchar(25),\n" +
" comment varchar(152)\n" +
")\n" +
"WITH (\n" +
" location = \\E'.*/region'\n\\Q" +
")");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,31 @@
*/
package io.trino.plugin.hudi;

import com.google.common.collect.ImmutableMap;
import io.trino.plugin.hudi.testing.TpchHudiTablesInitializer;
import io.trino.testing.BaseConnectorTest;
import io.trino.testing.QueryRunner;
import io.trino.testing.TestingConnectorBehavior;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

import static org.apache.hudi.common.model.HoodieRecord.HOODIE_META_COLUMNS;
import static io.trino.plugin.hudi.HudiQueryRunner.createHudiQueryRunner;
import static io.trino.plugin.hudi.testing.HudiTestUtils.COLUMNS_TO_HIDE;
import static org.apache.hudi.common.model.HoodieTableType.COPY_ON_WRITE;
import static org.assertj.core.api.Assertions.assertThat;

public abstract class BaseHudiConnectorTest
public class TestHudiConnectorTest
extends BaseConnectorTest
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
{
return createHudiQueryRunner(
ImmutableMap.of(),
ImmutableMap.of("hudi.columns-to-hide", COLUMNS_TO_HIDE),
new TpchHudiTablesInitializer(COPY_ON_WRITE, REQUIRED_TPCH_TABLES));
}

@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
Expand Down Expand Up @@ -95,12 +106,4 @@ public void testHideHiveSysSchema()
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).doesNotContain("sys");
assertQueryFails("SHOW TABLES IN hudi.sys", ".*Schema 'sys' does not exist");
}

protected static String columnsToHide()
{
List<String> columns = new ArrayList<>(HOODIE_META_COLUMNS.size() + 1);
columns.addAll(HOODIE_META_COLUMNS);
columns.add(TpchHudiTablesInitializer.FIELD_UUID);
return String.join(",", columns);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
import io.trino.testing.QueryRunner;

import static io.trino.plugin.hudi.HudiQueryRunner.createHudiQueryRunner;
import static io.trino.plugin.hudi.testing.HudiTestUtils.COLUMNS_TO_HIDE;
import static org.apache.hudi.common.model.HoodieTableType.COPY_ON_WRITE;

public class TestHudiCopyOnWriteConnectorTest
extends BaseHudiConnectorTest
public class TestHudiCopyOnWriteConnectorSmokeTest
extends BaseHudiConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
{
return createHudiQueryRunner(
ImmutableMap.of(),
ImmutableMap.of("hudi.columns-to-hide", columnsToHide()),
ImmutableMap.of("hudi.columns-to-hide", COLUMNS_TO_HIDE),
new TpchHudiTablesInitializer(COPY_ON_WRITE, REQUIRED_TPCH_TABLES));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
import io.trino.testing.QueryRunner;

import static io.trino.plugin.hive.containers.HiveHadoop.HIVE3_IMAGE;
import static io.trino.plugin.hudi.testing.HudiTestUtils.COLUMNS_TO_HIDE;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static org.apache.hudi.common.model.HoodieTableType.COPY_ON_WRITE;

public class TestHudiCopyOnWriteMinioConnectorTest
extends BaseHudiMinioConnectorTest
public class TestHudiCopyOnWriteMinioConnectorSmokeTest
extends BaseHudiConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
{
String bucketName = "test-hudi-connector-" + randomNameSuffix();
hiveMinioDataLake = closeAfterClass(new HiveMinioDataLake(bucketName, HIVE3_IMAGE));
HiveMinioDataLake hiveMinioDataLake = closeAfterClass(new HiveMinioDataLake(bucketName, HIVE3_IMAGE));
hiveMinioDataLake.start();
hiveMinioDataLake.getMinioClient().ensureBucketExists(bucketName);

return S3HudiQueryRunner.create(
ImmutableMap.of(),
ImmutableMap.of("hudi.columns-to-hide", columnsToHide()),
ImmutableMap.of("hudi.columns-to-hide", COLUMNS_TO_HIDE),
new TpchHudiTablesInitializer(COPY_ON_WRITE, REQUIRED_TPCH_TABLES),
hiveMinioDataLake);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
import io.trino.testing.QueryRunner;

import static io.trino.plugin.hudi.HudiQueryRunner.createHudiQueryRunner;
import static io.trino.plugin.hudi.testing.HudiTestUtils.COLUMNS_TO_HIDE;
import static org.apache.hudi.common.model.HoodieTableType.MERGE_ON_READ;

public class TestHudiMergeOnReadConnectorTest
extends BaseHudiConnectorTest
public class TestHudiMergeOnReadConnectorSmokeTest
extends BaseHudiConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
{
return createHudiQueryRunner(
ImmutableMap.of(),
ImmutableMap.of("hudi.columns-to-hide", columnsToHide()),
ImmutableMap.of("hudi.columns-to-hide", COLUMNS_TO_HIDE),
new TpchHudiTablesInitializer(MERGE_ON_READ, REQUIRED_TPCH_TABLES));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
import io.trino.testing.QueryRunner;

import static io.trino.plugin.hive.containers.HiveHadoop.HIVE3_IMAGE;
import static io.trino.plugin.hudi.testing.HudiTestUtils.COLUMNS_TO_HIDE;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static org.apache.hudi.common.model.HoodieTableType.MERGE_ON_READ;

public class TestHudiMergeOnReadMinioConnectorTest
extends BaseHudiMinioConnectorTest
public class TestHudiMergeOnReadMinioConnectorSmokeTest
extends BaseHudiConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
{
String bucketName = "test-hudi-connector-" + randomNameSuffix();
hiveMinioDataLake = closeAfterClass(new HiveMinioDataLake(bucketName, HIVE3_IMAGE));
HiveMinioDataLake hiveMinioDataLake = closeAfterClass(new HiveMinioDataLake(bucketName, HIVE3_IMAGE));
hiveMinioDataLake.start();
hiveMinioDataLake.getMinioClient().ensureBucketExists(bucketName);

return S3HudiQueryRunner.create(
ImmutableMap.of(),
ImmutableMap.of("hudi.columns-to-hide", columnsToHide()),
ImmutableMap.of("hudi.columns-to-hide", COLUMNS_TO_HIDE),
new TpchHudiTablesInitializer(MERGE_ON_READ, REQUIRED_TPCH_TABLES),
hiveMinioDataLake);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.hudi;
package io.trino.plugin.hudi.testing;

import io.trino.plugin.hive.containers.HiveMinioDataLake;
import com.google.common.collect.ImmutableList;

public abstract class BaseHudiMinioConnectorTest
extends BaseHudiConnectorTest
import static io.trino.plugin.hudi.testing.TpchHudiTablesInitializer.FIELD_UUID;
import static org.apache.hudi.common.model.HoodieRecord.HOODIE_META_COLUMNS;

public final class HudiTestUtils
{
protected HiveMinioDataLake hiveMinioDataLake;
private HudiTestUtils() {}

public static final String COLUMNS_TO_HIDE = String.join(",", ImmutableList.<String>builder()
.addAll(HOODIE_META_COLUMNS)
.add(FIELD_UUID)
.build());
}

0 comments on commit c3a9278

Please sign in to comment.