-
-
Notifications
You must be signed in to change notification settings - Fork 3
Document from_clickhouse #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mavam
wants to merge
7
commits into
topic/new-executor
Choose a base branch
from
topic/from-clickhouse
base: topic/new-executor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
590cc36
Document reading from data stores
mavam d904d21
Use Excalidraw source for ClickHouse diagram
mavam c90b979
Use to_tcp in routing guide
mavam 8d65547
Align ClickHouse docs with shared DB API
mavam 00f6055
Add data-store guide to sidebar
mavam eb4cbdb
Document ClickHouse uri support
mavam 404d48c
Clarify ClickHouse URI database behavior
mavam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/content/docs/guides/collecting/read-from-data-stores.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| --- | ||
| title: Read from data stores | ||
|
mavam marked this conversation as resolved.
|
||
| --- | ||
|
|
||
| This guide shows you how to read from external data stores with TQL. You'll learn how to read full tables, push filters into SQL, inspect metadata, and stream new rows from MySQL. | ||
|
|
||
| Today, this guide focuses on <Op>from_mysql</Op> and <Op>from_clickhouse</Op>. As Tenzir adds more data store integrations, the same patterns will apply. | ||
|
|
||
| :::note | ||
| `from_clickhouse` currently requires the new pipeline executor. Run pipelines that use it with `tenzir --neo`. | ||
| ::: | ||
|
|
||
| ## Read a full table | ||
|
|
||
| Use `table=...` when you want to fetch all rows from a table. | ||
|
|
||
| Read a ClickHouse table: | ||
|
|
||
| ```tql | ||
| from_clickhouse table="security.events", | ||
| host="clickhouse.example.com", | ||
| password=secret("CLICKHOUSE_PASSWORD"), | ||
| tls=false | ||
| ``` | ||
|
|
||
| Or use a ClickHouse URI: | ||
|
|
||
| ```tql | ||
| from_clickhouse uri="clickhouse://default:secret@clickhouse.example.com:9000/security", | ||
| table="events", | ||
| tls=false | ||
| ``` | ||
|
|
||
| Read a MySQL table: | ||
|
|
||
| ```tql | ||
| from_mysql table="users", | ||
| host="mysql.example.com", | ||
| user="tenzir", | ||
| password=secret("MYSQL_PASSWORD"), | ||
| database="identity" | ||
| ``` | ||
|
|
||
| Use this mode when you want Tenzir to treat the table as the source of truth and | ||
| apply filtering later in the pipeline. | ||
|
|
||
| ## Push filters and projections into SQL | ||
|
|
||
| Use `sql=...` when the data store should do the filtering, sorting, or column | ||
| selection before Tenzir receives the rows. | ||
|
|
||
| Filter in ClickHouse: | ||
|
|
||
| ```tql | ||
| from_clickhouse sql="SELECT time, host, severity, message FROM events WHERE severity >= 3 ORDER BY time DESC", | ||
| host="clickhouse.example.com", | ||
| password=secret("CLICKHOUSE_PASSWORD"), | ||
| tls=false | ||
| ``` | ||
|
|
||
| Filter in MySQL: | ||
|
|
||
| ```tql | ||
| from_mysql sql="SELECT id, user, last_login FROM users WHERE active = 1 ORDER BY last_login DESC", | ||
| host="mysql.example.com", | ||
| user="tenzir", | ||
| password=secret("MYSQL_PASSWORD"), | ||
| database="identity" | ||
| ``` | ||
|
|
||
| This pattern reduces network traffic and lets you use the source system's query | ||
| planner and indexes. | ||
|
|
||
| ## Inspect metadata | ||
|
|
||
| Both operators can return metadata instead of table rows. | ||
|
|
||
| List ClickHouse tables in a database: | ||
|
|
||
| ```tql | ||
| from_clickhouse sql="SHOW TABLES FROM security", | ||
| host="clickhouse.example.com", | ||
| password=secret("CLICKHOUSE_PASSWORD"), | ||
| tls=false | ||
| ``` | ||
|
|
||
| Show the columns of a MySQL table: | ||
|
|
||
| ```tql | ||
| from_mysql table="users", | ||
| show="columns", | ||
| host="mysql.example.com", | ||
| user="tenzir", | ||
| password=secret("MYSQL_PASSWORD"), | ||
| database="identity" | ||
| ``` | ||
|
|
||
| Use metadata queries when you want to discover available tables, inspect a | ||
| schema, or validate assumptions before you run a larger pipeline. In | ||
| ClickHouse, prefer regular SQL such as `SHOW`, `DESCRIBE`, or queries against | ||
| system catalogs. | ||
|
|
||
| ## Poll for new rows from MySQL | ||
|
|
||
| MySQL supports a live polling mode for tables with a monotonically increasing | ||
| integer tracking column. | ||
|
|
||
| ```tql | ||
| from_mysql table="audit_log", | ||
| live=true, | ||
| tracking_column="id", | ||
| host="mysql.example.com", | ||
| user="tenzir", | ||
| password=secret("MYSQL_PASSWORD"), | ||
| database="security" | ||
| where severity == "high" | ||
| ``` | ||
|
|
||
| Use this mode when you want to turn a database table into a continuously polled | ||
| event source. | ||
|
|
||
| `from_clickhouse` does not currently provide a comparable live mode. It runs a | ||
| query, emits the result, and then finishes. | ||
|
|
||
| ## Shape rows after reading | ||
|
|
||
| Both operators produce structured events, so you can transform the result right | ||
| away. | ||
|
|
||
| ```tql | ||
| from_clickhouse sql="SELECT host, severity, message FROM events", | ||
| host="clickhouse.example.com", | ||
| password=secret("CLICKHOUSE_PASSWORD"), | ||
| tls=false | ||
| where severity >= 3 | ||
| message = message.upper() | ||
| ``` | ||
|
|
||
| This lets you treat database rows like any other event stream in Tenzir. | ||
|
|
||
| ## See also | ||
|
|
||
| - <Guide>collecting/read-from-message-brokers</Guide> | ||
| - <Guide>transformation/filter-and-select-data</Guide> | ||
| - <Guide>routing/send-to-destinations</Guide> | ||
| - <Op>from_clickhouse</Op> | ||
| - <Op>from_mysql</Op> | ||
| - <Integration>clickhouse</Integration> | ||
| - <Integration>mysql</Integration> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.