Merge branch 'master' into spatial

Conflicts:
	client/src/main/java/com/metamx/druid/query/group/DefaultLimitSpec.java
	client/src/main/java/com/metamx/druid/query/group/GroupByQueryQueryToolChest.java
	client/src/main/java/com/metamx/druid/query/group/LimitSpec.java
	pom.xml
This commit is contained in:
fjy 2013-05-03 16:20:37 -07:00
commit 3417c50e98
17 changed files with 175 additions and 84 deletions

View File

@ -18,8 +18,7 @@
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.metamx.druid</groupId>
<artifactId>druid-client</artifactId>
@ -29,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -121,9 +121,18 @@ public class Initialization
if (tmp_props.getProperty(zkHostsProperty) != null) {
final ConfigurationObjectFactory factory = Config.createFactory(tmp_props);
ZkPathsConfig config;
try {
config = factory.build(ZkPathsConfig.class);
}
catch (IllegalArgumentException e) {
log.warn(e, "Unable to build ZkPathsConfig. Cannot load properties from ZK.");
config = null;
}
if (config != null) {
Lifecycle lifecycle = new Lifecycle();
try {
final ZkPathsConfig config = factory.build(ZkPathsConfig.class);
CuratorFramework curator = makeCuratorFramework(factory.build(CuratorConfig.class), lifecycle);
lifecycle.start();
@ -145,6 +154,7 @@ public class Initialization
finally {
lifecycle.stop();
}
}
} else {
log.warn("property[%s] not set, skipping ZK-specified properties.", zkHostsProperty);
}

View File

@ -1,10 +1,34 @@
/*
* 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.query.group;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs;
import com.metamx.common.ISE;
import com.metamx.druid.input.MapBasedRow;
import com.metamx.druid.input.Row;
import java.nio.ByteBuffer;
import java.util.Comparator;
@ -19,6 +43,7 @@ public class DefaultLimitSpec implements LimitSpec
private final List<String> orderBy;
private final int limit;
private final Comparator<Row> comparator;
@JsonCreator
public DefaultLimitSpec(
@ -28,12 +53,14 @@ public class DefaultLimitSpec implements LimitSpec
{
this.orderBy = (orderBy == null) ? Lists.<String>newArrayList() : orderBy;
this.limit = limit;
this.comparator = makeComparator();
}
public DefaultLimitSpec()
{
this.orderBy = Lists.newArrayList();
this.limit = 0;
this.comparator = makeComparator();
}
@JsonProperty
@ -51,9 +78,9 @@ public class DefaultLimitSpec implements LimitSpec
}
@Override
public Comparator getComparator()
public Comparator<Row> getComparator()
{
return null;
return comparator;
}
@Override
@ -78,4 +105,46 @@ public class DefaultLimitSpec implements LimitSpec
", limit=" + limit +
'}';
}
private Comparator<Row> makeComparator()
{
Ordering<Row> ordering = new Ordering<Row>()
{
@Override
public int compare(Row left, Row right)
{
return Longs.compare(left.getTimestampFromEpoch(), right.getTimestampFromEpoch());
}
};
for (final String dimension : orderBy) {
ordering = ordering.compound(
new Comparator<Row>()
{
@Override
public int compare(Row left, Row right)
{
if (left instanceof MapBasedRow && right instanceof MapBasedRow) {
// There are no multi-value dimensions at this point, they should have been flattened out
String leftDimVal = left.getDimension(dimension).get(0);
String rightDimVal = right.getDimension(dimension).get(0);
return leftDimVal.compareTo(rightDimVal);
} else {
throw new ISE("Unknown type for rows[%s, %s]", left.getClass(), right.getClass());
}
}
}
);
}
final Ordering<Row> theOrdering = ordering;
return new Comparator<Row>()
{
@Override
public int compare(Row row, Row row2)
{
return theOrdering.compare(row, row2);
}
};
}
}

View File

@ -50,7 +50,6 @@ import org.joda.time.Interval;
import org.joda.time.Minutes;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@ -162,7 +161,7 @@ public class GroupByQueryQueryToolChest extends QueryToolChest<Row, GroupByQuery
// sort results to be returned
if (!query.getLimitSpec().getOrderBy().isEmpty()) {
retVal = Sequences.sort(retVal, makeComparator(query));
retVal = Sequences.sort(retVal, query.getLimitSpec().getComparator());
}
return Sequences.limit(
@ -221,46 +220,4 @@ public class GroupByQueryQueryToolChest extends QueryToolChest<Row, GroupByQuery
{
return TYPE_REFERENCE;
}
private Comparator<Row> makeComparator(GroupByQuery query)
{
Ordering<Row> ordering = new Ordering<Row>()
{
@Override
public int compare(Row left, Row right)
{
return Longs.compare(left.getTimestampFromEpoch(), right.getTimestampFromEpoch());
}
};
for (final String dimension : query.getLimitSpec().getOrderBy()) {
ordering = ordering.compound(
new Comparator<Row>()
{
@Override
public int compare(Row left, Row right)
{
if (left instanceof MapBasedRow && right instanceof MapBasedRow) {
// There are no multi-value dimensions at this point, they should have been flattened out
String leftDimVal = left.getDimension(dimension).get(0);
String rightDimVal = right.getDimension(dimension).get(0);
return leftDimVal.compareTo(rightDimVal);
} else {
throw new ISE("Unknown type for rows[%s, %s]", left.getClass(), right.getClass());
}
}
}
);
}
final Ordering<Row> theOrdering = ordering;
return new Comparator<Row>()
{
@Override
public int compare(Row row, Row row2)
{
return theOrdering.compare(row, row2);
}
};
}
}

View File

@ -21,6 +21,7 @@ package com.metamx.druid.query.group;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.metamx.druid.input.Row;
import java.util.Comparator;
import java.util.List;
@ -37,7 +38,7 @@ public interface LimitSpec
public int getLimit();
public Comparator getComparator();
public Comparator<Row> getComparator();
public byte[] getCacheKey();
}

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -42,7 +42,7 @@ public abstract class DbConnectorConfig
@Config("druid.database.segmentTable")
public abstract String getSegmentTable();
@JsonProperty("validationQuery")
@JsonProperty("useValidationQuery")
@Config("druid.database.validation")
public boolean isValidationQuery() {
return false;

View File

@ -9,7 +9,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

11
pom.xml
View File

@ -23,7 +23,7 @@
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<packaging>pom</packaging>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
<name>druid</name>
<description>druid</description>
<scm>
@ -38,7 +38,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<metamx.java-util.version>0.22.3-SNAPSHOT</metamx.java-util.version>
<metamx.java-util.version>0.22.3</metamx.java-util.version>
<netflix.curator.version>2.0.1-21-22</netflix.curator.version>
</properties>
@ -51,7 +51,7 @@
<module>merger</module>
<module>realtime</module>
<module>examples</module>
<module>druid-services</module>
<module>services</module>
</modules>
<dependencyManagement>
@ -419,6 +419,11 @@
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -24,11 +24,11 @@
<artifactId>druid-services</artifactId>
<name>druid-services</name>
<description>druid-services</description>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
<parent>
<groupId>com.metamx</groupId>
<artifactId>druid</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.3-SNAPSHOT</version>
</parent>
<dependencies>
@ -42,7 +42,6 @@
<artifactId>druid-server</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
@ -64,6 +63,25 @@
</execution>
</executions>
</plugin>
<!--
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
</project>

View File

@ -0,0 +1,31 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/bin</directory>
<includes>
<include>*.sh</include>
</includes>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>/</directory>
<includes>
<include>LICENSE</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<outputDirectory>lib/</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>

1
services/src/bin/run.sh Normal file
View File

@ -0,0 +1 @@
echo "Hello World!"