Search in sources :

Example 11 with MaterializedRow

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

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(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 12 with MaterializedRow

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

the class TestEnums method assertQueryResultUnordered.

private void assertQueryResultUnordered(@Language("SQL") String query, List<List<Object>> expectedRows) {
    MaterializedResult rows = computeActual(query);
    assertEquals(ImmutableSet.copyOf(rows.getMaterializedRows()), expectedRows.stream().map(row -> new MaterializedRow(1, row)).collect(Collectors.toSet()));
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 13 with MaterializedRow

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

the class TestPrometheusMetricsIntegration method testConfirmMetricAvailableAndCheckUp.

@Test
public void testConfirmMetricAvailableAndCheckUp() throws Exception {
    int maxTries = 60;
    int timeBetweenTriesMillis = 1000;
    runner = createQueryRunner();
    session = runner.getDefaultSession();
    int tries = 0;
    final OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(120, TimeUnit.SECONDS).readTimeout(120, TimeUnit.SECONDS).build();
    HttpUrl.Builder urlBuilder = HttpUrl.parse(server.getUri().toString()).newBuilder().encodedPath("/api/v1/query");
    urlBuilder.addQueryParameter("query", "up[1d]");
    String url = urlBuilder.build().toString();
    Request request = new Request.Builder().url(url).build();
    String responseBody;
    // this seems to be a reliable way to ensure Prometheus has `up` metric data
    while (tries < maxTries) {
        responseBody = httpClient.newCall(request).execute().body().string();
        if (responseBody.contains("values")) {
            Logger log = Logger.get(TestPrometheusMetricsIntegration.class);
            log.info("prometheus response: %s", responseBody);
            break;
        }
        Thread.sleep(timeBetweenTriesMillis);
        tries++;
    }
    if (tries == maxTries) {
        fail("Prometheus container not available for metrics query in " + maxTries * timeBetweenTriesMillis + " milliseconds.");
    }
    // now we're making sure the client is ready
    tries = 0;
    while (tries < maxTries) {
        if (session != null && runner.tableExists(session, "up")) {
            break;
        }
        Thread.sleep(timeBetweenTriesMillis);
        tries++;
    }
    if (tries == maxTries) {
        fail("Prometheus container, or client, not available for metrics query in " + maxTries * timeBetweenTriesMillis + " milliseconds.");
    }
    MaterializedResult results = runner.execute(session, "SELECT * FROM prometheus.default.up LIMIT 1").toTestTypes();
    assertEquals(results.getRowCount(), 1);
    MaterializedRow row = results.getMaterializedRows().get(0);
    assertEquals(row.getField(0).toString(), "{instance=localhost:9090, __name__=up, job=prometheus}");
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Logger(com.facebook.airlift.log.Logger) MaterializedResult(com.facebook.presto.testing.MaterializedResult) HttpUrl(okhttp3.HttpUrl) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 14 with MaterializedRow

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

the class PrestoSparkQueryRunner method execute.

@Override
public MaterializedResult execute(Session session, String sql) {
    IPrestoSparkQueryExecutionFactory executionFactory = prestoSparkService.getQueryExecutionFactory();
    IPrestoSparkQueryExecution execution = executionFactory.create(sparkContext, createSessionInfo(session), Optional.of(sql), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), new TestingPrestoSparkTaskExecutorFactoryProvider(instanceId), Optional.empty(), Optional.empty());
    List<List<Object>> results = execution.execute();
    List<MaterializedRow> rows = results.stream().map(result -> new MaterializedRow(DEFAULT_PRECISION, result)).collect(toImmutableList());
    if (execution instanceof PrestoSparkQueryExecution) {
        PrestoSparkQueryExecution p = (PrestoSparkQueryExecution) execution;
        if (!p.getUpdateType().isPresent()) {
            return new MaterializedResult(rows, p.getOutputTypes());
        } else {
            return new MaterializedResult(rows, p.getOutputTypes(), ImmutableMap.of(), ImmutableSet.of(), p.getUpdateType(), OptionalLong.of((Long) getOnlyElement(getOnlyElement(rows).getFields())), ImmutableList.of());
        }
    } else {
        return new MaterializedResult(rows, ImmutableList.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty(), OptionalLong.empty(), ImmutableList.of());
    }
}
Also used : WARN(com.facebook.airlift.log.Level.WARN) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) QueryRunner(com.facebook.presto.testing.QueryRunner) ConnectorPlanOptimizerManager(com.facebook.presto.sql.planner.ConnectorPlanOptimizerManager) QueryAssertions.copyTpchTables(com.facebook.presto.tests.QueryAssertions.copyTpchTables) DEFAULT_PRECISION(com.facebook.presto.testing.MaterializedResult.DEFAULT_PRECISION) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Files.createTempDirectory(java.nio.file.Files.createTempDirectory) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) TEST_CATALOG_PROPERTIES(com.facebook.presto.tests.AbstractTestQueries.TEST_CATALOG_PROPERTIES) AbstractTestQueries(com.facebook.presto.tests.AbstractTestQueries) ENGLISH(java.util.Locale.ENGLISH) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) HiveHdfsConfiguration(com.facebook.presto.hive.HiveHdfsConfiguration) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) FunctionImplementationType(com.facebook.presto.spi.function.FunctionImplementationType) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SparkContext(org.apache.spark.SparkContext) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) Set(java.util.Set) Plugin(com.facebook.presto.spi.Plugin) UncheckedIOException(java.io.UncheckedIOException) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) FileHiveMetastore(com.facebook.presto.hive.metastore.file.FileHiveMetastore) TESTING_CATALOG(com.facebook.presto.testing.TestingSession.TESTING_CATALOG) Database(com.facebook.presto.hive.metastore.Database) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) OptionalLong(java.util.OptionalLong) PrestoSparkQueryExecution(com.facebook.presto.spark.PrestoSparkQueryExecutionFactory.PrestoSparkQueryExecution) TransactionManager(com.facebook.presto.transaction.TransactionManager) Session(com.facebook.presto.Session) SparkConf(org.apache.spark.SparkConf) PrincipalType(com.facebook.presto.spi.security.PrincipalType) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) File(java.io.File) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) Lock(java.util.concurrent.locks.Lock) TestingSession.createBogusTestingCatalog(com.facebook.presto.testing.TestingSession.createBogusTestingCatalog) Paths(java.nio.file.Paths) Logging(com.facebook.airlift.log.Logging) DRIVER(com.facebook.presto.spark.classloader_interface.SparkProcessType.DRIVER) TEST_SYSTEM_PROPERTIES(com.facebook.presto.tests.AbstractTestQueries.TEST_SYSTEM_PROPERTIES) Metadata(com.facebook.presto.metadata.Metadata) HdfsEnvironment(com.facebook.presto.hive.HdfsEnvironment) HivePlugin(com.facebook.presto.hive.HivePlugin) SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) SQL(com.facebook.presto.spi.function.RoutineCharacteristics.Language.SQL) Key(com.google.inject.Key) PrestoSparkConfInitializer(com.facebook.presto.spark.classloader_interface.PrestoSparkConfInitializer) PrestoSparkSession(com.facebook.presto.spark.classloader_interface.PrestoSparkSession) StatsCalculator(com.facebook.presto.cost.StatsCalculator) ConnectorManager(com.facebook.presto.connector.ConnectorManager) HiveClientConfig(com.facebook.presto.hive.HiveClientConfig) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SPARK_EXECUTOR_CORES_PROPERTY(com.facebook.presto.spark.PrestoSparkSettingsRequirements.SPARK_EXECUTOR_CORES_PROPERTY) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SplitManager(com.facebook.presto.split.SplitManager) TINY_SCHEMA_NAME(com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) HdfsConfigurationInitializer(com.facebook.presto.hive.HdfsConfigurationInitializer) TpchTable(io.airlift.tpch.TpchTable) TpchTable.getTables(io.airlift.tpch.TpchTable.getTables) List(java.util.List) IPrestoSparkQueryExecutionFactory(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory) Catalog(com.facebook.presto.metadata.Catalog) PrestoSparkTaskExecutorFactoryProvider(com.facebook.presto.spark.classloader_interface.PrestoSparkTaskExecutorFactoryProvider) Optional(java.util.Optional) IPrestoSparkTaskExecutorFactory(com.facebook.presto.spark.classloader_interface.IPrestoSparkTaskExecutorFactory) PluginManager(com.facebook.presto.server.PluginManager) NoHdfsAuthentication(com.facebook.presto.hive.authentication.NoHdfsAuthentication) Logger(com.facebook.airlift.log.Logger) SPARK_TASK_CPUS_PROPERTY(com.facebook.presto.spark.PrestoSparkSettingsRequirements.SPARK_TASK_CPUS_PROPERTY) HashMap(java.util.HashMap) IPrestoSparkQueryExecution(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution) HdfsConfiguration(com.facebook.presto.hive.HdfsConfiguration) ImmutableList(com.google.common.collect.ImmutableList) PageSourceManager(com.facebook.presto.split.PageSourceManager) Objects.requireNonNull(java.util.Objects.requireNonNull) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) EventListener(com.facebook.presto.spi.eventlistener.EventListener) MetastoreClientConfig(com.facebook.presto.hive.MetastoreClientConfig) HiveColumnConverterProvider(com.facebook.presto.hive.HiveColumnConverterProvider) NodePartitioningManager(com.facebook.presto.sql.planner.NodePartitioningManager) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) CatalogManager(com.facebook.presto.metadata.CatalogManager) Injector(com.google.inject.Injector) MaterializedResult(com.facebook.presto.testing.MaterializedResult) UUID.randomUUID(java.util.UUID.randomUUID) TestingAccessControlManager(com.facebook.presto.testing.TestingAccessControlManager) MaterializedRow(com.facebook.presto.testing.MaterializedRow) ERROR(com.facebook.airlift.log.Level.ERROR) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) SECONDS(java.util.concurrent.TimeUnit.SECONDS) IPrestoSparkQueryExecution(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution) OptionalLong(java.util.OptionalLong) IPrestoSparkQueryExecutionFactory(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MaterializedResult(com.facebook.presto.testing.MaterializedResult) PrestoSparkQueryExecution(com.facebook.presto.spark.PrestoSparkQueryExecutionFactory.PrestoSparkQueryExecution) IPrestoSparkQueryExecution(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 15 with MaterializedRow

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

the class TestAtopSmoke method assertThatQueryReturnsValue.

private void assertThatQueryReturnsValue(@Language("SQL") String sql, Object expected) {
    MaterializedResult rows = queryRunner.execute(sql);
    MaterializedRow materializedRow = Iterables.getOnlyElement(rows);
    int fieldCount = materializedRow.getFieldCount();
    assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
    Object value = materializedRow.getField(0);
    assertEquals(value, expected);
    assertTrue(Iterables.getOnlyElement(rows).getFieldCount() == 1);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

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