@Test public void testSelectCount() throws Exception { final ResultSet resultSet = client.createStatement().executeQuery("SELECT COUNT(*) AS cnt FROM druid.foo"); final List<Map<String, Object>> rows = getRows(resultSet); Assert.assertEquals( ImmutableList.of( ImmutableMap.of("cnt", 6L) ), rows ); }
@Test public void testExceptionalHandle() { final Response response = abstractListenerHandler.handleGET(error_id); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals(ImmutableMap.of("error", error_message), response.getEntity()); }
@Test public void workerHeartbeatUpdatesRemovedBlocks() throws Exception { // Create a worker. long worker = mBlockMaster.getWorkerId(NET_ADDRESS_1); mBlockMaster.workerRegister(worker, Arrays.asList("MEM"), ImmutableMap.of("MEM", 100L), ImmutableMap.of("MEM", 0L), NO_BLOCKS_ON_TIERS, RegisterWorkerPOptions.getDefaultInstance()); long blockId = 1L; mBlockMaster.commitBlock(worker, 50L, "MEM", blockId, 20L); // Indicate that blockId is removed on the worker. mBlockMaster.workerHeartbeat(worker, null, ImmutableMap.of("MEM", 0L), ImmutableList.of(blockId), NO_BLOCKS_ON_TIERS, mMetrics); assertTrue(mBlockMaster.getBlockInfo(blockId).getLocations().isEmpty()); }
@Test public void testReplaces() { Assert.assertFalse(factory.replaces(factory)); Assert.assertFalse(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY, VALUE), true))); Assert.assertTrue(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY, VALUE), false))); Assert.assertTrue(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY + "1", VALUE), true))); Assert.assertTrue(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY, VALUE + "1"), true))); Assert.assertTrue(factory.replaces(null)); }
@Test public void getDefaultValues() { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(), PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null), ImmutableMap.of()) { }; assertThat(config.get("multiA")).hasValue("foo,bar"); assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar"); assertThat(config.get("single")).hasValue("default"); assertThat(config.getStringArray("single")).containsExactly("default"); }
@Test public void testBuildQueryOr() { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( COL1, Domain.create(ValueSet.ofRanges(lessThan(BIGINT, 100L), greaterThan(BIGINT, 200L)), false))); Document query = MongoSession.buildQuery(tupleDomain); Document expected = new Document("$or", asList( new Document(COL1.getName(), new Document("$lt", 100L)), new Document(COL1.getName(), new Document("$gt", 200L)))); assertEquals(query, expected); }
@Test public void testSelectorWithLookupExtractionFn() { final Map<String, String> stringMap = ImmutableMap.of( "a", "7" ); LookupExtractor mapExtractor = new MapLookupExtractor(stringMap, false); LookupExtractionFn lookupFn = new LookupExtractionFn(mapExtractor, true, null, false, true); assertFilterMatches(new ColumnComparisonDimFilter(ImmutableList.of( new ExtractionDimensionSpec("dim0", "dim0", lookupFn), new ExtractionDimensionSpec("dim1", "dim1", lookupFn) )), ImmutableList.of("2", "5", "7", "8")); } }
@Test public void ruleAddedTableLayoutToTableScan() { tester().assertThat(pickTableLayout.pickTableLayoutWithoutPredicate()) .on(p -> p.tableScan( nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)))) .matches( constrainedTableScanWithTableLayout("nation", ImmutableMap.of(), ImmutableMap.of("nationkey", "nationkey"))); }
@Test public void testExtractFixedValuesFromAll() { assertEquals(TupleDomain.extractFixedValues(TupleDomain.all()).get(), ImmutableMap.of()); }
@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 testSemiJoinNotNeeded() { tester().assertThat(new PruneSemiJoinColumns()) .on(p -> buildProjectedSemiJoin(p, symbol -> symbol.getName().equals("leftValue"))) .matches( strictProject( ImmutableMap.of("leftValue", expression("leftValue")), values("leftKey", "leftKeyHash", "leftValue"))); }
@Test public void testSelectCountAlternateStyle() throws Exception { final ResultSet resultSet = client.prepareStatement("SELECT COUNT(*) AS cnt FROM druid.foo").executeQuery(); final List<Map<String, Object>> rows = getRows(resultSet); Assert.assertEquals( ImmutableList.of( ImmutableMap.of("cnt", 6L) ), rows ); }
@Test public void testGetDatasourceNonFullWithInterval() { Map<String, Object> actual = resource.getDatasource(dataSource, "1975/2015", null); Map<String, Object> expected = ImmutableMap.of( KEY_DIMENSIONS, ImmutableSet.of("d1", "d2"), KEY_METRICS, ImmutableSet.of("m1", "m2") ); EasyMock.verify(serverInventoryView); Assert.assertEquals(expected, actual); }
@Test public void testRowSignature() { final DimFilterHavingSpec havingSpec = new DimFilterHavingSpec(new SelectorDimFilter("foo", "1", null), null); havingSpec.setRowSignature(ImmutableMap.of("foo", ValueType.LONG)); Assert.assertTrue(havingSpec.eval(new MapBasedRow(0, ImmutableMap.of("foo", 1L)))); Assert.assertFalse(havingSpec.eval(new MapBasedRow(0, ImmutableMap.of("foo", 2L)))); }
@Test public void testQueryMaxTimeout() { exception.expect(IAE.class); exception.expectMessage("configured [timeout = 1000] is more than enforced limit of maxQueryTimeout [100]."); Query<?> query = new TestQuery( new TableDataSource("test"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("0/100"))), false, ImmutableMap.of(QueryContexts.TIMEOUT_KEY, 1000) ); QueryContexts.verifyMaxQueryTimeout(query, 100); }
@Test public void doesNotFireIfTableScanHasTableLayout() { tester().assertThat(pickTableLayout.pickTableLayoutWithoutPredicate()) .on(p -> p.tableScan( nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)), Optional.of(nationTableLayoutHandle))) .doesNotFire(); }
@Test(expectedExceptions = {IllegalStateException.class}, expectedExceptionsMessageRegExp = "missing expression for alias .*") public void testProjectLimitsScope() { assertMinimallyOptimizedPlan("SELECT 1 + orderkey FROM lineitem", output(ImmutableList.of("ORDERKEY"), project(ImmutableMap.of("EXPRESSION", expression("CAST(1 AS bigint) + ORDERKEY")), tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey"))))); } }
@Test public void testEmptySingleValuesMapToDomain() { assertEquals(TupleDomain.fromFixedValues(ImmutableMap.of()), TupleDomain.all()); }