The StreamingFormatConverter application reads any Spark acceptable stream (kafka, socket or
file streams like parquet, avro, orc, json or csv), converts it into a DataFrame,
optionally partitions it, and saves it in any Spark acceptable data stream format
(kafka, socket or file streams like parquet, avro, orc, json or csv).
One of the best features is the easy configuration and the support for output partitioning, by specifying both the partitioning column and the number of partition files per partition folder.
Full support for the parsing of various input files is provided. For more details check the Input Formats section.
In the examples folder there are multiple examples on
how the format converter can be used in real life applications.
The convert-format.sh is an example on
how the actual application can be used.
Taking out the preparation part, it comes down to the following lines, which can be used in
different setups, including the cluster-mode.
spark-submit -v \
...
--class org.tupol.spark.tools.StreamingFormatConverter \
--name StreamingFormatConverter \
--files $APPLICATION_CONF \
--jars "$JARS" \
$SPARK_TOOLS_JAR
Notice the following variables:
$APPLICATION_CONFneeds to point to a file actually calledapplication.conf, somewhere in the local file system.$JARSneeds to contains the comma separated list of dependency jars; as of now this list contains the following jars:- Scala 2.11:
config-1.3.0.jar,scalaz-core_2.11-7.2.26.jar,scala-utils_2.11-0.2.0.jar,spark-utils_2.11-0.4.2.jar - Scala 2.12:
config-1.3.0.jar,scalaz-core_2.12-7.2.26.jar,scala-utils_2.12-0.2.0.jar,spark-utils_2.12-0.4.2.jar
- Scala 2.11:
$SPARK_TOOLS_JARneeds to contain the local path to the actualspark-toolsjar:- Scala 2.11:
spark-tools_2.11-0.4.1.jar - Scala 2.12:
spark-tools_2.12-0.4.1.jar
- Scala 2.11:
Configuration Examples Description
sample-application-1.confSocket stream to Json file stream conversionsample-application-2.confJson file stream to CSV file stream conversionsample-application-3.confJson file stream to CSV file stream conversion with partitioning columnssample-application-4.confJson file stream to CSV file stream conversion with partitioning columns and custom delimitersample-application-5.confJson file stream to CSV file stream conversionsample-application-6.confKafka stream to Json file stream conversion
Check the README for more details on how to run these examples.
-
StreamingFormatConverter.input.formatRequired -
StreamingFormatConverter.input.formatRequired- the type of the input file and the corresponding source / parser
- possible values are:
socketkafka- file sources:
xml,csv,json,parquet,avro,orcandtext
-
StreamingFormatConverter.input.schemaOptional- this is an optional parameter that represents the json Apache Spark schema that should be
enforced on the input data - this schema can be easily obtained from a
DataFrameby calling theprettyJsonfunction - due to it's complex structure, this parameter can not be passed as a command line argument,
but it can only be passed through the
application.conffile - the schema is applied on read only on file streams; for other streams the developer has to find a way to apply it.
StreamingFormatConverter.input.schema.pathOptional- this is an optional parameter that represents local path or the class path to the json Apache Spark schema that should be enforced on the input data
- this schema can be easily obtained from a
DataFrameby calling theprettyJsonfunction - if this parameter is found the schema will be loaded from the given file, otherwise,
the
schemaparameter is tried
- this is an optional parameter that represents the json Apache Spark schema that should be
-
StreamingFormatConverter.output.formatRequired- the type of the input file and the corresponding source / parser
- possible values are:
kafka- file sources:
xml,csv,json,parquet,avro,orcandtext
-
StreamingFormatConverter.output.triggerOptionaltype: possible values: "Continuous", "Once", "ProcessingTime"interval: mandatory for "Continuous", "ProcessingTime"
-
StreamingFormatConverter.output.queryNameOptional -
StreamingFormatConverter.output.partition.columnsOptional -
StreamingFormatConverter.output.outputModeOptional -
StreamingFormatConverter.output.checkpointLocationOptional
The StreamingFormatConverter uses the spark-utils defined IO framework.
For more details about defining the data sources please check the
DataDource documentation.
For more details about defining the data sinks please check the
DataSink documentation.
pathRequired- For more details check the File Data Source
Warning: Not for production use!
optionsRequiredhostRequiredportRequiredincludeTimestampOptional
optionsRequiredkafka.bootstrap.serversRequiredassign|subscribe|subscribePatternRequired *startingOffsetsOptionalendingOffsetsOptionalfailOnDataLossOptionalkafkaConsumer.pollTimeoutMsOptionalfetchOffset.numRetriesOptionalfetchOffset.retryIntervalMsOptionalmaxOffsetsPerTriggerOptional
formatRequired- the type of the input file and the corresponding source / parser
- possible values are:
xml,csv,json,parquet,avro,orcandtext
triggerOptionaltype: possible values: "Continuous", "Once", "ProcessingTime"interval: mandatory for "Continuous", "ProcessingTime"
partition.columnsOptionaloutputModeOptionalcheckpointLocationOptional
pathRequired- For more details check the File Data Sink
kafka.bootstrap.serversRequiredtopicRequired
- For the CSV and JSON reader API see more details here.
- For the XML converter API see more details here.
- For the Avro converter API see more details here.
- Structured Streaming Programming Guide - Input Sources
- Structured Streaming + Kafka Integration Guide