DRILL-2641: Move unrelated tests in exec/jdbc module into appropriate modules
Also: - Update the tests to use the new test framework - Remove duplicate tests (TestHiveScalarUDFs.java) Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/375f8415 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/375f8415 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/375f8415 Branch: refs/heads/master Commit: 375f8415d6fc6d85ca7109bc3420494227c4b12b Parents: 931ed64 Author: vkorukanti <venki.koruka...@gmail.com> Authored: Fri Dec 26 11:39:46 2014 -0800 Committer: Mehant Baid <meha...@gmail.com> Committed: Fri Apr 10 21:21:14 2015 -0700 ---------------------------------------------------------------------- .../resources/bootstrap-storage-plugins.json | 15 - .../apache/drill/exec/hive/TestHiveStorage.java | 143 +++++- .../exec/hive/TestInfoSchemaOnHiveStorage.java | 120 +++++ .../exec/store/hive/HiveTestDataGenerator.java | 18 +- .../apache/drill/exec/sql/TestInfoSchema.java | 320 +++++++++++++ exec/jdbc/pom.xml | 11 - .../jdbc/DatabaseMetaDataGetColumnsTest.java | 31 +- .../drill/jdbc/test/TestHiveScalarUDFs.java | 57 --- .../apache/drill/jdbc/test/TestHiveStorage.java | 99 ---- .../apache/drill/jdbc/test/TestMetadataDDL.java | 470 ------------------- .../resources/bootstrap-storage-plugins.json | 15 - 11 files changed, 613 insertions(+), 686 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/contrib/storage-hive/core/src/main/resources/bootstrap-storage-plugins.json ---------------------------------------------------------------------- diff --git a/contrib/storage-hive/core/src/main/resources/bootstrap-storage-plugins.json b/contrib/storage-hive/core/src/main/resources/bootstrap-storage-plugins.json deleted file mode 100644 index 5c7174e..0000000 --- a/contrib/storage-hive/core/src/main/resources/bootstrap-storage-plugins.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "storage":{ - hive : { - type:"hive", - enabled: false, - config : { - "hive.metastore.uris" : "", - "javax.jdo.option.ConnectionURL" : "jdbc:derby:;databaseName=../sample-data/drill_hive_db;create=true", - "hive.metastore.warehouse.dir" : "/tmp/drill_hive_wh", - "fs.default.name" : "file:///", - "hive.metastore.sasl.enabled" : "false" - } - } - } -} http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java ---------------------------------------------------------------------- diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java index a76128f..cbbfcda 100644 --- a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java +++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestHiveStorage.java @@ -19,11 +19,149 @@ package org.apache.drill.exec.hive; import com.google.common.collect.ImmutableMap; import org.apache.hadoop.fs.FileSystem; +import org.joda.time.DateTime; import org.junit.Test; +import java.math.BigDecimal; +import java.sql.Date; +import java.sql.Timestamp; + public class TestHiveStorage extends HiveTestBase { @Test - public void testQueryingTablesInNonDefaultFS() throws Exception { + public void hiveReadWithDb() throws Exception { + test("select * from hive.kv"); + } + + @Test + public void queryEmptyHiveTable() throws Exception { + testBuilder() + .sqlQuery("SELECT * FROM hive.empty_table") + .expectsEmptyResultSet() + .go(); + } + + /** + * Test to ensure Drill reads the all supported types correctly both normal fields (converted to Nullable types) and + * partition fields (converted to Required types). + * @throws Exception + */ + @Test + public void readAllSupportedHiveDataTypes() throws Exception { + + testBuilder().sqlQuery("SELECT * FROM hive.readtest") + .unOrdered() + .baselineColumns( + "binary_field", + "boolean_field", + "tinyint_field", + "decimal0_field", + "decimal9_field", + "decimal18_field", + "decimal28_field", + "decimal38_field", + "double_field", + "float_field", + "int_field", + "bigint_field", + "smallint_field", + "string_field", + "varchar_field", + "timestamp_field", + "date_field", + "binary_part", + "boolean_part", + "tinyint_part", + "decimal0_part", + "decimal9_part", + "decimal18_part", + "decimal28_part", + "decimal38_part", + "double_part", + "float_part", + "int_part", + "bigint_part", + "smallint_part", + "string_part", + "varchar_part", + "timestamp_part", + "date_part") + .baselineValues( + "binaryfield", + false, + (byte) 34, + new BigDecimal("66"), + new BigDecimal("2347.92"), + new BigDecimal("2758725827.99990"), + new BigDecimal("29375892739852.8"), + new BigDecimal("89853749534593985.783"), + 8.345d, + 4.67f, + 123456, + 234235L, + (short) 3455, + "stringfield", + "varcharfield", + new DateTime(Timestamp.valueOf("2013-07-05 17:01:00").getTime()), + new DateTime(Date.valueOf("2013-07-05").getTime()), + "binary", + true, + (byte) 64, + new BigDecimal("370000000000"), // TODO(DRILL-2729) Should be 37 + new BigDecimal("369000.00"), // TODO(DRILL-2729) Should be 36.90 + new BigDecimal("-66367900898250.61888"), // TODO(DRILL-2729) Should be 3289379872.94565 + new BigDecimal("39579334534534.4"), + new BigDecimal("363945093845093890.900"), + 8.345d, + 4.67f, + 123456, + 234235L, + (short) 3455, + "string", + "varchar", + new DateTime(Timestamp.valueOf("2013-07-05 17:01:00").getTime()), + new DateTime(Date.valueOf("2013-07-05").getTime())) + .baselineValues( // All fields are null, but partition fields have non-null values + "", // For binary (varchar, string too) empty value is considered as empty string instead of "null" + null, null, null, null, null, null, null, null, null, null, null, null, + "", // string_field + "", // varchar_field + null, null, + "binary", + true, + (byte) 64, + new BigDecimal("370000000000"), // TODO(DRILL-2729) Should be 37 + new BigDecimal("369000.00"), // TODO(DRILL-2729) Should be 36.90 + new BigDecimal("-66367900898250.61888"), // TODO(DRILL-2729) Should be 3289379872.94565 + new BigDecimal("39579334534534.4"), + new BigDecimal("363945093845093890.900"), + 8.345d, + 4.67f, + 123456, + 234235L, + (short) 3455, + "string", + "varchar", + new DateTime(Timestamp.valueOf("2013-07-05 17:01:00").getTime()), + new DateTime(Date.valueOf("2013-07-05").getTime())) + .go(); + } + + @Test + public void orderByOnHiveTable() throws Exception { + testBuilder() + .sqlQuery("SELECT * FROM hive.kv ORDER BY `value` DESC") + .ordered() + .baselineColumns("key", "value") + .baselineValues(5, " key_5") + .baselineValues(4, " key_4") + .baselineValues(3, " key_3") + .baselineValues(2, " key_2") + .baselineValues(1, " key_1") + .go(); + } + + @Test + public void queryingTablesInNonDefaultFS() throws Exception { // Update the default FS settings in Hive test storage plugin to non-local FS hiveTest.updatePluginConfig(ImmutableMap.of(FileSystem.FS_DEFAULT_NAME_KEY, "hdfs://localhost:9001")); @@ -32,7 +170,6 @@ public class TestHiveStorage extends HiveTestBase { .unOrdered() .baselineColumns("key", "value") .baselineValues(1, " key_1") - .build() - .run(); + .go(); } } http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java ---------------------------------------------------------------------- diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java new file mode 100644 index 0000000..d8ab5c0 --- /dev/null +++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java @@ -0,0 +1,120 @@ +/** + * 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.drill.exec.hive; + +import org.junit.Test; + +public class TestInfoSchemaOnHiveStorage extends HiveTestBase { + + @Test + public void showTablesFromDb() throws Exception{ + testBuilder() + .sqlQuery("SHOW TABLES FROM hive.`default`") + .unOrdered() + .baselineColumns("TABLE_SCHEMA", "TABLE_NAME") + .baselineValues("hive.default", "partition_pruning_test") + .baselineValues("hive.default", "readtest") + .baselineValues("hive.default", "empty_table") + .baselineValues("hive.default", "infoschematest") + .baselineValues("hive.default", "hiveview") + .baselineValues("hive.default", "kv") + .go(); + + testBuilder() + .sqlQuery("SHOW TABLES IN hive.db1") + .unOrdered() + .baselineColumns("TABLE_SCHEMA", "TABLE_NAME") + .baselineValues("hive.db1", "kv_db1") + .go(); + } + + @Test + public void showDatabases() throws Exception{ + testBuilder() + .sqlQuery("SHOW DATABASES") + .unOrdered() + .baselineColumns("SCHEMA_NAME") + .baselineValues("hive.default") + .baselineValues("hive.db1") + .baselineValues("dfs.default") + .baselineValues("dfs.root") + .baselineValues("dfs.tmp") + .baselineValues("sys") + .baselineValues("dfs_test.home") + .baselineValues("dfs_test.default") + .baselineValues("dfs_test.tmp") + .baselineValues("cp.default") + .baselineValues("INFORMATION_SCHEMA") + .go(); + } + + @Test + public void describeTableNullableColumns() throws Exception{ + testBuilder() + .sqlQuery("DESCRIBE hive.`default`.kv") + .unOrdered() + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("key", "INTEGER", "YES") + .baselineValues("value", "VARCHAR", "YES") + .go(); + } + + @Test + public void varCharMaxLengthAndDecimalPrecisionInInfoSchema() throws Exception{ + final String query = "SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE " + + "FROM INFORMATION_SCHEMA.`COLUMNS` " + + "WHERE TABLE_SCHEMA = 'hive.default' AND TABLE_NAME = 'infoschematest' AND " + + "(COLUMN_NAME = 'stringtype' OR COLUMN_NAME = 'varchartype' OR " + + "COLUMN_NAME = 'inttype' OR COLUMN_NAME = 'decimaltype')"; + + testBuilder() + .sqlQuery(query) + .unOrdered() + .optionSettingQueriesForTestQuery("USE hive") + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "CHARACTER_MAXIMUM_LENGTH", "NUMERIC_PRECISION", "NUMERIC_SCALE") + .baselineValues("inttype", "INTEGER", -1, -1, -1) + .baselineValues("decimaltype", "DECIMAL", -1, 38, 2) + .baselineValues("stringtype", "VARCHAR", 65535, -1, -1) + .baselineValues("varchartype", "VARCHAR", 20, -1, -1) + .go(); + } + + @Test + public void defaultSchemaHive() throws Exception{ + testBuilder() + .sqlQuery("SELECT * FROM kv LIMIT 2") + .unOrdered() + .optionSettingQueriesForTestQuery("USE hive") + .baselineColumns("key", "value") + .baselineValues(1, " key_1") + .baselineValues(2, " key_2") + .go(); + } + + @Test + public void defaultTwoLevelSchemaHive() throws Exception{ + testBuilder() + .sqlQuery("SELECT * FROM kv_db1 LIMIT 2") + .unOrdered() + .optionSettingQueriesForTestQuery("USE hive.db1") + .baselineColumns("key", "value") + .baselineValues(1, " key_1") + .baselineValues(2, " key_2") + .go(); + } +} http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java ---------------------------------------------------------------------- diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java index 657da61..31e4c44 100644 --- a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java +++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java @@ -51,11 +51,6 @@ public class HiveTestDataGenerator { this.pluginRegistry = pluginRegistry; } - // TODO: Remove this once hive related tests in exec/jdbc are moved to contrib/storage-hive/core module - public HiveTestDataGenerator() { - this(null); - } - private void cleanDir(String dir) throws IOException{ File f = new File(dir); if (f.exists()) { @@ -137,17 +132,10 @@ public class HiveTestDataGenerator { executeQuery("CREATE DATABASE IF NOT EXISTS db1"); createTableAndLoadData("db1", "kv_db1", testDataFile); - // Generate data with date and timestamp data type - String testDateDataFile = generateTestDataFileWithDate(); - - // create table with date and timestamp data type executeQuery("USE default"); - executeQuery("CREATE TABLE IF NOT EXISTS default.foodate(a DATE, b TIMESTAMP) "+ - "ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE"); - executeQuery(String.format("LOAD DATA LOCAL INPATH '%s' OVERWRITE INTO TABLE default.foodate", testDateDataFile)); // create a table with no data - executeQuery("CREATE TABLE IF NOT EXISTS default.empty_table(a INT, b STRING)"); + executeQuery("CREATE TABLE IF NOT EXISTS empty_table(a INT, b STRING)"); // delete the table location of empty table File emptyTableLocation = new File(WH_DIR + "/empty_table"); if (emptyTableLocation.exists()) { @@ -263,8 +251,10 @@ public class HiveTestDataGenerator { // create a Hive view to test how its metadata is populated in Drill's INFORMATION_SCHEMA executeQuery("CREATE VIEW IF NOT EXISTS hiveview AS SELECT * FROM kv"); + // Generate data with date and timestamp data type + String testDateDataFile = generateTestDataFileWithDate(); + // create partitioned hive table to test partition pruning - executeQuery("USE default"); executeQuery("CREATE TABLE IF NOT EXISTS default.partition_pruning_test(a DATE, b TIMESTAMP) "+ "partitioned by (c int, d int, e int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE"); executeQuery(String.format("LOAD DATA LOCAL INPATH '%s' INTO TABLE default.partition_pruning_test partition(c=1, d=1, e=1)", testDateDataFile)); http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestInfoSchema.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestInfoSchema.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestInfoSchema.java new file mode 100644 index 0000000..8bcbc7a --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestInfoSchema.java @@ -0,0 +1,320 @@ +/** + * 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.drill.exec.sql; + +import com.google.common.collect.ImmutableList; +import org.apache.drill.BaseTestQuery; +import org.apache.drill.TestBuilder; +import org.junit.Test; + +import java.util.List; + +/** + * Contains tests for + * -- InformationSchema + * -- Queries on InformationSchema such as SHOW TABLES, SHOW SCHEMAS or DESCRIBE table + * -- USE schema + * -- SHOW FILES + */ +public class TestInfoSchema extends BaseTestQuery { + @Test + public void selectFromAllTables() throws Exception{ + test("select * from INFORMATION_SCHEMA.SCHEMATA"); + test("select * from INFORMATION_SCHEMA.CATALOGS"); + test("select * from INFORMATION_SCHEMA.VIEWS"); + test("select * from INFORMATION_SCHEMA.`TABLES`"); + test("select * from INFORMATION_SCHEMA.COLUMNS"); + } + + @Test + public void showTablesFromDb() throws Exception{ + final List<String[]> expected = + ImmutableList.of( + new String[] { "INFORMATION_SCHEMA", "VIEWS" }, + new String[] { "INFORMATION_SCHEMA", "COLUMNS" }, + new String[] { "INFORMATION_SCHEMA", "TABLES" }, + new String[] { "INFORMATION_SCHEMA", "CATALOGS" }, + new String[] { "INFORMATION_SCHEMA", "SCHEMATA" } + ); + + final TestBuilder t1 = testBuilder() + .sqlQuery("SHOW TABLES FROM INFORMATION_SCHEMA") + .unOrdered() + .baselineColumns("TABLE_SCHEMA", "TABLE_NAME"); + for(String[] expectedRow : expected) { + t1.baselineValues(expectedRow); + } + t1.go(); + + final TestBuilder t2 = testBuilder() + .sqlQuery("SHOW TABLES IN INFORMATION_SCHEMA") + .unOrdered() + .baselineColumns("TABLE_SCHEMA", "TABLE_NAME"); + for(String[] expectedRow : expected) { + t2.baselineValues(expectedRow); + } + t2.go(); + } + + @Test + public void showTablesFromDbWhere() throws Exception{ + testBuilder() + .sqlQuery("SHOW TABLES FROM INFORMATION_SCHEMA WHERE TABLE_NAME='VIEWS'") + .unOrdered() + .baselineColumns("TABLE_SCHEMA", "TABLE_NAME") + .baselineValues("INFORMATION_SCHEMA", "VIEWS") + .go(); + } + + @Test + public void showTablesLike() throws Exception{ + testBuilder() + .sqlQuery("SHOW TABLES LIKE '%CH%'") + .unOrdered() + .optionSettingQueriesForTestQuery("USE INFORMATION_SCHEMA") + .baselineColumns("TABLE_SCHEMA", "TABLE_NAME") + .baselineValues("INFORMATION_SCHEMA", "SCHEMATA") + .go(); + } + + @Test + public void showDatabases() throws Exception{ + final List<String[]> expected = + ImmutableList.of( + new String[] { "dfs.default" }, + new String[] { "dfs.root" }, + new String[] { "dfs.tmp" }, + new String[] { "cp.default" }, + new String[] { "sys" }, + new String[] { "dfs_test.home" }, + new String[] { "dfs_test.default" }, + new String[] { "dfs_test.tmp" }, + new String[] { "INFORMATION_SCHEMA" } + ); + + final TestBuilder t1 = testBuilder() + .sqlQuery("SHOW DATABASES") + .unOrdered() + .baselineColumns("SCHEMA_NAME"); + for(String[] expectedRow : expected) { + t1.baselineValues(expectedRow); + } + t1.go(); + + final TestBuilder t2 = testBuilder() + .sqlQuery("SHOW SCHEMAS") + .unOrdered() + .baselineColumns("SCHEMA_NAME"); + for(String[] expectedRow : expected) { + t2.baselineValues(expectedRow); + } + t2.go(); + } + + @Test + public void showDatabasesWhere() throws Exception{ + testBuilder() + .sqlQuery("SHOW DATABASES WHERE SCHEMA_NAME='dfs_test.tmp'") + .unOrdered() + .baselineColumns("SCHEMA_NAME") + .baselineValues("dfs_test.tmp") + .go(); + } + + @Test + public void showDatabasesLike() throws Exception{ + testBuilder() + .sqlQuery("SHOW DATABASES LIKE '%y%'") + .unOrdered() + .baselineColumns("SCHEMA_NAME") + .baselineValues("sys") + .go(); + } + + @Test + public void describeTable() throws Exception{ + testBuilder() + .sqlQuery("DESCRIBE CATALOGS") + .unOrdered() + .optionSettingQueriesForTestQuery("USE INFORMATION_SCHEMA") + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("CATALOG_NAME", "VARCHAR", "NO") + .baselineValues("CATALOG_DESCRIPTION", "VARCHAR", "NO") + .baselineValues("CATALOG_CONNECT", "VARCHAR", "NO") + .go(); + } + + @Test + public void describeTableWithSchema() throws Exception{ + testBuilder() + .sqlQuery("DESCRIBE INFORMATION_SCHEMA.`TABLES`") + .unOrdered() + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("TABLE_CATALOG", "VARCHAR", "NO") + .baselineValues("TABLE_SCHEMA", "VARCHAR", "NO") + .baselineValues("TABLE_NAME", "VARCHAR", "NO") + .baselineValues("TABLE_TYPE", "VARCHAR", "NO") + .go(); + } + + @Test + public void describeWhenSameTableNameExistsInMultipleSchemas() throws Exception{ + try { + test("USE dfs_test.tmp"); + test("CREATE OR REPLACE VIEW `TABLES` AS SELECT full_name FROM cp.`employee.json`"); + + testBuilder() + .sqlQuery("DESCRIBE `TABLES`") + .unOrdered() + .optionSettingQueriesForTestQuery("USE dfs_test.tmp") + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("full_name", "ANY", "YES") + .go(); + + testBuilder() + .sqlQuery("DESCRIBE INFORMATION_SCHEMA.`TABLES`") + .unOrdered() + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("TABLE_CATALOG", "VARCHAR", "NO") + .baselineValues("TABLE_SCHEMA", "VARCHAR", "NO") + .baselineValues("TABLE_NAME", "VARCHAR", "NO") + .baselineValues("TABLE_TYPE", "VARCHAR", "NO") + .go(); + } finally { + test("DROP VIEW dfs_test.tmp.`TABLES`"); + } + } + + @Test + public void describeTableWithColumnName() throws Exception{ + testBuilder() + .sqlQuery("DESCRIBE `TABLES` TABLE_CATALOG") + .unOrdered() + .optionSettingQueriesForTestQuery("USE INFORMATION_SCHEMA") + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("TABLE_CATALOG", "VARCHAR", "NO") + .go(); + } + + @Test + public void describeTableWithSchemaAndColumnName() throws Exception{ + testBuilder() + .sqlQuery("DESCRIBE INFORMATION_SCHEMA.`TABLES` TABLE_CATALOG") + .unOrdered() + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("TABLE_CATALOG", "VARCHAR", "NO") + .go(); + } + + @Test + public void describeTableWithColQualifier() throws Exception{ + testBuilder() + .sqlQuery("DESCRIBE COLUMNS 'TABLE%'") + .unOrdered() + .optionSettingQueriesForTestQuery("USE INFORMATION_SCHEMA") + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("TABLE_CATALOG", "VARCHAR", "NO") + .baselineValues("TABLE_SCHEMA", "VARCHAR", "NO") + .baselineValues("TABLE_NAME", "VARCHAR", "NO") + .go(); + } + + @Test + public void describeTableWithSchemaAndColQualifier() throws Exception{ + testBuilder() + .sqlQuery("DESCRIBE INFORMATION_SCHEMA.SCHEMATA 'SCHEMA%'") + .unOrdered() + .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE") + .baselineValues("SCHEMA_NAME", "VARCHAR", "NO") + .baselineValues("SCHEMA_OWNER", "VARCHAR", "NO") + .go(); + } + + @Test + public void defaultSchemaDfs() throws Exception{ + testBuilder() + .sqlQuery("SELECT R_REGIONKEY FROM `[WORKING_PATH]/../../sample-data/region.parquet` LIMIT 1") + .unOrdered() + .optionSettingQueriesForTestQuery("USE dfs_test") + .baselineColumns("R_REGIONKEY") + .baselineValues(0L) + .go(); + } + + @Test + public void defaultSchemaClasspath() throws Exception{ + testBuilder() + .sqlQuery("SELECT full_name FROM `employee.json` LIMIT 1") + .unOrdered() + .optionSettingQueriesForTestQuery("USE cp") + .baselineColumns("full_name") + .baselineValues("Sheri Nowmer") + .go(); + } + + + @Test + public void queryFromNonDefaultSchema() throws Exception{ + testBuilder() + .sqlQuery("SELECT full_name FROM cp.`employee.json` LIMIT 1") + .unOrdered() + .optionSettingQueriesForTestQuery("USE dfs_test") + .baselineColumns("full_name") + .baselineValues("Sheri Nowmer") + .go(); + } + + @Test + public void useSchema() throws Exception{ + testBuilder() + .sqlQuery("USE dfs_test.`default`") + .unOrdered() + .baselineColumns("ok", "summary") + .baselineValues(true, "Default schema changed to 'dfs_test.default'") + .go(); + } + + @Test + public void useSchemaNegative() throws Exception{ + testBuilder() + .sqlQuery("USE invalid.schema") + .unOrdered() + .baselineColumns("ok", "summary") + .baselineValues(false, "Failed to change default schema to 'invalid.schema'") + .go(); + } + + // Tests using backticks around the complete schema path + // select * from `dfs_test.tmp`.`/tmp/nation.parquet`; + @Test + public void completeSchemaRef1() throws Exception { + test("SELECT * FROM `cp.default`.`employee.json` limit 2"); + } + + @Test + public void showFiles() throws Exception { + test("show files from dfs_test.`/tmp`"); + test("show files from `dfs_test.default`.`/tmp`"); + } + + @Test + public void showFilesWithDefaultSchema() throws Exception{ + test("USE dfs_test.`default`"); + test("SHOW FILES FROM `/tmp`"); + } +} http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/exec/jdbc/pom.xml ---------------------------------------------------------------------- diff --git a/exec/jdbc/pom.xml b/exec/jdbc/pom.xml index 2385d74..acd4882 100644 --- a/exec/jdbc/pom.xml +++ b/exec/jdbc/pom.xml @@ -36,11 +36,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.drill.contrib.storage-hive</groupId> - <artifactId>drill-storage-hive-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> <groupId>org.apache.drill</groupId> <artifactId>drill-common</artifactId> <classifier>tests</classifier> @@ -55,12 +50,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.drill.contrib.storage-hive</groupId> - <artifactId>drill-storage-hive-core</artifactId> - <version>${project.version}</version> - <classifier>tests</classifier> - </dependency> - <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.4.3</version> http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java index 1a7b63d..a5bd35b 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.fail; import static org.junit.Assert.assertThat; import static org.hamcrest.CoreMatchers.*; -import org.apache.drill.exec.store.hive.HiveTestDataGenerator; import org.apache.drill.jdbc.Driver; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -135,7 +134,6 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { private static ResultSet mdrOptINTERVAL_H_S3; private static ResultSet mdrOptINTERVAL_Y4; - ////////// // For columns in schema hive_test.default's infoschematest table: // listtype column: VARCHAR(65535) ARRAY, non-null(?): @@ -176,6 +174,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { ResultSet util; + /* TODO(start): Uncomment this block once we have a test plugin which supports all the needed types. // Create Hive test data, only if not created already (speed optimization): util = stmt.executeQuery( "SELECT * FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE TABLE_SCHEMA = 'hive_test.default' " @@ -201,6 +200,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { : "Expected 17 Hive test columns see " + hiveTestColumnRowCount + "." + " Test code is out of date or Hive data is corrupted."; } + TODO(end) */ // Note: Assertions must be enabled (as they have been so far in tests). @@ -274,10 +274,12 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { mdrOptINTERVAL_H_S3 = setUpRow( "dfs.tmp", VIEW_NAME, "optINTERVAL_H_S3" ); mdrOptINTERVAL_Y4 = setUpRow( "dfs.tmp", VIEW_NAME, "optINTERVAL_Y4" ); + /* TODO(start): Uncomment this block once we have a test plugin which supports all the needed types. mdrReqARRAY = setUpRow( "hive_test.default", "infoschematest", "listtype" ); mdrReqMAP = setUpRow( "hive_test.default", "infoschematest", "maptype" ); testRowSTRUCT = setUpRow( "hive_test.default", "infoschematest", "structtype" ); testRowUnion = setUpRow( "hive_test.default", "infoschematest", "uniontypetype" ); + TODO(end) */ // Set up getColumns(...)) result set' metadata: @@ -384,6 +386,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { // Not bothering with other _local_view_ test columns for TABLE_SCHEM. @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_TABLE_SCHEM_hasRightValue_tdbARRAY() throws SQLException { assertThat( mdrReqARRAY.getString( "TABLE_SCHEM" ), equalTo( "hive_test.default" ) ); } @@ -491,6 +494,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { // Not bothering with other _local_view_ test columns for TABLE_SCHEM. @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_COLUMN_NAME_hasRightValue_tdbARRAY() throws SQLException { assertThat( mdrReqARRAY.getString( "COLUMN_NAME" ), equalTo( "listtype" ) ); } @@ -647,6 +651,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_DATA_TYPE_hasRightValue_tdbARRAY() throws SQLException { assertThat( mdrReqARRAY.getInt( "DATA_TYPE" ), equalTo( Types.ARRAY ) ); } @@ -662,6 +667,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_DATA_TYPE_hasRightValue_tbdSTRUCT() throws SQLException { assertThat( testRowSTRUCT.getInt( "DATA_TYPE" ), equalTo( Types.STRUCT ) ); } @@ -1030,6 +1036,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_COLUMN_SIZE_hasRightValue_tdbARRAY() throws SQLException { final int value = mdrReqARRAY.getInt( "COLUMN_SIZE" ); assertThat( "wasNull() [after " + value + "]", @@ -1038,6 +1045,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_COLUMN_SIZE_hasRightValue_tbdMAP() throws SQLException { final int value = mdrReqMAP.getInt( "COLUMN_SIZE" ); assertThat( "wasNull() [after " + value + "]", @@ -1046,6 +1054,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_COLUMN_SIZE_hasRightValue_tbdSTRUCT() throws SQLException { final int value = testRowSTRUCT.getInt( "COLUMN_SIZE" ); assertThat( "wasNull() [after " + value + "]", @@ -1054,6 +1063,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_COLUMN_SIZE_hasRightValue_tbdUnion() throws SQLException { final int value = testRowUnion.getInt( "COLUMN_SIZE" ); assertThat( "wasNull() [after " + value + "]", @@ -1263,6 +1273,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_DECIMAL_DIGITS_hasRightValue_tdbARRAY() throws SQLException { final int value = mdrReqARRAY.getInt( "DECIMAL_DIGITS" ); assertThat( "wasNull() [after " + value + "]", @@ -1271,6 +1282,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_DECIMAL_DIGITS_hasRightValue_tbdMAP() throws SQLException { final int value = mdrReqMAP.getInt( "DECIMAL_DIGITS" ); assertThat( "wasNull() [after " + value + "]", @@ -1279,6 +1291,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_DECIMAL_DIGITS_hasRightValue_tbdSTRUCT() throws SQLException { final int value = testRowSTRUCT.getInt( "DECIMAL_DIGITS" ); assertThat( "wasNull() [after " + value + "]", @@ -1287,6 +1300,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_DECIMAL_DIGITS_hasRightValue_tbdUnion() throws SQLException { final int value = testRowUnion.getInt( "DECIMAL_DIGITS" ); assertThat( "wasNull() [after " + value + "]", @@ -1479,6 +1493,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_NUM_PREC_RADIX_hasRightValue_tdbARRAY() throws SQLException { final int value = mdrReqARRAY.getInt( "NUM_PREC_RADIX" ); assertThat( "wasNull() [after " + value + "]", @@ -1487,6 +1502,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_NUM_PREC_RADIX_hasRightValue_tbdMAP() throws SQLException { final int value = mdrReqMAP.getInt( "NUM_PREC_RADIX" ); assertThat( "wasNull() [after " + value + "]", @@ -1495,6 +1511,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_NUM_PREC_RADIX_hasRightValue_tbdSTRUCT() throws SQLException { final int value = testRowSTRUCT.getInt( "NUM_PREC_RADIX" ); assertThat( "wasNull() [after " + value + "]", @@ -1503,6 +1520,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_NUM_PREC_RADIX_hasRightValue_tbdUnion() throws SQLException { final int value = testRowUnion.getInt( "NUM_PREC_RADIX" ); assertThat( "wasNull() [after " + value + "]", @@ -1717,12 +1735,14 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { // (See to-do note near top of file about reviewing nullability.) @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_NULLABLE_hasRightValue_tdbARRAY() throws SQLException { assertThat( mdrReqARRAY.getInt( "NULLABLE" ), equalTo( columnNoNulls ) ); } // (See to-do note near top of file about reviewing nullability.) @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_NULLABLE_hasRightValue_tbdMAP() throws SQLException { assertThat( mdrReqMAP.getInt( "NULLABLE" ), equalTo( columnNoNulls ) ); } @@ -2125,6 +2145,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_CHAR_OCTET_LENGTH_hasRightValue_tdbARRAY() throws SQLException { final int value = mdrReqARRAY.getInt( "CHAR_OCTET_LENGTH" ); assertThat( "wasNull() [after " + value + "]", @@ -2133,6 +2154,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_CHAR_OCTET_LENGTH_hasRightValue_tbdMAP() throws SQLException { final int value = mdrReqMAP.getInt( "CHAR_OCTET_LENGTH" ); assertThat( "wasNull() [after " + value + "]", @@ -2141,6 +2163,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_CHAR_OCTET_LENGTH_hasRightValue_tbdSTRUCT() throws SQLException { final int value = testRowSTRUCT.getInt( "CHAR_OCTET_LENGTH" ); assertThat( "wasNull() [after " + value + "]", @@ -2149,6 +2172,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_CHAR_OCTET_LENGTH_hasRightValue_tbdUnion() throws SQLException { final int value = testRowUnion.getInt( "CHAR_OCTET_LENGTH" ); assertThat( "wasNull() [after " + value + "]", @@ -2238,6 +2262,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { } @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_ORDINAL_POSITION_hasRightValue_tdbARRAY() throws SQLException { assertThat( mdrReqARRAY.getInt( "ORDINAL_POSITION" ), equalTo( 14 ) ); } @@ -2409,12 +2434,14 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTest { // (See to-do note near top of file about reviewing nullability.) @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_IS_NULLABLE_hasRightValue_tdbARRAY() throws SQLException { assertThat( mdrReqARRAY.getString( "IS_NULLABLE" ), equalTo( "NO" ) ); } // (See to-do note near top of file about reviewing nullability.) @Test + @Ignore("Enable once we have a test plugin which supports all the needed types.") public void test_IS_NULLABLE_hasRightValue_tbdMAP() throws SQLException { assertThat( mdrReqMAP.getString( "IS_NULLABLE" ), equalTo( "NO" ) ); } http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java deleted file mode 100644 index 2c1738c..0000000 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.drill.jdbc.test; - - -import org.apache.drill.exec.store.hive.HiveTestDataGenerator; -import org.apache.drill.jdbc.JdbcTest; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -public class TestHiveScalarUDFs extends JdbcTest { - - @BeforeClass - public static void generateHive() throws Exception{ - new HiveTestDataGenerator().generateTestData(); - } - - /** Test a hive function that implements the interface {@link org.apache.hadoop.hive.ql.exec.UDF}. */ - @Test - @Ignore("relies on particular timezone") - public void simpleUDF() throws Exception { - JdbcAssert.withNoDefaultSchema() - .sql("SELECT " + - "from_unixtime(1237573801) as unix_timestamp, " + - "UDFDegrees(cast(26.89 as DOUBLE)) as degrees " + - "FROM cp.`employee.json` LIMIT 1") - .returns("unix_timestamp=2009-03-20 11:30:01; degrees=1540.6835111067835"); - } - - /** Test a hive function that implements the interface {@link org.apache.hadoop.hive.ql.udf.generic.GenericUDF}. */ - @Test - public void simpleGenericUDF() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("SELECT CAST(" + - "encode('text', 'UTF-8') " + - "AS VARCHAR(5)) " + - "FROM cp.`employee.json` LIMIT 1") - .returns("EXPR$0=text"); - } -} http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java deleted file mode 100644 index 2c41e12..0000000 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.drill.jdbc.test; - -import org.apache.drill.exec.store.hive.HiveTestDataGenerator; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TestHiveStorage extends JdbcTestQueryBase{ - - @BeforeClass - public static void generateHive() throws Exception{ - new HiveTestDataGenerator().generateTestData(); - } - - @Test - public void testHiveReadWithDb() throws Exception{ - testQuery("select * from hive_test.`default`.kv"); - testQuery("select key from hive_test.`default`.kv group by key"); - } - - @Test - public void testHiveWithDate() throws Exception { - testQuery("select * from hive_test.`default`.foodate"); - testQuery("select date_add(a, time '12:23:33'), b from hive_test.`default`.foodate"); - } - - @Test - public void testQueryEmptyHiveTable() throws Exception { - testQuery("SELECT * FROM hive_test.`default`.empty_table"); - } - - @Test - public void testReadAllSupportedHiveDataTypes() throws Exception { - // There are known issues with displaying VarBinary in JDBC. So for now just execute the query and do not - // verify the results until display issues with VarBinary are resolved. - testQuery("SELECT * FROM hive_test.`default`.readtest"); - - /* - JdbcAssert.withFull("hive_test.`default`") - .sql("SELECT * FROM readtest") - .returns( - "binary_field=[B@7005f08f; " + // know issues with binary display - "boolean_field=false; " + - "tinyint_field=34; " + - "decimal_field=3489423929323435243; " + - "double_field=8.345; " + - "float_field=4.67; " + - "int_field=123456; " + - "bigint_field=234235; " + - "smallint_field=3455; " + - "string_field=stringfield; " + - "varchar_field=varcharfield; " + - "timestamp_field=2013-07-05T17:01:00.000-07:00; " + - "date_field=2013-07-05T00:00:00.000-07:00; " + - "binary_part=[B@7008383e; " + // know issues with binary display - "boolean_part=true; " + - "tinyint_part=64; " + - "decimal_part=3489423929323435243; " + - "double_part=8.345; " + - "float_part=4.67; " + - "int_part=123456; " + - "bigint_part=234235; " + - "smallint_part=3455; " + - "string_part=string; " + - "varchar_part=varchar; " + - "timestamp_part=2013-07-05T17:01:00.000-07:00; " + - "date_part=2013-07-05T00:00:00.000-07:00"); - */ - } - - @Test - public void testOrderByOnHiveTable() throws Exception { - JdbcAssert.withFull("hive_test.`default`") - .sql("SELECT * FROM kv ORDER BY `value` DESC") - .returns( - "key=5; value= key_5\n" + - "key=4; value= key_4\n" + - "key=3; value= key_3\n" + - "key=2; value= key_2\n" + - "key=1; value= key_1\n" - ); - } -} http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java deleted file mode 100644 index 3534f35..0000000 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java +++ /dev/null @@ -1,470 +0,0 @@ -/** - * 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.drill.jdbc.test; - -import static org.junit.Assert.assertTrue; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Set; - -import org.apache.drill.exec.store.hive.HiveTestDataGenerator; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; - -/** - * Contains tests for - * -- InformationSchema - * -- queries on InformationSchema such as SHOW TABLES, SHOW SCHEMAS or DESCRIBE table - * -- USE schema - * -- SHOW FILES - */ -public class TestMetadataDDL extends JdbcTestQueryBase { - - // TODO: Purge nextUntilEnd(...) and calls when remaining fragment race - // conditions are fixed (not just DRILL-2245 fixes). - ///** - // * Calls {@link ResultSet#next} on given {@code ResultSet} until it returns - // * false. (For TEMPORARY workaround for query cancelation race condition.) - // */ - //private void nextUntilEnd(final ResultSet resultSet) throws SQLException { - // while (resultSet.next()) { - // } - //} - - @BeforeClass - public static void generateHive() throws Exception{ - new HiveTestDataGenerator().generateTestData(); - } - - @Test - public void testInfoSchema() throws Exception{ - testQuery("select * from INFORMATION_SCHEMA.SCHEMATA"); - testQuery("select * from INFORMATION_SCHEMA.CATALOGS"); - testQuery("select * from INFORMATION_SCHEMA.VIEWS"); - testQuery("select * from INFORMATION_SCHEMA.`TABLES`"); - testQuery("select * from INFORMATION_SCHEMA.COLUMNS"); - } - - @Test - public void testSchemata() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("SELECT * FROM INFORMATION_SCHEMA.SCHEMATA") - .returnsSet(ImmutableSet.of( - "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs.default; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs.root; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs.tmp; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=YES", - "CATALOG_NAME=DRILL; SCHEMA_NAME=sys; SCHEMA_OWNER=<owner>; TYPE=system-tables; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs_test.home; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs_test.default; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs_test.tmp; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=YES", - "CATALOG_NAME=DRILL; SCHEMA_NAME=cp.default; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=hive_test.default; SCHEMA_OWNER=<owner>; TYPE=hive; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=hive_test.db1; SCHEMA_OWNER=<owner>; TYPE=hive; IS_MUTABLE=NO", - "CATALOG_NAME=DRILL; SCHEMA_NAME=INFORMATION_SCHEMA; SCHEMA_OWNER=<owner>; TYPE=ischema; IS_MUTABLE=NO") - ); - } - - @Test - public void testShowTables() throws Exception{ - JdbcAssert.withFull("hive_test.`default`") - .sql("SHOW TABLES") - .returnsSet(ImmutableSet.of( - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=readtest", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=empty_table", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=infoschematest", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=hiveview", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=kv", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=foodate", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=partition_pruning_test" - ) - ); - } - - @Test - public void testShowTablesFromDb() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("SHOW TABLES FROM INFORMATION_SCHEMA") - .returnsSet(ImmutableSet.of( - "TABLE_SCHEMA=INFORMATION_SCHEMA; TABLE_NAME=VIEWS", - "TABLE_SCHEMA=INFORMATION_SCHEMA; TABLE_NAME=COLUMNS", - "TABLE_SCHEMA=INFORMATION_SCHEMA; TABLE_NAME=TABLES", - "TABLE_SCHEMA=INFORMATION_SCHEMA; TABLE_NAME=CATALOGS", - "TABLE_SCHEMA=INFORMATION_SCHEMA; TABLE_NAME=SCHEMATA")); - - JdbcAssert.withFull("dfs_test.tmp") - .sql("SHOW TABLES IN hive_test.`default`") - .returnsSet(ImmutableSet.of( - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=readtest", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=empty_table", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=infoschematest", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=hiveview", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=kv", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=foodate", - "TABLE_SCHEMA=hive_test.default; TABLE_NAME=partition_pruning_test")); - } - - @Test - public void testShowTablesFromDbWhere() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("SHOW TABLES FROM INFORMATION_SCHEMA WHERE TABLE_NAME='VIEWS'") - .returns("TABLE_SCHEMA=INFORMATION_SCHEMA; TABLE_NAME=VIEWS\n"); - } - - @Test - public void testShowTablesLike() throws Exception{ - JdbcAssert.withFull("INFORMATION_SCHEMA") - .sql("SHOW TABLES LIKE '%CH%'") - .returns("TABLE_SCHEMA=INFORMATION_SCHEMA; TABLE_NAME=SCHEMATA\n"); - } - - @Test - public void testShowDatabases() throws Exception{ - Set<String> expected = ImmutableSet.of( - "SCHEMA_NAME=dfs.default", - "SCHEMA_NAME=dfs.root", - "SCHEMA_NAME=dfs.tmp", - "SCHEMA_NAME=sys", - "SCHEMA_NAME=dfs_test.home", - "SCHEMA_NAME=dfs_test.default", - "SCHEMA_NAME=dfs_test.tmp", - "SCHEMA_NAME=cp.default", - "SCHEMA_NAME=hive_test.default", - "SCHEMA_NAME=hive_test.db1", - "SCHEMA_NAME=INFORMATION_SCHEMA"); - - JdbcAssert.withNoDefaultSchema().sql("SHOW DATABASES").returnsSet(expected); - JdbcAssert.withNoDefaultSchema().sql("SHOW SCHEMAS").returnsSet(expected); - } - - @Test - public void testShowDatabasesWhere() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("SHOW DATABASES WHERE SCHEMA_NAME='dfs_test.tmp'") - .returns("SCHEMA_NAME=dfs_test.tmp\n"); - } - - @Test - public void testShowDatabasesLike() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("SHOW DATABASES LIKE '%i%'") - .returnsSet(ImmutableSet.of( - "SCHEMA_NAME=hive_test.default", - "SCHEMA_NAME=hive_test.db1")); - } - - @Test - public void testDescribeTable() throws Exception{ - JdbcAssert.withFull("INFORMATION_SCHEMA") - .sql("DESCRIBE CATALOGS") - .returnsSet(ImmutableSet.of( - "COLUMN_NAME=CATALOG_NAME; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=CATALOG_DESCRIPTION; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=CATALOG_CONNECT; DATA_TYPE=VARCHAR; IS_NULLABLE=NO")); - } - - - @Test - public void testDescribeTableNullableColumns() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("DESCRIBE hive_test.`default`.kv") - .returnsSet(ImmutableSet.of( - "COLUMN_NAME=key; DATA_TYPE=INTEGER; IS_NULLABLE=YES", - "COLUMN_NAME=value; DATA_TYPE=VARCHAR; IS_NULLABLE=YES")); - } - - @Test - public void testDescribeTableWithSchema() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("DESCRIBE INFORMATION_SCHEMA.`TABLES`") - .returnsSet(ImmutableSet.of( - "COLUMN_NAME=TABLE_CATALOG; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_SCHEMA; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_NAME; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_TYPE; DATA_TYPE=VARCHAR; IS_NULLABLE=NO")); - } - - @Test - public void testDescribeSameTableInMultipleSchemas() throws Exception{ - JdbcAssert.withNoDefaultSchema().withConnection(new Function<Connection, Void>() { - public Void apply(Connection connection) { - try { - ResultSet resultSet; - Statement statement = connection.createStatement(); - resultSet = statement.executeQuery("USE dfs_test.tmp"); - // TODO: Purge nextUntilEnd(...) and calls when remaining fragment - // race conditions are fixed (not just DRILL-2245 fixes). - // nextUntilEnd(resultSet); - resultSet.close(); - - // INFORMATION_SCHEMA already has a table named "TABLES". Now create a table with same name in "dfs_test.tmp" schema - resultSet = statement.executeQuery("CREATE OR REPLACE VIEW `TABLES` AS SELECT key FROM hive_test.kv"); - // TODO: Purge nextUntilEnd(...) and calls when remaining fragment - // race conditions are fixed (not just DRILL-2245 fixes). - // nextUntilEnd(resultSet); - resultSet.close(); - - // Test describe of `TABLES` with no schema qualifier - resultSet = statement.executeQuery("DESCRIBE `TABLES`"); - Set<String> result = JdbcAssert.toStringSet(resultSet); - resultSet.close(); - ImmutableSet<String> expected = ImmutableSet.of("COLUMN_NAME=key; DATA_TYPE=INTEGER; IS_NULLABLE=YES"); - assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), expected.equals(result)); - - // Test describe of `TABLES` with a schema qualifier which is not in default schema - resultSet = statement.executeQuery("DESCRIBE INFORMATION_SCHEMA.`TABLES`"); - result = JdbcAssert.toStringSet(resultSet); - resultSet.close(); - expected = ImmutableSet.of( - "COLUMN_NAME=TABLE_CATALOG; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_SCHEMA; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_NAME; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_TYPE; DATA_TYPE=VARCHAR; IS_NULLABLE=NO"); - assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), expected.equals(result)); - - // drop created view - resultSet = statement.executeQuery("DROP VIEW `TABLES`"); - // TODO: Purge nextUntilEnd(...) and calls when remaining fragment - // race conditions are fixed (not just DRILL-2245 fixes). - // nextUntilEnd(resultSet); - resultSet.close(); - - statement.close(); - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - } - - @Test - public void testDescribeTableWithColumnName() throws Exception{ - JdbcAssert.withFull("INFORMATION_SCHEMA") - .sql("DESCRIBE `TABLES` TABLE_CATALOG") - .returns("COLUMN_NAME=TABLE_CATALOG; DATA_TYPE=VARCHAR; IS_NULLABLE=NO\n"); - } - - @Test - public void testDescribeTableWithSchemaAndColumnName() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("DESCRIBE INFORMATION_SCHEMA.`TABLES` TABLE_CATALOG") - .returns("COLUMN_NAME=TABLE_CATALOG; DATA_TYPE=VARCHAR; IS_NULLABLE=NO\n"); - } - - @Test - public void testDescribeTableWithColQualifier() throws Exception{ - JdbcAssert.withFull("INFORMATION_SCHEMA") - .sql("DESCRIBE COLUMNS 'TABLE%'") - .returnsSet(ImmutableSet.of( - "COLUMN_NAME=TABLE_CATALOG; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_SCHEMA; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=TABLE_NAME; DATA_TYPE=VARCHAR; IS_NULLABLE=NO")); - } - - @Test - public void testDescribeTableWithSchemaAndColQualifier() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("DESCRIBE INFORMATION_SCHEMA.SCHEMATA 'SCHEMA%'") - .returnsSet(ImmutableSet.of( - "COLUMN_NAME=SCHEMA_NAME; DATA_TYPE=VARCHAR; IS_NULLABLE=NO", - "COLUMN_NAME=SCHEMA_OWNER; DATA_TYPE=VARCHAR; IS_NULLABLE=NO")); - } - - @Test - public void testVarCharMaxLengthAndDecimalPrecisionInInfoSchema() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE " + - "FROM INFORMATION_SCHEMA.`COLUMNS` " + - "WHERE TABLE_SCHEMA = 'hive_test.default' AND TABLE_NAME = 'infoschematest' AND " + - "(COLUMN_NAME = 'stringtype' OR COLUMN_NAME = 'varchartype' OR " + - "COLUMN_NAME = 'inttype' OR COLUMN_NAME = 'decimaltype')") - .returnsSet(ImmutableSet.of( - "COLUMN_NAME=inttype; DATA_TYPE=INTEGER; CHARACTER_MAXIMUM_LENGTH=-1; " + - "NUMERIC_PRECISION=-1; NUMERIC_SCALE=-1", - "COLUMN_NAME=decimaltype; DATA_TYPE=DECIMAL; CHARACTER_MAXIMUM_LENGTH=-1; " + - "NUMERIC_PRECISION=38; NUMERIC_SCALE=2", - "COLUMN_NAME=stringtype; DATA_TYPE=VARCHAR; CHARACTER_MAXIMUM_LENGTH=65535; " + - "NUMERIC_PRECISION=-1; NUMERIC_SCALE=-1", - "COLUMN_NAME=varchartype; DATA_TYPE=VARCHAR; CHARACTER_MAXIMUM_LENGTH=20; " + - "NUMERIC_PRECISION=-1; NUMERIC_SCALE=-1")); - } - - @Test - public void testDefaultSchemaDfs() throws Exception{ - JdbcAssert.withFull("dfs_test") - .sql(String.format("SELECT R_REGIONKEY FROM `%s/../../sample-data/region.parquet` LIMIT 2", WORKING_PATH)) - .returns( - "R_REGIONKEY=0\n" + - "R_REGIONKEY=1\n"); - } - - @Test - public void testDefaultSchemaClasspath() throws Exception{ - JdbcAssert.withFull("cp") - .sql("SELECT full_name FROM `employee.json` LIMIT 2") - .returns( - "full_name=Sheri Nowmer\n" + - "full_name=Derrick Whelply\n"); - } - - @Test - public void testDefaultSchemaHive() throws Exception{ - JdbcAssert.withFull("hive_test") - .sql("SELECT * FROM kv LIMIT 2") - .returns( - "key=1; value= key_1\n" + - "key=2; value= key_2\n"); - } - - @Test - public void testDefaultTwoLevelSchemaHive() throws Exception{ - JdbcAssert.withFull("hive_test.db1") - .sql("SELECT * FROM `kv_db1` LIMIT 2") - .returns( - "key=1; value= key_1\n" + - "key=2; value= key_2\n"); - } - - @Test - public void testQueryFromNonDefaultSchema() throws Exception{ - JdbcAssert.withFull("hive_test") - .sql("SELECT full_name FROM cp.`employee.json` LIMIT 2") - .returns( - "full_name=Sheri Nowmer\n" + - "full_name=Derrick Whelply\n"); - } - - @Test - public void testUseSchema() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("USE hive_test.`default`") - .returns("ok=true; summary=Default schema changed to 'hive_test.default'"); - } - - @Test - public void testUseSchemaNegative() throws Exception{ - JdbcAssert.withNoDefaultSchema() - .sql("USE invalid.schema") - .returns("ok=false; summary=Failed to change default schema to 'invalid.schema'"); - } - - @Test - public void testUseSchemaAndQuery() throws Exception{ - JdbcAssert.withNoDefaultSchema().withConnection(new Function<Connection, Void>() { - public Void apply(Connection connection) { - try { - Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery("USE hive_test.db1"); - String result = JdbcAssert.toString(resultSet).trim(); - resultSet.close(); - String expected = "ok=true; summary=Default schema changed to 'hive_test.db1'"; - assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), expected.equals(result)); - - - resultSet = statement.executeQuery("SELECT * FROM kv_db1 LIMIT 2"); - result = JdbcAssert.toString(resultSet).trim(); - resultSet.close(); - expected = "key=1; value= key_1\nkey=2; value= key_2"; - assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), expected.equals(result)); - statement.close(); - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - } - - // Tests using backticks around the complete schema path - // select * from `dfs_test.tmp`.`/tmp/nation.parquet`; - @Test - public void testCompleteSchemaRef1() throws Exception { - testQuery("select * from `cp.default`.`employee.json` limit 2"); - } - - @Test - public void testCompleteSchemaRef2() throws Exception { - JdbcAssert.withNoDefaultSchema().withConnection(new Function<Connection, Void>() { - public Void apply(Connection connection) { - try { - Statement statement = connection.createStatement(); - - // change default schema - ResultSet resultSet = statement.executeQuery("USE `dfs_test.default`"); - String result = JdbcAssert.toString(resultSet).trim(); - resultSet.close(); - String expected = "ok=true; summary=Default schema changed to 'dfs_test.default'"; - assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), expected.equals(result)); - - resultSet = statement.executeQuery( - String.format("select R_REGIONKEY from `%s/../../sample-data/region.parquet` LIMIT 1", WORKING_PATH)); - result = JdbcAssert.toString(resultSet).trim(); - resultSet.close(); - expected = "R_REGIONKEY=0"; - assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), - expected.equals(result)); - - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - } - - @Test - public void testShowFiles() throws Exception { - testQuery("show files from dfs_test.`/tmp`"); - testQuery("show files from `dfs_test.default`.`/tmp`"); - - } - - @Test - public void testShowFilesWithDefaultSchema() throws Exception{ - JdbcAssert.withNoDefaultSchema().withConnection(new Function<Connection, Void>() { - public Void apply(Connection connection) { - try { - ResultSet resultSet; - Statement statement = connection.createStatement(); - - // change default schema - resultSet = statement.executeQuery("USE dfs_test.`default`"); - // TODO: Purge nextUntilEnd(...) and calls when remaining fragment - // race conditions are fixed (not just DRILL-2245 fixes). - // nextUntilEnd(resultSet); - - // show files - resultSet = statement.executeQuery("show files from `/tmp`"); - - System.out.println(JdbcAssert.toString(resultSet)); - resultSet.close(); - statement.close(); - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - } -} http://git-wip-us.apache.org/repos/asf/drill/blob/375f8415/exec/jdbc/src/test/resources/bootstrap-storage-plugins.json ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/resources/bootstrap-storage-plugins.json b/exec/jdbc/src/test/resources/bootstrap-storage-plugins.json deleted file mode 100644 index 548ec3d..0000000 --- a/exec/jdbc/src/test/resources/bootstrap-storage-plugins.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "storage":{ - hive_test : { - type:"hive", - config : - { - "hive.metastore.uris" : "", - "javax.jdo.option.ConnectionURL" : "jdbc:derby:;databaseName=/tmp/drill_hive_db;create=true", - "hive.metastore.warehouse.dir" : "/tmp/drill_hive_wh", - "fs.default.name" : "file:///", - "hive.metastore.sasl.enabled" : "false" - } - } - } -}