-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Allow writing InputRowParser extensions that use hadoop/any libraries #1695
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.indexer; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.metamx.common.IAE; | ||
import io.druid.data.input.InputRow; | ||
import io.druid.data.input.impl.InputRowParser; | ||
import io.druid.data.input.impl.ParseSpec; | ||
import io.druid.data.input.impl.StringInputRowParser; | ||
import org.apache.hadoop.io.BytesWritable; | ||
import org.apache.hadoop.io.Text; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
*/ | ||
public class HadoopyStringInputRowParser implements InputRowParser<Object> | ||
{ | ||
private final StringInputRowParser parser; | ||
|
||
public HadoopyStringInputRowParser(@JsonProperty("parseSpec") ParseSpec parseSpec) | ||
{ | ||
this.parser = new StringInputRowParser(parseSpec); | ||
} | ||
|
||
@Override | ||
public InputRow parse(Object input) | ||
{ | ||
if (input instanceof Text) { | ||
return parser.parse(((Text) input).toString()); | ||
} else if (input instanceof BytesWritable) { | ||
BytesWritable valueBytes = (BytesWritable) input; | ||
return parser.parse(ByteBuffer.wrap(valueBytes.getBytes(), 0, valueBytes.getLength())); | ||
} else { | ||
throw new IAE("can't convert type [%s] to InputRow", input.getClass().getName()); | ||
} | ||
} | ||
|
||
@JsonProperty | ||
@Override | ||
public ParseSpec getParseSpec() | ||
{ | ||
return parser.getParseSpec(); | ||
} | ||
|
||
@Override | ||
public InputRowParser withParseSpec(ParseSpec parseSpec) | ||
{ | ||
return new HadoopyStringInputRowParser(parseSpec); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.indexer; | ||
|
||
import com.fasterxml.jackson.databind.Module; | ||
import com.fasterxml.jackson.databind.jsontype.NamedType; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.google.inject.Binder; | ||
import io.druid.initialization.DruidModule; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
*/ | ||
public class IndexingHadoopModule implements DruidModule | ||
{ | ||
@Override | ||
public List<? extends Module> getJacksonModules() | ||
{ | ||
return Arrays.<Module>asList( | ||
new SimpleModule("IndexingHadoopModule") | ||
.registerSubtypes( | ||
new NamedType(HadoopyStringInputRowParser.class, "hadoopyString") | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,23 +17,28 @@ | |
|
||
package io.druid.indexer; | ||
|
||
import com.fasterxml.jackson.databind.InjectableValues; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.base.Throwables; | ||
import com.google.common.collect.Lists; | ||
import io.druid.indexer.partitions.HashedPartitionsSpec; | ||
import io.druid.metadata.MetadataStorageConnectorConfig; | ||
import io.druid.indexer.partitions.PartitionsSpec; | ||
import io.druid.indexer.partitions.SingleDimensionPartitionsSpec; | ||
import io.druid.indexer.updater.MetadataStorageUpdaterJobSpec; | ||
import io.druid.jackson.DefaultObjectMapper; | ||
import io.druid.metadata.MetadataStorageConnectorConfig; | ||
import io.druid.segment.indexing.granularity.UniformGranularitySpec; | ||
import org.joda.time.Interval; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class HadoopIngestionSpecTest | ||
{ | ||
private static final ObjectMapper jsonMapper = new DefaultObjectMapper(); | ||
private static final ObjectMapper jsonMapper; | ||
static { | ||
jsonMapper = new DefaultObjectMapper(); | ||
jsonMapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, jsonMapper)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Injected ObjectMappers should be tagged with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
} | ||
|
||
@Test | ||
public void testGranularitySpec() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ | |
|
||
package io.druid.indexer; | ||
|
||
import com.fasterxml.jackson.databind.BeanProperty; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.InjectableValues; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
@@ -50,7 +53,15 @@ public class HadoopIngestionSpecUpdateDatasourcePathSpecSegmentsTest | |
private final String testDatasource = "test"; | ||
private final Interval testDatasourceInterval = new Interval("1970/3000"); | ||
private final Interval testDatasourceIntervalPartial = new Interval("2050/3000"); | ||
private final ObjectMapper jsonMapper = new DefaultObjectMapper(); | ||
private final ObjectMapper jsonMapper; | ||
|
||
public HadoopIngestionSpecUpdateDatasourcePathSpecSegmentsTest() | ||
{ | ||
jsonMapper = new DefaultObjectMapper(); | ||
jsonMapper.setInjectableValues( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
new InjectableValues.Std().addValue(ObjectMapper.class, jsonMapper) | ||
); | ||
} | ||
|
||
private static final DataSegment SEGMENT = new DataSegment( | ||
"test1", | ||
|
@@ -155,7 +166,8 @@ private HadoopDruidIndexerConfig testRunUpdateSegmentListIfDatasourcePathSpecIsU | |
ImmutableList.of( | ||
new Interval("2010-01-01/P1D") | ||
) | ||
) | ||
), | ||
jsonMapper | ||
), | ||
new HadoopIOConfig( | ||
jsonMapper.convertValue(datasourcePathSpec, Map.class), | ||
|
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.
Does this work recursively? Or would you get a Map where the values are regular objects rather than other Maps?
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.
it does convert recursively, everything to Map. also, it wouldn't matter for this test as long as
produces the right thing. Specific changes for DataSchema serde are tested in DataSchemaTest .