-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 #1695 from himanshug/allow_hadoop_based_input_row_…
…parser Allow writing InputRowParser extensions that use hadoop/any libraries
- Loading branch information
Showing
29 changed files
with
754 additions
and
254 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
69 changes: 69 additions & 0 deletions
69
indexing-hadoop/src/main/java/io/druid/indexer/HadoopyStringInputRowParser.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,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); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
indexing-hadoop/src/main/java/io/druid/indexer/IndexingHadoopModule.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,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) | ||
{ | ||
} | ||
} |
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
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.