-
Notifications
You must be signed in to change notification settings - Fork 3.8k
offline appenderator factory. #3483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
60 changes: 60 additions & 0 deletions
60
...c/main/java/io/druid/segment/realtime/appenderator/DefaultOfflineAppenderatorFactory.java
This file contains hidden or 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,60 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.segment.realtime.appenderator; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JacksonInject; | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.druid.segment.IndexIO; | ||
| import io.druid.segment.IndexMerger; | ||
| import io.druid.segment.indexing.DataSchema; | ||
| import io.druid.segment.indexing.RealtimeTuningConfig; | ||
| import io.druid.segment.loading.DataSegmentPusher; | ||
| import io.druid.segment.realtime.FireDepartmentMetrics; | ||
|
|
||
|
|
||
| public class DefaultOfflineAppenderatorFactory implements AppenderatorFactory | ||
| { | ||
| private final DataSegmentPusher dataSegmentPusher; | ||
| private final ObjectMapper objectMapper; | ||
| private final IndexIO indexIO; | ||
| private final IndexMerger indexMerger; | ||
|
|
||
| @JsonCreator | ||
| public DefaultOfflineAppenderatorFactory( | ||
| @JacksonInject DataSegmentPusher dataSegmentPusher, | ||
| @JacksonInject ObjectMapper objectMapper, | ||
| @JacksonInject IndexIO indexIO, | ||
| @JacksonInject IndexMerger indexMerger | ||
| ) { | ||
| this.dataSegmentPusher = dataSegmentPusher; | ||
| this.objectMapper = objectMapper; | ||
| this.indexIO = indexIO; | ||
| this.indexMerger = indexMerger; | ||
| } | ||
|
|
||
| @Override | ||
| public Appenderator build( | ||
| DataSchema schema, RealtimeTuningConfig config, FireDepartmentMetrics metrics | ||
| ) | ||
| { | ||
| return Appenderators.createOffline(schema, config, metrics, dataSegmentPusher, objectMapper, indexIO, indexMerger); | ||
| } | ||
| } |
This file contains hidden or 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
172 changes: 172 additions & 0 deletions
172
...st/java/io/druid/segment/realtime/appenderator/DefaultOfflineAppenderatorFactoryTest.java
This file contains hidden or 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,172 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.segment.realtime.appenderator; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.common.base.Suppliers; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.inject.Binder; | ||
| import com.google.inject.Injector; | ||
| import com.google.inject.Module; | ||
| import com.google.inject.name.Names; | ||
| import com.metamx.common.Granularity; | ||
| import io.druid.data.input.impl.DimensionsSpec; | ||
| import io.druid.data.input.impl.JSONParseSpec; | ||
| import io.druid.data.input.impl.MapInputRowParser; | ||
| import io.druid.data.input.impl.TimestampSpec; | ||
| import io.druid.granularity.QueryGranularities; | ||
| import io.druid.guice.GuiceInjectors; | ||
| import io.druid.initialization.Initialization; | ||
| import io.druid.query.DruidProcessingConfig; | ||
| import io.druid.query.aggregation.AggregatorFactory; | ||
| import io.druid.query.aggregation.CountAggregatorFactory; | ||
| import io.druid.query.aggregation.LongSumAggregatorFactory; | ||
| import io.druid.segment.column.ColumnConfig; | ||
| import io.druid.segment.indexing.DataSchema; | ||
| import io.druid.segment.indexing.RealtimeTuningConfig; | ||
| import io.druid.segment.indexing.granularity.UniformGranularitySpec; | ||
| import io.druid.segment.realtime.FireDepartmentMetrics; | ||
| import io.druid.segment.realtime.plumber.Committers; | ||
| import io.druid.timeline.partition.LinearShardSpec; | ||
| import org.joda.time.Interval; | ||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| public class DefaultOfflineAppenderatorFactoryTest | ||
| { | ||
| @Rule | ||
| public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
|
||
| @Test | ||
| public void testBuild() throws IOException, SegmentNotWritableException | ||
| { | ||
| Injector injector = Initialization.makeInjectorWithModules( | ||
| GuiceInjectors.makeStartupInjector(), | ||
| ImmutableList.<Module>of(new Module() | ||
| { | ||
| @Override | ||
| public void configure(Binder binder) | ||
| { | ||
| binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/tool"); | ||
| binder.bindConstant().annotatedWith(Names.named("servicePort")).to(9999); | ||
| binder.bind(DruidProcessingConfig.class).toInstance( | ||
| new DruidProcessingConfig() | ||
| { | ||
| @Override | ||
| public String getFormatString() | ||
| { | ||
| return "processing-%s"; | ||
| } | ||
|
|
||
| @Override | ||
| public int intermediateComputeSizeBytes() | ||
| { | ||
| return 100 * 1024 * 1024; | ||
| } | ||
|
|
||
| @Override | ||
| public int getNumThreads() | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| @Override | ||
| public int columnCacheSizeBytes() | ||
| { | ||
| return 25 * 1024 * 1024; | ||
| } | ||
| } | ||
| ); | ||
| binder.bind(ColumnConfig.class).to(DruidProcessingConfig.class); | ||
| } | ||
| } | ||
| ) | ||
| ); | ||
| ObjectMapper objectMapper = injector.getInstance(ObjectMapper.class); | ||
| AppenderatorFactory defaultOfflineAppenderatorFactory = objectMapper.reader(AppenderatorFactory.class) | ||
| .readValue("{\"type\":\"offline\"}"); | ||
|
|
||
| final Map<String, Object> parserMap = objectMapper.convertValue( | ||
| new MapInputRowParser( | ||
| new JSONParseSpec( | ||
| new TimestampSpec("ts", "auto", null), | ||
| new DimensionsSpec(null, null, null), | ||
| null, | ||
| null | ||
| ) | ||
| ), | ||
| Map.class | ||
| ); | ||
| DataSchema schema = new DataSchema( | ||
| "dataSourceName", | ||
| parserMap, | ||
| new AggregatorFactory[]{ | ||
| new CountAggregatorFactory("count"), | ||
| new LongSumAggregatorFactory("met", "met") | ||
| }, | ||
| new UniformGranularitySpec(Granularity.MINUTE, QueryGranularities.NONE, null), | ||
| objectMapper | ||
| ); | ||
|
|
||
| RealtimeTuningConfig tuningConfig = new RealtimeTuningConfig( | ||
| 75000, | ||
| null, | ||
| null, | ||
| temporaryFolder.newFolder(), | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| 0, | ||
| 0, | ||
| null, | ||
| null | ||
| ); | ||
|
|
||
| try (Appenderator appenderator = defaultOfflineAppenderatorFactory.build( | ||
| schema, | ||
| tuningConfig, | ||
| new FireDepartmentMetrics() | ||
| )) { | ||
| Assert.assertEquals("dataSourceName", appenderator.getDataSource()); | ||
| Assert.assertEquals(null, appenderator.startJob()); | ||
| SegmentIdentifier identifier = new SegmentIdentifier( | ||
| "dataSourceName", | ||
| new Interval("2000/2001"), | ||
| "A", | ||
| new LinearShardSpec(0) | ||
| ); | ||
| Assert.assertEquals(0, ((AppenderatorImpl) appenderator).getRowsInMemory()); | ||
| appenderator.add(identifier, AppenderatorTest.IR("2000", "bar", 1), Suppliers.ofInstance(Committers.nil())); | ||
| Assert.assertEquals(1, ((AppenderatorImpl) appenderator).getRowsInMemory()); | ||
| appenderator.add(identifier, AppenderatorTest.IR("2000", "baz", 1), Suppliers.ofInstance(Committers.nil())); | ||
| Assert.assertEquals(2, ((AppenderatorImpl) appenderator).getRowsInMemory()); | ||
| appenderator.close(); | ||
| Assert.assertEquals(0, ((AppenderatorImpl) appenderator).getRowsInMemory()); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when can this be null ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is part of bug fix. when using offline appenderator we don't server queries so no need for cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also remove the null check from the constr also then?