Search in sources :

Example 1 with ALLOW_INSECURE

use of com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE in project presto by prestodb.

the class TestHivePushdownFilterQueries method assertFileFormat.

private void assertFileFormat(HiveStorageFormat storageFormat) throws IOException {
    // Make an ORC table backed by file of some other format
    QueryRunner queryRunner = getQueryRunner();
    queryRunner.execute("CREATE TABLE test_file_format_orc WITH (format='ORC', partitioned_by=ARRAY['ds']) AS " + "SELECT * FROM lineitem_ex_partitioned LIMIT 1");
    try {
        queryRunner.execute(format("CREATE TABLE test_file_format WITH (format='%s', partitioned_by=ARRAY['ds']) AS " + "SELECT * FROM lineitem_ex_partitioned", storageFormat));
        Path orcDirectory = getPartitionDirectory("test_file_format_orc", "ds='2019-11-01'");
        deleteRecursively(orcDirectory, ALLOW_INSECURE);
        Path otherDirectory = getPartitionDirectory("test_file_format", "ds='2019-11-01'");
        Files.move(otherDirectory, orcDirectory, REPLACE_EXISTING);
        String cte = WITH_LINEITEM_EX + ", test_file_format_orc AS " + "(SELECT\n" + "    linenumber,\n" + "    orderkey,\n" + "    partkey,\n" + "    suppkey,\n" + "    quantity,\n" + "    extendedprice,\n" + "    tax,\n" + "    shipinstruct,\n" + "    shipmode,\n" + "    ship_by_air,\n" + "    is_returned,\n" + "    ship_day,\n" + "    ship_month,\n" + "    ship_timestamp,\n" + "    commit_timestamp,\n" + "    discount_real,\n" + "    discount,\n" + "    tax_real,\n" + "    ship_day_month,\n" + "    discount_long_decimal,\n" + "    tax_short_decimal,\n" + "    long_decimals,\n" + "    keys,\n" + "    doubles,\n" + "    nested_keys,\n" + "    flags,\n" + "    reals,\n" + "    info,\n" + "    dates,\n" + "    timestamps,\n" + "    comment,\n" + "    uppercase_comment,\n" + "    fixed_comment,\n" + "    char_array,\n" + "    varchar_array,\n" + "    '2019-11-01' AS ds\n" + "FROM lineitem_ex)";
        // no filter
        assertQueryUsingH2Cte("SELECT * FROM test_file_format_orc", cte);
        assertQueryUsingH2Cte("SELECT comment FROM test_file_format_orc", cte);
        assertQueryFails("SELECT COUNT(*) FROM test_file_format_orc", "Partial aggregation pushdown only supported for ORC/Parquet files. Table tpch.test_file_format_orc has file ((.*?)) of format (.*?). Set session property hive.pushdown_partial_aggregations_into_scan=false and execute query again");
        assertQueryUsingH2Cte(noPartialAggregationPushdown(queryRunner.getDefaultSession()), "SELECT COUNT(*) FROM test_file_format_orc", cte, Function.identity());
        // filter on partition column
        assertQueryUsingH2Cte("SELECT comment from test_file_format_orc WHERE ds='2019-11-01'", cte);
        assertQueryReturnsEmptyResult("SELECT comment FROM test_file_format_orc WHERE ds='2019-11-02'");
        // range filters and filter functions
        assertQueryUsingH2Cte("SELECT orderkey from test_file_format_orc WHERE orderkey < 1000", cte);
        assertQueryUsingH2Cte("SELECT orderkey, comment from test_file_format_orc WHERE orderkey < 1000 AND comment LIKE '%final%'", cte);
        assertQueryUsingH2Cte("SELECT COUNT(*) from test_file_format_orc WHERE orderkey < 1000", cte);
        assertQueryUsingH2Cte("SELECT COUNT(*) FROM test_file_format_orc WHERE concat(ds,'*') = '2019-11-01*'", cte);
        assertQueryUsingH2Cte("SELECT orderkey FROM test_file_format_orc WHERE comment LIKE '%final%'", cte);
        assertQueryUsingH2Cte("SELECT discount FROM test_file_format_orc WHERE discount > 0.01", cte);
        assertQueryUsingH2Cte("SELECT * FROM test_file_format_orc WHERE discount > 0.01 and discount + tax > 0.03", cte);
        assertQueryUsingH2Cte("SELECT COUNT(*) FROM test_file_format_orc WHERE discount = 0.0", cte);
        assertQueryUsingH2Cte("SELECT COUNT(*) FROM test_file_format_orc WHERE discount_real > 0.01", cte);
        assertQueryUsingH2Cte("SELECT * FROM test_file_format_orc WHERE tax_real > 0.01 and discount_real > 0.01", cte);
        assertQueryUsingH2Cte("SELECT keys FROM test_file_format_orc WHERE keys IS NOT NULL", cte);
        assertQueryUsingH2Cte("SELECT keys FROM test_file_format_orc WHERE keys IS NULL", cte);
        assertQueryUsingH2Cte("SELECT linenumber FROM test_file_format_orc WHERE keys[1] % 5 = 0 AND keys[2] > 100", cte);
        assertQueryUsingH2Cte("SELECT * FROM test_file_format_orc WHERE is_returned=false", cte);
        assertQueryUsingH2Cte("SELECT * FROM test_file_format_orc WHERE is_returned is NULL", cte);
        assertQueryUsingH2Cte("SELECT ship_day FROM test_file_format_orc WHERE ship_day > 2", cte);
        assertQueryUsingH2Cte("SELECT discount_long_decimal FROM test_file_format_orc WHERE discount_long_decimal > 0.05", cte);
        assertQueryUsingH2Cte("SELECT tax_short_decimal FROM test_file_format_orc WHERE tax_short_decimal < 0.03", cte);
        assertQueryUsingH2Cte("SELECT discount_long_decimal FROM test_file_format_orc WHERE discount_long_decimal > 0.01 AND tax_short_decimal > 0.01 AND (discount_long_decimal + tax_short_decimal) < 0.03", cte);
        Function<String, String> rewriter = query -> query.replaceAll("info.orderkey", "info[1]").replaceAll("dates\\[1\\].day", "dates[1][1]");
        assertQueryUsingH2Cte("SELECT dates FROM test_file_format_orc WHERE dates[1].day % 2 = 0", cte, rewriter);
        assertQueryUsingH2Cte("SELECT info.orderkey, dates FROM test_file_format_orc WHERE info IS NOT NULL AND dates IS NOT NULL AND info.orderkey % 7 = 0", cte, rewriter);
        // empty result
        assertQueryReturnsEmptyResult("SELECT comment FROM test_file_format_orc WHERE orderkey < 0");
        assertQueryReturnsEmptyResult("SELECT comment FROM test_file_format_orc WHERE comment LIKE '???'");
    } finally {
        assertUpdate("DROP TABLE IF EXISTS test_file_format");
        assertUpdate("DROP TABLE test_file_format_orc");
    }
}
Also used : Path(java.nio.file.Path) MoreFiles.deleteRecursively(com.google.common.io.MoreFiles.deleteRecursively) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) TINYINT(com.facebook.presto.common.type.StandardTypes.TINYINT) Function(java.util.function.Function) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Matcher(java.util.regex.Matcher) ALLOW_INSECURE(com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE) ImmutableList(com.google.common.collect.ImmutableList) RCTEXT(com.facebook.presto.hive.HiveStorageFormat.RCTEXT) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) BIGINT(com.facebook.presto.common.type.StandardTypes.BIGINT) TEXTFILE(com.facebook.presto.hive.HiveStorageFormat.TEXTFILE) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) BOOLEAN(com.facebook.presto.common.type.StandardTypes.BOOLEAN) AbstractTestQueryFramework(com.facebook.presto.tests.AbstractTestQueryFramework) ATOMIC_MOVE(java.nio.file.StandardCopyOption.ATOMIC_MOVE) HIVE_CATALOG(com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) Session(com.facebook.presto.Session) DATE(com.facebook.presto.common.type.StandardTypes.DATE) IOException(java.io.IOException) INTEGER(com.facebook.presto.common.type.StandardTypes.INTEGER) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) DOUBLE(com.facebook.presto.common.type.StandardTypes.DOUBLE) VARCHAR(com.facebook.presto.common.type.StandardTypes.VARCHAR) TpchTable.getTables(io.airlift.tpch.TpchTable.getTables) RCBINARY(com.facebook.presto.hive.HiveStorageFormat.RCBINARY) List(java.util.List) Paths(java.nio.file.Paths) PUSHDOWN_FILTER_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PUSHDOWN_FILTER_ENABLED) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) SMALLINT(com.facebook.presto.common.type.StandardTypes.SMALLINT) REAL(com.facebook.presto.common.type.StandardTypes.REAL) PARTIAL_AGGREGATION_PUSHDOWN_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PARTIAL_AGGREGATION_PUSHDOWN_ENABLED) QueryRunner(com.facebook.presto.testing.QueryRunner) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner)

