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"));
}
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()));
}
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}");
}
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());
}
}
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);
}
Aggregations