Skip to main content
How-to guide
The Kafka connector reads records from configured Kafka connections. It exposes message keys, values, topic metadata, offsets, and optional headers. Kafka is a source only; this engine does not provide a Kafka sink.

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 named events can use these non-secret settings:
Set TLS and authentication properties for your brokers. Store sensitive values through 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.
For a topic containing only the two sample messages, expect 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

Use assign instead of subscribe to select partitions explicitly. Replace orders with your topic and use partition numbers that exist.
The example offsets must still be available. An explicit starting-offset map must cover every selected partition. Use -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 accept USING 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.

Cleanup

Close the client when finished. If you created a private topic for this example, remove only that topic through your Kafka tools. Keep shared topics and named connections in place.
Last modified on November 23, 2026