@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))); }
@BeforeSuite public void setup() throws Exception { getMetastore().createProject(PROJECT_NAME); EventBuilder builder = new EventBuilder(PROJECT_NAME, getMetastore()); List<Event> events = IntStream.range(0, SCALE_FACTOR).mapToObj(i -> builder.createEvent("test", ImmutableMap.<String, Object>builder() .put("teststr", "test" + i) .put("testnumber", (double) i) .put("testbool", i % 2 == 0) .put("testmap", ImmutableMap.of("test" + i, (double) i)) .put("testarray", of((double) i)) .put("testdate", LocalDate.ofEpochDay(i)) .put("_time", Instant.ofEpochSecond(i * 100)).build())) .collect(Collectors.toList()); getEventStore().storeBatch(events); }
.put(QUARTER_OF_YEAR, ImmutableSet.of(of("1th quarter", "test", 100L))) .put(DAY_OF_WEEK, ImmutableSet.of(of("Thursday", "test", 100L))) .put(HOUR, ImmutableSet.of(of(parse("1970-01-01T00:00:00Z"), "test", 36L), of(parse("1970-01-01T01:00:00Z"), "test", 36L), of(parse("1970-01-01T02:00:00Z"), "test", 28L))) .put(DAY, ImmutableSet.of(of(LocalDate.parse("1970-01-01"), "test", 100L))) .put(WEEK, ImmutableSet.of(of(LocalDate.parse("1969-12-29"), "test", 100L))) .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()),
@BeforeSuite @Override public void setup() throws Exception { testingEnvironment = new TestingEnvironment(); PrestoConfig prestoConfig = testingEnvironment.getPrestoConfig(); JDBCConfig postgresqlConfig = testingEnvironment.getPostgresqlConfig(); metastoreDataSource = JDBCPoolDataSource.getOrCreateDataSource(postgresqlConfig); queryMetadataStore = new InMemoryQueryMetadataStore(); metastore = new PrestoRakamRaptorMetastore(testingEnvironment.getPrestoMetastore(), new EventBus(), new ProjectConfig(), prestoConfig); metastore.setup(); prestoQueryExecutor = new PrestoQueryExecutor(new ProjectConfig(), prestoConfig, null, metastore); PrestoMaterializedViewService materializedViewService = new PrestoMaterializedViewService( new PrestoConfig(), prestoQueryExecutor, metastore, queryMetadataStore, Clock.systemUTC()); QueryExecutorService queryExecutorService = new QueryExecutorService(prestoQueryExecutor, metastore, materializedViewService, '"'); eventExplorer = new PrestoEventExplorer(new ProjectConfig(), queryExecutorService, materializedViewService); eventStore = new TestingPrestoEventStore(prestoQueryExecutor, prestoConfig); super.setup(); }
@AfterSuite public void destroy() { getMetastore().deleteProject(PROJECT_NAME); }
@Override @BeforeSuite public void setup() throws Exception { testingPostgresqlServer = new TestingEnvironmentPg10(); InMemoryQueryMetadataStore queryMetadataStore = new InMemoryQueryMetadataStore(); JDBCPoolDataSource dataSource = JDBCPoolDataSource.getOrCreateDataSource(testingPostgresqlServer.getPostgresqlConfig(), "set time zone 'UTC'"); FieldDependencyBuilder.FieldDependency build = new FieldDependencyBuilder().build(); EventBus eventBus = new EventBus(); metastore = new PostgresqlMetastore(dataSource, new PostgresqlModule.PostgresqlVersion(dataSource), eventBus, new ProjectConfig()); PostgresqlQueryExecutor queryExecutor = new PostgresqlQueryExecutor(new ProjectConfig(), dataSource, metastore, new CustomDataSourceService(dataSource), false); PostgresqlMaterializedViewService postgresqlMaterializedViewService = new PostgresqlMaterializedViewService(queryExecutor, queryMetadataStore, Clock.systemUTC()); eventStore = new PostgresqlEventStore(dataSource, new PostgresqlModule.PostgresqlVersion(dataSource), build); PostgresqlMaterializedViewService materializedViewService = postgresqlMaterializedViewService; eventExplorer = new PostgresqlEventExplorer( new ProjectConfig(), new QueryExecutorService(queryExecutor, metastore, materializedViewService, '"'), materializedViewService); super.setup(); }
@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))); }
@Override @BeforeSuite public void setup() throws Exception { testingPostgresqlServer = new TestingEnvironmentPg9(); InMemoryQueryMetadataStore queryMetadataStore = new InMemoryQueryMetadataStore(); JDBCPoolDataSource dataSource = JDBCPoolDataSource.getOrCreateDataSource(testingPostgresqlServer.getPostgresqlConfig(), "set time zone 'UTC'"); FieldDependencyBuilder.FieldDependency build = new FieldDependencyBuilder().build(); EventBus eventBus = new EventBus(); metastore = new PostgresqlMetastore(dataSource, new PostgresqlModule.PostgresqlVersion(dataSource), eventBus, new ProjectConfig()); PostgresqlQueryExecutor queryExecutor = new PostgresqlQueryExecutor(new ProjectConfig(), dataSource, metastore, new CustomDataSourceService(dataSource), false); PostgresqlMaterializedViewService postgresqlMaterializedViewService = new PostgresqlMaterializedViewService(queryExecutor, queryMetadataStore, Clock.systemUTC()); eventStore = new PostgresqlEventStore(dataSource, new PostgresqlModule.PostgresqlVersion(dataSource), build); PostgresqlMaterializedViewService materializedViewService = postgresqlMaterializedViewService; eventExplorer = new PostgresqlEventExplorer( new ProjectConfig(), new QueryExecutorService(queryExecutor, metastore, materializedViewService, '"'), materializedViewService); super.setup(); }
@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)); }
@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); }