@Test public void testCollectionSingleName() throws Exception { QueryResult test = getEventExplorer().getEventStatistics(new RequestContext(PROJECT_NAME, null), Optional.of(ImmutableSet.of("test")), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("test", 100L))); }
@Test public void testTotalStatistics() throws Exception { QueryResult test = getEventExplorer().getEventStatistics(new RequestContext(PROJECT_NAME, null), Optional.empty(), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("test", 100L))); }
@Test public void testCollectionNotExisting() throws Exception { QueryResult test = getEventExplorer().getEventStatistics(new RequestContext(PROJECT_NAME, null), Optional.of(ImmutableSet.of()), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).join(); assertFalse(test.isFailed()); assertEquals(test.getResult(), of()); }
@Test public void testExtraDimensionsForStatistics() throws Exception { Collection<List<String>> dimensions = getEventExplorer().getExtraDimensions("test").values(); dimensions.stream().flatMap(e -> e.stream()).forEach(dimension -> { QueryResult test = getEventExplorer().getEventStatistics(new RequestContext(PROJECT_NAME, null), Optional.empty(), Optional.of(dimension), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).join(); assertFalse(test.isFailed()); Optional<TimestampTransformation> transformation = fromPrettyName(dimension); if (transformation.isPresent()) { assertEquals(copyOf(test.getResult()), EVENT_STATISTICS_RESULTS.get(transformation.get())); } else { // TODO: test custom parameters } }); }
@Test public void testAvgAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("testnumber", AVERAGE), new EventExplorer.Reference(COLUMN, "testbool"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("true", "test", 49.0), of("false", "test", 50.0))); }
@Test public void testMaximumAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("testnumber", MAXIMUM), new EventExplorer.Reference(COLUMN, "testbool"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("true", "test", 98.0), of("false", "test", 99.0))); }
@Test public void testMinimumAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("testnumber", MINIMUM), new EventExplorer.Reference(COLUMN, "testbool"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("true", "test", 0.0), of("false", "test", 1.0))); }
@Test public void testCountUniqueAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("testnumber", AggregationType.COUNT_UNIQUE), new EventExplorer.Reference(COLUMN, "testbool"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("true", "test", 50L), of("false", "test", 50L))); }
@Test public void testApproxAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("teststr", AggregationType.APPROXIMATE_UNIQUE), new EventExplorer.Reference(COLUMN, "testbool"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("true", "test", 50L), of("false", "test", 50L))); }
@Test public void testCountAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("testnumber", COUNT), new EventExplorer.Reference(COLUMN, "testbool"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("true", "test", 50L), of("false", "test", 50L))); }
@Test public void testSegmentAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("testnumber", AggregationType.COUNT_UNIQUE), new EventExplorer.Reference(COLUMN, "testbool"), new EventExplorer.Reference(COLUMN, "testbool"), null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("true", "true", 50L), of("false", "false", 50L))); }
@Test public void testSimpleWithFilter() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure(null, COUNT), null, null, "testbool", LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(test.getResult().get(0), of("test", 50L)); }
@Test public void testSumAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("testnumber", SUM), null, null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(test.getResult().get(0), of("test", 4950.0)); }
.build(); getEventExplorer().getExtraDimensions("test").values().stream().flatMap(e -> e.stream()) .forEach(dimension -> { Optional<TimestampTransformation> trans = fromPrettyName(dimension); QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("teststr", AggregationType.APPROXIMATE_UNIQUE), new EventExplorer.Reference(EventExplorer.ReferenceType.REFERENCE, trans.get().getPrettyName()),
@Test public void testAllDimensionsNumberBoolean() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure(null, COUNT), new EventExplorer.Reference(COLUMN, "testnumber"), new EventExplorer.Reference(COLUMN, "testbool"), null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(test.getResult().size(), 17); assertEquals(test.getResult().get(0).get(0), "Others"); assertEquals(test.getResult().get(1).get(0), "Others"); assertEquals(test.getResult().stream().mapToLong(a -> ((Number) a.get(2)).longValue()).sum(), 100L); for (int i = 2; i < test.getResult().size(); i++) { assertTrue(ImmutableSet.of("true", "false").contains(test.getResult().get(i).get(1))); assertEquals(test.getResult().get(i).get(2), 1L); } }
@Test public void testGroupingNumberBoolean() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure(null, COUNT), new EventExplorer.Reference(COLUMN, "testnumber"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC) .getResult().join(); assertFalse(test.isFailed()); assertEquals(test.getResult().size(), 16); assertEquals(test.getResult().get(0), ImmutableList.of("Others", "test", 85L)); assertEquals(test.getResult().stream().mapToLong(a -> (Long) a.get(2)).sum(), 100L); }
@Test public void testStatisticsDates() throws Exception { QueryResult test = getEventExplorer().getEventStatistics(new RequestContext(PROJECT_NAME, null), Optional.empty(), Optional.empty(), LocalDate.ofEpochDay(100), LocalDate.ofEpochDay(101), ZoneOffset.UTC).join(); assertTrue(!test.isFailed(), test.getError() != null ? test.getError().toString() : null); assertEquals(test.getResult(), of()); }
@Test public void testSimple() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure(null, COUNT), null, null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed(), test.isFailed() ? test.getError().message : null); assertEquals(test.getResult().get(0), of("test", 100L)); }
@Test public void testMultipleReferenceGrouping() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("teststr", AggregationType.APPROXIMATE_UNIQUE), new EventExplorer.Reference(EventExplorer.ReferenceType.REFERENCE, DAY_OF_MONTH.getPrettyName()), new EventExplorer.Reference(EventExplorer.ReferenceType.REFERENCE, DAY_OF_MONTH.getPrettyName()), null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("1th day", "1th day", 100L))); } }
@Test public void testInvalidAvgAggregation() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("teststr", AVERAGE), new EventExplorer.Reference(COLUMN, "testbool"), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertTrue(test.isFailed()); }