Search in sources :

Example 41 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project boostkit-bigdata by kunpengcompute.

the class TestHiveIntegrationSmokeTest method testBucketHiddenColumn.

@Test
public void testBucketHiddenColumn() {
    @Language("SQL") String createTable = "CREATE TABLE test_bucket_hidden_column " + "WITH (" + "bucketed_by = ARRAY['col0']," + "bucket_count = 2" + ") AS " + "SELECT * FROM (VALUES " + "(0, 11), (1, 12), (2, 13), " + "(3, 14), (4, 15), (5, 16), " + "(6, 17), (7, 18), (8, 19)" + " ) t (col0, col1) ";
    assertUpdate(createTable, 9);
    assertTrue(getQueryRunner().tableExists(getSession(), "test_bucket_hidden_column"));
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_bucket_hidden_column");
    assertEquals(tableMetadata.getMetadata().getProperties().get(BUCKETED_BY_PROPERTY), ImmutableList.of("col0"));
    assertEquals(tableMetadata.getMetadata().getProperties().get(BUCKET_COUNT_PROPERTY), 2);
    List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, BUCKET_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(BUCKET_COLUMN_NAME)) {
            // $bucket_number should be hidden column
            assertTrue(columnMetadata.isHidden());
        }
    }
    assertEquals(getBucketCount("test_bucket_hidden_column"), 2);
    MaterializedResult results = computeActual(format("SELECT *, \"%1$s\" FROM test_bucket_hidden_column WHERE \"%1$s\" = 1", BUCKET_COLUMN_NAME));
    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);
        int bucket = (int) row.getField(2);
        assertEquals(col1, col0 + 11);
        assertTrue(col1 % 2 == 0);
        // Because Hive's hash function for integer n is h(n) = n.
        assertEquals(bucket, col0 % 2);
    }
    assertEquals(results.getRowCount(), 4);
    assertUpdate("DROP TABLE test_bucket_hidden_column");
    assertFalse(getQueryRunner().tableExists(getSession(), "test_bucket_hidden_column"));
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) Language(org.intellij.lang.annotations.Language) MaterializedResult(io.prestosql.testing.MaterializedResult) ColumnConstraint(io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint) Constraint(io.prestosql.spi.connector.Constraint) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Example 42 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.

the class TestMongoIntegrationSmokeTest method createTableWithEveryType.

