Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
remove toShortString
minor other changes
  • Loading branch information
nishantmonu51 committed May 6, 2014
1 parent f272599 commit 66450ca
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 55 deletions.
4 changes: 1 addition & 3 deletions processing/src/main/java/io/druid/query/DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,5 @@
})
public interface DataSource
{
public Iterable<String> getNames();

public String toShortString();
public List<String> getNames();
}
31 changes: 31 additions & 0 deletions processing/src/main/java/io/druid/query/DataSourceUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package io.druid.query;

import java.util.List;

public class DataSourceUtil
{
public static String getMetricName(DataSource dataSource)
{
final List<String> names = dataSource.getNames();
return names.size() == 1 ? names.get(0) : names.toString();
}
}
10 changes: 3 additions & 7 deletions processing/src/main/java/io/druid/query/QueryDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;

import java.util.List;

@JsonTypeName("query")
public class QueryDataSource implements DataSource
{
Expand All @@ -38,17 +40,11 @@ public QueryDataSource(@JsonProperty("query") Query query)
}

@Override
public Iterable<String> getNames()
public List<String> getNames()
{
return query.getDataSource().getNames();
}

@Override
public String toShortString()
{
return query.getDataSource().toShortString();
}

@JsonProperty
public Query getQuery()
{
Expand Down
11 changes: 3 additions & 8 deletions processing/src/main/java/io/druid/query/TableDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.List;

@JsonTypeName("table")
Expand All @@ -45,15 +46,9 @@ public String getName(){
}

@Override
public Iterable<String> getNames()
public List<String> getNames()
{
return Lists.newArrayList(name);
}

@Override
public String toShortString()
{
return name;
return Arrays.asList(name);
}

public String toString() { return name; }
Expand Down
37 changes: 15 additions & 22 deletions processing/src/main/java/io/druid/query/UnionDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

public class UnionDataSource implements DataSource
{
Expand All @@ -45,30 +44,24 @@ public UnionDataSource(@JsonProperty("dataSources") List<TableDataSource> dataSo
}

@Override
public Iterable<String> getNames()
public List<String> getNames()
{
return Iterables.concat(Iterables.transform(dataSources, new Function<DataSource, Iterable<String>>()
{
@Override
public Iterable<String> apply(DataSource input)
{
return input.getNames();
}
}));
}

@Override
public String toShortString()
{
SortedSet<String> str = new TreeSet<>();
for(DataSource ds : dataSources){
str.add(ds.toShortString());
}
return str.toString();
return Lists.transform(
dataSources,
new Function<TableDataSource, String>()
{
@Override
public String apply(TableDataSource input)
{
return Iterables.getOnlyElement(input.getNames());
}
}
);
}

@JsonProperty
public List<TableDataSource> getDataSources(){
public List<TableDataSource> getDataSources()
{
return dataSources;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.druid.data.input.MapBasedRow;
import io.druid.data.input.Row;
import io.druid.query.DataSource;
import io.druid.query.DataSourceUtil;
import io.druid.query.IntervalChunkingQueryRunner;
import io.druid.query.Query;
import io.druid.query.QueryDataSource;
Expand Down Expand Up @@ -163,7 +164,7 @@ public ServiceMetricEvent.Builder makeMetricBuilder(GroupByQuery query)
}

return new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser3(String.format("%,d dims", query.getDimensions().size()))
.setUser4("groupBy")
.setUser5(Joiner.on(",").join(query.getIntervals()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.druid.collections.OrderedMergeSequence;
import io.druid.common.utils.JodaUtils;
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;
Expand Down Expand Up @@ -147,7 +148,7 @@ public ServiceMetricEvent.Builder makeMetricBuilder(SegmentMetadataQuery query)
}

return new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser4(query.getType())
.setUser5(Joiner.on(",").join(query.getIntervals()))
.setUser6(String.valueOf(query.hasFilters()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.metamx.emitter.service.ServiceMetricEvent;
import io.druid.collections.OrderedMergeSequence;
import io.druid.query.CacheStrategy;
import io.druid.query.DataSourceUtil;
import io.druid.query.IntervalChunkingQueryRunner;
import io.druid.query.Query;
import io.druid.query.QueryRunner;
Expand Down Expand Up @@ -121,7 +122,7 @@ public ServiceMetricEvent.Builder makeMetricBuilder(SearchQuery query)
}

return new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser4("search")
.setUser5(COMMA_JOIN.join(query.getIntervals()))
.setUser6(String.valueOf(query.hasFilters()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.druid.collections.OrderedMergeSequence;
import io.druid.granularity.QueryGranularity;
import io.druid.query.CacheStrategy;
import io.druid.query.DataSourceUtil;
import io.druid.query.IntervalChunkingQueryRunner;
import io.druid.query.Query;
import io.druid.query.QueryConfig;
Expand Down Expand Up @@ -123,7 +124,7 @@ public ServiceMetricEvent.Builder makeMetricBuilder(SelectQuery query)
}

return new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser4("Select")
.setUser5(COMMA_JOIN.join(query.getIntervals()))
.setUser6(String.valueOf(query.hasFilters()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.druid.collections.OrderedMergeSequence;
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;
Expand Down Expand Up @@ -117,7 +118,7 @@ public Sequence<Result<TimeBoundaryResultValue>> mergeSequences(Sequence<Sequenc
public ServiceMetricEvent.Builder makeMetricBuilder(TimeBoundaryQuery query)
{
return new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser4(query.getType())
.setUser6("false");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.druid.collections.OrderedMergeSequence;
import io.druid.granularity.QueryGranularity;
import io.druid.query.CacheStrategy;
import io.druid.query.DataSourceUtil;
import io.druid.query.IntervalChunkingQueryRunner;
import io.druid.query.Query;
import io.druid.query.QueryCacheHelper;
Expand Down Expand Up @@ -122,7 +123,7 @@ public ServiceMetricEvent.Builder makeMetricBuilder(TimeseriesQuery query)
}

return new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser4("timeseries")
.setUser5(COMMA_JOIN.join(query.getIntervals()))
.setUser6(String.valueOf(query.hasFilters()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.druid.collections.OrderedMergeSequence;
import io.druid.granularity.QueryGranularity;
import io.druid.query.CacheStrategy;
import io.druid.query.DataSourceUtil;
import io.druid.query.IntervalChunkingQueryRunner;
import io.druid.query.Query;
import io.druid.query.QueryCacheHelper;
Expand Down Expand Up @@ -138,7 +139,7 @@ public ServiceMetricEvent.Builder makeMetricBuilder(TopNQuery query)
}

return new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser4(String.format("topN/%s/%s", query.getThreshold(), query.getDimensionSpec().getDimension()))
.setUser5(COMMA_JOIN.join(query.getIntervals()))
.setUser6(String.valueOf(query.hasFilters()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public void testUnionDataSource() throws Exception
Lists.newArrayList("ds1", "ds2"),
Lists.newArrayList(dataSource.getNames())
);
Assert.assertEquals(Lists.newArrayList("ds1", "ds2").toString(), dataSource.toShortString());

final DataSource serde = jsonMapper.readValue(jsonMapper.writeValueAsString(dataSource), DataSource.class);
Assert.assertEquals(dataSource, serde);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.druid.client.RoutingDruidClient;
import io.druid.guice.annotations.Json;
import io.druid.guice.annotations.Smile;
import io.druid.query.DataSourceUtil;
import io.druid.query.Query;
import io.druid.server.log.RequestLogger;
import io.druid.server.router.QueryHostFinder;
Expand Down Expand Up @@ -282,7 +283,7 @@ public ClientResponse<OutputStream> done(ClientResponse<OutputStream> clientResp

emitter.emit(
new ServiceMetricEvent.Builder()
.setUser2(theQuery.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(theQuery.getDataSource()))
.setUser4(theQuery.getType())
.setUser5(COMMA_JOIN.join(theQuery.getIntervals()))
.setUser6(String.valueOf(theQuery.hasFilters()))
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/io/druid/server/QueryResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.metamx.emitter.service.ServiceMetricEvent;
import io.druid.guice.annotations.Json;
import io.druid.guice.annotations.Smile;
import io.druid.query.DataSourceUtil;
import io.druid.query.Query;
import io.druid.query.QuerySegmentWalker;
import io.druid.server.log.RequestLogger;
Expand Down Expand Up @@ -131,7 +132,7 @@ public void doPost(

emitter.emit(
new ServiceMetricEvent.Builder()
.setUser2(query.getDataSource().toShortString())
.setUser2(DataSourceUtil.getMetricName(query.getDataSource()))
.setUser4(query.getType())
.setUser5(COMMA_JOIN.join(query.getIntervals()))
.setUser6(String.valueOf(query.hasFilters()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,6 @@ public QueryRunner<T> apply(PartitionChunk<ReferenceCountingSegment> input)

private String getDataSourceName(DataSource dataSource)
{
Preconditions.checkArgument(
dataSource instanceof TableDataSource,
"Subqueries and Unions are only supported in the broker"
);

return Iterables.getOnlyElement(dataSource.getNames());
}

Expand Down

0 comments on commit 66450ca

Please sign in to comment.