Aggregations

Session (com.facebook.presto.Session)1 BIGINT (com.facebook.presto.common.type.StandardTypes.BIGINT)1 BOOLEAN (com.facebook.presto.common.type.StandardTypes.BOOLEAN)1 DATE (com.facebook.presto.common.type.StandardTypes.DATE)1 DOUBLE (com.facebook.presto.common.type.StandardTypes.DOUBLE)1 INTEGER (com.facebook.presto.common.type.StandardTypes.INTEGER)1 REAL (com.facebook.presto.common.type.StandardTypes.REAL)1 SMALLINT (com.facebook.presto.common.type.StandardTypes.SMALLINT)1 TINYINT (com.facebook.presto.common.type.StandardTypes.TINYINT)1 VARCHAR (com.facebook.presto.common.type.StandardTypes.VARCHAR)1 HIVE_CATALOG (com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG)1 PARTIAL_AGGREGATION_PUSHDOWN_ENABLED (com.facebook.presto.hive.HiveSessionProperties.PARTIAL_AGGREGATION_PUSHDOWN_ENABLED)1 PUSHDOWN_FILTER_ENABLED (com.facebook.presto.hive.HiveSessionProperties.PUSHDOWN_FILTER_ENABLED)1 RCBINARY (com.facebook.presto.hive.HiveStorageFormat.RCBINARY)1 RCTEXT (com.facebook.presto.hive.HiveStorageFormat.RCTEXT)1 TEXTFILE (com.facebook.presto.hive.HiveStorageFormat.TEXTFILE)1 QueryRunner (com.facebook.presto.testing.QueryRunner)1 AbstractTestQueryFramework (com.facebook.presto.tests.AbstractTestQueryFramework)1 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)1 Splitter (com.google.common.base.Splitter)1