Skip to content

Commit

Permalink
buildV9Directly in MergeTask and AppendTask (apache#3976)
Browse files Browse the repository at this point in the history
* buildV9Directly in MergeTask and AppendTask

* add doc
  • Loading branch information
kaijianding authored and fjy committed Feb 28, 2017
1 parent 78b8a57 commit ef6a19c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/content/ingestion/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Append tasks append a list of segments together into a single segment (one after
"id": <task_id>,
"dataSource": <task_datasource>,
"segments": <JSON list of DataSegment objects to append>,
"buildV9Directly": <true or false, default true>,
"aggregations": <optional list of aggregators>
}
```
Expand All @@ -180,6 +181,7 @@ The grammar is:
"dataSource": <task_datasource>,
"aggregations": <list of aggregators>,
"rollup": <whether or not to rollup data during a merge>,
"buildV9Directly": <true or false, default true>,
"segments": <JSON list of DataSegment objects to merge>
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.common.collect.Ordering;
import io.druid.indexing.common.TaskToolbox;
import io.druid.query.aggregation.AggregatorFactory;
import io.druid.segment.IndexMerger;
import io.druid.segment.IndexSpec;
import io.druid.segment.IndexableAdapter;
import io.druid.segment.QueryableIndexIndexableAdapter;
Expand All @@ -49,9 +50,10 @@
*/
public class AppendTask extends MergeTaskBase
{

private static final Boolean defaultBuildV9Directly = Boolean.TRUE;
private final IndexSpec indexSpec;
private final List<AggregatorFactory> aggregators;
private final Boolean buildV9Directly;

@JsonCreator
public AppendTask(
Expand All @@ -60,12 +62,14 @@ public AppendTask(
@JsonProperty("segments") List<DataSegment> segments,
@JsonProperty("aggregations") List<AggregatorFactory> aggregators,
@JsonProperty("indexSpec") IndexSpec indexSpec,
@JsonProperty("buildV9Directly") Boolean buildV9Directly,
@JsonProperty("context") Map<String, Object> context
)
{
super(id, dataSource, segments, context);
this.indexSpec = indexSpec == null ? new IndexSpec() : indexSpec;
this.aggregators = aggregators;
this.buildV9Directly = buildV9Directly == null ? defaultBuildV9Directly : buildV9Directly;
}

@Override
Expand Down Expand Up @@ -131,7 +135,8 @@ public boolean apply(Rowboat input)
);
}

return toolbox.getIndexMerger().append(
IndexMerger indexMerger = buildV9Directly ? toolbox.getIndexMergerV9() : toolbox.getIndexMerger();
return indexMerger.append(
adapters,
aggregators == null ? null : aggregators.toArray(new AggregatorFactory[aggregators.size()]),
outDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.common.collect.Lists;
import io.druid.indexing.common.TaskToolbox;
import io.druid.query.aggregation.AggregatorFactory;
import io.druid.segment.IndexMerger;
import io.druid.segment.IndexSpec;
import io.druid.segment.QueryableIndex;
import io.druid.timeline.DataSegment;
Expand All @@ -42,10 +43,12 @@
*/
public class MergeTask extends MergeTaskBase
{
private static final Boolean defaultBuildV9Directly = Boolean.TRUE;
@JsonIgnore
private final List<AggregatorFactory> aggregators;
private final Boolean rollup;
private final IndexSpec indexSpec;
private final Boolean buildV9Directly;

@JsonCreator
public MergeTask(
Expand All @@ -55,20 +58,23 @@ public MergeTask(
@JsonProperty("aggregations") List<AggregatorFactory> aggregators,
@JsonProperty("rollup") Boolean rollup,
@JsonProperty("indexSpec") IndexSpec indexSpec,
@JsonProperty("buildV9Directly") Boolean buildV9Directly,
@JsonProperty("context") Map<String, Object> context
)
{
super(id, dataSource, segments, context);
this.aggregators = Preconditions.checkNotNull(aggregators, "null aggregations");
this.rollup = rollup == null ? Boolean.TRUE : rollup;
this.indexSpec = indexSpec == null ? new IndexSpec() : indexSpec;
this.buildV9Directly = buildV9Directly == null ? defaultBuildV9Directly : buildV9Directly;
}

@Override
public File merge(final TaskToolbox toolbox, final Map<DataSegment, File> segments, final File outDir)
throws Exception
{
return toolbox.getIndexMerger().mergeQueryableIndex(
IndexMerger indexMerger = buildV9Directly ? toolbox.getIndexMergerV9() : toolbox.getIndexMerger();
return indexMerger.mergeQueryableIndex(
Lists.transform(
ImmutableList.copyOf(segments.values()),
new Function<File, QueryableIndex>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public void testMergeTaskSerde() throws Exception
aggregators,
true,
indexSpec,
true,
null
);

Expand Down Expand Up @@ -529,6 +530,7 @@ public void testAppendTaskSerde() throws Exception
new CountAggregatorFactory("cnt")
),
indexSpec,
true,
null
);

Expand Down

0 comments on commit ef6a19c

Please sign in to comment.