Search in sources :

Example 51 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method testInsertPartitionedTableShuffleOnPartitionColumns.

public void testInsertPartitionedTableShuffleOnPartitionColumns(Session session, HiveStorageFormat storageFormat) {
    String tableName = "test_insert_partitioned_table_shuffle_on_partition_columns";
    @Language("SQL") String createTable = "" + "CREATE TABLE " + tableName + " " + "(" + "  order_key BIGINT," + "  comment VARCHAR," + "  order_status VARCHAR" + ") " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ 'order_status' ]" + ") ";
    assertUpdate(session, createTable);
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, tableName);
    assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
    assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("order_status"));
    assertUpdate(session, "INSERT INTO " + tableName + " " + "SELECT orderkey, comment, orderstatus " + "FROM tpch.tiny.orders", "SELECT count(*) from orders");
    // verify the partitions
    List<?> partitions = getPartitions(tableName);
    assertEquals(partitions.size(), 3);
    assertQuery(session, "SELECT * from " + tableName, "SELECT orderkey, comment, orderstatus FROM orders");
    assertQuery(session, "SELECT count(distinct \"$path\") from " + tableName, "SELECT 3");
    assertUpdate(session, "DROP TABLE " + tableName);
    assertFalse(getQueryRunner().tableExists(session, tableName));
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) Language(org.intellij.lang.annotations.Language)

Example 52 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method testFileSizeHiddenColumn.

@Test
public void testFileSizeHiddenColumn() {
    @Language("SQL") String createTable = "CREATE TABLE test_file_size " + "AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
    assertUpdate(createTable, 8);
    assertTrue(getQueryRunner().tableExists(getSession(), "test_file_size"));
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_file_size");
    List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, FILE_SIZE_COLUMN_NAME, FILE_MODIFIED_TIME_COLUMN_NAME);
    List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
    assertEquals(columnMetadatas.size(), columnNames.size());
    for (int i = 0; i < columnMetadatas.size(); i++) {
        ColumnMetadata columnMetadata = columnMetadatas.get(i);
        assertEquals(columnMetadata.getName(), columnNames.get(i));
        if (columnMetadata.getName().equals(FILE_SIZE_COLUMN_NAME)) {
            assertTrue(columnMetadata.isHidden());
        }
    }
    MaterializedResult results = computeActual(format("SELECT *, \"%s\" FROM test_file_size", FILE_SIZE_COLUMN_NAME));
    Map<Integer, Long> fileSizeMap = new HashMap<>();
    for (int i = 0; i < results.getRowCount(); i++) {
        MaterializedRow row = results.getMaterializedRows().get(i);
        int col0 = (int) row.getField(0);
        int col1 = (int) row.getField(1);
        long fileSize = (Long) row.getField(2);
        assertTrue(fileSize > 0);
        assertEquals(col0 % 3, col1);
        if (fileSizeMap.containsKey(col1)) {
            assertEquals(fileSizeMap.get(col1).longValue(), fileSize);
        } else {
            fileSizeMap.put(col1, fileSize);
        }
    }
    assertEquals(fileSizeMap.size(), 3);
    assertUpdate("DROP TABLE test_file_size");
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) HashMap(java.util.HashMap) Constraint(com.facebook.presto.spi.Constraint) ColumnConstraint(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint) Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 53 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method testMismatchedBucketWithBucketPredicate.

@Test
public void testMismatchedBucketWithBucketPredicate() {
    try {
        assertUpdate("CREATE TABLE test_mismatch_bucketing_with_predicate_8\n" + "WITH (bucket_count = 8, bucketed_by = ARRAY['key8']) AS\n" + "SELECT custkey key8, comment value8 FROM orders", 15000);
        assertUpdate("CREATE TABLE test_mismatch_bucketing_with_predicate_32\n" + "WITH (bucket_count = 32, bucketed_by = ARRAY['key32']) AS\n" + "SELECT custkey key32, comment value32 FROM orders", 15000);
        Session withMismatchOptimization = Session.builder(getSession()).setSystemProperty(COLOCATED_JOIN, "true").setCatalogSessionProperty(catalog, "optimize_mismatched_bucket_count", "true").build();
        Session withoutMismatchOptimization = Session.builder(getSession()).setSystemProperty(COLOCATED_JOIN, "true").setCatalogSessionProperty(catalog, "optimize_mismatched_bucket_count", "false").build();
        @Language("SQL") String query = "SELECT count(*) AS count\n" + "FROM (\n" + "  SELECT key32\n" + "  FROM test_mismatch_bucketing_with_predicate_32\n" + "  WHERE \"$bucket\" between 16 AND 31\n" + ") a\n" + "JOIN test_mismatch_bucketing_with_predicate_8 b\n" + "ON a.key32 = b.key8";
        assertQuery(withMismatchOptimization, query, "SELECT 130361");
        assertQuery(withoutMismatchOptimization, query, "SELECT 130361");
    } finally {
        assertUpdate("DROP TABLE IF EXISTS test_mismatch_bucketing_with_predicate_8");
        assertUpdate("DROP TABLE IF EXISTS test_mismatch_bucketing_with_predicate_32");
    }
}
Also used : Language(org.intellij.lang.annotations.Language) ConnectorSession(com.facebook.presto.spi.ConnectorSession) HiveQueryRunner.createBucketedSession(com.facebook.presto.hive.HiveQueryRunner.createBucketedSession) Session(com.facebook.presto.Session) HiveQueryRunner.createMaterializeExchangesSession(com.facebook.presto.hive.HiveQueryRunner.createMaterializeExchangesSession) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 54 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class AbstractTestHiveFunctions method assertQuery.

