@Test public void testGroupByNanArray() { MaterializedResult actual = computeActual("SELECT a FROM (VALUES (ARRAY[nan(), 2e0, 3e0]), (ARRAY[nan(), 2e0, 3e0])) t(a) GROUP BY a"); List<MaterializedRow> actualRows = actual.getMaterializedRows(); assertEquals(actualRows.size(), 1); assertTrue(Double.isNaN(((List<Double>) actualRows.get(0).getField(0)).get(0))); assertEquals(((List<Double>) actualRows.get(0).getField(0)).get(1), 2.0); assertEquals(((List<Double>) actualRows.get(0).getField(0)).get(2), 3.0); }
@Test public void testTransactionsTable() { List<MaterializedRow> result = computeActual("SELECT * FROM system.runtime.transactions").getMaterializedRows(); assertTrue(result.size() >= 1); // At least one row for the current transaction. }
@Test @Transactional(propagation = Propagation.NOT_SUPPORTED) void verifyBeanInitialized() { assertInTransaction(false); assertTrue(beanInitialized, "This test instance should have been initialized due to InitializingBean semantics."); }
@Test public void testCreateSchema() { assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default")); metadata.createSchema(SESSION, "test", ImmutableMap.of()); assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default", "test")); }
@Test public void testTableSampleBernoulli() { DescriptiveStatistics stats = new DescriptiveStatistics(); int total = computeExpected("SELECT orderkey FROM orders", ImmutableList.of(BIGINT)).getMaterializedRows().size(); for (int i = 0; i < 100; i++) { List<MaterializedRow> values = computeActual("SELECT orderkey FROM orders TABLESAMPLE BERNOULLI (50)").getMaterializedRows(); assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows"); stats.addValue(values.size() * 1.0 / total); } double mean = stats.getGeometricMean(); assertTrue(mean > 0.45 && mean < 0.55, format("Expected mean sampling rate to be ~0.5, but was %s", mean)); }
@Test public void testScheduleLocal() { Split split = new Split(CONNECTOR_ID, TestingTransactionHandle.create(), new TestSplitLocal()); Set<Split> splits = ImmutableSet.of(split); Map.Entry<Node, Split> assignment = Iterables.getOnlyElement(nodeSelector.computeAssignments(splits, ImmutableList.copyOf(taskMap.values())).getAssignments().entries()); assertEquals(assignment.getKey().getHostAndPort(), split.getAddresses().get(0)); assertEquals(assignment.getValue(), split); }
@Test public void testDoubleMapMultimap() { Type mapType = mapType(VARCHAR, BIGINT); List<Double> expectedKeys = ImmutableList.of(1.0, 2.0, 3.0); List<Map<String, Long>> expectedValues = ImmutableList.of(ImmutableMap.of("a", 1L), ImmutableMap.of("b", 2L, "c", 3L, "d", 4L), ImmutableMap.of("a", 1L)); testMultimapAgg(DOUBLE, expectedKeys, mapType, expectedValues); }
@Test @Transactional(propagation = Propagation.NOT_SUPPORTED) void autowiringFromConfigClass() { assertNotNull(employee, "The employee should have been autowired."); assertEquals(employee.getName(), "John Smith"); assertNotNull(pet, "The pet should have been autowired."); assertEquals(pet.getName(), "Fido"); }
@Test public void testBloomFilterPredicateValuesNonExisting() { BloomFilter bloomFilter = new BloomFilter(TEST_VALUES.size() * 10, 0.01); for (Map.Entry<Object, Type> testValue : TEST_VALUES.entrySet()) { boolean matched = checkInBloomFilter(bloomFilter, testValue.getKey(), testValue.getValue()); assertFalse(matched, "type " + testValue.getKey().getClass()); } // test unsupported type: can be supported by ORC but is not implemented yet assertTrue(checkInBloomFilter(bloomFilter, new Date(), DATE), "unsupported type DATE should always return true"); }
@Test public void testAll() { assertTrue(TupleDomain.all().isAll()); assertEquals(TupleDomain.<ColumnHandle>all(), TupleDomain.withColumnDomains(ImmutableMap.of( A, Domain.all(BIGINT)))); assertEquals(TupleDomain.<ColumnHandle>all(), TupleDomain.withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of())); }
@Test public void testSvmRegressor() { Model model = new SvmRegressor(); model.train(getDataset()); Slice serialized = ModelUtils.serialize(model); Model deserialized = ModelUtils.deserialize(serialized); assertNotNull(deserialized, "deserialization failed"); assertTrue(deserialized instanceof SvmRegressor, "deserialized model is not a svm"); }
@Test public void testGetUpdateCount() throws Exception { try (Connection connection = createConnection()) { try (Statement statement = connection.createStatement()) { assertTrue(statement.execute("SELECT 123 x, 'foo' y")); assertEquals(statement.getUpdateCount(), -1); assertEquals(statement.getLargeUpdateCount(), -1); } } }
@Test public void testStatsExtraction() throws Exception { try (PrestoResultSet rs = (PrestoResultSet) statement.executeQuery("SELECT 123 x, 456 x")) { assertNotNull(rs.getStats()); assertTrue(rs.next()); assertNotNull(rs.getStats()); assertFalse(rs.next()); assertNotNull(rs.getStats()); } }
@Test @Transactional(propagation = Propagation.NOT_SUPPORTED) void verifyResourceAnnotationInjectedFields() { assertInTransaction(false); assertEquals(foo, "Foo", "The foo field should have been injected via @Resource."); }
@Test public void testGroupByNanRow() { MaterializedResult actual = computeActual("SELECT a, b, c FROM (VALUES ROW(nan(), 1, 2), ROW(nan(), 1, 2)) t(a, b, c) GROUP BY 1, 2, 3"); List<MaterializedRow> actualRows = actual.getMaterializedRows(); assertEquals(actualRows.size(), 1); assertTrue(Double.isNaN((Double) actualRows.get(0).getField(0))); assertEquals(actualRows.get(0).getField(1), 1); assertEquals(actualRows.get(0).getField(2), 2); }
@Test public void testListUnknownSchema() { assertNull(metadata.getTableHandle(SESSION, new SchemaTableName("totally_invalid_database_name", "dual"))); assertEquals(metadata.listTables(SESSION, "totally_invalid_database_name"), ImmutableList.of()); assertEquals(metadata.listTableColumns(SESSION, new SchemaTablePrefix("totally_invalid_database_name", "dual")), ImmutableMap.of()); }
@Test public void testStochasticPriorityQueue() { assertTrue(populateAndExtract(new StochasticPriorityQueue<>()).size() == 3); }
@Test public void testGetCurrentNode() { Node expected = activeNodes.get(0); NodeInfo nodeInfo = new NodeInfo(new NodeConfig() .setEnvironment("test") .setNodeId(expected.getNodeIdentifier())); DiscoveryNodeManager manager = new DiscoveryNodeManager(selector, nodeInfo, new NoOpFailureDetector(), expectedVersion, testHttpClient, internalCommunicationConfig); assertEquals(manager.getCurrentNode(), expected); }
@Test public void testArrayHistograms() { ArrayType arrayType = new ArrayType(VARCHAR); MapType mapType = mapType(arrayType, BIGINT); InternalAggregationFunction aggregationFunction = getAggregation(mapType.getTypeSignature(), arrayType.getTypeSignature()); assertAggregation( aggregationFunction, ImmutableMap.of(ImmutableList.of("a", "b", "c"), 1L, ImmutableList.of("d", "e", "f"), 1L, ImmutableList.of("c", "b", "a"), 1L), createStringArraysBlock(ImmutableList.of(ImmutableList.of("a", "b", "c"), ImmutableList.of("d", "e", "f"), ImmutableList.of("c", "b", "a")))); }
@Test @Transactional(propagation = Propagation.NOT_SUPPORTED) void verifyAnnotationAutowiredFields() { assertInTransaction(false); assertNull(nonrequiredLong, "The nonrequiredLong field should NOT have been autowired."); assertNotNull(pet, "The pet field should have been autowired."); assertEquals(pet.getName(), "Fido", "pet's name."); }