@Test(invocationCount = 5) public void testIncrementalRealtimeExpiration() throws Exception { String tableName = CryptUtil.generateRandomKey(10); populate(tableName); MaterializedView view = new MaterializedView("testview", "testview", format("select count(*) as count from %s", checkCollection(tableName)), Duration.ofSeconds(1), true, true, ImmutableMap.of()); getMaterializedViewService().create(new RequestContext(PROJECT_NAME), view).join(); QueryExecutorService queryService = getQueryService(); QueryResult result = queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); populate(tableName); getClock().increment(Duration.ofSeconds(2).toMillis()); result = queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); int total = 0; for (List<Object> objects : result.getResult()) { total += ((Number) objects.get(0)).intValue(); } assertEquals(SCALE_FACTOR * 2, total); }
public QueryExecutorService getQueryService() { return new QueryExecutorService(getQueryExecutor(), getMetastore(), getMaterializedViewService(), getEscapeIdentifier()); }
public void populate(String collection) throws Exception { EventBuilder builder = new EventBuilder(PROJECT_NAME, getMetastore()); List<Event> events = IntStream.range(0, SCALE_FACTOR).mapToObj(i -> builder.createEvent(collection, 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); }
@BeforeSuite public void setup() throws Exception { getMetastore().createProject(PROJECT_NAME); populate("test"); }
@Test public void testCacheExpiration() throws Exception { MaterializedView view = new MaterializedView("testview", "testview", "select count(*) as count from test", Duration.ofSeconds(1), false, false, ImmutableMap.of()); getMaterializedViewService().create(new RequestContext(PROJECT_NAME), view).join(); QueryExecutorService queryService = getQueryService(); QueryResult result = queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); getClock().increment(Duration.ofSeconds(2).toMillis()); result = queryService.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()); }
@BeforeSuite @Override public void setup() throws Exception { testingEnvironment = new TestingEnvironment(); PrestoConfig prestoConfig = testingEnvironment.getPrestoConfig(); metastore = new PrestoRakamRaptorMetastore(testingEnvironment.getPrestoMetastore(), new EventBus(), new ProjectConfig(), prestoConfig); metastore.setup(); prestoQueryExecutor = new PrestoQueryExecutor(new ProjectConfig(), prestoConfig, null, metastore); materializedViewService = new PrestoMaterializedViewService( new PrestoConfig(), prestoQueryExecutor, metastore, getDatabaseMetadataStore(), Clock.systemUTC()); eventStore = new TestingPrestoEventStore(prestoQueryExecutor, prestoConfig); super.setup(); }
@AfterSuite public void destroy() { getMetastore().deleteProject(PROJECT_NAME); }
@AfterMethod public void tearDown() throws Exception { QueryResult testview; try { testview = getMaterializedViewService().delete(new RequestContext(PROJECT_NAME), "testview").join(); if (testview.isFailed()) { throw new IllegalStateException(testview.getError().toString()); } } catch (Exception e) { e.printStackTrace(); } queryMetadataStore.clear(); }
@Test public void testIncrementalExpirationNoData() throws Exception { MaterializedView view = new MaterializedView("testview", "testview", "select count(*) as count from test", Duration.ofSeconds(1), true, false, ImmutableMap.of()); getMaterializedViewService().create(new RequestContext(PROJECT_NAME), view).join(); QueryExecutorService queryService = getQueryService(); QueryResult result = queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); getClock().increment(Duration.ofSeconds(2).toMillis()); result = queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); int total = 0; for (List<Object> objects : result.getResult()) { total += ((Number) objects.get(0)).intValue(); } assertEquals(SCALE_FACTOR, total); }
@Test public void testCache() throws Exception { MaterializedView view = new MaterializedView("testview", "testview", "select count(*) as count from test", Duration.ofDays(1), false, 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()); }
@BeforeSuite public void setup() throws Exception { testingPostgresqlServer = new TestingEnvironmentPg9(); 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()); queryExecutor = new PostgresqlQueryExecutor(new ProjectConfig(), dataSource, metastore, new CustomDataSourceService(dataSource), false); eventStore = new PostgresqlEventStore(dataSource, new PostgresqlModule.PostgresqlVersion(dataSource), build); super.setup(); }
throws Exception { String tableName = CryptUtil.generateRandomKey(10); populate(tableName); getMaterializedViewService().create(new RequestContext(PROJECT_NAME), view).join(); QueryExecutorService queryService = getQueryService(); QueryResult result = queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); assertEquals(1, result.getResult().size()); populate(tableName); getClock().increment(Duration.ofSeconds(2).toMillis());
@Test public void testCacheRenewConcurrentInSingle() throws Exception { MaterializedView view = new MaterializedView("testview", "testview", "select count(*) as count from test", Duration.ofSeconds(10), false, false, ImmutableMap.of()); getMaterializedViewService().create(new RequestContext(PROJECT_NAME), view).join(); QueryExecutorService queryService = getQueryService(); QueryResult result = queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult().join(); assertFalse(result.isFailed()); getClock().increment(Duration.ofSeconds(10).toMillis()); List<CompletableFuture<QueryResult>> collect = IntStream.range(0, 10) .mapToObj(i -> queryService.executeQuery(PROJECT_NAME, "select * from materialized.testview", ZoneId.systemDefault()).getResult()) .collect(Collectors.toList()); for (CompletableFuture<QueryResult> future : collect) { result = future.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(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()); }
@BeforeSuite public void setup() throws Exception { testingPostgresqlServer = new TestingEnvironmentPg10(); 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()); queryExecutor = new PostgresqlQueryExecutor(new ProjectConfig(), dataSource, metastore, new CustomDataSourceService(dataSource), false); eventStore = new PostgresqlEventStore(dataSource, new PostgresqlModule.PostgresqlVersion(dataSource), build); super.setup(); }