Skip to content
Open
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
712 changes: 712 additions & 0 deletions data/scripts/q_test_tpcds_external_tables_schema.postgres.sql

Large diffs are not rendered by default.

472 changes: 472 additions & 0 deletions data/scripts/q_test_tpcds_schema.postgres.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.hadoop.hive.cli;

import java.io.File;
import java.util.List;

import org.apache.hadoop.hive.cli.control.CliAdapter;
import org.apache.hadoop.hive.cli.control.CliConfigs;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class TestMiniLlapLocalPostgresJdbcCliDriver {
static CliAdapter adapter = new CliConfigs.MiniLlapLocalPostgresJdbcCliConfig().getCliAdapter();

@Parameters(name = "{0}")
public static List<Object[]> getParameters() throws Exception {
return adapter.getParameters();
}

@ClassRule
public static TestRule cliClassRule = adapter.buildClassRule();

@Rule
public TestRule cliTestRule = adapter.buildTestRule();

private String name;
private File qfile;

public TestMiniLlapLocalPostgresJdbcCliDriver(String name, File qfile) {
this.name = name;
this.qfile = qfile;
}

@Test
public void testCliDriver() throws Exception {
adapter.runTest(name, qfile);
}
}
7 changes: 7 additions & 0 deletions itests/src/test/resources/testconfiguration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ tez.perf.disabled.query.files=\
mv_query67.q,\
mv_query68.q

jdbc.disabled.query.files=\
mv_query30.q,\
mv_query44.q,\
mv_query45.q,\
mv_query67.q,\
mv_query68.q

hive.kafka.query.files=\
kafka_storage_handler.q

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.hadoop.hive.ql.QTestMiniClusters.MiniClusterType;
import org.apache.hadoop.hive.ql.hooks.ExplainFormattedCBOHook;
import org.apache.hadoop.hive.ql.parse.CoreParseNegative;
import org.apache.hadoop.hive.ql.qoption.QTestDatabaseHandler;

public class CliConfigs {

Expand Down Expand Up @@ -201,7 +202,46 @@ public MiniLlapLocalCliConfig() {
}
}
}


public static class MiniLlapLocalPostgresJdbcCliConfig extends AbstractCliConfig implements JdbcCliConfig {
private final QTestDatabaseHandler.DatabaseType databaseType;
private final String jdbcInitScript;
private final String externalTablesInitScript;

public MiniLlapLocalPostgresJdbcCliConfig() {
super(CoreJdbcCliDriver.class);
try {
databaseType = QTestDatabaseHandler.DatabaseType.POSTGRES;
jdbcInitScript = "q_test_tpcds_schema.postgres.sql";
externalTablesInitScript = "q_test_tpcds_external_tables_schema.postgres.sql";

setQueryDir("ql/src/test/queries/clientpositive/perf");
setLogDir("itests/qtest/target/qfile-results/clientpositive/jdbc/postgres");
setResultsDir("ql/src/test/results/clientpositive/jdbc/postgres");
setHiveConfDir("data/conf/llap");
setClusterType(MiniClusterType.LLAP_LOCAL);
excludesFrom(testConfigProps, "jdbc.disabled.query.files");
} catch (Exception e) {
throw new RuntimeException("can't construct cliconfig", e);
}
}

@Override
public QTestDatabaseHandler.DatabaseType getDatabaseType() {
return databaseType;
}

@Override
public String getJdbcInitScript() {
return jdbcInitScript;
}

@Override
public String getExternalTablesInitScript() {
return externalTablesInitScript;
}
}

public static class MiniLlapLocalCompactorCliConfig extends AbstractCliConfig {

public MiniLlapLocalCompactorCliConfig() {
Expand Down Expand Up @@ -341,7 +381,7 @@ public TPCDSFormattedCBOConfig() {
}
}
}

