Stream Sources
Stream sources read from Kafka, Redis, Kinesis, or SQS with Spark Structured Streaming.
Providers: kafka | redis | kinesis | sqs
Asset fields
Every asset in this type carries these fields; provider and format values live under options.
| Field | Type | Default | Notes |
|---|---|---|---|
name (required) | string | - | - |
Settings options
These settings.options apply to every provider:
| Field | Type | Default | Notes |
|---|---|---|---|
format | csv or json or raw | - | Data format for stream processing. |
Minimal example
A complete stream source with one asset, written for provider kafka:
Code
Providers
kafka
An example for provider kafka:
Code
Connection
Use settings.connection_name for a saved connection, or configure it inline:
| Field | Type | Default | Notes |
|---|---|---|---|
url (required) | string | - | Kafka bootstrap servers, for example kafka:9092 or host1:9092,host2:9092. |
auth is one of:
PLAINTEXT
| Field | Type | Default | Notes |
|---|---|---|---|
security_protocol (required) | PLAINTEXT | - | Kafka security protocol. |
SSL
| Field | Type | Default | Notes |
|---|---|---|---|
security_protocol (required) | SSL | - | Kafka security protocol. |
ssl_truststore_location | string | - | Path to Kafka SSL truststore. |
ssl_truststore_password | string | - | Password for Kafka SSL truststore. |
SASL_PLAINTEXT
| Field | Type | Default | Notes |
|---|---|---|---|
security_protocol (required) | SASL_PLAINTEXT | - | Kafka security protocol. |
sasl_mechanism (required) | PLAIN or SCRAM-SHA-256 or SCRAM-SHA-512 | - | Kafka SASL mechanism. |
user (required) | string | - | Kafka SASL username. |
password (required) | string | - | Kafka SASL password. |
SASL_SSL
| Field | Type | Default | Notes |
|---|---|---|---|
security_protocol (required) | SASL_SSL | - | Kafka security protocol. |
sasl_mechanism (required) | PLAIN or SCRAM-SHA-256 or SCRAM-SHA-512 | - | Kafka SASL mechanism. |
user (required) | string | - | Kafka SASL username. |
password (required) | string | - | Kafka SASL password. |
ssl_truststore_location | string | - | Path to Kafka SSL truststore. |
ssl_truststore_password | string | - | Password for Kafka SSL truststore. |
Asset options
assets[].options:
| Field | Type | Default | Notes |
|---|---|---|---|
subscribe_pattern | string | - | Java regex string to subscribe to topics matching the pattern. Only one of 'assign', 'subscribe' or 'subscribePattern' options can be specified. Maps to subscribePattern. |
assign | string | - | JSON string specifying specific TopicPartitions, e.g., {"topicA":[0,1],"topicB":[2,4]}. Only one of 'assign', 'subscribe' or 'subscribePattern' options can be specified. |
starting_timestamp | string | - | The start point of timestamp when a query is started, a string specifying a starting timestamp for all partitions in topics being subscribed. Takes precedence over startingOffsetsByTimestamp and startingOffsets. For streaming queries, this only applies when a new query is started. Requires Kafka 0.10.1.0 or higher. Maps to startingTimestamp. |
starting_offsets_by_timestamp | string | - | The start point of timestamp when a query is started, a JSON string specifying a starting timestamp for each TopicPartition, e.g., {"topicA":{"0":1000,"1":1000},"topicB":{"0":2000}}. Takes precedence over startingOffsets. Requires Kafka 0.10.1.0 or higher. Maps to startingOffsetsByTimestamp. |
starting_offsets | string | latest | The start point when a query is started. Options: 'earliest', 'latest' (streaming only), or JSON string specifying a starting offset for each TopicPartition, e.g., {"topicA":{"0":23,"1":-1}}. In JSON, -2 refers to earliest, -1 to latest. Default: 'latest' for streaming, 'earliest' for batch. Maps to startingOffsets. |
ending_timestamp | string | - | The end point when a batch query is ended, a string specifying an ending timestamp for all partitions in topics being subscribed. Takes precedence over endingOffsetsByTimestamp and endingOffsets. Batch queries only. Maps to endingTimestamp. |
ending_offsets_by_timestamp | string | - | The end point when a batch query is ended, a JSON string specifying an ending timestamp for each TopicPartition, e.g., {"topicA":{"0":1000,"1":1000}}. Takes precedence over endingOffsets. Batch queries only. Maps to endingOffsetsByTimestamp. |
ending_offsets | string | - | The end point when a batch query is ended. Options: 'latest' or JSON string specifying an ending offset for each TopicPartition, e.g., {"topicA":{"0":23,"1":-1}}. In JSON, -1 refers to latest, -2 (earliest) is not allowed. Batch queries only. Default: 'latest'. Maps to endingOffsets. |
fail_on_data_loss | boolean | - | Whether to fail the query when it's possible that data is lost (e.g., topics are deleted, or offsets are out of range). This may be a false alarm. Default: true. Maps to failOnDataLoss. |
poll_timeout | number | - | The timeout in milliseconds to poll data from Kafka in executors. When not defined it falls back to spark.network.timeout. Default: 120000. Maps to kafkaConsumer.pollTimeoutMs. |
fetch_offset_retries_number | number | - | Number of times to retry before giving up fetching Kafka offsets. Default: 3. Maps to fetchOffset.numRetries. |
fetch_offset_retry_interval | number | - | Milliseconds to wait before retrying to fetch Kafka offsets. Default: 10. Maps to fetchOffset.retryIntervalMs. |
max_offsets_per_trigger | number | - | Rate limit on maximum number of offsets processed per trigger interval. The specified total number of offsets will be proportionally split across topicPartitions of different volume. Streaming queries only. Maps to maxOffsetsPerTrigger. |
min_offsets_per_trigger | number | - | Minimum number of offsets to be processed per trigger interval. The specified total number of offsets will be proportionally split across topicPartitions of different volume. Note, if the maxTriggerDelay is exceeded, a trigger will be fired even if the number of available offsets doesn't reach minOffsetsPerTrigger. Streaming queries only. Maps to minOffsetsPerTrigger. |
max_trigger_delay | string | - | Maximum amount of time for which trigger can be delayed between two triggers provided some data is available from the source. This option is only applicable if minOffsetsPerTrigger is set. Streaming queries only. Default: 15m. Maps to maxTriggerDelay. |
min_partitions | number | - | Desired minimum number of partitions to read from Kafka. By default, Spark has a 1-1 mapping of topicPartitions to Spark partitions consuming from Kafka. If you set this option to a value greater than your topicPartitions, Spark will divvy up large Kafka partitions to smaller pieces. The number of Spark tasks will be approximately minPartitions. Maps to minPartitions. |
group_id_prefix | string | - | Prefix of consumer group identifiers (group.id) that are generated by structured streaming queries. If 'kafka.group.id' is set, this option will be ignored. Default: spark-kafka-source. Maps to groupIdPrefix. |
kafka_group_id | string | - | The Kafka group id to use in Kafka consumer while reading from Kafka. Use this with extreme caution. By default, each query generates a unique group id for reading data. Concurrently running queries (both, batch and streaming) or sources with the same group id are likely interfere with each other causing each query to read only part of the data. When this is set, option 'groupIdPrefix' will be ignored. Maps to kafka.group.id. |
include_headers | boolean | - | Whether to include the Kafka headers in the row. Requires Kafka client version 0.11.0.0 or up. Default: false. Maps to includeHeaders. |
header_names | array of string | - | Kafka header names to extract as individual STRING columns (one column per name). Requires include_headers=true. Headers not present on a record yield NULL in their column. If omitted: in streaming mode all headers are exposed as a single 'headers' MapType<string,string> column (use headers['name'] in SQL); in test_limit batch mode header keys are auto-discovered and emitted as individual STRING columns. |
starting_offsets_by_timestamp_strategy | error or latest | - | The strategy used when the specified starting offset by timestamp (either global or per partition) doesn't match with the offset Kafka returned. Options: 'error' (fail the query) or 'latest' (assigns the latest offset for these partitions). Default: error. Maps to startingOffsetsByTimestampStrategy. |
redis
An example for provider redis:
Code
Connection
Use settings.connection_name for a saved connection, or configure it inline:
| Field | Type | Default | Notes |
|---|---|---|---|
url (required) | string | - | Redis host |
auth | object | - | - |
auth.password | string | - | Redis password. |
Asset options
assets[].options:
| Field | Type | Default | Notes |
|---|---|---|---|
offsets | string | - | JSON string specifying stream offset positions. Format: {"offsets":{"streamKey":{"groupName":"redis-source","offset":"1548083485360-0"}}}. Use '0-0' to process from the beginning. Default: starts from latest message. Maps to stream.offsets. |
group_name | string | - | Consumer group name. Spark-Redis automatically creates this group if it doesn't exist. Default: 'spark-source'. Maps to stream.group.name. |
consumer_prefix | string | - | Prefix for consumer names in the consumer group. Allows customization of consumer naming. Maps to stream.consumer.prefix. |
batch_size | number | - | Maximum number of items to pull in a single XREADGROUP call. Default: 100. Maps to stream.read.batch.size. |
block_time | number | - | Blocking time (milliseconds) to wait for messages to appear in the Redis stream. Default: 0. Maps to stream.read.block. |
parallelism | number | - | Number of parallel consumers for reading from a single Redis key. Each consumer maps to a Spark partition. No ordering guarantees when using multiple consumers. Maps to stream.parallelism. |
database_number | number | - | Redis database number (0-15). Overrides spark.redis.db configured in SparkSession. Default: 0. Maps to dbNum. |
timeout | number | - | Connection timeout in milliseconds. Overrides spark.redis.timeout configured in SparkSession. Default: 2000. |
kinesis
An example for provider kinesis:
Code
Connection
Use settings.connection_name for a saved connection, or configure it inline:
| Field | Type | Default | Notes |
|---|---|---|---|
url (required) | string | - | Kinesis endpoint or stream service URL. |
auth (required) | object | - | - |
auth.access_key (required) | string | - | - |
auth.secret_key (required) | string | - | - |
auth.region (required) | string | - | - |
Asset options
assets[].options:
| Field | Type | Default | Notes |
|---|---|---|---|
consumer_type | string | - | Consumer type. Possible values are 'GetRecords', 'SubscribeToShard'. Default: GetRecords. Maps to kinesis.consumerType. |
fail_on_data_loss | boolean | false | Fail the streaming job if any active shard is missing or expired. Default: false. Maps to kinesis.failOnDataLoss. |
max_fetch_records_per_shard | number | 100000 | Maximum number of records to fetch per shard per microbatch. Default: 100,000. Maps to kinesis.maxFetchRecordsPerShard. |
max_fetch_time_per_shard | number | - | Maximum time (seconds) to fetch records per shard per microbatch. If not defined, decision is based on kinesis.maxFetchRecordsPerShard. If defined, task terminates when either maxFetchRecordsPerShard or maxFetchTimePerShardSec is reached first. Must be no less than 10 seconds. Maps to kinesis.maxFetchTimePerShardSec. |
starting_position | string | - | Starting Position in Kinesis to fetch data from. Possible values are 'LATEST', 'TRIM_HORIZON', 'EARLIEST' (alias for TRIM_HORIZON), or 'AT_TIMESTAMP YYYY-MM-DDTHH:MMkinesis.startingPosition. |
describe_shard_interval | string | 1s | Minimum Interval between two ListShards API calls to get latest shards. Possible values are time values such as 50s, 100ms. Default: 1s. Maps to kinesis.describeShardInterval. |
min_batches_to_retain | number | - | The minimum number of batches of kinesis metadata that must be retained and made recoverable. Default: same as spark.sql.streaming.minBatchesToRetain. Maps to kinesis.minBatchesToRetain. |
check_new_record_threads | number | 8 | Number of threads in Spark driver to check if there are new records in Kinesis stream. Default: 8. Maps to kinesis.checkNewRecordThreads. |
metadata_committer_type | string | HDFS | Where to save Kinesis connector metadata. Possible values are 'HDFS', 'DYNAMODB'. Default: HDFS. Maps to kinesis.metadataCommitterType. |
metadata_path | string | - | A path to HDFS or S3. Only valid when kinesis.metadataCommitterType is HDFS. Default: same as checkpointLocation. Maps to kinesis.metadataPath. |
metadata_retries_number | number | 5 | Maximum Number of retries for metadata requests. Default: 5. Maps to kinesis.metadataNumRetries. |
metadata_retry_intervals | number | 1000 | Wait time before retrying metadata requests in milliseconds. Default: 1000. Maps to kinesis.metadataRetryIntervalsMs. |
metadata_max_retry_interval | number | 10000 | Max wait time between 2 retries of metadata requests in milliseconds. Default: 10000. Maps to kinesis.metadataMaxRetryIntervalMs. |
client_retries_number | number | 5 | Maximum Number of retries for Kinesis API requests. Default: 5. Maps to kinesis.clientNumRetries. |
client_retry_intervals | number | 1000 | Wait time before retrying Kinesis requests in milliseconds. Default: 1000. Maps to kinesis.clientRetryIntervalsMs. |
client_max_retry_interval | number | 10000 | Max wait time between 2 retries of Kinesis requests in milliseconds. Default: 10000. Maps to kinesis.clientMaxRetryIntervalMs. |
consumer_name | string | - | Kinesis stream Enhanced Fan Out consumer name. Required when kinesis.consumerType is 'SubscribeToShard'. Maps to kinesis.consumerName. |
sts_role_arn | string | - | AWS STS Role ARN for Kinesis operations describe, read record, etc. Used for cross-account access. Maps to kinesis.stsRoleArn. |
sts_session_name | string | - | AWS STS Session name. Used for cross-account access. Maps to kinesis.stsSessionName. |
sts_endpoint_url | string | - | AWS STS Endpoint URL. Used for cross-account access. Maps to kinesis.stsEndpointUrl. |
kinesis_region | string | - | Region the Kinesis stream belongs to. Default: inferred value from kinesis.endpointUrl. Maps to kinesis.kinesisRegion. |
credential_provider_class | string | - | Custom connector credential provider implements org.apache.spark.sql.connector.kinesis.ConnectorAwsCredentialsProvider. If the implementation returns temporary credentials, it is responsible for refreshing the credentials before they expire. Maps to kinesis.credentialProviderClass. |
credential_provider_param | string | - | Custom connector credential provider's input parameter. Maps to kinesis.credentialProviderParam. |
dynamodb_table_name | string | - | DynamoDB table name. Required when kinesis.metadataCommitterType is 'DYNAMODB'. Maps to kinesis.dynamodb.tableName. |
subscribe_to_shard_timeout | number | 60 | Timeout waiting for subscribeToShard finish (seconds). Default: 60. Maps to kinesis.subscribeToShard.timeoutSec. |
subscribe_to_shard_max_retries | number | 10 | Max retries of subscribeToShard request. Default: 10. Maps to kinesis.subscribeToShard.maxRetries. |
get_records_number_of_records_per_fetch | number | 10000 | Maximum Number of records to fetch per getRecords API call. Default: 10,000. Maps to kinesis.getRecords.numberOfRecordsPerFetch. |
get_records_fetch_interval | number | 200 | Minimum interval of two getRecords API calls in milliseconds. Default: 200. Maps to kinesis.getRecords.fetchIntervalMs. |
sqs
An example for provider sqs:
Code
Connection
Use settings.connection_name for a saved connection, or configure it inline:
| Field | Type | Default | Notes |
|---|---|---|---|
url (required) | string | - | SQS queue URL. |
auth (required) | object | - | - |
auth.access_key (required) | string | - | - |
auth.secret_key (required) | string | - | - |
auth.region (required) | string | - | - |
Asset options
assets[].options:
| Field | Type | Default | Notes |
|---|---|---|---|
poll_interval | integer | 1000 | Polling interval in milliseconds for SQS queue. Default: 1000. Maps to pollIntervalMs. |