Search in sources :

Example 1 with GenericQueryMetricsFactory

use of org.apache.druid.query.GenericQueryMetricsFactory in project druid by druid-io.

the class DataSourceMetadataQueryTest method testFilterSegments.

@Test
public void testFilterSegments() {
    GenericQueryMetricsFactory queryMetricsFactory = DefaultGenericQueryMetricsFactory.instance();
    DataSourceQueryQueryToolChest toolChest = new DataSourceQueryQueryToolChest(queryMetricsFactory);
    List<LogicalSegment> segments = toolChest.filterSegments(null, Arrays.asList(new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2012-01-01/P1D");
        }

        @Override
        public Interval getTrueInterval() {
            return getInterval();
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2012-01-01T01/PT1H");
        }

        @Override
        public Interval getTrueInterval() {
            return getInterval();
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2013-01-01/P1D");
        }

        @Override
        public Interval getTrueInterval() {
            return getInterval();
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2013-01-01T01/PT1H");
        }

        @Override
        public Interval getTrueInterval() {
            return getInterval();
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2013-01-01T02/PT1H");
        }

        @Override
        public Interval getTrueInterval() {
            return getInterval();
        }
    }));
    Assert.assertEquals(segments.size(), 2);
    // should only have the latest segments.
    List<LogicalSegment> expected = Arrays.asList(new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2013-01-01/P1D");
        }

        @Override
        public Interval getTrueInterval() {
            return getInterval();
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2013-01-01T02/PT1H");
        }

        @Override
        public Interval getTrueInterval() {
            return getInterval();
        }
    });
    for (int i = 0; i < segments.size(); i++) {
        Assert.assertEquals(expected.get(i).getInterval(), segments.get(i).getInterval());
    }
}
Also used : LogicalSegment(org.apache.druid.timeline.LogicalSegment) GenericQueryMetricsFactory(org.apache.druid.query.GenericQueryMetricsFactory) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 2 with GenericQueryMetricsFactory

use of org.apache.druid.query.GenericQueryMetricsFactory in project druid by druid-io.

the class DataSourceMetadataQueryTest method testFilterOverlappingSegments.

@Test
public void testFilterOverlappingSegments() {
    final GenericQueryMetricsFactory queryMetricsFactory = DefaultGenericQueryMetricsFactory.instance();
    final DataSourceQueryQueryToolChest toolChest = new DataSourceQueryQueryToolChest(queryMetricsFactory);
    final List<LogicalSegment> segments = toolChest.filterSegments(null, ImmutableList.of(new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2015/2016-08-01");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2015/2016-08-01");
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2016-08-01/2017");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2016-08-01/2017");
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2017/2017-08-01");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2017/2018");
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2017-08-01/2017-08-02");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2017-08-01/2017-08-02");
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2017-08-02/2018");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2017/2018");
        }
    }));
    final List<LogicalSegment> expected = ImmutableList.of(new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2017/2017-08-01");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2017/2018");
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2017-08-01/2017-08-02");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2017-08-01/2017-08-02");
        }
    }, new LogicalSegment() {

        @Override
        public Interval getInterval() {
            return Intervals.of("2017-08-02/2018");
        }

        @Override
        public Interval getTrueInterval() {
            return Intervals.of("2017/2018");
        }
    });
    Assert.assertEquals(expected.size(), segments.size());
    for (int i = 0; i < expected.size(); i++) {
        Assert.assertEquals(expected.get(i).getInterval(), segments.get(i).getInterval());
        Assert.assertEquals(expected.get(i).getTrueInterval(), segments.get(i).getTrueInterval());
    }
}
Also used : LogicalSegment(org.apache.druid.timeline.LogicalSegment) GenericQueryMetricsFactory(org.apache.druid.query.GenericQueryMetricsFactory) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with GenericQueryMetricsFactory

use of org.apache.druid.query.GenericQueryMetricsFactory in project druid by druid-io.

the class SqlModuleTest method makeInjectorWithProperties.

