Search in sources :

Example 1 with AllColumnIncluderator

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

the class DruidSchemaTest method testRunSegmentMetadataQueryWithContext.

/**
 * Ensure that the BrokerInternalQueryConfig context is honored for this internally generated SegmentMetadata Query
 */
@Test
public void testRunSegmentMetadataQueryWithContext() throws Exception {
    Map<String, Object> queryContext = ImmutableMap.of("priority", 5);
    String brokerInternalQueryConfigJson = "{\"context\": { \"priority\": 5} }";
    TestHelper.makeJsonMapper();
    BrokerInternalQueryConfig brokerInternalQueryConfig = MAPPER.readValue(MAPPER.writeValueAsString(MAPPER.readValue(brokerInternalQueryConfigJson, BrokerInternalQueryConfig.class)), BrokerInternalQueryConfig.class);
    DataSegment segment = newSegment("test", 0);
    List<SegmentId> segmentIterable = ImmutableList.of(segment.getId());
    // This is the query that we expect this method to create. We will be testing that it matches the query generated by the method under test.
    SegmentMetadataQuery expectedMetadataQuery = new SegmentMetadataQuery(new TableDataSource(segment.getDataSource()), new MultipleSpecificSegmentSpec(segmentIterable.stream().map(SegmentId::toDescriptor).collect(Collectors.toList())), new AllColumnIncluderator(), false, queryContext, EnumSet.noneOf(SegmentMetadataQuery.AnalysisType.class), false, false);
    QueryLifecycleFactory factoryMock = EasyMock.createMock(QueryLifecycleFactory.class);
    QueryLifecycle lifecycleMock = EasyMock.createMock(QueryLifecycle.class);
    // Need to create schema for this test because the available schemas don't mock the QueryLifecycleFactory, which I need for this test.
    DruidSchema mySchema = new DruidSchema(factoryMock, serverView, segmentManager, new MapJoinableFactory(ImmutableSet.of(globalTableJoinable), ImmutableMap.of(globalTableJoinable.getClass(), GlobalTableDataSource.class)), PLANNER_CONFIG_DEFAULT, new NoopEscalator(), brokerInternalQueryConfig, null);
    EasyMock.expect(factoryMock.factorize()).andReturn(lifecycleMock).once();
    // This is the mat of the test, making sure that the query created by the method under test matches the expected query, specifically the operator configured context
    EasyMock.expect(lifecycleMock.runSimple(expectedMetadataQuery, AllowAllAuthenticator.ALLOW_ALL_RESULT, Access.OK)).andReturn(null);
    EasyMock.replay(factoryMock, lifecycleMock);
    mySchema.runSegmentMetadataQuery(segmentIterable);
    EasyMock.verify(factoryMock, lifecycleMock);
}
Also used : MultipleSpecificSegmentSpec(org.apache.druid.query.spec.MultipleSpecificSegmentSpec) QueryLifecycle(org.apache.druid.server.QueryLifecycle) SegmentId(org.apache.druid.timeline.SegmentId) DataSegment(org.apache.druid.timeline.DataSegment) AllColumnIncluderator(org.apache.druid.query.metadata.metadata.AllColumnIncluderator) NoopEscalator(org.apache.druid.server.security.NoopEscalator) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryLifecycleFactory(org.apache.druid.server.QueryLifecycleFactory) SegmentMetadataQuery(org.apache.druid.query.metadata.metadata.SegmentMetadataQuery) BrokerInternalQueryConfig(org.apache.druid.client.BrokerInternalQueryConfig) MapJoinableFactory(org.apache.druid.segment.join.MapJoinableFactory) Test(org.junit.Test)

Example 2 with AllColumnIncluderator

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

the class DruidSchema method runSegmentMetadataQuery.

/**
 * Execute a SegmentMetadata query and return a {@link Sequence} of {@link SegmentAnalysis}.
 *
 * @param segments Iterable of {@link SegmentId} objects that are subject of the SegmentMetadata query.
 * @return {@link Sequence} of {@link SegmentAnalysis} objects
 */
@VisibleForTesting
protected Sequence<SegmentAnalysis> runSegmentMetadataQuery(final Iterable<SegmentId> segments) {
    // Sanity check: getOnlyElement of a set, to ensure all segments have the same dataSource.
    final String dataSource = Iterables.getOnlyElement(StreamSupport.stream(segments.spliterator(), false).map(SegmentId::getDataSource).collect(Collectors.toSet()));
    final MultipleSpecificSegmentSpec querySegmentSpec = new MultipleSpecificSegmentSpec(StreamSupport.stream(segments.spliterator(), false).map(SegmentId::toDescriptor).collect(Collectors.toList()));
    final SegmentMetadataQuery segmentMetadataQuery = new SegmentMetadataQuery(new TableDataSource(dataSource), querySegmentSpec, new AllColumnIncluderator(), false, brokerInternalQueryConfig.getContext(), EnumSet.noneOf(SegmentMetadataQuery.AnalysisType.class), false, false);
    return queryLifecycleFactory.factorize().runSimple(segmentMetadataQuery, escalator.createEscalatedAuthenticationResult(), Access.OK);
}
Also used : MultipleSpecificSegmentSpec(org.apache.druid.query.spec.MultipleSpecificSegmentSpec) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) SegmentId(org.apache.druid.timeline.SegmentId) SegmentMetadataQuery(org.apache.druid.query.metadata.metadata.SegmentMetadataQuery) AllColumnIncluderator(org.apache.druid.query.metadata.metadata.AllColumnIncluderator) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)2 TableDataSource (org.apache.druid.query.TableDataSource)2 AllColumnIncluderator (org.apache.druid.query.metadata.metadata.AllColumnIncluderator)2 SegmentMetadataQuery (org.apache.druid.query.metadata.metadata.SegmentMetadataQuery)2 MultipleSpecificSegmentSpec (org.apache.druid.query.spec.MultipleSpecificSegmentSpec)2 SegmentId (org.apache.druid.timeline.SegmentId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BrokerInternalQueryConfig (org.apache.druid.client.BrokerInternalQueryConfig)1 MapJoinableFactory (org.apache.druid.segment.join.MapJoinableFactory)1 QueryLifecycle (org.apache.druid.server.QueryLifecycle)1 QueryLifecycleFactory (org.apache.druid.server.QueryLifecycleFactory)1 NoopEscalator (org.apache.druid.server.security.NoopEscalator)1 DataSegment (org.apache.druid.timeline.DataSegment)1 Test (org.junit.Test)1