-
Notifications
You must be signed in to change notification settings - Fork 55
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
Implement parquet simple record as a source for the druid spark indexer #111
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4a20864
Implement parquet simple record as a source for the druid spark indexer
Igosuki 4c9b4d6
Exclude guava deps
Igosuki d37e617
DC/OS git submit script
Igosuki 558f3fe
Druid 0.11.0
Igosuki ab98e37
Use druid 0.11.1-SNAPSHOT
Igosuki 3624573
Use latest druid and the avro flattener api with parquet
Igosuki 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 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,121 @@ | ||
#!/usr/bin/shs | ||
|
||
set -x | ||
|
||
# Define target environment | ||
if [ "$environment" = "staging" ]; then SUFFIX="-staging"; fi | ||
|
||
|
||
# SPARK_DCOS_URL the spark service url | ||
# SPARK_MASTER spark master url, including port | ||
# SPARK_ARGS spark arguments, as a json array's content | ||
# SPARK_JARS list of urls where to download jars from | ||
# SPARK_CLASS_NAME class name of the spark app | ||
# SPARK_APP_NAME spark app name for display | ||
# SPARK_DRIVER_CORES driver cores | ||
# SPARK_DRIVER_MEMORY driver memory | ||
# SPARK_CORES_MAX max available cores on mesos | ||
# SPARK_EXECUTOR_MEMORY executor memory | ||
# SPARK_CASSANDRA_HOST cassandra host name | ||
# SPARK_CASSANDRA_USER cassandra user name | ||
# SPARK_CASSANDRA_PASSWORD cassandra password | ||
# SPARK_POSTGRES_HOST postgres host | ||
# SPARK_POSTGRES_USER postgres user | ||
# SPARK_POSTGRES_PASSWORD postgres password | ||
|
||
SPARK_DCOS_URL="mydcosurl" | ||
SPARK_MASTER="mysparkmaster" | ||
SPARK_ARGS="" | ||
SPARK_JARS="myjarurl" | ||
SPARK_CLASS_NAME="$jobclass" | ||
SPARK_APP_NAME="SparkJobs$SUFFIX" | ||
SPARK_DRIVER_CORES="2" | ||
SPARK_DRIVER_MEMORY="1024" | ||
SPARK_CORES_MAX="10" | ||
SPARK_EXECUTOR_MEMORY="2g" | ||
SPARK_CASSANDRA_HOST="xxx" | ||
DCOS_ACS_TOKEN="read acs token" | ||
SPARK_DOCKER_IMAGE="mesosphere/spark:1.1.0-2.1.1-hadoop-2.6" | ||
|
||
if [ "$environment" = "staging" ]; then | ||
SPARK_CASSANDRA_USER="xxx" | ||
SPARK_CASSANDRA_PASSWORD="xxxx" | ||
SPARK_POSTGRES_HOST="xxxx" | ||
SPARK_POSTGRES_USER="xxxx" | ||
SPARK_POSTGRES_PASSWORD="xxxx" | ||
else | ||
SPARK_CASSANDRA_USER="xxx" | ||
SPARK_CASSANDRA_PASSWORD="xxxx" | ||
SPARK_POSTGRES_HOST="xxxx" | ||
SPARK_POSTGRES_USER="xxxx" | ||
SPARK_POSTGRES_PASSWORD="xxxx" | ||
fi | ||
|
||
generate_payload() { | ||
cat <<-EOF | ||
{ | ||
"action" : "CreateSubmissionRequest", | ||
"appArgs" : [ $SPARK_ARGS ], | ||
"appResource" : "$SPARK_JARS", | ||
"clientSparkVersion" : "2.1.1", | ||
"environmentVariables" : { | ||
"SPARK_ENV_LOADED" : "1" | ||
}, | ||
"mainClass" : "$SPARK_CLASS_NAME", | ||
"sparkProperties" : { | ||
"spark.jars" : "$SPARK_JARS", | ||
"spark.driver.supervise" : "false", | ||
"spark.app.name" : "$SPARK_APP_NAME", | ||
"spark.eventLog.enabled": "true", | ||
"spark.submit.deployMode" : "cluster", | ||
"spark.master" : "spark://${SPARK_MASTER}", | ||
"spark.driver.cores" : "${SPARK_DRIVER_CORES}", | ||
"spark.driver.memory" : "${SPARK_DRIVER_MEMORY}", | ||
"spark.cores.max" : "${SPARK_CORES_MAX}", | ||
"spark.executor.memory" : "${SPARK_EXECUTOR_MEMORY}", | ||
"spark.postgres.hostname" : "${SPARK_POSTGRES_HOST}", | ||
"spark.postgres.username" : "${SPARK_POSTGRES_USER}", | ||
"spark.postgres.password" : "${SPARK_POSTGRES_PASSWORD}", | ||
"spark.mesos.executor.docker.image": "${SPARK_DOCKER_IMAGE}", | ||
"spark.driver.supervise": false, | ||
"spark.ssl.noCertVerification": true | ||
} | ||
} | ||
EOF | ||
} | ||
|
||
acsHeader="Authorization: token=$DCOS_ACS_TOKEN" | ||
|
||
submission=$(curl -sS -X POST "${SPARK_DCOS_URL}/v1/submissions/create" --header "$acsHeader" --header "Content-Type:application/json;charset=UTF-8" --data "$(generate_payload)") | ||
submissionSuccess=$(echo $submission | jq -r 'select(.success)') | ||
|
||
if [[ $submissionSuccess ]]; then | ||
SECONDS=0 | ||
|
||
submissionId=$(echo $submission | jq -rj '.submissionId') | ||
# Wait for the job to finish | ||
until test "$(curl --header "$acsHeader" -sS $SPARK_DCOS_URL/v1/submissions/status/$submissionId | jq -r '.driverState')" != "RUNNING"; do sleep 10; echo "Waiting..."; done | ||
lastStatus=$(curl --header "$acsHeader" -sS $SPARK_DCOS_URL/v1/submissions/status/$submissionId | jq -r '.') | ||
echo $lastStatus | ||
taskState=$(echo $lastStatus | jq -r '.message' | grep state | cut -d " " -f 2) | ||
taskMessage=$(echo $lastStatus | jq -r '.message' | grep message | cut -d " " -f 2) | ||
|
||
if [ "$taskState" = "TASK_FINISHED" ] || [ "$taskState" = "TASK_OK" ]; then | ||
echo "Job succeeded." | ||
echo "$taskMessage" | ||
DURATION=$SECONDS | ||
curl -s https://metrics-api.librato.com/v1/metrics -u $LIBRATO_USERNAME:$LIBRATO_TOKEN -H 'Content-Type: application/json' \ | ||
-d "{\"gauges\":{\"spark_jobs.$SPARK_APP_NAME.duration.s\":{\"value\":$DURATION,\"source\":\"jenkins\"}}}" | ||
exit 0; | ||
else | ||
echo "Job failed:" | ||
echo "$taskMessage" | ||
# TODO: notify people! | ||
exit 1; | ||
fi | ||
else | ||
echo "Submission failed ! Exiting..." | ||
echo $submission | jq -r '.message' | ||
exit 1 | ||
fi | ||
|
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
55 changes: 55 additions & 0 deletions
55
src/main/java/io/druid/indexer/spark/parquet/ParquetInputRowParser.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,55 @@ | ||
package io.druid.indexer.spark.parquet; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.Maps; | ||
import io.druid.data.input.InputRow; | ||
import io.druid.data.input.MapBasedInputRow; | ||
import io.druid.data.input.avro.AvroParsers; | ||
import io.druid.data.input.impl.InputRowParser; | ||
import io.druid.data.input.impl.ParseSpec; | ||
import io.druid.java.util.common.parsers.ObjectFlattener; | ||
import org.apache.avro.generic.GenericRecord; | ||
|
||
import java.util.Map; | ||
|
||
public class ParquetInputRowParser implements InputRowParser<GenericRecord> { | ||
private final ParseSpec parseSpec; | ||
private final ObjectFlattener<GenericRecord> avroFlattener; | ||
|
||
@JsonCreator | ||
public ParquetInputRowParser( | ||
@JsonProperty("parseSpec") ParseSpec parseSpec | ||
) | ||
{ | ||
this.parseSpec = parseSpec; | ||
this.avroFlattener = AvroParsers.makeFlattener(parseSpec, false, false); | ||
} | ||
|
||
@JsonProperty | ||
@Override | ||
public ParseSpec getParseSpec() | ||
{ | ||
return parseSpec; | ||
} | ||
|
||
@Override | ||
public ParquetInputRowParser withParseSpec(ParseSpec parseSpec) | ||
{ | ||
return new ParquetInputRowParser(parseSpec); | ||
} | ||
|
||
@Override | ||
public InputRow parse(GenericRecord input) | ||
{ | ||
// We should really create a ParquetBasedInputRow that does not need an intermediate map but accesses | ||
// the SimpleRecord directly... | ||
MapBasedInputRow mapBasedInputRow = (MapBasedInputRow) AvroParsers.parseGenericRecord(input, parseSpec, avroFlattener); | ||
Map<String, Object> event = mapBasedInputRow.getEvent(); | ||
Map<String, Object> newMap = Maps.newHashMapWithExpectedSize(event.size()); | ||
for (String key : mapBasedInputRow.getEvent().keySet()) { | ||
newMap.put(key, event.get(key)); | ||
} | ||
return new MapBasedInputRow(mapBasedInputRow.getTimestampFromEpoch(), mapBasedInputRow.getDimensions(), newMap); | ||
} | ||
} |
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.
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.
Just putting a note here as a reminder to correct this before merge.