io.druid.query.datasourcemetadata.DataSourceQueryQueryToolChest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of druid-processing Show documentation
Show all versions of druid-processing Show documentation
A module that is everything required to understands Druid Segments
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.druid.query.datasourcemetadata;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.metamx.common.guava.Sequence;
import com.metamx.common.guava.Sequences;
import com.metamx.emitter.service.ServiceMetricEvent;
import io.druid.query.BySegmentSkippingQueryRunner;
import io.druid.query.CacheStrategy;
import io.druid.query.DataSourceUtil;
import io.druid.query.Query;
import io.druid.query.QueryRunner;
import io.druid.query.QueryToolChest;
import io.druid.query.Result;
import io.druid.query.aggregation.MetricManipulationFn;
import io.druid.timeline.LogicalSegment;
import java.util.List;
import java.util.Map;
/**
*/
public class DataSourceQueryQueryToolChest
extends QueryToolChest, DataSourceMetadataQuery>
{
private static final TypeReference> TYPE_REFERENCE = new TypeReference>()
{
};
@Override
public List filterSegments(DataSourceMetadataQuery query, List segments)
{
if (segments.size() <= 1) {
return segments;
}
final T max = segments.get(segments.size() - 1);
return Lists.newArrayList(
Iterables.filter(
segments,
new Predicate()
{
@Override
public boolean apply(T input)
{
return max != null && input.getInterval().overlaps(max.getInterval());
}
}
)
);
}
@Override
public QueryRunner> mergeResults(
final QueryRunner> runner
)
{
return new BySegmentSkippingQueryRunner>(runner)
{
@Override
protected Sequence> doRun(
QueryRunner> baseRunner,
Query> input,
Map context
)
{
DataSourceMetadataQuery query = (DataSourceMetadataQuery) input;
return Sequences.simple(
query.mergeResults(
Sequences.toList(
baseRunner.run(query, context),
Lists.>newArrayList()
)
)
);
}
};
}
@Override
public ServiceMetricEvent.Builder makeMetricBuilder(DataSourceMetadataQuery query)
{
return new ServiceMetricEvent.Builder()
.setDimension("dataSource", DataSourceUtil.getMetricName(query.getDataSource()))
.setDimension("type", query.getType());
}
@Override
public Function, Result> makePreComputeManipulatorFn(
DataSourceMetadataQuery query, MetricManipulationFn fn
)
{
return Functions.identity();
}
@Override
public TypeReference> getResultTypeReference()
{
return TYPE_REFERENCE;
}
@Override
public CacheStrategy getCacheStrategy(DataSourceMetadataQuery query)
{
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy