@Override public User get() { if (user == null) { String userAttr = event.getAttribute("_user"); if (userAttr != null) { user = userStorage.getUser(new RequestContext(event.project(), null), userAttr).join(); } } return user; } };
public void createTable(String project) { String query = format("select date_trunc('minute', cast(%s as timestamp)) as _time, cast(_collection as varchar) as _collection, count(*) as total from _all group by 1, 2", checkTableColumn(projectConfig.getTimeColumn())); MaterializedView report = new MaterializedView(tableName(), format("Event explorer metrics"), query, Duration.ofHours(1), true, true, ImmutableMap.of()); materializedViewService.create(new RequestContext(project, null), report).join(); } }
@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(invocationCount = 5) public void testIncrementalRealtime() throws Exception { MaterializedView view = new MaterializedView("testview", "testview", "select count(*) as count from test", Duration.ofDays(1), true, true, ImmutableMap.of()); getMaterializedViewService().create(new RequestContext(PROJECT_NAME), view).join(); QueryResult result = getQueryService().executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); assertEquals(1, result.getResult().size()); assertEquals(1, result.getResult().get(0).size()); assertEquals(SCALE_FACTOR, ((Number) result.getResult().get(0).get(0)).intValue()); }
@Test public void testIncremental() throws Exception { MaterializedView view = new MaterializedView("testview", "testview", "select count(*) as count from test", Duration.ofDays(1), true, false, ImmutableMap.of()); getMaterializedViewService().create(new RequestContext(PROJECT_NAME), view).join(); QueryResult result = getQueryService().executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); assertEquals(1, result.getResult().size()); assertEquals(1, result.getResult().get(0).size()); assertEquals(SCALE_FACTOR, ((Number) result.getResult().get(0).get(0)).intValue()); }
@Test(dataProvider = "types") public void testFilter(FunnelQueryExecutor.FunnelType funnelType) throws Exception { QueryResult query = getFunnelQueryExecutor().query(new RequestContext(PROJECT_NAME, null), of(new FunnelStep("test0", Optional.of("teststr = 'test1'")), new FunnelStep("test1", Optional.of("teststr = 'test1'"))), Optional.of("teststr"), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), Optional.of(new FunnelWindow(30, DAY)), UTC, Optional.empty(), funnelType).getResult().join(); assertFalse(query.isFailed()); assertEquals(query.getResult(), of(of("Step 1", "test1", 3L), of("Step 2", "test1", 3L))); }
@Test public void testSingleStepApproximate() throws Exception { QueryResult query = getFunnelQueryExecutor().query(new RequestContext(PROJECT_NAME, null), of(new FunnelStep("test0", null)), Optional.empty(), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), Optional.empty(), UTC, Optional.empty(), FunnelQueryExecutor.FunnelType.APPROXIMATE).getResult().join(); assertFalse(query.isFailed()); }
@Test public void testFilterApproximate() throws Exception { QueryResult query = getFunnelQueryExecutor().query(new RequestContext(PROJECT_NAME, null), of(new FunnelStep("test0", Optional.of("teststr = 'test1'")), new FunnelStep("test1", Optional.of("teststr = 'test1'"))), Optional.of("teststr"), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), Optional.empty(), UTC, Optional.empty(), APPROXIMATE).getResult().join(); assertFalse(query.isFailed()); }
@Test(dataProvider = "types") public void testMultipleSteps(FunnelQueryExecutor.FunnelType funnelType) throws Exception { QueryResult query = getFunnelQueryExecutor().query(new RequestContext(PROJECT_NAME, null), of(new FunnelStep("test0", null), new FunnelStep("test1", null), new FunnelStep("test2", null)), Optional.empty(), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), Optional.of(new FunnelWindow(30, DAY)), UTC, Optional.empty(), funnelType).getResult().join(); assertFalse(query.isFailed()); assertEquals(query.getResult(), of(of("Step 1", 3L), of("Step 2", 3L), of("Step 3", 3L))); }
@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 testDimensionApproximate() throws Exception { QueryResult query = getFunnelQueryExecutor().query(new RequestContext(PROJECT_NAME, null), of(new FunnelStep("test0", null), new FunnelStep("test1", null)), Optional.of("teststr"), Optional.empty(), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), Optional.of(new FunnelWindow(30, DAY)), UTC, Optional.empty(), NORMAL).getResult().join(); assertFalse(query.isFailed()); }
@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 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()); }