author.
19 | */
20 | public static final Author AUTHOR = Author.AUTHOR;
21 |
22 | /**
23 | * The table book.
24 | */
25 | public static final Book BOOK = Book.BOOK;
26 | }
27 |
--------------------------------------------------------------------------------
/topic/machine-learning/pycaret/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.pytest.ini_options]
2 | minversion = "2.0"
3 | addopts = """
4 | -rfEX -p pytester --strict-markers --verbosity=3
5 | """
6 | # --cov=. --cov-report=term-missing --cov-report=xml
7 | env = [
8 | "CRATEDB_CONNECTION_STRING=crate://crate@localhost/?ssl=false",
9 | "PYDEVD_DISABLE_FILE_VALIDATION=1",
10 | ]
11 |
12 | #log_level = "DEBUG"
13 | #log_cli_level = "DEBUG"
14 |
15 | testpaths = [
16 | "*.py",
17 | ]
18 | xfail_strict = true
19 | markers = [
20 | ]
21 |
22 | [tool.coverage.run]
23 | branch = false
24 |
25 | [tool.coverage.report]
26 | fail_under = 0
27 | show_missing = true
28 | omit = [
29 | "conftest.py",
30 | "test*.py",
31 | ]
32 |
--------------------------------------------------------------------------------
/by-language/php-pdo/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "45808adbf65b93c0c731f795e5332f95",
8 | "packages": [],
9 | "packages-dev": [],
10 | "aliases": [],
11 | "minimum-stability": "stable",
12 | "stability-flags": [],
13 | "prefer-stable": false,
14 | "prefer-lowest": false,
15 | "platform": {
16 | "php": "^7.1|^8.0|^8.1|^8.2"
17 | },
18 | "platform-dev": [],
19 | "plugin-api-version": "2.3.0"
20 | }
21 |
--------------------------------------------------------------------------------
/framework/dlt/.dlt/secrets.toml:
--------------------------------------------------------------------------------
1 | [destination.cratedb.credentials]
2 | # CrateDB PostgreSQL interface
3 | host = "localhost"
4 | port = 5432
5 | username = "crate"
6 | password = ""
7 |
8 | [destination.sqlalchemy.credentials]
9 | # CrateDB HTTP interface
10 | # https://dlthub.com/docs/dlt-ecosystem/destinations/sqlalchemy
11 | drivername = "crate"
12 | host = "localhost"
13 | port = 4200
14 | database = ""
15 | username = "crate"
16 | password = ""
17 |
18 | [sources.sql_database.credentials]
19 | # CrateDB HTTP interface
20 | # https://dlthub.com/docs/dlt-ecosystem/verified-sources/sql_database/setup
21 | drivername = "crate"
22 | host = "localhost"
23 | port = 4200
24 | database = ""
25 | username = "crate"
26 | password = ""
27 |
--------------------------------------------------------------------------------
/topic/machine-learning/langchain/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.pytest.ini_options]
2 | minversion = "2.0"
3 | addopts = """
4 | -rfEX -p pytester --strict-markers --verbosity=3 --capture=no
5 | """
6 | # --cov=. --cov-report=term-missing --cov-report=xml
7 | env = [
8 | "CRATEDB_CONNECTION_STRING=crate://crate@localhost/?schema=testdrive",
9 | "PYDEVD_DISABLE_FILE_VALIDATION=1",
10 | ]
11 |
12 | #log_level = "DEBUG"
13 | #log_cli_level = "DEBUG"
14 |
15 | testpaths = [
16 | "*.py",
17 | ]
18 | xfail_strict = true
19 | markers = [
20 | ]
21 |
22 | [tool.coverage.run]
23 | branch = false
24 |
25 | [tool.coverage.report]
26 | fail_under = 0
27 | show_missing = true
28 | omit = [
29 | "conftest.py",
30 | "test*.py",
31 | ]
32 |
--------------------------------------------------------------------------------
/framework/flink/kafka-jdbcsink-python/.env:
--------------------------------------------------------------------------------
1 | CRATEDB_HOST=crate
2 | CRATEDB_PORT=4200
3 | CRATEDB_PG_PORT=5432
4 |
5 | WEATHER_PRODUCER_CITY=Vienna
6 | WEATHER_PRODUCER_API_KEY=#GET THE API KEY - https://www.weatherapi.com/
7 | WEATHER_PRODUCER_FETCH_EVERY_SECONDS=30
8 | WEATHER_PRODUCER_KAFKA_TOPIC=weather_topic
9 | WEATHER_PRODUCER_KAFKA_BOOTSTRAP_SERVER=kafka
10 |
11 | FLINK_CONSUMER_KAFKA_TOPIC=weather_topic
12 | FLINK_CONSUMER_BOOTSTRAP_SERVER=kafka
13 | FLINK_CONSUMER_CRATEDB_PG_URI=jdbc:postgresql://crate:5432/crate
14 | FLINK_CONSUMER_CRATEDB_USER=crate
15 | FLINK_CONSUMER_CRATEDB_PASSWORD=empty
16 |
17 | # Jar versions.
18 | POSTGRESQL_JAR_VERSION=42.7.2
19 | FLINK_CONNECTOR_JDBC_VERSION=3.1.2-1.18
20 | FLINK_KAFKA_JAR_URL_VERSION=3.1.0-1.18
--------------------------------------------------------------------------------
/by-language/php-pdo/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crate/pdo-pgsql-example",
3 | "description": "PDO_PGSQL example for CrateDB",
4 | "authors": [
5 | {
6 | "name": "Crate.io",
7 | "email": "office@crate.io",
8 | "homepage": "https://cratedb.com/",
9 | "role": "maintainer"
10 | }
11 | ],
12 | "license": "Apache-2.0",
13 | "homepage": "https://github.com/crate/cratedb-examples/tree/main/by-language/php-pdo",
14 | "keywords": ["database", "cratedb", "sql", "postgresql"],
15 | "require": {
16 | "php": "^7.1|^8.0|^8.1|^8.2"
17 | },
18 | "scripts": {
19 | "test": "php basic.php 'pgsql:host=localhost;port=5432;user=crate'"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/by-language/php-amphp/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crate/amphp-example",
3 | "description": "AMPHP example for CrateDB",
4 | "authors": [
5 | {
6 | "name": "Crate.io",
7 | "email": "office@crate.io",
8 | "homepage": "https://cratedb.com/",
9 | "role": "maintainer"
10 | }
11 | ],
12 | "license": "Apache-2.0",
13 | "homepage": "https://github.com/crate/cratedb-examples/tree/main/by-language/php-amphp",
14 | "keywords": ["database", "cratedb", "sql"],
15 | "require": {
16 | "php": "^8.1|^8.2|^8.3",
17 | "amphp/postgres": "^2.0"
18 | },
19 | "scripts": {
20 | "test": "php basic.php 'host=localhost port=5432 user=crate'"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/operation/http-api-behind-nginx/README.rst:
--------------------------------------------------------------------------------
1 | #############################
2 | CrateDB HTTP API behind Nginx
3 | #############################
4 |
5 |
6 | *****
7 | About
8 | *****
9 |
10 | Nginx configuration for hosting the CrateDB HTTP API endpoint on a subdirectory
11 | path. Here: `/db`.
12 |
13 |
14 | *****
15 | Usage
16 | *****
17 |
18 | Start CrateDB::
19 |
20 | docker run -it --rm --publish=4200:4200 --publish=5432:5432 --name=cratedb crate/crate:5.0.1 -Cdiscovery.type=single-node -Ccluster.routing.allocation.disk.threshold_enabled=false
21 |
22 | Start Nginx::
23 |
24 | wget https://raw.githubusercontent.com/crate/cratedb-examples/main/stacks/http-api-behind-nginx/nginx.conf
25 | nginx -c $(pwd)/nginx.conf
26 |
27 | Then, navigate to http://localhost:7070/db/.
28 |
--------------------------------------------------------------------------------
/by-dataframe/polars/README.md:
--------------------------------------------------------------------------------
1 | # Connect to CrateDB and CrateDB Cloud using Polars
2 |
3 | ## About
4 |
5 | Example programs demonstrating connectivity with [Polars] and [CrateDB].
6 |
7 | ## Usage
8 |
9 | ```shell
10 | python read_pg.py
11 | python read_sqlalchemy.py
12 | python write_pg.py
13 | python write_sqlalchemy.py
14 | python write_adbc.py
15 | python one_db_to_another.py
16 | ```
17 |
18 | > [!TIP]
19 | > For more information, please refer to the header sections of each of the
20 | provided example programs.
21 |
22 | ## Tests
23 |
24 | To test the accompanied example programs all at once, invoke the software tests:
25 | ```shell
26 | pytest
27 | ```
28 |
29 |
30 | [CrateDB]: https://github.com/crate/crate
31 | [CrateDB Cloud]: https://console.cratedb.cloud/
32 | [Polars]: https://pola.rs/
33 |
--------------------------------------------------------------------------------
/topic/machine-learning/llama-index/env.standalone:
--------------------------------------------------------------------------------
1 | # Backend: Ollama
2 | # export LLM_BACKEND=ollama
3 | # export OLLAMA_BASE_URL=https://l59hg3k5z1bxtw-11434.proxy.runpod.net/
4 | # export OLLAMA_BASE_URL=http://100.127.86.113:11434/
5 | # export LLM_MODEL=phi4-mini:latest
6 | # export LLM_MODEL=phi4-mini:3.8b-fp16
7 | # export LLM_MODEL=deepseek-r1:7b
8 | # export LLM_MODEL=llama3.2:latest
9 | # export LLM_MODEL=qwen3:0.6b
10 | # export LLM_MODEL=gemma3:1b
11 | # export LLM_MODEL=sqlcoder:7b
12 | # export LLM_MODEL=duckdb-nsql:7b
13 |
14 | # Backend: OpenAI
15 | export LLM_BACKEND=openai
16 | export LLM_MODEL=gpt-4.1
17 | # export OPENAI_API_KEY=sk-XJZ7pfog5Gp8Kus8D--invalid--0CJ5lyAKSefZLaV1Y9S1
18 |
19 | export CRATEDB_SQLALCHEMY_URL="crate://crate@localhost:4200/"
20 | export CRATEDB_TABLE_NAME=time_series_data
21 |
--------------------------------------------------------------------------------
/topic/timeseries/test.py:
--------------------------------------------------------------------------------
1 | import os
2 | from pathlib import Path
3 |
4 | import pytest
5 | from testbook import testbook
6 |
7 |
8 | def test_notebook(notebook):
9 | """
10 | Execute Jupyter Notebook, one test case per .ipynb file.
11 | """
12 | if notebook.name == "dask-weather-data-import.ipynb":
13 |
14 | # Skip Kaggle tests when having no authentication information.
15 | kaggle_auth_exists = Path("~/.kaggle/kaggle.json").exists() or (
16 | "KAGGLE_USERNAME" in os.environ and "KAGGLE_KEY" in os.environ
17 | )
18 | if not kaggle_auth_exists:
19 | raise pytest.skip(f"Kaggle dataset can not be tested "
20 | f"without authentication: {notebook.name}")
21 |
22 | with testbook(notebook) as tb:
23 | tb.execute()
24 |
--------------------------------------------------------------------------------
/framework/streamlit/basic_sys_summits.py:
--------------------------------------------------------------------------------
1 | """
2 | A basic Streamlit application connecting to CrateDB using SQLAlchemy.
3 |
4 | It reads the built-in `sys.summits` table into a dataframe, and
5 | displays its contents.
6 |
7 | - https://docs.streamlit.io/develop/tutorials/databases
8 | - https://cratedb.com/docs/sqlalchemy-cratedb/
9 | """
10 | import streamlit as st
11 |
12 | # Set a title for the page.
13 | st.title("Streamlit with CrateDB Example")
14 |
15 | # Connect to CrateDB, and read the built-in `sys.summits` table.
16 | conn = st.connection("cratedb", type="sql")
17 | df = conn.query('SELECT * FROM "sys"."summits";', ttl="10m")
18 |
19 | # Output data as dataframe and table.
20 | st.dataframe(df)
21 | st.table(df)
22 |
23 | # Output data as Markdown.
24 | for row in df.itertuples():
25 | st.write(f"{row.mountain}")
26 |
--------------------------------------------------------------------------------
/by-dataframe/polars/read_sqlalchemy.py:
--------------------------------------------------------------------------------
1 | """
2 | Read from CrateDB using Polars and SQLAlchemy.
3 |
4 | Install dependencies:
5 |
6 | pip install polars sqlalchemy-cratedb
7 | """
8 |
9 | import polars as pl
10 | import sqlalchemy as sa
11 |
12 | CRATEDB_URI = "crate://crate:crate@localhost:4200"
13 | SQL_QUERY = "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3"
14 |
15 |
16 | def main():
17 | # LIMITATION:
18 | # This uses the HTTP protocol; 1.9GB is the max amount of data you can
19 | # select; use batches, `COPY TO`, or the PostgreSQL wire protocol to
20 | # overcome this limitation.
21 | engine = sa.create_engine(CRATEDB_URI)
22 | df = pl.read_database(
23 | query=SQL_QUERY,
24 | connection=engine,
25 | )
26 | print(df)
27 |
28 |
29 | if __name__ == "__main__":
30 | main()
31 |
--------------------------------------------------------------------------------
/by-language/java-qa/README.md:
--------------------------------------------------------------------------------
1 | # JDBC QA tests
2 |
3 |
4 | ## About
5 |
6 | Ported from https://github.com/crate/crate-qa/pull/278.
7 |
8 |
9 | ## Why?
10 |
11 | - To have more integration tests, and keep them, running against CrateDB nightly.
12 | - To constantly monitor that corresponding test cases don't break, even when
13 | underlying software versions change. In this case, regular updates to `pom.xml`
14 | will be driven by GitHub's Dependabot, and Java versions can be added as they
15 | become available on runners or through corresponding setup recipes.
16 |
17 |
18 | ## pom.xml
19 |
20 | The `pom.xml` was generated with `mvn archetype:generate`.
21 | ```shell
22 | mvn archetype:generate \
23 | -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false \
24 | -DgroupId=io.crate -DartifactId=jdbc-qa
25 | ```
26 |
--------------------------------------------------------------------------------
/by-language/r/README.md:
--------------------------------------------------------------------------------
1 | # Connecting to CrateDB with R
2 |
3 | ## About
4 |
5 | The files `basic_rpostgres.r` and `basic_rpostgresql.r` include basic
6 | example programs that use the R packages [RPostgres] resp. [RPostgreSQL],
7 | the canonical database interfaces and 'PostgreSQL' drivers for 'R',
8 | to connect to CrateDB.
9 |
10 | ## Usage
11 |
12 | Start a CrateDB instance for evaluation purposes.
13 | ```shell
14 | docker run -it --rm --publish=4200:4200 --publish=5432:5432 crate:latest
15 | ```
16 |
17 | Invoke example programs.
18 | ```shell
19 | Rscript basic_rpostgres.r
20 | Rscript basic_rpostgresql.r
21 | ```
22 |
23 | Invoke software tests.
24 | ```shell
25 | make test
26 | ```
27 |
28 |
29 | [RPostgres]: https://cran.r-project.org/web/packages/RPostgres/
30 | [RPostgreSQL]: https://cran.r-project.org/web/packages/RPostgreSQL/
31 |
--------------------------------------------------------------------------------
/topic/machine-learning/llm/sql-request.txt:
--------------------------------------------------------------------------------
1 | Given an input question, first create a syntactically correct CrateDB query to run,
2 | then look at the results of the query and return the answer. You can order the
3 | results by a relevant column to return the most interesting examples in the database.
4 |
5 | Never query for all the columns from a specific table, only ask for a few relevant
6 | columns given the question.
7 |
8 | Pay attention to use only the column names that you can see in the schema description.
9 | Be careful to not query for columns that do not exist. Pay attention to which column
10 | is in which table. Also, qualify column names with the table name when needed. You
11 | are required to use the following format, each taking one line:
12 |
13 | Question: Question here
14 | SQLQuery: SQL Query to run
15 | Only use tables listed below.
16 |
--------------------------------------------------------------------------------
/application/roapi/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Using ROAPI with CrateDB.
4 | # https://github.com/roapi/roapi
5 | # https://github.com/crate/crate
6 |
7 | # The miniature stack defined as {Docker,Podman} services and tasks registers a
8 | # few data sources with ROAPI, mounts them as CrateDB tables using its PostgreSQL
9 | # JDBC foreign data wrapper, then queries them.
10 |
11 | # Start services: CrateDB and ROAPI.
12 | docker compose up --build --detach
13 |
14 | # Register data files with ROAPI.
15 | docker compose run --rm roapi-register-data
16 |
17 | # Probe if data sources exist in ROAPI.
18 | # docker compose run --rm roapi-query-data
19 |
20 | # Mount table using foreign data wrappers.
21 | docker compose run --rm cratedb-register-data
22 |
23 | # Query foreign table `doc.uk_cities` from CrateDB.
24 | docker compose run --rm cratedb-query-data
25 |
--------------------------------------------------------------------------------
/by-language/python-connectorx/demo.py:
--------------------------------------------------------------------------------
1 | """
2 | Example program connecting to CrateDB [1] using ConnectorX [2],
3 | using its PostgreSQL interface [3].
4 |
5 | [1] https://cratedb.com/database
6 | [2] https://sfu-db.github.io/connector-x/
7 | [3] https://sfu-db.github.io/connector-x/databases/postgres.html
8 | """
9 |
10 | # /// script
11 | # requires-python = ">=3.10"
12 | # dependencies = [
13 | # "connectorx<0.5",
14 | # "pandas>2,<3",
15 | # ]
16 | # ///
17 |
18 | from pprint import pprint
19 | import connectorx as cx
20 |
21 |
22 | def main():
23 | data = cx.read_sql(
24 | "postgresql://crate@localhost/",
25 | "SELECT country, height, mountain, range, region FROM sys.summits ORDER BY height DESC LIMIT 10",
26 | protocol="cursor",
27 | )
28 | pprint(data)
29 |
30 |
31 | if __name__ == "__main__":
32 | main()
33 |
--------------------------------------------------------------------------------
/framework/dbt/basic/README.md:
--------------------------------------------------------------------------------
1 | # dbt CrateDB basic example
2 |
3 | ## What's Inside
4 | A basic model materialization using the `table` strategy.
5 |
6 | ## Setup
7 | ```shell
8 | uv pip install -r requirements.txt
9 | ```
10 |
11 | ## Usage
12 |
13 | Try running the following commands:
14 | - `dbt run`
15 | - `dbt test`
16 |
17 | Optionally, use `--debug` to display executed SQL statements.
18 |
19 | ## Resources
20 | - Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)
21 | - Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers
22 | - Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support
23 | - Find [dbt events](https://events.getdbt.com) near you
24 | - Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices
25 |
--------------------------------------------------------------------------------
/framework/mcp/example_pg_mcp_install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Acquire MCP server part of `pg-mcp`.
3 | # https://github.com/stuzero/pg-mcp-server
4 | # https://github.com/crate-workbench/pg-mcp-server
5 |
6 | # FIXME: Improve installation after packaging has been improved.
7 | # https://github.com/stuzero/pg-mcp-server/issues/10
8 |
9 | set -e
10 | TARGET="/tmp/pg-mcp-server"
11 | rm -rf ${TARGET}
12 | git clone --depth 1 --no-checkout --filter=blob:none \
13 | https://github.com/crate-workbench/pg-mcp-server.git \
14 | ${TARGET}
15 | cd ${TARGET}
16 | git checkout 82733d1a886bf1a14592d1fbb305205901f2bb35 -- pyproject.toml uv.lock server test.py
17 | cat pyproject.toml | grep -v requires-python | sponge pyproject.toml
18 | uv pip install .
19 |
20 | # /Users/amo/dev/crate-workbench/sources/pg-mcp-server
21 | # https://github.com/crate-workbench/pg-mcp.git
22 |
--------------------------------------------------------------------------------
/topic/multi-model/README.md:
--------------------------------------------------------------------------------
1 | # CrateDB UK Offshore Wind Farms Data Workshop
2 |
3 | This workshop explores multi-model data modeling and queries with [CrateDB](https://cratedb.com), using data from [The Crown Estate](https://www.thecrownestate.co.uk/our-business/marine/offshore-wind) which manages the UK's offshore wind farms. It is derived from a conference presentation that you can [watch on YouTube](https://www.youtube.com/watch?v=xqiLGjaTlBk).
4 |
5 | Use the Jupyter notebook to run the queries from the talk yourself, in your own CrateDB cluster in the cloud... click the button below to try it out in Google Colab!
6 |
7 |
8 | DEFAULT_SCHEMA
28 | */
29 | public static final DefaultSchema DEFAULT_SCHEMA = new DefaultSchema();
30 |
31 | /**
32 | * The table author.
33 | */
34 | public final Author AUTHOR = Author.AUTHOR;
35 |
36 | /**
37 | * The table book.
38 | */
39 | public final Book BOOK = Book.BOOK;
40 |
41 | /**
42 | * No further instances allowed
43 | */
44 | private DefaultSchema() {
45 | super("", null);
46 | }
47 |
48 |
49 | @Override
50 | public Catalog getCatalog() {
51 | return DefaultCatalog.DEFAULT_CATALOG;
52 | }
53 |
54 | @Override
55 | public final List