private Injector makeInjectorWithProperties(final Properties props) {
    return Guice.createInjector(ImmutableList.of(new DruidGuiceExtensions(), new LifecycleModule(), new ServerModule(), new JacksonModule(), (Module) binder -> {
        binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
        binder.bind(JsonConfigurator.class).in(LazySingleton.class);
        binder.bind(Properties.class).toInstance(props);
        binder.bind(ExprMacroTable.class).toInstance(ExprMacroTable.nil());
        binder.bind(AuthorizerMapper.class).toInstance(CalciteTests.TEST_AUTHORIZER_MAPPER);
        binder.bind(Escalator.class).toInstance(new NoopEscalator());
        binder.bind(ServiceEmitter.class).toInstance(serviceEmitter);
        binder.bind(RequestLogger.class).toInstance(new NoopRequestLogger());
        binder.bind(new TypeLiteral<Supplier<DefaultQueryConfig>>() {
        }).toInstance(Suppliers.ofInstance(new DefaultQueryConfig(null)));
        binder.bind(FilteredServerInventoryView.class).toInstance(inventoryView);
        binder.bind(TimelineServerView.class).toInstance(timelineServerView);
        binder.bind(DruidLeaderClient.class).annotatedWith(Coordinator.class).toInstance(druidLeaderClient);
        binder.bind(DruidLeaderClient.class).annotatedWith(IndexingService.class).toInstance(druidLeaderClient);
        binder.bind(DruidNodeDiscoveryProvider.class).toInstance(druidNodeDiscoveryProvider);
        binder.bind(GenericQueryMetricsFactory.class).toInstance(genericQueryMetricsFactory);
        binder.bind(QuerySegmentWalker.class).toInstance(querySegmentWalker);
        binder.bind(QueryToolChestWarehouse.class).toInstance(queryToolChestWarehouse);
        binder.bind(LookupExtractorFactoryContainerProvider.class).toInstance(lookupExtractorFactoryContainerProvider);
        binder.bind(JoinableFactory.class).toInstance(joinableFactory);
        binder.bind(SegmentLoader.class).toInstance(segmentLoader);
        binder.bind(QuerySchedulerProvider.class).in(LazySingleton.class);
        binder.bind(QueryScheduler.class).toProvider(QuerySchedulerProvider.class).in(LazySingleton.class);
    }, new SqlModule(props), new TestViewManagerModule()));
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) DruidGuiceExtensions(org.apache.druid.guice.DruidGuiceExtensions) Properties(java.util.Properties) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) ServerModule(org.apache.druid.guice.ServerModule) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) NoopEscalator(org.apache.druid.server.security.NoopEscalator) Escalator(org.apache.druid.server.security.Escalator) NoopEscalator(org.apache.druid.server.security.NoopEscalator) TypeLiteral(com.google.inject.TypeLiteral) QuerySchedulerProvider(org.apache.druid.server.QuerySchedulerProvider) IndexingService(org.apache.druid.client.indexing.IndexingService) RequestLogger(org.apache.druid.server.log.RequestLogger) NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) TimelineServerView(org.apache.druid.client.TimelineServerView) QueryToolChestWarehouse(org.apache.druid.query.QueryToolChestWarehouse) LifecycleModule(org.apache.druid.guice.LifecycleModule) FilteredServerInventoryView(org.apache.druid.client.FilteredServerInventoryView) NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) GenericQueryMetricsFactory(org.apache.druid.query.GenericQueryMetricsFactory) Coordinator(org.apache.druid.client.coordinator.Coordinator) JacksonModule(org.apache.druid.jackson.JacksonModule) SegmentLoader(org.apache.druid.segment.loading.SegmentLoader) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) Module(com.google.inject.Module) LifecycleModule(org.apache.druid.guice.LifecycleModule) JacksonModule(org.apache.druid.jackson.JacksonModule) DruidModule(org.apache.druid.initialization.DruidModule) ServerModule(org.apache.druid.guice.ServerModule) Validator(javax.validation.Validator)

Aggregations

GenericQueryMetricsFactory (org.apache.druid.query.GenericQueryMetricsFactory)3 DefaultGenericQueryMetricsFactory (org.apache.druid.query.DefaultGenericQueryMetricsFactory)2 LogicalSegment (org.apache.druid.timeline.LogicalSegment)2 Interval (org.joda.time.Interval)2 Test (org.junit.Test)2 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 Properties (java.util.Properties)1 Validator (javax.validation.Validator)1 FilteredServerInventoryView (org.apache.druid.client.FilteredServerInventoryView)1 TimelineServerView (org.apache.druid.client.TimelineServerView)1 Coordinator (org.apache.druid.client.coordinator.Coordinator)1 IndexingService (org.apache.druid.client.indexing.IndexingService)1 DruidNodeDiscoveryProvider (org.apache.druid.discovery.DruidNodeDiscoveryProvider)1 DruidGuiceExtensions (org.apache.druid.guice.DruidGuiceExtensions)1 JsonConfigurator (org.apache.druid.guice.JsonConfigurator)1 LifecycleModule (org.apache.druid.guice.LifecycleModule)1 ServerModule (org.apache.druid.guice.ServerModule)1 DruidModule (org.apache.druid.initialization.DruidModule)1 JacksonModule (org.apache.druid.jackson.JacksonModule)1