Skip to content

Commit

Permalink
Merge branch 'master' of github.com:metamx/druid into test-harness
Browse files Browse the repository at this point in the history
  • Loading branch information
rjurney committed Jul 9, 2013
2 parents 6568728 + 2403056 commit b2cb9be
Show file tree
Hide file tree
Showing 41 changed files with 596 additions and 227 deletions.
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.5.5-SNAPSHOT</version>
<version>0.5.6-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
5 changes: 4 additions & 1 deletion client/src/main/java/com/metamx/druid/QueryableNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.metamx.druid.coordination.DataSegmentAnnouncer;
import com.metamx.druid.coordination.DruidServerMetadata;
import com.metamx.druid.curator.announcement.Announcer;
import com.metamx.druid.http.NoopRequestLogger;
import com.metamx.druid.http.RequestLogger;
import com.metamx.druid.initialization.CuratorConfig;
import com.metamx.druid.initialization.Initialization;
Expand Down Expand Up @@ -374,12 +375,14 @@ private void initializeRequestLogger()
getEmitter()
));
}
else {
else if ("file".equalsIgnoreCase(loggingType)) {
setRequestLogger(Initialization.makeFileRequestLogger(
getJsonMapper(),
getScheduledExecutorFactory(),
getProps()
));
} else {
setRequestLogger(new NoopRequestLogger());
}
}
catch (IOException e) {
Expand Down
31 changes: 31 additions & 0 deletions client/src/main/java/com/metamx/druid/http/NoopRequestLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012 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 com.metamx.druid.http;

/**
*/
public class NoopRequestLogger implements RequestLogger
{
@Override
public void log(RequestLogLine requestLogLine) throws Exception
{
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.metamx.druid.query;

import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -76,7 +77,7 @@ public ChainedExecutionQueryRunner(
{
this.exec = exec;
this.ordering = ordering;
this.queryables = Iterables.unmodifiableIterable(queryables);
this.queryables = Iterables.unmodifiableIterable(Iterables.filter(queryables, Predicates.notNull()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@

import javax.annotation.Nullable;
import java.nio.ByteBuffer;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SegmentMetadataQueryQueryToolChest extends QueryToolChest<SegmentAnalysis, SegmentMetadataQuery>
{
private static final TypeReference<SegmentAnalysis> TYPE_REFERENCE = new TypeReference<SegmentAnalysis>(){};
private static final TypeReference<SegmentAnalysis> TYPE_REFERENCE = new TypeReference<SegmentAnalysis>()
{
};
private static final byte[] SEGMENT_METADATA_CACHE_PREFIX = new byte[]{0x4};

@Override
Expand Down Expand Up @@ -228,6 +231,6 @@ public int compare(SegmentAnalysis left, SegmentAnalysis right)
{
return left.getId().compareTo(right.getId());
}
};
}.nullsFirst();
}
}
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.5.5-SNAPSHOT</version>
<version>0.5.6-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Longs;
import com.metamx.druid.processing.ColumnSelectorFactory;
Expand All @@ -40,6 +41,8 @@ public CountAggregatorFactory(
@JsonProperty("name") String name
)
{
Preconditions.checkNotNull(name, "Must have a valid, non-null aggregator name");

this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.metamx.druid.aggregation;

import com.google.common.collect.Ordering;
import com.google.common.primitives.Doubles;
import com.metamx.druid.processing.FloatMetricSelector;

Expand All @@ -28,14 +29,14 @@
*/
public class DoubleSumAggregator implements Aggregator
{
static final Comparator COMPARATOR = new Comparator()
static final Comparator COMPARATOR = new Ordering()
{
@Override
public int compare(Object o, Object o1)
{
return Doubles.compare(((Number) o).doubleValue(), ((Number) o1).doubleValue());
}
};
}.nullsFirst();

static double combineValues(Object lhs, Object rhs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Doubles;
import com.metamx.druid.processing.ColumnSelectorFactory;

Expand All @@ -44,6 +45,9 @@ public DoubleSumAggregatorFactory(
@JsonProperty("fieldName") final String fieldName
)
{
Preconditions.checkNotNull(name, "Must have a valid, non-null aggregator name");
Preconditions.checkNotNull(fieldName, "Must have a valid, non-null fieldName");

this.name = name;
this.fieldName = fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Floats;
import com.google.common.primitives.Longs;
import com.metamx.druid.processing.ColumnSelectorFactory;
Expand Down Expand Up @@ -49,12 +51,18 @@ public HistogramAggregatorFactory(
@JsonProperty("breaks") final List<Float> breaksList
)
{
Preconditions.checkNotNull(name, "Must have a valid, non-null aggregator name");
Preconditions.checkNotNull(fieldName, "Must have a valid, non-null fieldName");

this.name = name;
this.fieldName = fieldName;
this.breaksList = breaksList;
this.breaks = new float[breaksList.size()];
for(int i = 0; i < breaksList.size(); ++i) this.breaks[i] = breaksList.get(i);
this.breaksList = (breaksList == null) ? Lists.<Float>newArrayList() :breaksList;
this.breaks = new float[this.breaksList.size()];
for (int i = 0; i < this.breaksList.size(); ++i) {
this.breaks[i] = this.breaksList.get(i);
}
}

@Override
public Aggregator factorize(ColumnSelectorFactory metricFactory)
{
Expand Down Expand Up @@ -95,14 +103,12 @@ public AggregatorFactory getCombiningFactory()
@Override
public Object deserialize(Object object)
{
if (object instanceof byte []) {
return Histogram.fromBytes((byte []) object);
}
else if (object instanceof ByteBuffer) {
if (object instanceof byte[]) {
return Histogram.fromBytes((byte[]) object);
} else if (object instanceof ByteBuffer) {
return Histogram.fromBytes((ByteBuffer) object);
}
else if(object instanceof String) {
byte[] bytes = Base64.decodeBase64(((String)object).getBytes(Charsets.UTF_8));
} else if (object instanceof String) {
byte[] bytes = Base64.decodeBase64(((String) object).getBytes(Charsets.UTF_8));
return Histogram.fromBytes(bytes);
}
return object;
Expand All @@ -111,7 +117,7 @@ else if(object instanceof String) {
@Override
public Object finalizeComputation(Object object)
{
return ((Histogram)object).asVisual();
return ((Histogram) object).asVisual();
}

@Override
Expand Down Expand Up @@ -149,7 +155,7 @@ public byte[] getCacheKey()
@Override
public String getTypeName()
{
throw new UnsupportedOperationException("HistogramAggregatorFactory does not support getTypeName()");
throw new UnsupportedOperationException("HistogramAggregatorFactory does not support getTypeName()");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Doubles;
import com.metamx.druid.processing.ColumnSelectorFactory;
Expand Down Expand Up @@ -51,7 +52,6 @@ public class JavaScriptAggregatorFactory implements AggregatorFactory
private final String fnCombine;



private final JavaScriptAggregator.ScriptAggregator compiledScript;

@JsonCreator
Expand All @@ -63,6 +63,12 @@ public JavaScriptAggregatorFactory(
@JsonProperty("fnCombine") final String fnCombine
)
{
Preconditions.checkNotNull(name, "Must have a valid, non-null aggregator name");
Preconditions.checkNotNull(fieldNames, "Must have a valid, non-null fieldNames");
Preconditions.checkNotNull(fnAggregate, "Must have a valid, non-null fnAggregate");
Preconditions.checkNotNull(fnReset, "Must have a valid, non-null fnReset");
Preconditions.checkNotNull(fnCombine, "Must have a valid, non-null fnCombine");

this.name = name;
this.fieldNames = fieldNames;

Expand All @@ -83,7 +89,8 @@ public Aggregator factorize(final ColumnSelectorFactory columnFactory)
new com.google.common.base.Function<String, ObjectColumnSelector>()
{
@Override
public ObjectColumnSelector apply(@Nullable String s) {
public ObjectColumnSelector apply(@Nullable String s)
{
return columnFactory.makeObjectColumnSelector(s);
}
}
Expand All @@ -101,7 +108,8 @@ public BufferAggregator factorizeBuffered(final ColumnSelectorFactory columnSele
new com.google.common.base.Function<String, ObjectColumnSelector>()
{
@Override
public ObjectColumnSelector apply(@Nullable String s) {
public ObjectColumnSelector apply(@Nullable String s)
{
return columnSelectorFactory.makeObjectColumnSelector(s);
}
}
Expand Down Expand Up @@ -148,7 +156,8 @@ public String getName()
}

@JsonProperty
public List<String> getFieldNames() {
public List<String> getFieldNames()
{
return fieldNames;
}

Expand Down Expand Up @@ -182,7 +191,7 @@ public byte[] getCacheKey()
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] fieldNameBytes = Joiner.on(",").join(fieldNames).getBytes(Charsets.UTF_8);
byte[] sha1 = md.digest((fnAggregate+fnReset+fnCombine).getBytes(Charsets.UTF_8));
byte[] sha1 = md.digest((fnAggregate + fnReset + fnCombine).getBytes(Charsets.UTF_8));

return ByteBuffer.allocate(1 + fieldNameBytes.length + sha1.length)
.put(CACHE_TYPE_ID)
Expand Down Expand Up @@ -225,7 +234,11 @@ public String toString()
'}';
}

public static JavaScriptAggregator.ScriptAggregator compileScript(final String aggregate, final String reset, final String combine)
public static JavaScriptAggregator.ScriptAggregator compileScript(
final String aggregate,
final String reset,
final String combine
)
{
final ContextFactory contextFactory = ContextFactory.getGlobal();
Context context = contextFactory.enterContext();
Expand All @@ -234,8 +247,8 @@ public static JavaScriptAggregator.ScriptAggregator compileScript(final String a
final ScriptableObject scope = context.initStandardObjects();

final Function fnAggregate = context.compileFunction(scope, aggregate, "aggregate", 1, null);
final Function fnReset = context.compileFunction(scope, reset, "reset", 1, null);
final Function fnCombine = context.compileFunction(scope, combine, "combine", 1, null);
final Function fnReset = context.compileFunction(scope, reset, "reset", 1, null);
final Function fnCombine = context.compileFunction(scope, combine, "combine", 1, null);
Context.exit();

return new JavaScriptAggregator.ScriptAggregator()
Expand All @@ -244,7 +257,9 @@ public static JavaScriptAggregator.ScriptAggregator compileScript(final String a
public double aggregate(final double current, final ObjectColumnSelector[] selectorList)
{
Context cx = Context.getCurrentContext();
if(cx == null) cx = contextFactory.enterContext();
if (cx == null) {
cx = contextFactory.enterContext();
}

final int size = selectorList.length;
final Object[] args = new Object[size + 1];
Expand Down Expand Up @@ -292,8 +307,9 @@ public Object run(final Context cx)
}

@Override
public void close() {
if(Context.getCurrentContext() != null) {
public void close()
{
if (Context.getCurrentContext() != null) {
Context.exit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Longs;
import com.metamx.druid.processing.ColumnSelectorFactory;

Expand All @@ -44,6 +45,9 @@ public LongSumAggregatorFactory(
@JsonProperty("fieldName") final String fieldName
)
{
Preconditions.checkNotNull(name, "Must have a valid, non-null aggregator name");
Preconditions.checkNotNull(fieldName, "Must have a valid, non-null fieldName");

this.name = name;
this.fieldName = fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Doubles;
import com.metamx.druid.processing.ColumnSelectorFactory;

Expand All @@ -44,6 +45,9 @@ public MaxAggregatorFactory(
@JsonProperty("fieldName") final String fieldName
)
{
Preconditions.checkNotNull(name, "Must have a valid, non-null aggregator name");
Preconditions.checkNotNull(fieldName, "Must have a valid, non-null fieldName");

this.name = name;
this.fieldName = fieldName;
}
Expand Down
Loading

0 comments on commit b2cb9be

Please sign in to comment.