# 9.KafkaSQL

Use the SQL statement to the news data visualization in topic, for SQL queries, and table names field need to use double quotes to mark, example SQL is as follows:

```bash
select * from "ke_test_topic" where "partition" in (0,1,2) limit 100
```

As shown in the following figure:

## Edit SQL

![kafka\_sql@2x.png](/files/-M5XRZYqZicuCMvZISPq)

## DataSets

![kafka\_sql\_result@2x.png](/files/-M5XRZYtxt96P5VmzFx5)

```bash
Note: Access to topic message data, depending on the underlying interface record of the earliest and latest offset, the default display up to 5000 records.
```

## Parse JSONObject Or JSONArrays

Kafka topic datasets like this:

```
[{"id":123,"name":"smartloli"},{"id":456,"name":"smartloli2"},{"id":789,"name":"smartloli3"}]
```

Then you can use sql query topic like this:

```
select JSONS("msg",'name') from "topic_name" where "partition" in (0) limit 10
```

When Kafka topic datasets like this:

```
{"id":123,"name":"smartloli001"}
{"id":456,"name":"smartloli002"}
```

Then you can use sql query topic like this:

```
select JSON("msg",'name') from "topic_name" where "partition" in (0) limit 10
```

Add `and`:

```
select JSON("msg",'name') from "topic_name" where "partition" in (0) and JSON("msg",'name') = 'smartloli001' limit 10
```

## Filter Query \[where ... and]

Kafka topic datasets like this:

```
kafka-eagle-01
kafka-eagle-02
kafka-eagle-02
kafka-eagle-03
kafka-eagle-03
...
kafka-eagle-03
kafka-eagle-04
```

Then you can use sql query topic like this:

```
select * from "topic_name" where "partition" in (0) and "msg" = 'kafka-eagle-03' limit 10
```

Add `like`:

```
select * from "topic_name" where "partition" in (0) and "msg" like 'kafka-eagle%' limit 10
```

Or:

```
select * from "topic_name" where "partition" in (0) and "msg" like '%kafka-eagle%' limit 10
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs2.kafka-eagle.org/3.quick-start/9.kafkasql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
