Ingest and Operate Modern Data Pipelines
Notebook
Note
This notebook requires a Standard or Premium cluster. Pipelines are not available on Free Starter clusters.
What you will learn
This notebook covers four pipeline operations in SingleStore:
Load purchase events from S3 with
CREATE PIPELINEUpdate a live pipeline without losing progress using
ALTER PIPELINEProfile ingestion throughput with
PIPELINES_BATCHESReplace polling with event-driven Kinesis file discovery
Dataset: Real-Time Digital Marketing purchase events (public S3, no credentials needed).
Before you start
Cluster requirement: Standard or Premium. Pipelines are not available on Free Starter clusters.
Setup steps:
Select your cluster and any database from the dropdowns at the top.
Run cells top to bottom. To rerun from scratch, run the Section 7 — Cleanup cell first.
After Section 1, select
pipelines_demofrom the database dropdown so%%sqlDDL lands in the right database.
How the pieces fit together
A pipeline continuously reads files from S3 (or Kafka) and loads them into a table, tracking which files have already been processed so restarts pick up where they left off.
S3 bucket (NDJSON / Parquet files)
│
▼ CREATE LINK → CREATE PIPELINE
SingleStore pipeline
│ ├── ALTER PIPELINE (update config without resetting offsets)
│ ├── PIPELINES_BATCHES (per-batch throughput metrics)
│ └── Kinesis notification (event-driven file discovery)
▼
target table
Section 1 — Connect and create the working database
Installs dependencies, connects to your cluster, and creates pipelines_demo.
Two SQL patterns used in this notebook:
%%sql— DDL, control statements, and display SELECTs.run_sql()— where Python is needed: error handling, polling loops, and DataFrame results.
After running the cell below, select pipelines_demo from the database dropdown above.
In [1]:
1%pip install singlestoredb pandas --quiet
In [2]:
1import time2import pandas as pd3import singlestoredb as s24 5pd.set_option("display.max_colwidth", 120)6 7DB_NAME = "pipelines_demo"8 9def connect():10 global conn11 conn = s2.connect()12 conn.autocommit(True)13 14def run_sql(query, params=None):15 for attempt in range(4):16 try:17 with conn.cursor() as cur:18 cur.execute(query, params)19 if cur.description:20 cols = [d[0] for d in cur.description]21 return pd.DataFrame(cur.fetchall(), columns=cols)22 return None23 except Exception as e:24 msg = str(e)25 if getattr(e, "errno", None) in (2006, 2013) or "Lost connection" in msg or "gone away" in msg:26 connect()27 else:28 raise29 30connect()31print("SingleStore version:", run_sql("SELECT @@memsql_version AS v").iloc[0, 0])32print()33print("Next: select 'pipelines_demo' from the database dropdown above, then run the next cell.")
In [3]:
1%%sql2CREATE DATABASE IF NOT EXISTS pipelines_demo;
In [4]:
1# Point the run_sql() connection at pipelines_demo so unqualified table/pipeline2# references in Python cells resolve to the same database as %%sql DDL.3run_sql(f"USE {DB_NAME}")4print("Working database:", run_sql("SELECT DATABASE() AS db").iloc[0, 0])
Action Required
Select pipelines_demo from the database dropdown at the top of this notebook before running any cells below. This ensures all %%sql DDL lands in the correct database.
Section 2 — Create a table and load S3 data with a pipeline
Creates rtdm_purchases_raw, points a pipeline at a public S3 bucket, and waits for the first batch. Also inserts sample rows with a JSON tags column to show field extraction from complex types.
In [5]:
1# Stop and drop any pipelines from a previous run before touching the table.2# A pipeline holds a reference to its target table — DROP TABLE will fail3# if the pipeline still exists.4for p in ["rtdm_pipeline", "rtdm_pipeline_glob"]:5 try:6 run_sql(f"STOP PIPELINE {p}")7 except Exception:8 pass9 run_sql(f"DROP PIPELINE IF EXISTS {p}")10print("Pipelines cleared. Ready to create the target table.")
In [6]:
1%%sql2DROP TABLE IF EXISTS rtdm_purchases_raw;3 4CREATE TABLE rtdm_purchases_raw (5 seq_id BIGINT,6 subscriber_id BIGINT,7 vendor VARCHAR(200),8 tags JSON,9 ts DATETIME(6) DEFAULT NOW(6),10 SORT KEY (ts)11);
Create and start the pipeline
The cell below creates the pipeline (reading NDJSON from public S3, no credentials needed), starts it, and polls until the first batch arrives (up to ~60 seconds). BATCH_INTERVAL 2500 sets the idle wait to 2.5 seconds — after the pipeline exhausts available files, it waits that long before checking for new ones.
In [7]:
1%%sql2DROP PIPELINE IF EXISTS rtdm_pipeline;3 4CREATE PIPELINE rtdm_pipeline5AS LOAD DATA S3 'singlestore-realtime-digital-marketing/v2/1k-2p/purchases.*.json'6CONFIG '{"region": "us-east-1"}'7BATCH_INTERVAL 25008INTO TABLE rtdm_purchases_raw9FORMAT JSON10(11 seq_id <- seqId,12 subscriber_id <- subscriberid,13 @v <- vendor14)15SET vendor = FROM_BASE64(@v);16 17START PIPELINE rtdm_pipeline;
In [8]:
1print("Pipeline started. Waiting for first batch...")2for _ in range(12):3 time.sleep(5)4 n = run_sql("SELECT COUNT(*) AS n FROM rtdm_purchases_raw").iloc[0, 0]5 if int(n) > 0:6 print(f"Rows loaded: {n}")7 break8 print(" ...waiting")
In [9]:
1%%sql2SELECT seq_id, subscriber_id, vendor, ts3FROM rtdm_purchases_raw4LIMIT 5;
Extracting fields from JSON columns
The tags column lands as raw JSON. The cell below inserts sample rows then uses JSON_EXTRACT_STRING to pull out individual fields — the same pattern applies to Parquet map and array columns.
In [10]:
1%%sql2DELETE FROM rtdm_purchases_raw WHERE seq_id >= 999001;3 4INSERT INTO rtdm_purchases_raw (seq_id, subscriber_id, vendor, tags)5VALUES6 (999001, 1, 'DemoVendorA', '{"category": "new_visitor", "device": "mobile", "time_of_day": "afternoon"}'),7 (999002, 2, 'DemoVendorB', '{"category": "new_visitor", "device": "mobile", "time_of_day": "afternoon"}'),8 (999003, 3, 'DemoVendorC', '{"category": "new_visitor", "device": "mobile", "time_of_day": "afternoon"}');
In [11]:
1%%sql2SELECT seq_id, vendor,3 JSON_EXTRACT_STRING(tags, 'category') AS category,4 JSON_EXTRACT_STRING(tags, 'device') AS device,5 JSON_EXTRACT_STRING(tags, 'time_of_day') AS time_of_day6FROM rtdm_purchases_raw7WHERE seq_id >= 999001;
Parquet type mapping
Map Parquet complex fields in the column list of CREATE PIPELINE. Arrays and maps land as JSON; use JSON_EXTRACT_STRING, JSON_EXTRACT_DOUBLE, or JSON_ARRAY_UNPACK to access individual elements.
Section 3 — Update a live pipeline with ALTER PIPELINE
Dropping and recreating a pipeline resets its file offset, causing every file to be re-ingested. ALTER PIPELINE lets you update a pipeline's configuration without resetting its offsets — the pipeline remembers which files it already processed.
Each clause updates a different part of the pipeline definition:
SET CONFIG— updates the JSON config block (e.g. region, compression flags)SET S3 ...— updates the source pathSET CREDENTIALS— rotates credentials
Pattern: stop → alter → restart.
The cell below simulates a config update — for example, changing a region setting or toggling a compression flag. It stops the pipeline, applies the new CONFIG block with SET CONFIG, restarts it, then confirms the change in information_schema.PIPELINES.
In [12]:
1%%sql2-- Always stop before altering to avoid unpredictable behaviour.3STOP PIPELINE rtdm_pipeline;4 5ALTER PIPELINE rtdm_pipeline6SET CONFIG '{"region": "us-east-1", "disable_gunzip": false}';7 8START PIPELINE rtdm_pipeline;
In [13]:
1%%sql2SELECT PIPELINE_NAME, STATE, ALTER_TIME, CONFIG_JSON3FROM information_schema.PIPELINES4WHERE PIPELINE_NAME = 'rtdm_pipeline';
Always stop before altering
Run STOP PIPELINE before ALTER PIPELINE. Altering a running pipeline can cause unpredictable behaviour. Restart with START PIPELINE after the change is applied.
Section 4 — Profile ingestion with PIPELINES_BATCHES
information_schema.PIPELINES_BATCHES records one row per partition per completed batch, giving you timing and throughput metrics to diagnose slow ingestion.
Key columns
| Column | What it measures |
|---|---|
BATCH_TIME | Wall-clock seconds for the batch |
BATCH_ROWS_INSERTED | Rows inserted into the target table |
BATCH_ROWS_WRITTEN | Total rows affected by write operations (inserts, updates, deletes) |
High BATCH_TIME relative to BATCH_ROWS_INSERTED indicates a parse or commit bottleneck. Compare BATCH_ROWS_WRITTEN to BATCH_ROWS_INSERTED to understand what mix of write operations each batch performed.
In [14]:
1%%sql2SELECT BATCH_ID, BATCH_STATE,3 FROM_UNIXTIME(MIN(BATCH_START_UNIX_TIMESTAMP)) AS batch_start,4 MAX(BATCH_TIME) AS elapsed_sec,5 SUM(BATCH_ROWS_INSERTED) AS rows_inserted,6 SUM(BATCH_ROWS_WRITTEN) AS rows_written7FROM information_schema.PIPELINES_BATCHES8WHERE PIPELINE_NAME = 'rtdm_pipeline'9GROUP BY BATCH_ID, BATCH_STATE10ORDER BY BATCH_ID DESC11LIMIT 10;
Section 5 — Event-driven S3 file discovery via Kinesis
By default, SingleStore polls S3 on a fixed interval. Kinesis-based event-driven discovery eliminates polling: S3 publishes an ObjectCreated event the moment a file lands, and SingleStore begins downloading immediately.
Setup
In AWS: create an S3 event notification sending
s3:ObjectCreated:*to a Kinesis Data Stream.In SingleStore, add
KINESIS_STREAMto your pipeline:
CREATE PIPELINE rtdm_pipeline_kinesis
AS LOAD DATA S3 'your-bucket/prefix/*'
CONFIG '{"region": "us-east-1"}'
KINESIS_STREAM 'arn:aws:kinesis:us-east-1:123456789:stream/your-stream'
CREDENTIALS '{"aws_access_key_id": "...", "aws_secret_access_key": "..."}'
BATCH_INTERVAL 2500
INTO TABLE rtdm_purchases_raw
FORMAT JSON (...);
Polling vs. event-driven
| Polling | Kinesis event-driven | |
|---|---|---|
| Latency | Seconds to minutes | Near real-time |
| S3 API cost | List calls every interval | Event notifications only |
| Setup | None | S3 notification + Kinesis stream |
| Best for | Batch / hourly loads | Low-latency streaming ingest |
Note: This section is reference-only — AWS credentials and a configured stream are required to run.
Section 6 — Target specific files with glob patterns
SingleStore lists S3 objects using the literal prefix before the first glob character, then applies the glob as a filter on the returned names. A longer literal prefix reduces the S3 listing scan; a narrower glob alone filters the matches but does not change how many objects S3 lists.
For example, both purchases.*.json and purchases.*.000[0-2].json list the same objects from S3 — the glob 000[0-2] filters the result client-side. To reduce listing work, use a path with a longer unique prefix such as purchases/2026-10/.
Supported glob syntax
| Pattern | Matches |
|---|---|
* | Any string (existing behaviour) |
? | Any single character |
[abc] | One of: a, b, or c |
[a-z] | Any character in the range |
[^abc] | Any character not in the set |
Examples
-- Longer literal prefix narrows the S3 listing to one month
'my-bucket/purchases/2026-10/*.json'
-- Glob filter: only files with a single-character vendor prefix
'my-bucket/events/vendor_?.parquet'
-- Glob filter: exclude files starting with underscore
'my-bucket/events/[^_]*.json'
The pattern 000[0-2] matches files ending in .0000, .0001, or .0002. After the pipeline runs, PIPELINES_FILES confirms only the targeted files were discovered.
In [15]:
1%%sql2DROP PIPELINE IF EXISTS rtdm_pipeline_glob;3 4-- Pattern 000[0-2] matches files ending in .0000, .0001, or .0002 — a subset of the full dataset.5CREATE PIPELINE rtdm_pipeline_glob6AS LOAD DATA S3 'singlestore-realtime-digital-marketing/v2/1k-2p/purchases.*.000[0-2].json'7CONFIG '{"region": "us-east-1"}'8BATCH_INTERVAL 25009INTO TABLE rtdm_purchases_raw10FORMAT JSON11(12 seq_id <- seqId,13 subscriber_id <- subscriberid,14 @v <- vendor15)16SET vendor = FROM_BASE64(@v);17 18START PIPELINE rtdm_pipeline_glob;
In [16]:
1time.sleep(5)2try:3 run_sql("STOP PIPELINE rtdm_pipeline_glob")4except Exception:5 pass6print("Glob pipeline stopped. Checking discovered files...")
In [17]:
1%%sql2SELECT FILE_NAME, FILE_SIZE, FILE_STATE3FROM information_schema.PIPELINES_FILES4WHERE PIPELINE_NAME = 'rtdm_pipeline_glob'5LIMIT 10;
Section 7 — Cleanup
Stops and drops both pipelines, drops the working table and pipelines_demo database. Run this before rerunning the notebook from scratch.
In [18]:
1for p in ["rtdm_pipeline", "rtdm_pipeline_glob"]:2 try:3 run_sql(f"STOP PIPELINE {p}")4 except Exception:5 pass
In [19]:
1%%sql2DROP PIPELINE IF EXISTS rtdm_pipeline;3DROP PIPELINE IF EXISTS rtdm_pipeline_glob;4DROP TABLE IF EXISTS rtdm_purchases_raw;
In [20]:
1run_sql(f"DROP DATABASE IF EXISTS {DB_NAME}")2print(f"Database '{DB_NAME}' dropped. Cleanup complete.")
Key takeaways
| Concept | What this notebook showed |
|---|---|
| Parquet complex types | Arrays and maps land as JSON; use JSON_EXTRACT_STRING / JSON_ARRAY_UNPACK to work with elements |
ALTER PIPELINE | Update credentials or bucket config on a live pipeline without resetting offsets — stop first, alter, restart |
PIPELINES_BATCHES | Per-batch timing and row counts; use BATCH_TIME vs BATCH_ROWS_INSERTED to find bottlenecks |
| Event-driven discovery | Kinesis stream integration eliminates polling latency; file discovery time drops to near-zero |
| Glob patterns | Use ?, [a-z], [^x] in S3 paths to reduce file list size and speed up discovery scans |

Details
About this Template
Walk through production-ready pipeline patterns using the Real-Time Digital Marketing dataset: load complex Parquet types, modify a live pipeline with ALTER LINK, profile ingestion performance with SHOW PROFILE PIPELINE, and use event-driven S3 file discovery via Kinesis for low-latency ingest.
This Notebook can be run in Standard and Enterprise deployments.
Tags
See Notebook in action
Launch this notebook in SingleStore and start executing queries instantly.
License
This Notebook has been released under the Apache 2.0 open source license.