forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#528 from metamx/union-query-source
Union query source
- Loading branch information
Showing
34 changed files
with
419 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
processing/src/main/java/io/druid/query/DataSourceUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
processing/src/main/java/io/druid/query/UnionDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Druid - a distributed column store. | ||
* | ||
* 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. | ||
* | ||
* This file Copyright (C) 2014 N3TWORK, Inc. and contributed to the Druid project | ||
* under the Druid Corporate Contributor License Agreement. | ||
*/ | ||
|
||
package io.druid.query; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
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; | ||
|
||
public class UnionDataSource implements DataSource | ||
{ | ||
@JsonProperty | ||
private final List<TableDataSource> dataSources; | ||
|
||
@JsonCreator | ||
public UnionDataSource(@JsonProperty("dataSources") List<TableDataSource> dataSources) | ||
{ | ||
Preconditions.checkNotNull(dataSources, "dataSources cannot be null for unionDataSource"); | ||
this.dataSources = dataSources; | ||
} | ||
|
||
@Override | ||
public List<String> getNames() | ||
{ | ||
return Lists.transform( | ||
dataSources, | ||
new Function<TableDataSource, String>() | ||
{ | ||
@Override | ||
public String apply(TableDataSource input) | ||
{ | ||
return Iterables.getOnlyElement(input.getNames()); | ||
} | ||
} | ||
); | ||
} | ||
|
||
@JsonProperty | ||
public List<TableDataSource> getDataSources() | ||
{ | ||
return dataSources; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
UnionDataSource that = (UnionDataSource) o; | ||
|
||
if (!dataSources.equals(that.dataSources)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return dataSources.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "UnionDataSource{" + | ||
"dataSources=" + dataSources + | ||
'}'; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
processing/src/main/java/io/druid/query/UnionQueryRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Druid - a distributed column store. | ||
* | ||
* 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. | ||
* | ||
* This file Copyright (C) 2014 N3TWORK, Inc. and contributed to the Druid project | ||
* under the Druid Corporate Contributor License Agreement. | ||
*/ | ||
|
||
package io.druid.query; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.Iterables; | ||
import com.metamx.common.guava.Sequence; | ||
import com.metamx.common.guava.Sequences; | ||
|
||
public class UnionQueryRunner<T> implements QueryRunner<T> | ||
{ | ||
private final QueryRunner<T> baseRunner; | ||
|
||
public UnionQueryRunner(QueryRunner<T> baseRunner) | ||
{ | ||
this.baseRunner = baseRunner; | ||
} | ||
|
||
@Override | ||
public Sequence<T> run(final Query<T> query) | ||
{ | ||
DataSource dataSource = query.getDataSource(); | ||
if (dataSource instanceof UnionDataSource) { | ||
return Sequences.concat( | ||
Iterables.transform( | ||
((UnionDataSource) dataSource).getDataSources(), | ||
new Function<DataSource, Sequence<T>>() | ||
{ | ||
@Override | ||
public Sequence<T> apply(DataSource singleSource) | ||
{ | ||
return baseRunner.run( | ||
query.withDataSource(singleSource) | ||
); | ||
} | ||
} | ||
) | ||
); | ||
} else { | ||
return baseRunner.run(query); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.