Before you start
Prepare a Kafka topic and an identity that can inspect its metadata and read its records. Brokers must be reachable from the engine and workers. Use Kafka connection settings to configure a named connection before starting the engine. For example, a connection namedevents can use these non-secret settings:
secret_properties and the configured secret resolver. Do not put passwords in source options or examples.
Prepare a Spark Connect client using Connect a Python client. Use a small private topic containing two known text messages, first and second, to check the example.
Read records
This client read captures a bounded set of records. It uses the selected partitions’ end offsets when the source is planned.first and second. Order is defined by offsets within each partition. There is no single global order across partitions. Messages added after the planned end offsets are outside that read.
startingOffsets = "latest" starts at those end offsets, so a bounded read can return no rows. Use earliest or explicit offsets to read retained records.
Read selected partitions
Useassign instead of subscribe to select partitions explicitly. Replace orders with your topic and use partition numbers that exist.
-2 for the earliest retained offset or -1 for the latest offset in that map.
Record schema
The connector returns a fixed record schema. It does not infer a message schema or accept a user-supplied source schema. Cast known text values or decode supported payloads after reading them. Avro file support does not add automatic schema-registry decoding to Kafka records.
Source options
Choose exactly one of
connection and kafka.bootstrap.servers. Choose exactly one of subscribe and assign. Broker security and network properties belong in the connection definition.
Limits
The source validates cluster, topic, and partition identity. Starting offsets outside retained history fail. Connection limits bound partition count, network operations, and broker-response buffers. There is no Kafka write path. The SQL file-view form does not acceptUSING kafka; use the client reader above. Arbitrary Kafka source options, subscribePattern, and endingOffsets are not accepted.
To store query results, select a supported sink connector, such as Iceberg or a file dataset.