Search in sources :

Example 26 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class AbstractTestQueries method testShowSession.

@Test
public void testShowSession() {
    Session session = new Session(getSession().getQueryId(), Optional.empty(), getSession().isClientTransactionSupport(), getSession().getIdentity(), getSession().getSource(), getSession().getCatalog(), getSession().getSchema(), getSession().getTraceToken(), getSession().getTimeZoneKey(), getSession().getLocale(), getSession().getRemoteUserAddress(), getSession().getUserAgent(), getSession().getClientInfo(), getSession().getClientTags(), getSession().getResourceEstimates(), getSession().getStartTime(), ImmutableMap.<String, String>builder().put("test_string", "foo string").put("test_long", "424242").build(), ImmutableMap.of(), ImmutableMap.of(TESTING_CATALOG, ImmutableMap.<String, String>builder().put("connector_string", "bar string").put("connector_long", "11").build()), getQueryRunner().getMetadata().getSessionPropertyManager(), getSession().getPreparedStatements(), ImmutableMap.of(), getSession().getTracer());
    MaterializedResult result = computeActual(session, "SHOW SESSION");
    ImmutableMap<String, MaterializedRow> properties = Maps.uniqueIndex(result.getMaterializedRows(), input -> {
        assertEquals(input.getFieldCount(), 5);
        return (String) input.getField(0);
    });
    assertEquals(properties.get("test_string"), new MaterializedRow(1, "test_string", "foo string", "test default", "varchar", "test string property"));
    assertEquals(properties.get("test_long"), new MaterializedRow(1, "test_long", "424242", "42", "bigint", "test long property"));
    assertEquals(properties.get(TESTING_CATALOG + ".connector_string"), new MaterializedRow(1, TESTING_CATALOG + ".connector_string", "bar string", "connector default", "varchar", "connector string property"));
    assertEquals(properties.get(TESTING_CATALOG + ".connector_long"), new MaterializedRow(1, TESTING_CATALOG + ".connector_long", "11", "33", "bigint", "connector long property"));
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 27 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class AbstractTestQueries method testValuesWithNonTrivialType.

@Test
public void testValuesWithNonTrivialType() {
    MaterializedResult actual = computeActual("VALUES (0E0/0E0, 1E0/0E0, -1E0/0E0)");
    List<MaterializedRow> rows = actual.getMaterializedRows();
    assertEquals(rows.size(), 1);
    MaterializedRow row = rows.get(0);
    assertTrue(((Double) row.getField(0)).isNaN());
    assertEquals(row.getField(1), Double.POSITIVE_INFINITY);
    assertEquals(row.getField(2), Double.NEGATIVE_INFINITY);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 28 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class AbstractTestQueries method testNonDeterministicAggregationPredicatePushdown.

@Test
public void testNonDeterministicAggregationPredicatePushdown() {
    MaterializedResult materializedResult = computeActual("" + "SELECT COUNT(*)\n" + "FROM (\n" + "  SELECT orderkey, COUNT(*)\n" + "  FROM lineitem\n" + "  GROUP BY orderkey\n" + "  LIMIT 1000\n" + ")\n" + "WHERE rand() > 0.5");
    MaterializedRow row = getOnlyElement(materializedResult.getMaterializedRows());
    assertEquals(row.getFieldCount(), 1);
    long count = (Long) row.getField(0);
    // Technically non-deterministic unit test but has essentially a next to impossible chance of a false positive
    assertTrue(count > 0 && count < 1000);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 29 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class AbstractTestQueries method testNonDeterministicTableScanPredicatePushdown.

@Test
public void testNonDeterministicTableScanPredicatePushdown() {
    MaterializedResult materializedResult = computeActual("" + "SELECT COUNT(*)\n" + "FROM (\n" + "  SELECT *\n" + "  FROM lineitem\n" + "  LIMIT 1000\n" + ")\n" + "WHERE rand() > 0.5");
    MaterializedRow row = getOnlyElement(materializedResult.getMaterializedRows());
    assertEquals(row.getFieldCount(), 1);
    long count = (Long) row.getField(0);
    // Technically non-deterministic unit test but has essentially a next to impossible chance of a false positive
    assertTrue(count > 0 && count < 1000);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 30 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class AbstractTestQueries method testShowFunctions.

@Test
public void testShowFunctions() {
    MaterializedResult result = computeActual("SHOW FUNCTIONS");
    ImmutableMultimap<String, MaterializedRow> functions = Multimaps.index(result.getMaterializedRows(), input -> {
        assertEquals(input.getFieldCount(), 10);
        return (String) input.getField(0);
    });
    assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
    assertEquals(functions.get("avg").asList().size(), 6);
    assertEquals(functions.get("avg").asList().get(0).getField(1), "decimal(p,s)");
    assertEquals(functions.get("avg").asList().get(0).getField(2), "decimal(p,s)");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(1).getField(2), "bigint");
    assertEquals(functions.get("avg").asList().get(1).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(2).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(2).getField(2), "double");
    assertEquals(functions.get("avg").asList().get(2).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(3).getField(1), "interval day to second");
    assertEquals(functions.get("avg").asList().get(3).getField(2), "interval day to second");
    assertEquals(functions.get("avg").asList().get(3).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(4).getField(1), "interval year to month");
    assertEquals(functions.get("avg").asList().get(4).getField(2), "interval year to month");
    assertEquals(functions.get("avg").asList().get(4).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(5).getField(1), "real");
    assertEquals(functions.get("avg").asList().get(5).getField(2), "real");
    assertEquals(functions.get("avg").asList().get(5).getField(3), "aggregate");
    assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
    assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("abs").asList().get(0).getField(4), true);
    assertEquals(functions.get("abs").asList().get(0).getField(6), false);
    assertEquals(functions.get("abs").asList().get(0).getField(7), true);
    assertEquals(functions.get("abs").asList().get(0).getField(8), false);
    assertEquals(functions.get("abs").asList().get(0).getField(9), "");
    assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
    assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("rand").asList().get(0).getField(4), false);
    assertEquals(functions.get("rand").asList().get(0).getField(6), false);
    assertEquals(functions.get("rand").asList().get(0).getField(7), true);
    assertEquals(functions.get("rand").asList().get(0).getField(8), false);
    assertEquals(functions.get("rand").asList().get(0).getField(9), "");
    assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
    assertEquals(functions.get("rank").asList().get(0).getField(3), "window");
    assertEquals(functions.get("rank").asList().get(0).getField(4), true);
    assertEquals(functions.get("rank").asList().get(0).getField(6), false);
    assertEquals(functions.get("rank").asList().get(0).getField(7), true);
    assertEquals(functions.get("rank").asList().get(0).getField(8), false);
    assertEquals(functions.get("rank").asList().get(0).getField(9), "");
    assertTrue(functions.containsKey("greatest"), "Expected function names " + functions + " to contain 'greatest'");
    assertEquals(functions.get("greatest").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("greatest").asList().get(0).getField(4), true);
    assertEquals(functions.get("greatest").asList().get(0).getField(6), true);
    assertEquals(functions.get("greatest").asList().get(0).getField(7), true);
    assertEquals(functions.get("greatest").asList().get(0).getField(8), false);
    assertEquals(functions.get("greatest").asList().get(0).getField(9), "");
    assertTrue(functions.containsKey("split_part"), "Expected function names " + functions + " to contain 'split_part'");
    assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar(x)");
    assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar(x), varchar(y), bigint");
    assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("split_part").asList().get(0).getField(4), true);
    assertEquals(functions.get("split_part").asList().get(0).getField(6), false);
    assertEquals(functions.get("split_part").asList().get(0).getField(7), true);
    assertEquals(functions.get("split_part").asList().get(0).getField(8), false);
    assertEquals(functions.get("split_part").asList().get(0).getField(9), "");
    assertFalse(functions.containsKey("like"), "Expected function names " + functions + " not to contain 'like'");
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Aggregations

MaterializedRow (com.facebook.presto.testing.MaterializedRow)91 MaterializedResult (com.facebook.presto.testing.MaterializedResult)80 Test (org.testng.annotations.Test)67 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)31 ImmutableList (com.google.common.collect.ImmutableList)16 Constraint (com.facebook.presto.spi.Constraint)15 ConnectorSession (com.facebook.presto.spi.ConnectorSession)14 Language (org.intellij.lang.annotations.Language)13 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)12 List (java.util.List)11 Session (com.facebook.presto.Session)10 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)10 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)9 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)9 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)9 UUID (java.util.UUID)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 ImmutableMap (com.google.common.collect.ImmutableMap)8