@Test
public void createTableWithEveryType() {
    String query = "" + "CREATE TABLE test_types_table AS " + "SELECT" + " 'foo' _varchar" + ", cast('bar' as varbinary) _varbinary" + ", cast(1 as bigint) _bigint" + ", 3.14E0 _double" + ", true _boolean" + ", DATE '1980-05-07' _date" + ", TIMESTAMP '1980-05-07 11:22:33.456' _timestamp" + ", ObjectId('ffffffffffffffffffffffff') _objectid";
    assertUpdate(query, 1);
    MaterializedResult results = getQueryRunner().execute(getSession(), "SELECT * FROM test_types_table").toTestTypes();
    assertEquals(results.getRowCount(), 1);
    MaterializedRow row = results.getMaterializedRows().get(0);
    assertEquals(row.getField(0), "foo");
    assertEquals(row.getField(1), "bar".getBytes(UTF_8));
    assertEquals(row.getField(2), 1L);
    assertEquals(row.getField(3), 3.14);
    assertEquals(row.getField(4), true);
    assertEquals(row.getField(5), LocalDate.of(1980, 5, 7));
    assertEquals(row.getField(6), LocalDateTime.of(1980, 5, 7, 11, 22, 33, 456_000_000));
    assertUpdate("DROP TABLE test_types_table");
    assertFalse(getQueryRunner().tableExists(getSession(), "test_types_table"));
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Example 43 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method testCreateAndInsert.

@Test
public void testCreateAndInsert() {
    Session session = getSession();
    List<MaterializedRow> expected = MaterializedResult.resultBuilder(session, BIGINT, BIGINT).row(101L, 1L).row(201L, 2L).row(202L, 2L).row(301L, 3L).row(302L, 3L).build().getMaterializedRows();
    transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(session, transactionSession -> {
        assertUpdate(transactionSession, "CREATE TABLE tmp_create_insert WITH (partitioned_by=array ['z']) AS " + "SELECT * from (VALUES (CAST (101 AS BIGINT), CAST (1 AS BIGINT)), (201, 2), (202, 2)) t(a, z)", 3);
        assertUpdate(transactionSession, "INSERT INTO tmp_create_insert VALUES (301, 3), (302, 3)", 2);
        MaterializedResult actualFromCurrentTransaction = computeActual(transactionSession, "SELECT * FROM tmp_create_insert");
        assertEqualsIgnoreOrder(actualFromCurrentTransaction, expected);
    });
    MaterializedResult actualAfterTransaction = computeActual(session, "SELECT * FROM tmp_create_insert");
    assertEqualsIgnoreOrder(actualAfterTransaction, expected);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Session(io.prestosql.Session) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Example 44 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.

the class QueryAssertions method assertQuery.

public void assertQuery(Session session, @Language("SQL") String actual, @Language("SQL") String expected, boolean ensureOrdering) {
    MaterializedResult actualResults = null;
    try {
        actualResults = execute(session, actual);
    } catch (RuntimeException ex) {
        fail("Execution of 'actual' query failed: " + actual, ex);
    }
    MaterializedResult expectedResults = null;
    try {
        expectedResults = execute(expected);
    } catch (RuntimeException ex) {
        fail("Execution of 'expected' query failed: " + expected, ex);
    }
    assertEquals(actualResults.getTypes(), expectedResults.getTypes(), "Types mismatch for query: \n " + actual + "\n:");
    List<MaterializedRow> actualRows = actualResults.getMaterializedRows();
    List<MaterializedRow> expectedRows = expectedResults.getMaterializedRows();
    if (ensureOrdering) {
        if (!actualRows.equals(expectedRows)) {
            assertEquals(actualRows, expectedRows, "For query: \n " + actual + "\n:");
        }
    } else {
        assertEqualsIgnoreOrder(actualRows, expectedRows, "For query: \n " + actual);
    }
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

Example 45 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.

the class TestHindex method testIndexNotCreatedNotExist.

// Tests the case of asserting that the uncreated new index does not exist
@Test
public void testIndexNotCreatedNotExist() {
    String indexName = getNewIndexName();
    createTable1(getNewTableName());
    // Validate if created
    String testerQuery = "SHOW INDEX";
    Pair<Integer, MaterializedResult> resultPairIndexCreation = getSplitAndMaterializedResult(testerQuery);
    MaterializedResult resultIndexCreation = resultPairIndexCreation.getSecond();
    boolean indexExists = false;
    for (MaterializedRow item : resultIndexCreation.getMaterializedRows()) {
        if (item.getField(0).toString().equals(indexName)) {
            indexExists = true;
            break;
        }
    }
    assertFalse(indexExists);
    // Show index with if exists
    testerQuery = "SHOW INDEX IF EXISTS " + indexName;
    Pair<Integer, MaterializedResult> resultPairIndexCreation2 = getSplitAndMaterializedResult(testerQuery);
    MaterializedResult resultIndexCreation2 = resultPairIndexCreation2.getSecond();
    int size = resultIndexCreation2.getRowCount();
    assertEquals(size, 0);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test)

Aggregations

MaterializedRow (io.prestosql.testing.MaterializedRow)89 MaterializedResult (io.prestosql.testing.MaterializedResult)80 Test (org.testng.annotations.Test)57 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)18 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)16 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)14 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)14 Constraint (io.prestosql.spi.connector.Constraint)14 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)14 ImmutableList (com.google.common.collect.ImmutableList)13 HiveColumnHandle.bucketColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle.bucketColumnHandle)12 ConnectorPageSource (io.prestosql.spi.connector.ConnectorPageSource)12 ConnectorSplit (io.prestosql.spi.connector.ConnectorSplit)12 AbstractTestIntegrationSmokeTest (io.prestosql.tests.AbstractTestIntegrationSmokeTest)12 List (java.util.List)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 Session (io.prestosql.Session)9 Language (org.intellij.lang.annotations.Language)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Plan (io.prestosql.sql.planner.Plan)8