public void assertQuery(@Language("SQL") String sql, Column... cols) {
    checkArgument(cols != null && cols.length > 0);
    int numColumns = cols.length;
    int numRows = cols[0].values.length;
    checkArgument(Stream.of(cols).allMatch(c -> c != null && c.values.length == numRows));
    MaterializedResult result = client.execute(sql).getResult();
    assertEquals(result.getRowCount(), numRows);
    for (int i = 0; i < numColumns; i++) {
        assertEquals(result.getTypes().get(i), cols[i].type);
    }
    List<MaterializedRow> rows = result.getMaterializedRows();
    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < numColumns; j++) {
            Object actual = rows.get(i).getField(j);
            Object expected = cols[j].values[i];
            if (cols[j].type == DOUBLE) {
                assertEquals(((Number) actual).doubleValue(), ((double) expected), 0.000001);
            } else {
                assertEquals(actual, expected);
            }
        }
    }
}
Also used : Logger(com.facebook.airlift.log.Logger) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) Key(com.google.inject.Key) Assert.assertEquals(org.testng.Assert.assertEquals) HiveFunctionsTestUtils.createTestingPrestoServer(com.facebook.presto.hive.functions.HiveFunctionsTestUtils.createTestingPrestoServer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Files(com.google.common.io.Files) TypeManager(com.facebook.presto.common.type.TypeManager) Splitter(com.google.common.base.Splitter) Type(com.facebook.presto.common.type.Type) Language(org.intellij.lang.annotations.Language) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BeforeClass(org.testng.annotations.BeforeClass) Assert.fail(org.testng.Assert.fail) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) File(java.io.File) String.format(java.lang.String.format) TimeZoneKey(com.facebook.presto.common.type.TimeZoneKey) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Stream(java.util.stream.Stream) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Optional(java.util.Optional) TestingPrestoClient(com.facebook.presto.tests.TestingPrestoClient) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 55 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestEliminateSorts method testEliminateSorts.

@Test
public void testEliminateSorts() {
    @Language("SQL") String sql = "SELECT quantity, row_number() OVER (ORDER BY quantity) FROM lineitem ORDER BY quantity";
    PlanMatchPattern pattern = output(window(windowMatcherBuilder -> windowMatcherBuilder.specification(windowSpec).addFunction(functionCall("row_number", Optional.empty(), ImmutableList.of())), anyTree(LINEITEM_TABLESCAN_Q)));
    assertUnitPlan(sql, pattern);
}
Also used : TranslateExpressions(com.facebook.presto.sql.planner.iterative.rule.TranslateExpressions) PlanMatchPattern.specification(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.specification) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) PlanMatchPattern.anyTree(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) IterativeOptimizer(com.facebook.presto.sql.planner.iterative.IterativeOptimizer) Test(org.testng.annotations.Test) RemoveRedundantIdentityProjections(com.facebook.presto.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) PlanMatchPattern.window(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.window) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) ImmutableList(com.google.common.collect.ImmutableList) RuleStatsRecorder(com.facebook.presto.sql.planner.RuleStatsRecorder) PlanMatchPattern.functionCall(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.sort(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.sort) ImmutableSet(com.google.common.collect.ImmutableSet) SortOrder(com.facebook.presto.common.block.SortOrder) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) PlanMatchPattern.tableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan) SqlParser(com.facebook.presto.sql.parser.SqlParser) List(java.util.List) Optional(java.util.Optional) ExpectedValueProvider(com.facebook.presto.sql.planner.assertions.ExpectedValueProvider) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) Language(org.intellij.lang.annotations.Language) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Aggregations

Language (org.intellij.lang.annotations.Language)111 TableMetadata (com.facebook.presto.metadata.TableMetadata)25 Test (org.testng.annotations.Test)24 MaterializedResult (com.facebook.presto.testing.MaterializedResult)19 PsiFile (com.intellij.psi.PsiFile)18 MaterializedRow (com.facebook.presto.testing.MaterializedRow)11 List (java.util.List)11 Optional (java.util.Optional)11 Test (org.junit.Test)11 ImmutableList (com.google.common.collect.ImmutableList)10 Session (com.facebook.presto.Session)9 Constraint (com.facebook.presto.spi.Constraint)9 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)9 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)8 ColumnConstraint (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)7 ExpectedValueProvider (com.facebook.presto.sql.planner.assertions.ExpectedValueProvider)7 PlanMatchPattern (com.facebook.presto.sql.planner.assertions.PlanMatchPattern)7 SortOrder (com.facebook.presto.common.block.SortOrder)6