public static class NegativeLlapLocalCliConfig extends AbstractCliConfig {
public NegativeLlapLocalCliConfig() {
super(CoreNegativeCliDriver.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.hadoop.hive.cli.control;

import org.apache.commons.io.FileUtils;
import org.apache.hadoop.hive.ql.externalDB.AbstractExternalDB;
import org.apache.hadoop.hive.ql.QTestUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class CoreJdbcCliDriver extends CoreCliDriver {
private AbstractExternalDB externalDB;
private static final Logger LOG = LoggerFactory.getLogger(CoreJdbcCliDriver.class);
private boolean externalTablesCreated = false;

public CoreJdbcCliDriver(AbstractCliConfig testCliConfig) {
super(testCliConfig);
}

@Override
@BeforeClass
public void beforeClass() throws Exception {
super.beforeClass();

if (cliConfig instanceof JdbcCliConfig jc) {
LOG.info("Launching docker container, running jdbc init script...");
Path scriptFile = Paths.get(
QTestUtil.getScriptsDir(getQt().getConf()) + File.separator + jc.getJdbcInitScript()
);
if (Files.notExists(scriptFile)) {
LOG.info("No jdbc init script detected. Skipping");
return;
}
externalDB = getQt().getDatabaseHandler().initDb(jc.getDatabaseType(), scriptFile);
}
}

@Override
@Before
public void setUp() throws Exception {
super.setUp();
if (!externalTablesCreated && cliConfig instanceof JdbcCliConfig jc) {
LOG.info("Running init script for external tables...");
File scriptFile = new File(
QTestUtil.getScriptsDir(getQt().getConf()) + File.separator +
jc.getExternalTablesInitScript()
);
if (!scriptFile.isFile()) {
LOG.info("No init script for external tables detected. Skipping");
return;
}
String initCommands = FileUtils.readFileToString(scriptFile, StandardCharsets.UTF_8);
getQt().getCliDriver().processLine(initCommands);
externalTablesCreated = true;
}
}

@Override
@After
public void tearDown() throws Exception {
// Skip clearTestSideEffects() — external tables must persist across tests in the suite.
getQt().clearPostTestEffects();
}

@Override
@AfterClass
public void shutdown() throws Exception {
LOG.info("Cleaning up...");
if (externalDB != null) {
LOG.info("Cleaning up docker...");
externalDB.stop();
}
super.shutdown();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.hadoop.hive.cli.control;

import org.apache.hadoop.hive.ql.qoption.QTestDatabaseHandler;

public interface JdbcCliConfig {

QTestDatabaseHandler.DatabaseType getDatabaseType();

String getJdbcInitScript();

String getExternalTablesInitScript();
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public static String getScriptsDir(HiveConf conf) {
return scriptsDir;
}

public QTestDatabaseHandler getDatabaseHandler() {
return (QTestDatabaseHandler) dispatcher.getHandler("database");
}

public void shutdown() throws Exception {
if (System.getenv(QTEST_LEAVE_FILES) == null) {
cleanUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -50,40 +51,40 @@
public class QTestDatabaseHandler implements QTestOptionHandler {
private static final Logger LOG = LoggerFactory.getLogger(QTestDatabaseHandler.class);

private enum DatabaseType {
public enum DatabaseType {
POSTGRES {
@Override
AbstractExternalDB create() {
public AbstractExternalDB create() {
return new PostgresExternalDB();
}
}, MYSQL {
@Override
AbstractExternalDB create() {
public AbstractExternalDB create() {
return new MySQLExternalDB();
}
}, MARIADB {
@Override
AbstractExternalDB create() {
public AbstractExternalDB create() {
return new MariaDB();
}
}, MSSQL {
@Override
AbstractExternalDB create() {
public AbstractExternalDB create() {
return new MSSQLServer();
}
}, ORACLE {
@Override
AbstractExternalDB create() {
public AbstractExternalDB create() {
return new Oracle();
}
}, DERBY {
@Override
AbstractExternalDB create() {
public AbstractExternalDB create() {
return new Derby();
}
};

abstract AbstractExternalDB create();
public abstract AbstractExternalDB create();
}

private final String scriptsDir;
Expand All @@ -93,6 +94,24 @@ public QTestDatabaseHandler(final String scriptDirectory) {
this.scriptsDir = scriptDirectory;
}

public AbstractExternalDB initDb(String dbType, Path initScript) throws Exception {
return initDb(DatabaseType.valueOf(dbType.toUpperCase()), "qtestDB", initScript);
}

public AbstractExternalDB initDb(DatabaseType dbType, Path initScript) throws Exception {
return initDb(dbType, "qtestDB", initScript);
}

public AbstractExternalDB initDb(DatabaseType dbType, String dbName, Path initScript) throws Exception {
AbstractExternalDB db = dbType.create();
db.setName(dbName);
if (initScript != null) {
db.setInitScript(initScript);
}
db.start();
return db;
}

@Override
public void processArguments(String arguments) {
String[] args = arguments.split(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public void register(String prefix, QTestOptionHandler datasetHandler) {
handlers.put(prefix, datasetHandler);
}

public QTestOptionHandler getHandler(String prefix) {
return handlers.get(prefix);
}

public void process(File file) {
synchronized (QTestUtil.class) {
parse(file);
Expand Down
Loading
Loading