├── framework ├── graphene │ ├── __init__.py │ ├── requirements.txt │ ├── app.py │ ├── schema.py │ ├── database.py │ └── models.py ├── dbt │ ├── basic │ │ ├── analyses │ │ │ └── .gitkeep │ │ ├── macros │ │ │ ├── .gitkeep │ │ │ └── overrides.sql │ │ ├── seeds │ │ │ └── .gitkeep │ │ ├── snapshots │ │ │ └── .gitkeep │ │ ├── tests │ │ │ └── .gitkeep │ │ ├── requirements.txt │ │ ├── .gitignore │ │ ├── models │ │ │ └── example │ │ │ │ ├── starter_second.sql │ │ │ │ ├── schema.yml │ │ │ │ └── starter_first.sql │ │ ├── profiles.yml │ │ ├── README.md │ │ └── dbt_project.yml │ └── materialize │ │ ├── requirements.txt │ │ ├── .gitignore │ │ ├── packages.yml │ │ ├── models │ │ └── example │ │ │ ├── jobslog.sql │ │ │ └── test.sql │ │ ├── profiles.yml │ │ ├── dbt_project.yml │ │ ├── README.md │ │ └── tests │ │ └── test.yml ├── gradio │ ├── .gitignore │ ├── requirements-dev.txt │ ├── requirements.txt │ ├── pyproject.toml │ └── basic_sys_summits.py ├── mcp │ ├── .gitignore │ ├── requirements-test.txt │ ├── requirements.txt │ ├── example_pg_mcp_server.py │ ├── pyproject.toml │ └── example_pg_mcp_install.sh ├── records │ ├── requirements-test.txt │ ├── requirements.txt │ ├── pyproject.toml │ └── test.py ├── streamlit │ ├── requirements-dev.txt │ ├── requirements.txt │ ├── pyproject.toml │ ├── .streamlit │ │ ├── secrets.toml │ │ └── secrets-cratedb-cloud.toml │ ├── basic_sys_summits.py │ └── test.py ├── dlt │ ├── requirements-dev.txt │ ├── pyproject.toml │ ├── .gitignore │ ├── requirements.txt │ ├── .dlt │ │ ├── config.toml │ │ └── secrets.toml │ └── pokemon.py └── flink │ ├── kafka-jdbcsink-java │ ├── .gitignore │ ├── Makefile │ └── .env │ └── kafka-jdbcsink-python │ ├── Dockerfile │ ├── pyproject.toml │ ├── flink_job.Dockerfile │ ├── .env │ ├── requirements.txt │ └── example.json ├── by-language ├── java-jdbc │ ├── .gitignore │ └── Makefile ├── java-jooq │ ├── .java-version │ ├── .gitignore │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── src │ │ ├── main │ │ │ └── resources │ │ │ │ ├── simplelogger.properties │ │ │ │ ├── application.properties │ │ │ │ └── bootstrap.sql │ │ ├── generated │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── crate │ │ │ │ └── demo │ │ │ │ └── jooq │ │ │ │ └── model │ │ │ │ ├── Tables.java │ │ │ │ ├── Keys.java │ │ │ │ ├── DefaultSchema.java │ │ │ │ └── DefaultCatalog.java │ │ └── test │ │ │ └── java │ │ │ └── io │ │ │ └── crate │ │ │ └── demo │ │ │ └── jooq │ │ │ └── ApplicationTest.java │ └── build.gradle ├── java-qa │ ├── .gitignore │ ├── Makefile │ ├── README.md │ └── pom.xml ├── php-pdo │ ├── .gitignore │ ├── composer.lock │ └── composer.json ├── php-amphp │ ├── .gitignore │ └── composer.json ├── ruby │ ├── .gitignore │ ├── Rakefile │ └── Gemfile ├── python-turbodbc │ ├── .gitignore │ ├── requirements-dev.txt │ ├── requirements.txt │ ├── requirements-prereq.txt │ ├── test.py │ ├── pyproject.toml │ ├── odbc.ini │ ├── README-OCI.md │ └── backlog.rst ├── r │ ├── .gitignore │ ├── Makefile │ ├── backlog.md │ ├── README.md │ ├── basic_rpostgresql.r │ └── basic_rpostgres.r ├── rust-postgres │ ├── .gitignore │ ├── src │ │ └── tests.rs │ ├── Cargo.toml │ └── README.md ├── java-quarkus-panache │ ├── .sdkmanrc │ ├── src │ │ ├── test │ │ │ ├── resources │ │ │ │ └── testcontainers.properties │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── crate │ │ │ │ └── test │ │ │ │ └── CrateDBTestResource.java │ │ └── main │ │ │ ├── resources │ │ │ └── application.properties │ │ │ ├── docker │ │ │ ├── Dockerfile.native │ │ │ └── Dockerfile.native-micro │ │ │ └── java │ │ │ └── io │ │ │ └── crate │ │ │ ├── CrateDBJsonJdbcType.java │ │ │ └── MyApplication.java │ ├── .dockerignore │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── settings.gradle │ ├── .gitignore │ └── build.gradle ├── python-dbapi │ ├── requirements.txt │ ├── requirements-dev.txt │ ├── test.py │ ├── pyproject.toml │ └── README.rst ├── csharp-npgsql │ ├── .gitignore │ ├── BasicPoco.cs │ └── demo.csproj ├── python-connectorx │ ├── requirements-dev.txt │ ├── requirements.txt │ ├── backlog.md │ ├── test.py │ ├── pyproject.toml │ ├── demo.py │ └── README.md ├── elixir-postgrex │ ├── .gitignore │ ├── backlog.md │ ├── mix.exs │ └── README.md ├── csharp-efcore │ ├── .gitignore │ ├── backlog.md │ ├── demo.csproj │ ├── README.md │ └── tests │ │ └── BlogDemoTest.cs ├── python-sqlalchemy │ ├── requirements-dev.txt │ ├── .gitignore │ ├── requirements.txt │ ├── pyproject.toml │ └── test.py ├── go-pgx │ ├── main_test.go │ ├── setup.sql │ ├── main.go │ ├── go.mod │ ├── DEVELOP.md │ ├── README.md │ └── bulk_operations.go └── python-pg8000 │ ├── basic.py │ └── README.rst ├── notebook ├── marimo │ ├── .gitignore │ └── requirements.txt └── jupyter │ ├── docs │ ├── jupysql.ipynb │ ├── conf.py │ └── index.md │ ├── README.md │ ├── test.py │ └── conftest.py ├── testing ├── testcontainers │ ├── java │ │ ├── .java-version │ │ ├── .gitignore │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ └── src │ │ │ └── test │ │ │ ├── resources │ │ │ └── init.sql │ │ │ └── java │ │ │ └── io │ │ │ └── crate │ │ │ └── example │ │ │ └── testing │ │ │ ├── TestManual.java │ │ │ └── TestClassScope.java │ ├── python-unittest │ │ ├── .ngr-type │ │ ├── requirements.txt │ │ ├── test_unittest.py │ │ └── README.md │ └── python-pytest │ │ ├── requirements.txt │ │ ├── pyproject.toml │ │ ├── test_pytest.py │ │ └── README.md └── native │ ├── python-unittest │ ├── .ngr-type │ ├── requirements.txt │ ├── test_unittest.py │ └── README.md │ └── python-pytest │ ├── requirements.txt │ ├── pyproject.toml │ └── README.md ├── application ├── metabase │ ├── requirements.txt │ ├── requirements-test.txt │ ├── pyproject.toml │ ├── README.md │ ├── test.py │ └── docker-compose.yml ├── records │ ├── requirements-test.txt │ ├── requirements.txt │ ├── test.py │ ├── pyproject.toml │ ├── example.sh │ └── README.md ├── ingestr │ ├── .dlt │ │ └── config.toml │ ├── .gitignore │ ├── requirements.txt │ ├── test.sh │ ├── .env │ └── README.md ├── apache-superset │ ├── requirements-test.txt │ ├── requirements.txt │ ├── pyproject.toml │ ├── util.py │ └── data.sql ├── cratedb-toolkit │ ├── requirements-test.txt │ ├── requirements.txt │ └── pyproject.toml ├── microsoft-ssis │ ├── ssis-cratedb-demo │ │ ├── Project.params │ │ ├── cratedb.conmgr │ │ └── ssis-cratedb-demo.dtproj.user │ ├── ssis-cratedb-demo.sln │ └── README.md ├── roapi │ ├── notes.md │ ├── test.sh │ └── roapi.Dockerfile └── pgpool │ └── test.sh ├── by-dataframe ├── dask │ ├── requirements-dev.txt │ ├── requirements.txt │ └── pyproject.toml ├── pandas │ ├── requirements-dev.txt │ ├── requirements.txt │ ├── test_read.py │ └── pyproject.toml ├── polars │ ├── requirements-test.txt │ ├── requirements.txt │ ├── pyproject.toml │ ├── read_pg.py │ ├── README.md │ ├── read_sqlalchemy.py │ ├── write_adbc.py │ ├── one_db_to_another.py │ └── test.py └── spark │ └── scala-http │ ├── build.sbt │ └── README.md ├── topic ├── machine-learning │ ├── langchain │ │ ├── .gitignore │ │ ├── requirements.txt │ │ ├── requirements-dev.txt │ │ ├── pyproject.toml │ │ ├── init.sql │ │ └── conversational_memory.py │ ├── llm │ │ ├── requirements.txt │ │ ├── sql-response.txt │ │ └── sql-request.txt │ ├── llama-index │ │ ├── requirements-dev.txt │ │ ├── requirements.txt │ │ ├── env.azure │ │ ├── pyproject.toml │ │ ├── env.standalone │ │ └── init.sql │ ├── mlflow │ │ ├── .gitignore │ │ ├── requirements.txt │ │ ├── requirements-dev.txt │ │ ├── pyproject.toml │ │ └── test.py │ ├── pycaret │ │ ├── .gitignore │ │ ├── backlog.md │ │ ├── requirements.txt │ │ ├── requirements-dev.txt │ │ └── pyproject.toml │ └── open-webui │ │ ├── init │ │ ├── .env │ │ ├── tool-servers.json │ │ ├── test.sh │ │ ├── init.sql │ │ └── Dockerfile │ │ └── .env ├── chatbot │ └── table-augmented-generation │ │ ├── app │ │ └── requirements.txt │ │ └── workshop │ │ ├── requirements-test.txt │ │ ├── test.py │ │ ├── pyproject.toml │ │ └── conftest.py ├── timeseries │ ├── weather-data-grafana-dashboard.png │ ├── requirements-dev.txt │ ├── requirements.txt │ ├── pyproject.toml │ ├── test.py │ └── conftest.py ├── multi-model │ ├── multi-model-offshore-wind-farms.jpg │ ├── multi-model-offshore-wind-farms-query.png │ └── README.md ├── serverless │ └── azure-eventhub │ │ └── Azure Function │ │ ├── requirements.txt │ │ ├── value_cache.py │ │ └── function_app.py └── autoscaling │ └── README.md ├── operation ├── compose │ └── ssl │ │ ├── keystore │ │ ├── truststore │ │ ├── client_pgsql.sh │ │ ├── client_crash.sh │ │ ├── Makefile │ │ ├── client_sqlalchemy.py │ │ ├── crate.yml │ │ ├── client_dbapi.py │ │ ├── client_psycopg.py │ │ └── compose.yml ├── http-api-behind-nginx │ ├── README.rst │ └── nginx.conf └── testbench-yellowcab │ └── README.rst ├── requirements.txt ├── .gitattributes ├── .gitignore └── .github └── workflows ├── application-roapi.yml ├── application-pgpool.yml ├── application-ingestr.yml ├── framework-flink-kafka-java.yml ├── ml-open-webui.yml ├── operation-compose-ssl.yml ├── lang-r.yml ├── lang-rust-postgres.yml └── ml-llm.yml /framework/graphene/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/dbt/basic/analyses/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/dbt/basic/macros/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/dbt/basic/seeds/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/dbt/basic/snapshots/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/dbt/basic/tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /by-language/java-jdbc/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /by-language/java-jooq/.java-version: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /by-language/java-qa/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /by-language/php-pdo/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | -------------------------------------------------------------------------------- /framework/dbt/basic/macros/overrides.sql: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/gradio/.gitignore: -------------------------------------------------------------------------------- 1 | /flagged 2 | -------------------------------------------------------------------------------- /notebook/marimo/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /by-language/php-amphp/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | -------------------------------------------------------------------------------- /by-language/ruby/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | -------------------------------------------------------------------------------- /framework/mcp/.gitignore: -------------------------------------------------------------------------------- 1 | uv.lock 2 | pg-mcp 3 | -------------------------------------------------------------------------------- /framework/mcp/requirements-test.txt: -------------------------------------------------------------------------------- 1 | pytest<9 2 | -------------------------------------------------------------------------------- /testing/testcontainers/java/.java-version: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /by-language/java-qa/Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | mvn test 3 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/.gitignore: -------------------------------------------------------------------------------- 1 | .venv* 2 | -------------------------------------------------------------------------------- /by-language/r/.gitignore: -------------------------------------------------------------------------------- 1 | .RData 2 | .Rhistory 3 | -------------------------------------------------------------------------------- /framework/records/requirements-test.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | -------------------------------------------------------------------------------- /notebook/jupyter/docs/jupysql.ipynb: -------------------------------------------------------------------------------- 1 | ../jupysql.ipynb -------------------------------------------------------------------------------- /application/metabase/requirements.txt: -------------------------------------------------------------------------------- 1 | metabase-api<3.5 2 | -------------------------------------------------------------------------------- /application/records/requirements-test.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | -------------------------------------------------------------------------------- /by-language/rust-postgres/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.lock 3 | -------------------------------------------------------------------------------- /framework/streamlit/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/.sdkmanrc: -------------------------------------------------------------------------------- 1 | java=21.0.3-tem 2 | -------------------------------------------------------------------------------- /by-language/python-dbapi/requirements.txt: -------------------------------------------------------------------------------- 1 | crate>=2.0.0.dev6 2 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | -------------------------------------------------------------------------------- /framework/dbt/basic/requirements.txt: -------------------------------------------------------------------------------- 1 | dbt-cratedb2>=0.0.1 2 | -------------------------------------------------------------------------------- /testing/native/python-unittest/.ngr-type: -------------------------------------------------------------------------------- 1 | python-unittest 2 | -------------------------------------------------------------------------------- /by-language/csharp-npgsql/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | TestResults 4 | -------------------------------------------------------------------------------- /by-language/python-connectorx/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/requirements.txt: -------------------------------------------------------------------------------- 1 | turbodbc>=5.1.1,<6 2 | -------------------------------------------------------------------------------- /framework/dbt/materialize/requirements.txt: -------------------------------------------------------------------------------- 1 | dbt-cratedb2>=0.0.1 2 | -------------------------------------------------------------------------------- /testing/testcontainers/python-unittest/.ngr-type: -------------------------------------------------------------------------------- 1 | python-unittest 2 | -------------------------------------------------------------------------------- /by-dataframe/dask/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | pytest-cov<8 3 | -------------------------------------------------------------------------------- /by-dataframe/pandas/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | pytest-cov<8 3 | -------------------------------------------------------------------------------- /by-dataframe/polars/requirements-test.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | pytest-cov<8 3 | -------------------------------------------------------------------------------- /by-language/elixir-postgrex/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | deps 3 | *.lock 4 | -------------------------------------------------------------------------------- /framework/gradio/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | gradio-client<2.1 2 | pytest<10 3 | -------------------------------------------------------------------------------- /by-language/python-dbapi/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | pytest-cov<8 3 | -------------------------------------------------------------------------------- /topic/machine-learning/langchain/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | *.sql 3 | !init.sql 4 | -------------------------------------------------------------------------------- /application/ingestr/.dlt/config.toml: -------------------------------------------------------------------------------- 1 | [runtime] 2 | 3 | dlthub_telemetry=false 4 | -------------------------------------------------------------------------------- /by-language/csharp-efcore/.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | bin 3 | obj 4 | TestResults 5 | -------------------------------------------------------------------------------- /by-language/python-connectorx/requirements.txt: -------------------------------------------------------------------------------- 1 | connectorx<0.5 2 | pandas>2,<3 3 | -------------------------------------------------------------------------------- /by-language/python-sqlalchemy/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | pytest-cov<8 3 | -------------------------------------------------------------------------------- /framework/dbt/basic/.gitignore: -------------------------------------------------------------------------------- 1 | .user.yml 2 | target/ 3 | dbt_packages/ 4 | logs/ 5 | -------------------------------------------------------------------------------- /framework/gradio/requirements.txt: -------------------------------------------------------------------------------- 1 | gradio==5.* 2 | sqlalchemy-cratedb>=0.41.0.dev2 3 | -------------------------------------------------------------------------------- /application/metabase/requirements-test.txt: -------------------------------------------------------------------------------- 1 | pytest<10 2 | pytest-docker-compose-v2<0.3 3 | -------------------------------------------------------------------------------- /framework/dlt/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | cratedb-toolkit>=0.0.33 2 | pueblo[sfa] 3 | pytest<10 4 | -------------------------------------------------------------------------------- /framework/streamlit/requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit==1.* 2 | sqlalchemy-cratedb>=0.41.0.dev2 3 | -------------------------------------------------------------------------------- /application/apache-superset/requirements-test.txt: -------------------------------------------------------------------------------- 1 | playwright<2 2 | pytest<10 3 | requests<3 4 | -------------------------------------------------------------------------------- /by-language/python-sqlalchemy/.gitignore: -------------------------------------------------------------------------------- 1 | .venv* 2 | __pycache__ 3 | .coverage 4 | coverage.xml 5 | -------------------------------------------------------------------------------- /notebook/marimo/requirements.txt: -------------------------------------------------------------------------------- 1 | duckdb 2 | marimo 3 | pandas<2.3 4 | polars 5 | sqlalchemy-cratedb 6 | -------------------------------------------------------------------------------- /testing/native/python-unittest/requirements.txt: -------------------------------------------------------------------------------- 1 | cr8>=0.27.2 2 | crash>=0.31.5 3 | crate>=2.0.0.dev6 4 | -------------------------------------------------------------------------------- /topic/machine-learning/llm/requirements.txt: -------------------------------------------------------------------------------- 1 | llm<0.27 2 | llm-anthropic<0.18 3 | llm-ollama<0.14 4 | -------------------------------------------------------------------------------- /application/records/requirements.txt: -------------------------------------------------------------------------------- 1 | records<0.7 2 | sqlalchemy-cratedb>=0.41.0.dev2 3 | tablib[ods] 4 | -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-java/.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | *.tar.gz 3 | *.jar 4 | .venv* 5 | __pycache__ 6 | -------------------------------------------------------------------------------- /framework/graphene/requirements.txt: -------------------------------------------------------------------------------- 1 | sqlalchemy-cratedb 2 | graphene-sqlalchemy 3 | Flask 4 | Flask-GraphQL -------------------------------------------------------------------------------- /framework/records/requirements.txt: -------------------------------------------------------------------------------- 1 | records<0.7 2 | sqlalchemy-cratedb>=0.41.0.dev2 3 | tablib[pandas] 4 | -------------------------------------------------------------------------------- /application/cratedb-toolkit/requirements-test.txt: -------------------------------------------------------------------------------- 1 | gitpython<4 2 | platformdirs<5 3 | pytest<10 4 | requests<3 5 | -------------------------------------------------------------------------------- /application/cratedb-toolkit/requirements.txt: -------------------------------------------------------------------------------- 1 | crate>=2.0.0.dev6 2 | cratedb-toolkit[influxdb,mongodb]>=0.0.33 3 | -------------------------------------------------------------------------------- /application/ingestr/.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | *.ndjson 3 | *.tar.gz 4 | *.jar 5 | .venv* 6 | __pycache__ 7 | !.env -------------------------------------------------------------------------------- /framework/dbt/materialize/.gitignore: -------------------------------------------------------------------------------- 1 | .user.yml 2 | target/ 3 | dbt_packages/ 4 | logs/ 5 | package-lock.yml 6 | -------------------------------------------------------------------------------- /framework/dbt/materialize/packages.yml: -------------------------------------------------------------------------------- 1 | packages: 2 | - package: dbt-labs/dbt_utils 3 | version: 1.3.0 4 | -------------------------------------------------------------------------------- /application/ingestr/requirements.txt: -------------------------------------------------------------------------------- 1 | ingestr @ git+https://github.com/crate-workbench/ingestr.git@kafka-decoder 2 | -------------------------------------------------------------------------------- /by-language/java-jooq/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .idea 3 | *.iws 4 | *.iml 5 | *.ipr 6 | build/ 7 | out/ 8 | target/ 9 | -------------------------------------------------------------------------------- /by-language/r/Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | 3 | test: 4 | Rscript basic_rpostgres.r 5 | Rscript basic_rpostgresql.r 6 | -------------------------------------------------------------------------------- /operation/compose/ssl/keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/operation/compose/ssl/keystore -------------------------------------------------------------------------------- /topic/machine-learning/llama-index/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | cratedb-toolkit>=0.0.33 2 | pueblo[testing] 3 | sqlparse 4 | -------------------------------------------------------------------------------- /topic/machine-learning/mlflow/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .ruff_cache 3 | .venv* 4 | /mlartifacts 5 | /mlruns 6 | /model 7 | -------------------------------------------------------------------------------- /topic/machine-learning/pycaret/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .env.local 3 | *.log 4 | catboost_info/ 5 | mlruns/ 6 | model/ 7 | -------------------------------------------------------------------------------- /operation/compose/ssl/truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/operation/compose/ssl/truststore -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pueblo>=0.0.8 2 | 3 | # Development. 4 | # pueblo @ git+https://github.com/pyveci/pueblo.git@main 5 | -------------------------------------------------------------------------------- /testing/testcontainers/java/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .idea 3 | *.iws 4 | *.iml 5 | *.ipr 6 | build/ 7 | out/ 8 | target/ 9 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/src/test/resources/testcontainers.properties: -------------------------------------------------------------------------------- 1 | #hub.image.name.prefix=my.company.com/some/path/ -------------------------------------------------------------------------------- /testing/native/python-pytest/requirements.txt: -------------------------------------------------------------------------------- 1 | crash>=0.31.5 2 | crate>=2.0.0.dev6 3 | pytest<10 4 | pytest-cratedb>=0.4.0 5 | -------------------------------------------------------------------------------- /application/apache-superset/requirements.txt: -------------------------------------------------------------------------------- 1 | apache-superset 2 | flask-jwt-extended>=4.7.1 3 | sqlalchemy-cratedb>=0.41.0.dev2 4 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !build/*-runner 3 | !build/*-runner.jar 4 | !build/lib/* 5 | !build/quarkus-app/* -------------------------------------------------------------------------------- /testing/testcontainers/python-unittest/requirements.txt: -------------------------------------------------------------------------------- 1 | crash>=0.31.5 2 | crate>=2.0.0.dev6 3 | cratedb-toolkit[testing]>=0.0.33 4 | -------------------------------------------------------------------------------- /topic/chatbot/table-augmented-generation/app/requirements.txt: -------------------------------------------------------------------------------- 1 | python-dotenv 2 | openai>=1.0.0 3 | crate 4 | pandas 5 | ipywidgets 6 | -------------------------------------------------------------------------------- /topic/chatbot/table-augmented-generation/workshop/requirements-test.txt: -------------------------------------------------------------------------------- 1 | pueblo[notebook,testing]>=0.0.10 2 | sqlalchemy-cratedb 3 | -------------------------------------------------------------------------------- /topic/machine-learning/llm/sql-response.txt: -------------------------------------------------------------------------------- 1 | Given an input question, synthesize a response from the query results. 2 | Query: 3 | -------------------------------------------------------------------------------- /operation/compose/ssl/client_pgsql.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | psql "postgresql://crate@localhost:5432/?sslmode=require" -c "SELECT 42" 4 | -------------------------------------------------------------------------------- /testing/testcontainers/python-pytest/requirements.txt: -------------------------------------------------------------------------------- 1 | crash>=0.31.5 2 | crate>=2.0.0.dev6 3 | cratedb-toolkit[testing]>=0.0.33 4 | pytest<10 5 | -------------------------------------------------------------------------------- /application/microsoft-ssis/ssis-cratedb-demo/Project.params: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /by-language/go-pgx/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAll(t *testing.T) { 8 | main() 9 | } 10 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/requirements-prereq.txt: -------------------------------------------------------------------------------- 1 | # Turbodbc wants NumPy and PyArrow to be installed upfront. 2 | numpy>=2 3 | pyarrow<20 4 | wheel 5 | -------------------------------------------------------------------------------- /by-language/ruby/Rakefile: -------------------------------------------------------------------------------- 1 | task default: %w[test] 2 | 3 | task :test do 4 | ruby "ruby_example.rb crate_ruby" 5 | ruby "ruby_example.rb pg" 6 | end 7 | -------------------------------------------------------------------------------- /framework/mcp/requirements.txt: -------------------------------------------------------------------------------- 1 | cratedb-mcp 2 | cratedb-toolkit>=0.0.33 3 | mcp<1.7 4 | mcp-alchemy~=2025.4 5 | sqlalchemy-cratedb>=0.42.0.dev2 6 | where 7 | -------------------------------------------------------------------------------- /topic/timeseries/weather-data-grafana-dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/topic/timeseries/weather-data-grafana-dashboard.png -------------------------------------------------------------------------------- /by-language/java-jooq/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/by-language/java-jooq/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /topic/multi-model/multi-model-offshore-wind-farms.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/topic/multi-model/multi-model-offshore-wind-farms.jpg -------------------------------------------------------------------------------- /by-language/elixir-postgrex/backlog.md: -------------------------------------------------------------------------------- 1 | # Backlog for connecting to CrateDB with Elixir 2 | 3 | - Evaluate connectivity with Ecto 4 | https://hexdocs.pm/ecto/Ecto.html 5 | -------------------------------------------------------------------------------- /by-language/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'crate_ruby', '<1' 6 | gem 'pg', '<2' 7 | gem 'rake', '<14' 8 | -------------------------------------------------------------------------------- /by-language/rust-postgres/src/tests.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | mod tests { 3 | use crate::main; 4 | #[test] 5 | fn test_main() { 6 | main(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /by-dataframe/polars/requirements.txt: -------------------------------------------------------------------------------- 1 | adbc-driver-postgresql<1.10 2 | connectorx>=0.4.5a1 3 | pandas<2.4 4 | polars<1.37 5 | pyarrow<23 6 | sqlalchemy-cratedb>=0.42.0.dev2 7 | -------------------------------------------------------------------------------- /topic/machine-learning/pycaret/backlog.md: -------------------------------------------------------------------------------- 1 | # Backlog 2 | 3 | - Describe / program how to import `churn-dataset.csv`. 4 | - Format and lint notebooks using `black` and `ruff`. 5 | -------------------------------------------------------------------------------- /topic/multi-model/multi-model-offshore-wind-farms-query.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/topic/multi-model/multi-model-offshore-wind-farms-query.png -------------------------------------------------------------------------------- /by-language/java-jooq/src/main/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | # https://www.slf4j.org/api/org/slf4j/simple/SimpleLogger.html 2 | org.slf4j.simpleLogger.defaultLogLevel=debug 3 | -------------------------------------------------------------------------------- /testing/testcontainers/java/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/testing/testcontainers/java/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /framework/dbt/basic/models/example/starter_second.sql: -------------------------------------------------------------------------------- 1 | 2 | -- Use the `ref` function to select from other models 3 | 4 | select * 5 | from {{ ref('starter_first') }} 6 | where id = 1 7 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crate/cratedb-examples/HEAD/by-language/java-quarkus-panache/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.7z filter=lfs diff=lfs merge=lfs -text 2 | *.bz2 filter=lfs diff=lfs merge=lfs -text 3 | *.gz filter=lfs diff=lfs merge=lfs -text 4 | *.zip filter=lfs diff=lfs merge=lfs -text 5 | -------------------------------------------------------------------------------- /topic/timeseries/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # Real. 2 | pueblo[notebook,testing]>=0.0.10 3 | 4 | # Development. 5 | # pueblo[notebook,testing] @ git+https://github.com/pyveci/pueblo.git@amo/testbook 6 | -------------------------------------------------------------------------------- /by-language/go-pgx/setup.sql: -------------------------------------------------------------------------------- 1 | -- dbext:type=CRATE:host=localhost:port=4200:dbname=doc 2 | 3 | CREATE TABLE IF NOT EXISTS testdrive.go_users ( 4 | id LONG, 5 | name STRING, 6 | value FLOAT 7 | ) 8 | -------------------------------------------------------------------------------- /by-language/java-jdbc/Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | mvn exec:java -Dexec.args="--dburl 'jdbc:postgresql://localhost:5432/testdrive'" 3 | mvn exec:java -Dexec.args="--dburl 'jdbc:crate://localhost:5432/testdrive'" 4 | -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-python/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10 2 | 3 | WORKDIR /app 4 | COPY * /app 5 | 6 | RUN pip install poetry 7 | RUN poetry config virtualenvs.create false && poetry install 8 | -------------------------------------------------------------------------------- /topic/timeseries/requirements.txt: -------------------------------------------------------------------------------- 1 | cratedb-toolkit[datasets]>=0.0.33 2 | refinitiv-data<1.7 3 | pandas==2.0.* 4 | pycaret==3.3.2 5 | pydantic<3 6 | sqlalchemy==2.0.* 7 | sqlalchemy-cratedb>=0.41.0.dev2 8 | -------------------------------------------------------------------------------- /by-language/python-connectorx/backlog.md: -------------------------------------------------------------------------------- 1 | SELECT * FROM sys.summits ORDER BY height DESC LIMIT 10 2 | pyo3_runtime.PanicException: not implemented: point 3 | https://github.com/sfu-db/connector-x/issues/723 4 | -------------------------------------------------------------------------------- /by-language/java-jooq/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | application.datasource.url=jdbc:postgresql://localhost:5432/testdrive 2 | application.datasource.username=crate 3 | application.datasource.password= 4 | -------------------------------------------------------------------------------- /by-language/rust-postgres/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cratedb-rust-tests" 3 | version = "0.0.0" 4 | authors = ["The CrateDB Developers"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | postgres = "0.19.7" 9 | -------------------------------------------------------------------------------- /notebook/jupyter/docs/conf.py: -------------------------------------------------------------------------------- 1 | project = "CrateDB Jupyter Examples" 2 | copyright = "2023-2025, The CrateDB Developers" 3 | author = "The CrateDB Developers" 4 | 5 | html_theme = "furo" 6 | extensions = ["myst_nb"] 7 | -------------------------------------------------------------------------------- /by-dataframe/pandas/requirements.txt: -------------------------------------------------------------------------------- 1 | click<9 2 | colorlog<7 3 | crate>=2.0.0.dev6 4 | pandas==2.3.* 5 | pueblo>=0.0.10 6 | sqlalchemy-cratedb[all] @ git+https://github.com/crate-workbench/sqlalchemy-cratedb@amo/postgresql-async 7 | -------------------------------------------------------------------------------- /by-language/r/backlog.md: -------------------------------------------------------------------------------- 1 | # Backlog for R with CrateDB 2 | 3 | ## Bugs 4 | 5 | - `SELECT * FROM sys.summits` will fail like: 6 | ``` 7 | RPosgreSQL warning: unrecognized PostgreSQL field type point (id:600) in column 1 8 | ``` 9 | -------------------------------------------------------------------------------- /application/records/test.py: -------------------------------------------------------------------------------- 1 | import shlex 2 | import subprocess 3 | import pytest 4 | 5 | 6 | def run(command: str): 7 | subprocess.check_call(shlex.split(command)) 8 | 9 | 10 | def test_example(): 11 | run("sh example.sh") 12 | -------------------------------------------------------------------------------- /by-language/python-sqlalchemy/requirements.txt: -------------------------------------------------------------------------------- 1 | click<9 2 | colorlog<7 3 | crate>=2.0.0.dev6 4 | pueblo>=0.0.7 5 | sqlalchemy>=2,<2.1 6 | sqlalchemy-cratedb[all] @ git+https://github.com/crate-workbench/sqlalchemy-cratedb@amo/postgresql-async 7 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/gradle.properties: -------------------------------------------------------------------------------- 1 | #Gradle properties 2 | quarkusPluginId=io.quarkus 3 | quarkusPluginVersion=3.8.3 4 | quarkusPlatformGroupId=io.quarkus.platform 5 | quarkusPlatformArtifactId=quarkus-bom 6 | quarkusPlatformVersion=3.8.3 -------------------------------------------------------------------------------- /by-dataframe/dask/requirements.txt: -------------------------------------------------------------------------------- 1 | click<9 2 | colorlog<7 3 | dask[dataframe]>=2024.4.1 # Python 3.11.9 breaks previous Dask 4 | distributed>=2024.4.1 # Python 3.11.9 breaks previous Dask 5 | pueblo>=0.0.10 6 | sqlalchemy-cratedb>=0.41.0.dev2 7 | -------------------------------------------------------------------------------- /framework/dbt/materialize/models/example/jobslog.sql: -------------------------------------------------------------------------------- 1 | {{ config(materialized='ephemeral') }} 2 | 3 | SELECT id 4 | ,started 5 | ,ended 6 | ,stmt 7 | ,error 8 | ,username 9 | ,classification['type'] as type 10 | FROM sys.jobs_log 11 | 12 | -------------------------------------------------------------------------------- /by-language/python-connectorx/test.py: -------------------------------------------------------------------------------- 1 | import shlex 2 | import subprocess 3 | 4 | 5 | def run(command: str): 6 | subprocess.check_call(shlex.split(command)) 7 | 8 | 9 | def test_demo(): 10 | cmd = "time python3 demo.py" 11 | run(cmd) 12 | -------------------------------------------------------------------------------- /notebook/jupyter/README.md: -------------------------------------------------------------------------------- 1 | # CrateDB Jupyter Examples 2 | 3 | A few examples using CrateDB from Jupyter Notebooks. 4 | If you are here already, we recommend to check out the [JupySQL] examples 5 | at least. 6 | 7 | 8 | [JupySQL]: https://jupysql.ploomber.io/ 9 | -------------------------------------------------------------------------------- /notebook/jupyter/test.py: -------------------------------------------------------------------------------- 1 | from testbook import testbook 2 | 3 | 4 | def test_notebook(notebook): 5 | """ 6 | Execute Jupyter Notebook, one test case per .ipynb file. 7 | """ 8 | with testbook(notebook) as tb: 9 | tb.execute() 10 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/test.py: -------------------------------------------------------------------------------- 1 | import shlex 2 | import subprocess 3 | import pytest 4 | 5 | 6 | def run(command: str): 7 | subprocess.check_call(shlex.split(command)) 8 | 9 | 10 | def test_demo(): 11 | cmd = "time python demo.py" 12 | run(cmd) 13 | -------------------------------------------------------------------------------- /operation/compose/ssl/client_crash.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Connect to CrateDB using SSL, with host name verification turned off. 4 | uvx crash -v --hosts https://localhost:4200 \ 5 | --user=crate --format=dynamic \ 6 | --verify-ssl=false \ 7 | --command "SELECT 42" 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .venv* 3 | __pycache__ 4 | _build 5 | .coverage* 6 | .env 7 | .DS_Store 8 | .meltano 9 | .pytest_cache 10 | .zig-cache 11 | build 12 | coverage.xml 13 | mlruns/ 14 | archive/ 15 | venv/ 16 | logs.log 17 | *.tmp 18 | *.swp 19 | *.bak 20 | *.egg-info 21 | *.lock 22 | -------------------------------------------------------------------------------- /framework/dbt/basic/profiles.yml: -------------------------------------------------------------------------------- 1 | cratedb_localhost: 2 | outputs: 3 | dev: 4 | type: cratedb 5 | host: localhost 6 | user: crate 7 | pass: crate 8 | port: 5432 9 | dbname: crate 10 | schema: doc 11 | catalog: crate 12 | target: dev 13 | -------------------------------------------------------------------------------- /topic/chatbot/table-augmented-generation/workshop/test.py: -------------------------------------------------------------------------------- 1 | from testbook import testbook 2 | 3 | 4 | def test_notebook(notebook): 5 | """ 6 | Execute Jupyter Notebook, one test case per .ipynb file. 7 | """ 8 | with testbook(notebook) as tb: 9 | tb.execute() 10 | -------------------------------------------------------------------------------- /framework/dbt/materialize/profiles.yml: -------------------------------------------------------------------------------- 1 | cratedb_localhost: 2 | outputs: 3 | dev: 4 | type: cratedb 5 | host: localhost 6 | user: crate 7 | pass: crate 8 | port: 5432 9 | dbname: crate 10 | schema: doc 11 | catalog: crate 12 | target: dev 13 | -------------------------------------------------------------------------------- /by-language/java-jooq/src/main/resources/bootstrap.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS "author" ( 2 | id INTEGER PRIMARY KEY, 3 | name VARCHAR(255) 4 | ); 5 | 6 | CREATE TABLE IF NOT EXISTS "book" ( 7 | id INTEGER PRIMARY KEY, 8 | title VARCHAR(255) 9 | ); 10 | -------------------------------------------------------------------------------- /notebook/jupyter/docs/index.md: -------------------------------------------------------------------------------- 1 | # CrateDB Jupyter Examples 2 | 3 | This is a little Sphinx documentation stub that includes Jupyter Notebooks, 4 | by using [MyST-NB]. 5 | 6 | ```{toctree} 7 | :maxdepth: 2 8 | :glob: 9 | 10 | * 11 | ``` 12 | 13 | 14 | [MyST-NB]: https://myst-nb.readthedocs.io/ 15 | -------------------------------------------------------------------------------- /testing/native/python-pytest/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rsfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | -------------------------------------------------------------------------------- /application/apache-superset/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEXs -p pytester --strict-markers --verbosity=3 5 | """ 6 | log_level = "DEBUG" 7 | log_cli_level = "DEBUG" 8 | testpaths = ["*.py"] 9 | xfail_strict = true 10 | markers = [ 11 | ] 12 | -------------------------------------------------------------------------------- /framework/dlt/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | -------------------------------------------------------------------------------- /framework/gradio/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | -------------------------------------------------------------------------------- /testing/testcontainers/python-pytest/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rsfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | -------------------------------------------------------------------------------- /framework/records/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEXs -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | -------------------------------------------------------------------------------- /framework/streamlit/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | -------------------------------------------------------------------------------- /topic/serverless/azure-eventhub/Azure Function/requirements.txt: -------------------------------------------------------------------------------- 1 | # DO NOT include azure-functions-worker in this file 2 | # The Python Worker is managed by Azure Functions platform 3 | # Manually managing azure-functions-worker may cause unexpected issues 4 | 5 | azure-functions 6 | azure-eventhub 7 | crate==1.0.1 8 | -------------------------------------------------------------------------------- /application/cratedb-toolkit/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEXs -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | -------------------------------------------------------------------------------- /by-language/java-jooq/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /by-language/csharp-efcore/backlog.md: -------------------------------------------------------------------------------- 1 | # Backlog for Entity Framework Core for PostgreSQL with CrateDB 2 | 3 | - Provide test rig for all data types of CrateDB, like `DemoTypes.cs` of `csharp-npgsql`. 4 | - Can DDL statements be derived from the model, and automatically be applied? 5 | - Can models be derived by introspecting the database? 6 | -------------------------------------------------------------------------------- /testing/testcontainers/java/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /by-dataframe/spark/scala-http/build.sbt: -------------------------------------------------------------------------------- 1 | name := "SparkCrateDBhttpExample" 2 | 3 | version := "0.1" 4 | 5 | scalaVersion := "2.11.12" 6 | 7 | libraryDependencies ++= Seq( 8 | "org.scala-lang.modules" %% "scala-xml" % "1.0.6", 9 | "org.scalaj" %% "scalaj-http" % "2.4.2", 10 | "org.apache.spark" %% "spark-sql" % "2.4.8" 11 | ) 12 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenCentral() 4 | gradlePluginPortal() 5 | mavenLocal() 6 | } 7 | plugins { 8 | id "${quarkusPluginId}" version "${quarkusPluginVersion}" 9 | } 10 | } 11 | rootProject.name='java-quarkus-panache' 12 | -------------------------------------------------------------------------------- /framework/dbt/materialize/models/example/test.sql: -------------------------------------------------------------------------------- 1 | {{ config(materialized='incremental', 2 | unique_key='id', 3 | incremental_strategy='delete+insert' 4 | ) 5 | }} 6 | 7 | select * from {{ ref('jobslog') }} 8 | {% if is_incremental() %} 9 | 10 | where started >= (select max(started) from {{ this }}) 11 | 12 | {% endif %} 13 | -------------------------------------------------------------------------------- /framework/streamlit/.streamlit/secrets.toml: -------------------------------------------------------------------------------- 1 | # Streamlit secrets file for CrateDB on localhost. 2 | # https://docs.streamlit.io/develop/api-reference/connections/secrets.toml 3 | # .streamlit/secrets.toml 4 | 5 | [connections.cratedb] 6 | dialect = "crate" 7 | host = "localhost" 8 | port = "4200" 9 | username = "crate" 10 | password = "" 11 | -------------------------------------------------------------------------------- /topic/machine-learning/llama-index/requirements.txt: -------------------------------------------------------------------------------- 1 | cratedb-about==0.0.10 2 | langchain-openai<1.2 3 | llama-index-embeddings-langchain<0.5 4 | llama-index-embeddings-openai<0.6 5 | llama-index-llms-azure-openai<0.5 6 | llama-index-llms-ollama<0.10 7 | llama-index-llms-openai<0.7 8 | llama-index-tools-mcp<0.5 9 | python-dotenv 10 | sqlalchemy-cratedb 11 | -------------------------------------------------------------------------------- /by-language/python-dbapi/test.py: -------------------------------------------------------------------------------- 1 | import shlex 2 | import subprocess 3 | import pytest 4 | 5 | 6 | def run(command: str): 7 | subprocess.check_call(shlex.split(command)) 8 | 9 | 10 | def test_basic(): 11 | cmd = "time python basic.py" 12 | run(cmd) 13 | 14 | 15 | def test_vector(): 16 | cmd = "time python vector.py" 17 | run(cmd) 18 | -------------------------------------------------------------------------------- /framework/dbt/materialize/dbt_project.yml: -------------------------------------------------------------------------------- 1 | # Project name and metadata. 2 | name: 'testdrive_materialized' 3 | version: '1.0.0' 4 | config-version: 2 5 | 6 | # Configure connection profile dbt uses for this project. 7 | profile: 'cratedb_localhost' 8 | 9 | # Directories to be removed by `dbt clean`. 10 | clean-targets: 11 | - "target" 12 | - "dbt_packages" 13 | -------------------------------------------------------------------------------- /framework/dlt/.gitignore: -------------------------------------------------------------------------------- 1 | # ignore secrets, virtual environments and typical python compilation artifacts 2 | # remark: Add it in this case, in order to provide out-of-the-box settings for localhost 3 | # secrets.toml 4 | # ignore basic python artifacts 5 | .env 6 | **/__pycache__/ 7 | **/*.py[cod] 8 | **/*$py.class 9 | # ignore duckdb 10 | *.duckdb 11 | *.wal 12 | -------------------------------------------------------------------------------- /topic/machine-learning/pycaret/requirements.txt: -------------------------------------------------------------------------------- 1 | # Real. 2 | dask==2024.12.1 3 | mlflow-cratedb==2.14.1 4 | plotly<6.6 5 | pycaret[models,parallel,test]==3.3.2 6 | pydantic<3 7 | python-dotenv<2 8 | sqlalchemy==2.* 9 | sqlalchemy-cratedb>=0.41.0.dev2 10 | 11 | # Development. 12 | # mlflow-cratedb @ git+https://github.com/crate-workbench/mlflow-cratedb.git@main 13 | -------------------------------------------------------------------------------- /by-language/python-connectorx/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | 14 | [tool.ruff] 15 | line-length = 100 16 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | 14 | [tool.ruff] 15 | line-length = 100 16 | -------------------------------------------------------------------------------- /application/metabase/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEXs -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | --docker-compose-no-build 7 | --use-running-containers 8 | """ 9 | log_level = "DEBUG" 10 | log_cli_level = "DEBUG" 11 | testpaths = ["*.py"] 12 | xfail_strict = true 13 | markers = [ 14 | ] 15 | -------------------------------------------------------------------------------- /topic/machine-learning/mlflow/requirements.txt: -------------------------------------------------------------------------------- 1 | # Real. 2 | dask>=2024.4.1 # Python 3.11.9 breaks previous Dask 3 | distributed>=2024.4.1 # Python 3.11.9 breaks previous Dask 4 | mlflow-cratedb==2.14.1 5 | pydantic<3 6 | salesforce-merlion>=2,<3 7 | sqlalchemy==2.* 8 | 9 | # Development. 10 | # mlflow-cratedb @ git+https://github.com/crate-workbench/mlflow-cratedb.git@main 11 | -------------------------------------------------------------------------------- /framework/dlt/requirements.txt: -------------------------------------------------------------------------------- 1 | # Development 2 | #dlt[cratedb,parquet] @ git+https://github.com/crate-workbench/dlt@cratedb 3 | 4 | # Staging 5 | dlt[parquet] 6 | dlt-cratedb>=0.0.1 7 | 8 | # Production 9 | # TODO: switch to official dlt[cratedb]>=1.12.0 once it’s published with CrateDB support. 10 | # dlt[cratedb,parquet]>=1.12.0 11 | 12 | pandas>=2,<2.4 13 | pymysql>=1,<1.2 14 | -------------------------------------------------------------------------------- /topic/machine-learning/open-webui/init/.env: -------------------------------------------------------------------------------- 1 | # ------------------------------------------ 2 | # System configuration 3 | # ------------------------------------------ 4 | 5 | # If you run `setup.sh` from within the Docker Compose 6 | # environment, you will not need to change those settings. 7 | 8 | CRATEDB_URL=http://cratedb:4200 9 | OPEN_WEBUI_URL=http://open-webui:8080 10 | -------------------------------------------------------------------------------- /framework/dlt/.dlt/config.toml: -------------------------------------------------------------------------------- 1 | # Put your main configuration values here. 2 | #add_dlt_id = false 3 | #add_dlt_load_id = false 4 | 5 | [runtime] 6 | 7 | # The system log level of dlt. 8 | log_level="DEBUG" 9 | 10 | # Use the `dlthub_telemetry` setting to enable/disable anonymous 11 | # usage data reporting, see https://dlthub.com/docs/reference/telemetry. 12 | dlthub_telemetry = false 13 | -------------------------------------------------------------------------------- /topic/machine-learning/langchain/requirements.txt: -------------------------------------------------------------------------------- 1 | crash 2 | cratedb-about==0.0.10 3 | google-cloud-aiplatform<2 4 | langchain-cratedb<0.2.1 5 | langchain-mcp-adapters<0.2 6 | langchain-google-vertexai<4 7 | langchain-openai<1.2 8 | langchain-text-splitters<1.2 9 | langgraph<1.1 10 | pueblo[cli,nlp]>=0.0.10 11 | pypdf<7 12 | python-dotenv<2 13 | requests<3 14 | requests-cache<2 15 | unstructured<0.19 16 | -------------------------------------------------------------------------------- /by-language/go-pgx/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | hosts := flag.String("hosts", "localhost", "CrateDB hostname") 10 | port := flag.Int("port", 5432, "CrateDB postgres port") 11 | flag.Parse() 12 | connStr := fmt.Sprintf("postgres://crate@%s:%d/testdrive", *hosts, *port) 13 | runBasicQueries(connStr) 14 | runBulkOperations(connStr) 15 | } 16 | -------------------------------------------------------------------------------- /framework/mcp/example_pg_mcp_server.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | # FIXME: Improve invocation after packaging has been improved. 3 | # https://github.com/stuzero/pg-mcp-server/issues/10 4 | from server.app import logger, mcp 5 | 6 | # TODO: Bring flexible invocation (sse vs. stdio) to mainline. 7 | logger.info("Starting MCP server with STDIO transport") 8 | mcp.run(transport="stdio") 9 | -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-java/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Sandbox operations for IIoT tutorials 3 | # 4 | 5 | # Start foundation infrastructure. 6 | start: 7 | docker compose up 8 | 9 | # Publish a message to the Kafka broker. 10 | test-publish: 11 | echo hello | kcat -b localhost -P -t testdrive 12 | 13 | # Consume messages from the Kafka broker. 14 | test-consume: 15 | kcat -b localhost -C -t testdrive -o end 16 | -------------------------------------------------------------------------------- /topic/machine-learning/open-webui/.env: -------------------------------------------------------------------------------- 1 | # ------------------------------------------ 2 | # User configuration 3 | # ------------------------------------------ 4 | 5 | # Define your OpenAI API key here if you want to make it persistent. 6 | # You can also use other models with Open WebUI, however that is 7 | # currently out of the scope of this miniature rig. 8 | 9 | # OPENAI_API_KEY=your_openai_api_key 10 | -------------------------------------------------------------------------------- /by-language/go-pgx/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/cratedb-examples/by-language/go-pgx 2 | 3 | go 1.23.0 4 | 5 | toolchain go1.24.1 6 | 7 | require github.com/jackc/pgx/v5 v5.7.6 8 | 9 | require ( 10 | github.com/jackc/pgpassfile v1.0.0 // indirect 11 | github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect 12 | golang.org/x/crypto v0.37.0 // indirect 13 | golang.org/x/text v0.24.0 // indirect 14 | ) 15 | -------------------------------------------------------------------------------- /application/microsoft-ssis/ssis-cratedb-demo/cratedb.conmgr: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /by-dataframe/pandas/test_read.py: -------------------------------------------------------------------------------- 1 | import shlex 2 | import subprocess 3 | 4 | 5 | def run(command: str): 6 | subprocess.check_call(shlex.split(command)) 7 | 8 | 9 | def test_read_urllib3(): 10 | cmd = "time python read_pandas.py --dburi=crate+urllib3://crate@localhost:4200" 11 | run(cmd) 12 | 13 | 14 | def test_read_psycopg3(): 15 | cmd = "time python read_pandas.py --dburi=crate+psycopg://crate@localhost:5432" 16 | run(cmd) 17 | -------------------------------------------------------------------------------- /application/apache-superset/util.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | uri_login = "http://localhost:8088/api/v1/security/login" 4 | 5 | 6 | def get_access_token(): 7 | response = requests.post(uri_login, json={"username": "admin", "password": "admin", "provider": "db"}) 8 | return response.json()["access_token"] 9 | 10 | 11 | def get_auth_headers(): 12 | access_token = get_access_token() 13 | return {"Authorization": f"Bearer {access_token}"} 14 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | quarkus.datasource.db-kind = postgresql 2 | 3 | # Crate DB specific configuration 4 | quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/testdrive 5 | quarkus.datasource.username=crate 6 | quarkus.datasource.password= 7 | quarkus.hibernate-orm.dialect=io.crate.CrateDBDialect 8 | 9 | quarkus.hibernate-orm.database.generation=update 10 | quarkus.hibernate-orm.sql-load-script=no-file -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "cratedb-weather-data" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["ivan.sanchez "] 6 | readme = "README.md" 7 | 8 | [tool.poetry.dependencies] 9 | python = "^3.9" 10 | requests = "^2.31.0" 11 | kafka-python = "^2.0.2" 12 | apache-flink = "^1.18.1" 13 | 14 | [build-system] 15 | requires = ["poetry-core"] 16 | build-backend = "poetry.core.masonry.api" 17 | -------------------------------------------------------------------------------- /by-language/elixir-postgrex/mix.exs: -------------------------------------------------------------------------------- 1 | defmodule CrateDBExample.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :cratedb_elixir_example, 7 | version: "0.0.0", 8 | elixir: "~> 1.0", 9 | deps: deps(), 10 | ] 11 | end 12 | 13 | def application() do 14 | [] 15 | end 16 | 17 | defp deps() do 18 | [ 19 | {:jason, "~> 1.4"}, 20 | {:postgrex, "~> 0.21"}, 21 | ] 22 | end 23 | 24 | end 25 | -------------------------------------------------------------------------------- /framework/mcp/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "cratedb-mcp-examples" 3 | version = "0.0.0" 4 | requires-python = ">=3.9" 5 | 6 | [tool.setuptools.packages.find] 7 | where = ["."] 8 | 9 | [tool.pytest.ini_options] 10 | minversion = "2.0" 11 | addopts = """ 12 | -rfEXs -p pytester --strict-markers --verbosity=3 13 | --capture=no 14 | """ 15 | log_level = "DEBUG" 16 | log_cli_level = "DEBUG" 17 | testpaths = ["*.py"] 18 | xfail_strict = true 19 | markers = [ 20 | ] 21 | -------------------------------------------------------------------------------- /topic/machine-learning/langchain/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # Production. 2 | cratedb-toolkit[io]>=0.0.33 3 | pueblo[notebook,testing] 4 | 5 | # Staging. 6 | # cratedb-toolkit[io] @ git+https://github.com/crate-workbench/cratedb-toolkit.git@main 7 | # pueblo[notebook,testing] @ git+https://github.com/pyveci/pueblo.git@main 8 | 9 | # Development. 10 | #--editable=/Users/amo/dev/crate/ecosystem/cratedb-retentions[io] 11 | #--editable=/Users/amo/dev/pyveci/sources/pueblo[testing] 12 | -------------------------------------------------------------------------------- /framework/streamlit/.streamlit/secrets-cratedb-cloud.toml: -------------------------------------------------------------------------------- 1 | # Streamlit secrets file for CrateDB Cloud. 2 | # https://docs.streamlit.io/develop/api-reference/connections/secrets.toml 3 | # .streamlit/secrets.toml 4 | 5 | [connections.cratedb] 6 | dialect = "crate" 7 | host = "example.gke1.us-central1.gcp.cratedb.net" 8 | port = "4200" 9 | username = "admin" 10 | password = "g_,8.F0fNbVSk0.*!n54S5c," 11 | 12 | [connections.cratedb.create_engine_kwargs.connect_args] 13 | ssl = true 14 | -------------------------------------------------------------------------------- /topic/machine-learning/llama-index/env.azure: -------------------------------------------------------------------------------- 1 | export LLM_BACKEND=azure 2 | export LLM_MODEL=gpt-4.1 3 | 4 | export OPENAI_API_KEY=TODO 5 | export OPENAI_API_TYPE=azure 6 | export OPENAI_AZURE_ENDPOINT=https://TODO.openai.azure.com 7 | export OPENAI_AZURE_API_VERSION=2024-08-01-preview 8 | export LLM_INSTANCE=TODO 9 | export EMBEDDING_MODEL_INSTANCE=TODO 10 | export CRATEDB_SQLALCHEMY_URL="crate://USER:PASSWORD@HOST:4200/?ssl=true" 11 | export CRATEDB_TABLE_NAME=time_series_data 12 | -------------------------------------------------------------------------------- /topic/machine-learning/mlflow/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # Real. 2 | cratedb-toolkit[io]>=0.0.33 3 | pueblo[notebook,testing]>=0.0.10 4 | 5 | # Development. 6 | # cratedb-toolkit[io] @ git+https://github.com/crate-workbench/cratedb-toolkit.git@7f3a493 7 | # pueblo[notebook,testing] @ git+https://github.com/pyveci/pueblo.git@main 8 | 9 | # Workstation. 10 | #--editable=/Users/amo/dev/crate/ecosystem/cratedb-retentions[io] 11 | #--editable=/Users/amo/dev/pyveci/sources/pueblo[testing] 12 | -------------------------------------------------------------------------------- /application/records/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --capture=no 6 | """ 7 | log_level = "DEBUG" 8 | log_cli_level = "DEBUG" 9 | testpaths = ["*.py"] 10 | xfail_strict = true 11 | markers = [ 12 | ] 13 | 14 | 15 | [tool.coverage.run] 16 | branch = false 17 | omit = [ 18 | "test*", 19 | ] 20 | 21 | [tool.coverage.report] 22 | fail_under = 0 23 | show_missing = true 24 | -------------------------------------------------------------------------------- /topic/machine-learning/pycaret/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # Real. 2 | cratedb-toolkit[io]>=0.0.33 3 | pueblo[notebook,testing]>=0.0.10 4 | 5 | # Development. 6 | # cratedb-toolkit[io] @ git+https://github.com/crate-workbench/cratedb-toolkit.git@7f3a493 7 | # pueblo[notebook,testing] @ git+https://github.com/pyveci/pueblo.git@main 8 | 9 | # Workstation. 10 | # --editable=/Users/amo/dev/crate/ecosystem/cratedb-retentions[io] 11 | # --editable=/Users/amo/dev/pyveci/sources/pueblo[testing] 12 | -------------------------------------------------------------------------------- /by-language/go-pgx/DEVELOP.md: -------------------------------------------------------------------------------- 1 | # Maintenance 2 | 3 | A few project maintenance commands. 4 | 5 | Invoke linter. 6 | ```shell 7 | gofmt -l -d . 8 | ``` 9 | 10 | Format code. 11 | ```shell 12 | gofmt -w . 13 | ``` 14 | 15 | Display available minor and patch upgrades for all direct and indirect dependencies. 16 | ```shell 17 | go list -u -m all 18 | ``` 19 | 20 | Update to the latest patch releases, including test dependencies. 21 | ```shell 22 | go get -u=patch -t 23 | go mod tidy 24 | ``` 25 | -------------------------------------------------------------------------------- /topic/machine-learning/open-webui/init/tool-servers.json: -------------------------------------------------------------------------------- 1 | { 2 | "TOOL_SERVER_CONNECTIONS": [ 3 | { 4 | "url": "http://cratedb-mcpo:8000", 5 | "path": "openapi.json", 6 | "auth_type": "bearer", 7 | "key": "", 8 | "config": { 9 | "enable": true, 10 | "access_control": null 11 | }, 12 | "info": { 13 | "name": "CrateDB", 14 | "description": "CrateDB Text-to-SQL and documentation inquiry." 15 | } 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /topic/chatbot/table-augmented-generation/workshop/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 | env = [ 7 | "CRATEDB_CONNECTION_STRING=crate://crate@localhost/?schema=notebook", 8 | "PYDEVD_DISABLE_FILE_VALIDATION=1", 9 | ] 10 | 11 | log_level = "DEBUG" 12 | log_cli_level = "DEBUG" 13 | 14 | testpaths = [ 15 | "*.py", 16 | ] 17 | xfail_strict = true 18 | markers = [ 19 | ] 20 | -------------------------------------------------------------------------------- /application/ingestr/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # ingestr integration test backplane. 4 | 5 | set -eu 6 | 7 | export INGESTR_DISABLE_TELEMETRY=true 8 | 9 | # Install `uv`. 10 | function setup() { 11 | if ! command -v uv >/dev/null 2>&1; then 12 | pip install uv 13 | fi 14 | if ! command -v xonsh >/dev/null 2>&1; then 15 | uv tool install xonsh 16 | fi 17 | } 18 | 19 | # Invoke Kafka tests. 20 | function test_kafka() { 21 | xonsh kafka-demo.xsh 22 | } 23 | 24 | setup 25 | test_kafka 26 | -------------------------------------------------------------------------------- /by-dataframe/dask/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --cov --cov-report=term-missing 6 | --capture=no 7 | """ 8 | log_level = "DEBUG" 9 | log_cli_level = "DEBUG" 10 | testpaths = ["*.py"] 11 | xfail_strict = true 12 | markers = [ 13 | ] 14 | 15 | 16 | [tool.coverage.run] 17 | branch = false 18 | omit = [ 19 | "test*", 20 | ] 21 | 22 | [tool.coverage.report] 23 | fail_under = 0 24 | show_missing = true 25 | -------------------------------------------------------------------------------- /by-dataframe/pandas/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --cov --cov-report=term-missing 6 | --capture=no 7 | """ 8 | log_level = "DEBUG" 9 | log_cli_level = "DEBUG" 10 | testpaths = ["*.py"] 11 | xfail_strict = true 12 | markers = [ 13 | ] 14 | 15 | 16 | [tool.coverage.run] 17 | branch = false 18 | omit = [ 19 | "test*", 20 | ] 21 | 22 | [tool.coverage.report] 23 | fail_under = 0 24 | show_missing = true 25 | -------------------------------------------------------------------------------- /by-dataframe/polars/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --cov --cov-report=term-missing 6 | --capture=no 7 | """ 8 | log_level = "DEBUG" 9 | log_cli_level = "DEBUG" 10 | testpaths = ["*.py"] 11 | xfail_strict = true 12 | markers = [ 13 | ] 14 | 15 | 16 | [tool.coverage.run] 17 | branch = false 18 | omit = [ 19 | "test*", 20 | ] 21 | 22 | [tool.coverage.report] 23 | fail_under = 0 24 | show_missing = true 25 | -------------------------------------------------------------------------------- /application/roapi/notes.md: -------------------------------------------------------------------------------- 1 | # Notes 2 | 3 | ## Backlog 4 | 5 | ```shell 6 | # Currently, advanced options can't be provided at runtime, please use a config file. 7 | # https://github.com/roapi/roapi#config-file 8 | # echo '[{"tableName": "ubuntu-ami", "uri": "test_data/ubuntu-ami.json", "option": {"format": "json", "pointer": "/aaData", "array_encoded": true}}]' | \ 9 | # http POST http://localhost:8080/api/table 10 | #psql -P pager=off "postgresql://localhost:5434?sslmode=disable" -c 'SELECT * FROM "ubuntu-ami"' 11 | ``` 12 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle/ 3 | build/ 4 | 5 | # Eclipse 6 | .project 7 | .classpath 8 | .settings/ 9 | bin/ 10 | 11 | # IntelliJ 12 | .idea 13 | *.ipr 14 | *.iml 15 | *.iws 16 | 17 | # NetBeans 18 | nb-configuration.xml 19 | 20 | # Visual Studio Code 21 | .vscode 22 | .factorypath 23 | 24 | # OSX 25 | .DS_Store 26 | 27 | # Vim 28 | *.swp 29 | *.swo 30 | 31 | # patch 32 | *.orig 33 | *.rej 34 | 35 | # Local environment 36 | .env 37 | 38 | # Plugin directory 39 | /.quarkus/cli/plugins/ 40 | -------------------------------------------------------------------------------- /testing/testcontainers/java/src/test/resources/init.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE alltypes ( 2 | name STRING PRIMARY KEY, 3 | date TIMESTAMP, 4 | datetime_tz TIMESTAMP WITH TIME ZONE, 5 | datetime_notz TIMESTAMP WITHOUT TIME ZONE, 6 | nullable_datetime TIMESTAMP, 7 | nullable_date TIMESTAMP, 8 | kind STRING, 9 | flag BOOLEAN, 10 | position INTEGER, 11 | description STRING, 12 | details ARRAY(OBJECT), 13 | attributes OBJECT(DYNAMIC), 14 | coordinates GEO_POINT 15 | ) WITH (number_of_replicas=0); 16 | -------------------------------------------------------------------------------- /by-language/python-dbapi/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --cov --cov-report=term-missing --cov-report=xml 6 | --capture=no 7 | """ 8 | log_level = "DEBUG" 9 | log_cli_level = "DEBUG" 10 | testpaths = ["*.py"] 11 | xfail_strict = true 12 | markers = [ 13 | ] 14 | 15 | 16 | [tool.coverage.run] 17 | branch = false 18 | omit = [ 19 | "test*", 20 | ] 21 | 22 | [tool.coverage.report] 23 | fail_under = 0 24 | show_missing = true 25 | -------------------------------------------------------------------------------- /by-language/python-sqlalchemy/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 5 | --cov --cov-report=term-missing --cov-report=xml 6 | --capture=no 7 | """ 8 | log_level = "DEBUG" 9 | log_cli_level = "DEBUG" 10 | testpaths = ["*.py"] 11 | xfail_strict = true 12 | markers = [ 13 | ] 14 | 15 | 16 | [tool.coverage.run] 17 | branch = false 18 | omit = [ 19 | "test*", 20 | ] 21 | 22 | [tool.coverage.report] 23 | fail_under = 0 24 | show_missing = true 25 | -------------------------------------------------------------------------------- /framework/dbt/basic/models/example/schema.yml: -------------------------------------------------------------------------------- 1 | 2 | version: 2 3 | 4 | models: 5 | - name: starter_first 6 | description: "A starter dbt model" 7 | columns: 8 | - name: id 9 | description: "The primary key for this table" 10 | tests: 11 | - unique 12 | - not_null 13 | 14 | - name: starter_second 15 | description: "A starter dbt model" 16 | columns: 17 | - name: id 18 | description: "The primary key for this table" 19 | tests: 20 | - unique 21 | - not_null 22 | -------------------------------------------------------------------------------- /by-language/csharp-npgsql/BasicPoco.cs: -------------------------------------------------------------------------------- 1 | namespace demo; 2 | 3 | public class BasicPoco 4 | { 5 | 6 | public string? name { get; set; } 7 | public int? age { get; set; } 8 | 9 | public override bool Equals(object? obj) 10 | { 11 | var other = (BasicPoco?) obj; 12 | return name == other?.name && age == other?.age; 13 | } 14 | 15 | public override int GetHashCode() 16 | { 17 | return base.GetHashCode(); 18 | } 19 | 20 | public override string ToString() => "Name: " + name + " Age: " + age; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /operation/compose/ssl/Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL:=help 2 | 3 | .PHONY: test 4 | test: ## Run the integration tests. 5 | @\ 6 | docker compose up --detach 7 | sh client_crash.sh 8 | sh client_pgsql.sh 9 | uv run client_dbapi.py 10 | uv run client_sqlalchemy.py 11 | uv run client_psycopg.py 12 | docker compose down 13 | 14 | .PHONY: help 15 | help: ## Show this help message. 16 | @echo 'usage: make [target]' 17 | @echo 18 | @echo 'targets:' 19 | @grep -E '^[8+a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 20 | -------------------------------------------------------------------------------- /operation/compose/ssl/client_sqlalchemy.py: -------------------------------------------------------------------------------- 1 | # Connect to CrateDB using SSL, with host name verification turned off. 2 | 3 | # /// script 4 | # requires-python = ">=3.9" 5 | # dependencies = [ 6 | # "sqlalchemy-cratedb>=0.42.0.dev2", 7 | # ] 8 | # /// 9 | import sqlalchemy as sa 10 | 11 | 12 | def main(): 13 | engine = sa.create_engine("crate://localhost/?sslmode=require") 14 | with engine.connect() as connection: 15 | results = connection.execute(sa.text("SELECT 42;")) 16 | print(results.fetchall()) 17 | 18 | 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /topic/machine-learning/llama-index/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pytest.ini_options] 2 | minversion = "2.0" 3 | addopts = """ 4 | -rfEX -p pytester --strict-markers --verbosity=3 --capture=no 5 | --cov=. --cov-report=term-missing --cov-report=xml 6 | """ 7 | 8 | #log_level = "DEBUG" 9 | #log_cli_level = "DEBUG" 10 | 11 | testpaths = [ 12 | "*.py", 13 | ] 14 | xfail_strict = true 15 | markers = [ 16 | ] 17 | 18 | [tool.coverage.run] 19 | branch = false 20 | 21 | [tool.coverage.report] 22 | fail_under = 0 23 | show_missing = true 24 | omit = [ 25 | "conftest.py", 26 | "test*.py", 27 | ] 28 | -------------------------------------------------------------------------------- /by-dataframe/polars/read_pg.py: -------------------------------------------------------------------------------- 1 | """ 2 | Read from CrateDB using Polars and ConnectorX. 3 | 4 | Install dependencies: 5 | 6 | pip install polars connectorx 7 | """ 8 | 9 | import polars as pl 10 | 11 | CRATEDB_URI = "postgresql://crate:crate@localhost:5432/?sslmode=disable" 12 | SQL_QUERY = "SELECT mountain, height, latitude(coordinates), longitude(coordinates) FROM sys.summits ORDER BY height DESC LIMIT 3" 13 | 14 | 15 | def main(): 16 | df = pl.read_database_uri(query=SQL_QUERY, uri=CRATEDB_URI, protocol="cursor") 17 | print(df) 18 | 19 | 20 | if __name__ == "__main__": 21 | main() 22 | -------------------------------------------------------------------------------- /operation/compose/ssl/crate.yml: -------------------------------------------------------------------------------- 1 | auth.host_based.enabled: true 2 | auth: 3 | host_based: 4 | config: 5 | 1: 6 | user: crate 7 | method: trust 8 | 9 | 99: 10 | method: password 11 | 12 | ssl.http.enabled: true 13 | ssl.psql.enabled: true 14 | ssl.keystore_filepath: /crate/config/keystore 15 | ssl.keystore_password: crate.io 16 | ssl.keystore_key_password: crate.io 17 | ssl.truststore_filepath: /crate/config/truststore 18 | ssl.truststore_password: crate.io 19 | 20 | path: 21 | logs: /var/log/crate 22 | data: /data/crate 23 | 24 | network.bind_host: 0.0.0.0 25 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/odbc.ini: -------------------------------------------------------------------------------- 1 | # More options: 2 | # https://www.zabbix.com/documentation/current/en/manual/config/items/itemtypes/odbc_checks/unixodbc_postgresql 3 | 4 | [postgresql] 5 | Description = General ODBC for PostgreSQL 6 | 7 | # General 8 | FileUsage = 1 9 | 10 | # If the driver manager was built with thread support, this entry 11 | # alters the default thread serialization level (available since 1.6). 12 | Threading = 2 13 | 14 | # Linux 15 | #Driver = /usr/lib64/libodbcpsql.so 16 | #Setup = /usr/lib64/libodbcpsqlS.so 17 | 18 | # macOS 19 | Driver = /usr/local/lib/psqlodbcw.so 20 | -------------------------------------------------------------------------------- /operation/compose/ssl/client_dbapi.py: -------------------------------------------------------------------------------- 1 | # Connect to CrateDB using SSL, with host name verification turned off. 2 | 3 | # /// script 4 | # requires-python = ">=3.9" 5 | # dependencies = [ 6 | # "crate", 7 | # ] 8 | # /// 9 | from crate import client 10 | 11 | 12 | def main(): 13 | connection = client.connect("https://localhost:4200", verify_ssl_cert=False) 14 | cursor = connection.cursor() 15 | cursor.execute("SELECT 42") 16 | results = cursor.fetchall() 17 | cursor.close() 18 | connection.close() 19 | 20 | print(results) 21 | 22 | 23 | if __name__ == "__main__": 24 | main() 25 | 26 | -------------------------------------------------------------------------------- /framework/dbt/basic/models/example/starter_first.sql: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Welcome to your first dbt model! 4 | Did you know that you can also configure models directly within SQL files? 5 | This will override configurations stated in dbt_project.yml 6 | 7 | Try changing "table" to "view" below 8 | */ 9 | 10 | {{ config(materialized='table') }} 11 | 12 | with source_data as ( 13 | 14 | select 1 as id 15 | union all 16 | select null as id 17 | 18 | ) 19 | 20 | select * 21 | from source_data 22 | 23 | /* 24 | Uncomment the line below to remove records with null `id` values 25 | */ 26 | 27 | where id is not null 28 | -------------------------------------------------------------------------------- /operation/compose/ssl/client_psycopg.py: -------------------------------------------------------------------------------- 1 | # Connect to CrateDB using SSL, with host name verification turned off. 2 | 3 | # /// script 4 | # requires-python = ">=3.9" 5 | # dependencies = [ 6 | # "psycopg[binary]", 7 | # ] 8 | # /// 9 | import psycopg 10 | 11 | 12 | def main(): 13 | connection = psycopg.connect("postgresql://crate@localhost:5432/?sslmode=require") 14 | with connection.cursor(row_factory=psycopg.rows.dict_row) as cursor: 15 | cursor.execute("SELECT 42") 16 | result = cursor.fetchall() 17 | print(result) 18 | connection.close() 19 | 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /by-language/rust-postgres/README.md: -------------------------------------------------------------------------------- 1 | # Connecting to CrateDB with Rust 2 | 3 | ## About 4 | 5 | The file `src/main.rs` includes a basic example program that uses the Rust 6 | [postgres] package, a native, synchronous PostgreSQL client, to connect to 7 | CrateDB. 8 | 9 | ## Usage 10 | 11 | Start a CrateDB instance for evaluation purposes. 12 | ```shell 13 | docker run -it --rm --publish=4200:4200 --publish=5432:5432 crate:latest 14 | ``` 15 | 16 | Invoke example program. 17 | ```shell 18 | cargo run 19 | ``` 20 | 21 | Invoke software tests. 22 | ```shell 23 | cargo test 24 | ``` 25 | 26 | 27 | [postgres]: https://crates.io/crates/postgres 28 | -------------------------------------------------------------------------------- /by-language/python-pg8000/basic.py: -------------------------------------------------------------------------------- 1 | import ssl 2 | 3 | import pg8000 4 | 5 | # When connecting to CrateDB Cloud you may want to use SSL 6 | # ssl_context = ssl.create_default_context() 7 | 8 | conn = pg8000.connect( 9 | user="crate", 10 | password="", 11 | host="localhost", 12 | port=5432, 13 | database="doc", 14 | # ssl_context=ssl_context, 15 | ) 16 | 17 | query = """ 18 | SELECT mountain,height 19 | FROM sys.summits 20 | WHERE height >= :minimum_height 21 | ORDER BY height DESC 22 | LIMIT :number_of_rows; 23 | """ 24 | 25 | ps = conn.prepare(query) 26 | ps.run(minimum_height=4000, number_of_rows=10) 27 | -------------------------------------------------------------------------------- /topic/timeseries/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 | env = [ 7 | "CRATEDB_CONNECTION_STRING=crate://crate@localhost/?schema=notebook", 8 | "PYDEVD_DISABLE_FILE_VALIDATION=1", 9 | ] 10 | 11 | log_level = "DEBUG" 12 | log_cli_level = "DEBUG" 13 | 14 | testpaths = [ 15 | "*.py", 16 | ] 17 | xfail_strict = true 18 | markers = [ 19 | ] 20 | 21 | [tool.coverage.run] 22 | branch = false 23 | 24 | [tool.coverage.report] 25 | fail_under = 0 26 | show_missing = true 27 | omit = [ 28 | "conftest.py", 29 | "test*.py", 30 | ] 31 | -------------------------------------------------------------------------------- /by-language/go-pgx/README.md: -------------------------------------------------------------------------------- 1 | # Connecting to CrateDB with Go 2 | 3 | ## About 4 | 5 | The files `test/basic_queries.go` and `test/bulk_operations.go` include 6 | basic example programs that use the canonical PostgreSQL driver for Go, 7 | [pgx], to connect to CrateDB. 8 | 9 | ## Usage 10 | 11 | Start a CrateDB instance for evaluation purposes. 12 | ```shell 13 | docker run -it --rm --publish=4200:4200 --publish=5432:5432 \ 14 | crate:latest -Cdiscovery.type=single-node 15 | ``` 16 | 17 | Invoke example program. 18 | ```shell 19 | go run . 20 | ``` 21 | 22 | Invoke test cases. 23 | ```shell 24 | go test -v 25 | ``` 26 | 27 | 28 | [pgx]: https://github.com/jackc/pgx 29 | -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-python/flink_job.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10-bullseye 2 | # Python version is important, because as of today (2024-03-04) kafka-flink is only 3 | # supported for python<=3.10 4 | 5 | ARG POSTGRESQL_JAR_URL 6 | ARG FLINK_SQL_JAR_URL 7 | ARG FLINK_KAFKA_JAR_URL 8 | 9 | WORKDIR /app 10 | COPY * /app 11 | RUN wget ${POSTGRESQL_JAR_URL} --directory-prefix=/app/jars 12 | RUN wget ${FLINK_SQL_JAR_URL} --directory-prefix=/app/jars 13 | RUN wget ${FLINK_KAFKA_JAR_URL} --directory-prefix=/app/jars 14 | 15 | RUN apt update && apt install -y openjdk-11-jdk 16 | RUN pip install poetry 17 | 18 | RUN poetry config virtualenvs.create false && poetry install 19 | -------------------------------------------------------------------------------- /topic/machine-learning/mlflow/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 | env = [ 7 | "CRATEDB_CONNECTION_STRING=crate://crate@localhost/?schema=testdrive", 8 | "PYDEVD_DISABLE_FILE_VALIDATION=1", 9 | ] 10 | 11 | #log_level = "DEBUG" 12 | #log_cli_level = "DEBUG" 13 | 14 | testpaths = [ 15 | "*.py", 16 | ] 17 | xfail_strict = true 18 | markers = [ 19 | ] 20 | 21 | [tool.coverage.run] 22 | branch = false 23 | 24 | [tool.coverage.report] 25 | fail_under = 0 26 | show_missing = true 27 | omit = [ 28 | "conftest.py", 29 | "test*.py", 30 | ] 31 | -------------------------------------------------------------------------------- /by-language/java-jooq/src/generated/java/io/crate/demo/jooq/model/Tables.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is generated by jOOQ. 3 | */ 4 | package io.crate.demo.jooq.model; 5 | 6 | 7 | import io.crate.demo.jooq.model.tables.Author; 8 | import io.crate.demo.jooq.model.tables.Book; 9 | 10 | 11 | /** 12 | * Convenience access to all tables in the default schema. 13 | */ 14 | @SuppressWarnings({ "all", "unchecked", "rawtypes" }) 15 | public class Tables { 16 | 17 | /** 18 | * The table 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 | Open In Colab 9 | -------------------------------------------------------------------------------- /by-language/csharp-efcore/demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net$(NETCoreAppMaximumVersion) 6 | enable 7 | false 8 | false 9 | false 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /topic/serverless/azure-eventhub/Azure Function/value_cache.py: -------------------------------------------------------------------------------- 1 | class ValueCache: 2 | """ 3 | ValueCache class is used to structure enriched data for insert. 4 | """ 5 | 6 | def __init__(self): 7 | self.errors = [] 8 | self.readings = [] 9 | 10 | def add_error(self, payload, message, type): 11 | self.errors.append( 12 | { 13 | "payload": payload, 14 | "error": {"message": message, "type": type}, 15 | "type": type, 16 | } 17 | ) 18 | 19 | def add_reading(self, payload, location, timestamp, sensor_id): 20 | self.readings.append( 21 | { 22 | "location": location, 23 | "sensor_id": sensor_id, 24 | "reading_ts": timestamp, 25 | "reading": payload, 26 | } 27 | ) 28 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/src/main/docker/Dockerfile.native: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. 3 | # 4 | # Before building the container image run: 5 | # 6 | # ./gradlew build -Dquarkus.package.type=native 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.native -t quarkus/code-with-quarkus . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus 15 | # 16 | ### 17 | FROM registry.access.redhat.com/ubi8/ubi-minimal:8.8 18 | WORKDIR /work/ 19 | RUN chown 1001 /work \ 20 | && chmod "g+rwX" /work \ 21 | && chown 1001:root /work 22 | COPY --chown=1001:root build/*-runner /work/application 23 | 24 | EXPOSE 8080 25 | USER 1001 26 | 27 | ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] 28 | -------------------------------------------------------------------------------- /application/pgpool/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Using Pgpool-II with CrateDB. 4 | 5 | # The miniature stack defines {Docker,Podman} services and tasks to spin 6 | # up CrateDB and Pgpool-II, and to query a CrateDB system table through 7 | # Pgpool's in-memory cache. 8 | 9 | # https://github.com/pgpool/pgpool2 10 | # https://github.com/crate/crate 11 | # https://github.com/crate/cratedb-examples/tree/main/application/pgpool 12 | 13 | # Start services: CrateDB and Pgpool-II. 14 | docker compose up --detach --wait 15 | 16 | # Polyfill a missing function in CrateDB. 17 | # BACKEND Error: "Unknown function: pg_catalog.has_function_privilege('crate', 'pgpool_regclass(cstring)', 'execute')" 18 | docker compose run --rm provision-functions 19 | 20 | # Query data from CrateDB. 21 | # docker compose run --rm cratedb-query-data 22 | 23 | # Query data via Pgpool. 24 | docker compose run --rm pgpool-query-data 25 | -------------------------------------------------------------------------------- /notebook/jupyter/conftest.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | import pytest 5 | import sqlalchemy as sa 6 | from pueblo.testing.notebook import generate_tests 7 | 8 | 9 | def pytest_generate_tests(metafunc): 10 | """ 11 | Generate pytest test case per Jupyter Notebook. 12 | """ 13 | here = Path(__file__).parent 14 | generate_tests(metafunc, path=here) 15 | 16 | 17 | @pytest.fixture(autouse=True) 18 | def reset_database_tables(): 19 | """ 20 | Before running a test case, reset relevant tables in database. 21 | """ 22 | 23 | connection_string = os.environ.get("CRATEDB_CONNECTION_STRING") 24 | 25 | engine = sa.create_engine(connection_string, echo=os.environ.get("DEBUG")) 26 | connection = engine.connect() 27 | 28 | reset_tables = [] 29 | 30 | for table in reset_tables: 31 | connection.execute(sa.text(f"DROP TABLE IF EXISTS {table};")) 32 | -------------------------------------------------------------------------------- /framework/dbt/materialize/README.md: -------------------------------------------------------------------------------- 1 | # dbt CrateDB example about model materialization 2 | 3 | ## What's Inside 4 | Ephemeral and incremental materialization using the `delete+insert` 5 | strategy. 6 | 7 | ## Setup 8 | ```shell 9 | uv pip install -r requirements.txt 10 | ``` 11 | 12 | ## Usage 13 | 14 | Try running the following commands: 15 | - `dbt run` 16 | - `dbt test` 17 | 18 | Optionally, use `--debug` to display executed SQL statements. 19 | 20 | ## Resources 21 | - Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction) 22 | - Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers 23 | - Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support 24 | - Find [dbt events](https://events.getdbt.com) near you 25 | - Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices 26 | -------------------------------------------------------------------------------- /framework/graphene/app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from flask import Flask 4 | from flask_graphql import GraphQLView 5 | 6 | from database import db_session, init_db 7 | from schema import schema 8 | 9 | app = Flask(__name__) 10 | app.debug = True 11 | 12 | example_query = """ 13 | { 14 | allEmployees(sort: [NAME_ASC, ID_ASC]) { 15 | edges { 16 | node { 17 | id 18 | name 19 | department { 20 | id 21 | name 22 | } 23 | role { 24 | id 25 | name 26 | } 27 | } 28 | } 29 | } 30 | } 31 | """ 32 | 33 | 34 | app.add_url_rule( 35 | "/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True) 36 | ) 37 | 38 | 39 | @app.teardown_appcontext 40 | def shutdown_session(exception=None): 41 | db_session.remove() 42 | 43 | 44 | if __name__ == "__main__": 45 | init_db() 46 | app.run() 47 | -------------------------------------------------------------------------------- /framework/dbt/materialize/tests/test.yml: -------------------------------------------------------------------------------- 1 | models: 2 | - name: test 3 | columns: 4 | - name: id 5 | data_tests: 6 | - unique 7 | - not_null 8 | - name: started 9 | data_tests: 10 | - unique 11 | - not_null 12 | - name: type 13 | data_tests: 14 | - accepted_values: 15 | values: ['SELECT', 'INSERT', 'DELETE', 'DDL', 'MANAGEMENT', 'UNDEFINED'] 16 | - name: started 17 | data_tests: 18 | - dbt_utils.accepted_range: 19 | min_value: 1734815733815 20 | max_value: "now()" 21 | 22 | #- name: classification['labels'] 23 | # data_tests: 24 | # - accepted_values: 25 | # values: [[], ["Collect"], ["Collect", "Order"], ["Collect", "Union"], ["Collect", "GroupHashAggregate"], ["Collect", "GroupHashAggregate", "Order"], ["InsertFromValues"], ["TableFunction"]] 26 | -------------------------------------------------------------------------------- /framework/streamlit/test.py: -------------------------------------------------------------------------------- 1 | from streamlit.testing.v1 import AppTest 2 | 3 | 4 | def test_read_sys_summits(): 5 | """ 6 | Verify reading CrateDB's built-in `sys.summits` database table through Streamlit. 7 | """ 8 | 9 | # Invoke Streamlit application. 10 | at = AppTest.from_file("basic_sys_summits.py").run() 11 | 12 | # There should not be an exception. 13 | assert not at.exception 14 | 15 | # Probe dataframe output. 16 | df = at.dataframe.values[0] 17 | mountains = df["mountain"].values 18 | assert "Mont Blanc" in mountains 19 | assert "Matterhorn" in mountains 20 | 21 | # Probe table output. 22 | df = at.table.values[0] 23 | mountains = df["mountain"].values 24 | assert "Mont Blanc" in mountains 25 | assert "Matterhorn" in mountains 26 | 27 | # Probe Markdown output. 28 | assert "Mont Blanc" in at.markdown.values 29 | assert "Monte Rosa" in at.markdown.values 30 | -------------------------------------------------------------------------------- /topic/machine-learning/open-webui/init/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Test Open WebUI configuration via HTTP API. 4 | 5 | # Runtime options. 6 | set -euo pipefail 7 | 8 | # Uncomment for local debugging, but **never** in automated runs. 9 | # set -x 10 | 11 | # Load configuration. 12 | source .env 13 | 14 | # Sign in to receive JWT token. 15 | token=$( http --ignore-stdin POST ${OPEN_WEBUI_URL}/api/v1/auths/signin email= password= | jq -r .token ) 16 | if [[ -z "${token}" ]]; then 17 | echo "FATAL: Could not obtain JWT token from Open WebUI" >&2 18 | exit 1 19 | fi 20 | 21 | # Check for a canonical available model to validate that Open WebUI configuration worked. 22 | http ${OPEN_WEBUI_URL}/api/models Authorization:"Bearer $token" refresh==true | \ 23 | grep '"id":"gpt-4.1"' >/dev/null 2>&1 || { 24 | echo "ERROR: Model gpt-4.1 not available" 25 | exit 1 26 | } 27 | 28 | echo "gpt-4.1 model found" 29 | echo "Ready." 30 | -------------------------------------------------------------------------------- /topic/machine-learning/llama-index/init.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS time_series_data ( 2 | timestamp TIMESTAMP, 3 | value DOUBLE, 4 | location STRING, 5 | sensor_id INT 6 | ); 7 | 8 | INSERT INTO time_series_data (timestamp, value, location, sensor_id) 9 | VALUES 10 | ('2023-09-14T00:00:00', 10.5, 'Sensor A', 1), 11 | ('2023-09-14T01:00:00', 15.2, 'Sensor A', 1), 12 | ('2023-09-14T02:00:00', 18.9, 'Sensor A', 1), 13 | ('2023-09-14T03:00:00', 12.7, 'Sensor B', 2), 14 | ('2023-09-14T04:00:00', 17.3, 'Sensor B', 2), 15 | ('2023-09-14T05:00:00', 20.1, 'Sensor B', 2), 16 | ('2023-09-14T06:00:00', 22.5, 'Sensor A', 1), 17 | ('2023-09-14T07:00:00', 18.3, 'Sensor A', 1), 18 | ('2023-09-14T08:00:00', 16.8, 'Sensor A', 1), 19 | ('2023-09-14T09:00:00', 14.6, 'Sensor B', 2), 20 | ('2023-09-14T10:00:00', 13.2, 'Sensor B', 2), 21 | ('2023-09-14T11:00:00', 11.7, 'Sensor B', 2); 22 | 23 | REFRESH TABLE time_series_data; 24 | -------------------------------------------------------------------------------- /by-language/csharp-npgsql/demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net$(NETCoreAppMaximumVersion) 6 | enable 7 | false 8 | false 9 | false 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /application/metabase/README.md: -------------------------------------------------------------------------------- 1 | # Verify Metabase with CrateDB 2 | 3 | ## About 4 | 5 | This folder includes software integration tests for verifying 6 | that Metabase works well together with CrateDB. 7 | The test harness is based on Docker Compose. 8 | 9 | ## What's Inside 10 | 11 | A basic test case that reads CrateDB's `sys.summit` table through 12 | Metabase, after connecting CrateDB as a PostgreSQL database. 13 | 14 | ## Setup 15 | 16 | Setup sandbox and install packages. 17 | ```bash 18 | pip install uv 19 | uv venv .venv 20 | source .venv/bin/activate 21 | uv pip install -r requirements.txt -r requirements-test.txt 22 | ``` 23 | 24 | ## Usage 25 | 26 | Run integration tests. 27 | ```bash 28 | pytest 29 | ``` 30 | 31 | Watch service logs. 32 | ```shell 33 | docker compose logs -f 34 | ``` 35 | 36 | Note that the setup is configured to keep the containers alive after starting 37 | them. If you want to actively recycle them, invoke `docker compose down` before 38 | running `pytest`. 39 | -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-python/requirements.txt: -------------------------------------------------------------------------------- 1 | apache-beam==2.48.0 2 | apache-flink==1.18.1 3 | apache-flink-libraries==1.18.1 4 | avro-python3==1.10.2 5 | certifi==2024.2.2 6 | charset-normalizer==3.3.2 7 | cloudpickle==2.2.1 8 | crate>=2.0.0.dev6 9 | crcmod==1.7 10 | dill==0.3.1.1 11 | dnspython==2.6.1 12 | docopt==0.6.2 13 | fastavro==1.9.4 14 | fasteners==0.19 15 | find-libpython==0.3.1 16 | geojson==3.1.0 17 | greenlet==3.0.3 18 | grpcio==1.62.0 19 | hdfs==2.7.3 20 | httplib2==0.22.0 21 | idna==3.6 22 | kafka-python==2.0.2 23 | numpy==1.24.4 24 | objsize==0.6.1 25 | orjson==3.9.15 26 | pandas==2.2.1 27 | pemja==0.3.0 28 | proto-plus==1.23.0 29 | protobuf==4.23.4 30 | py4j==0.10.9.7 31 | pyarrow==11.0.0 32 | pydot==1.4.2 33 | pymongo==4.6.2 34 | pyparsing==3.1.2 35 | python-dateutil==2.9.0.post0 36 | pytz==2024.1 37 | regex==2023.12.25 38 | requests==2.31.0 39 | six==1.16.0 40 | SQLAlchemy==2.0.28 41 | typing_extensions==4.10.0 42 | tzdata==2024.1 43 | urllib3==2.0.7 44 | zstandard==0.22.0 45 | -------------------------------------------------------------------------------- /operation/compose/ssl/compose.yml: -------------------------------------------------------------------------------- 1 | # CrateDB single-node configuration with SSL (self-signed certificates). 2 | 3 | name: cratedb-with-ssl 4 | 5 | services: 6 | 7 | cratedb: 8 | image: crate/crate:nightly 9 | command: ["crate", "-Cstats.enabled=true"] 10 | ports: 11 | - 4200:4200 12 | - 5432:5432 13 | volumes: 14 | - ./crate.yml:/crate/config/crate.yml 15 | - ./keystore:/crate/config/keystore 16 | - ./truststore:/crate/config/truststore 17 | healthcheck: 18 | test: ["CMD", "curl", "--fail", "--insecure", "https://localhost:4200"] 19 | start_period: 3s 20 | interval: 1.5s 21 | retries: 30 22 | timeout: 30s 23 | 24 | # Wait for the service being available, even when 25 | # invoked through `docker compose up --detach`. 26 | # https://marcopeg.com/2019/docker-compose-healthcheck/ 27 | wait-for-cratedb: 28 | image: dadarek/wait-for-dependencies 29 | depends_on: 30 | cratedb: 31 | condition: service_healthy 32 | -------------------------------------------------------------------------------- /testing/testcontainers/python-pytest/test_pytest.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using "Testcontainers for Python" with CrateDB and pytest 3 | 4 | Build test harnesses around CrateDB using the `cratedb_service` 5 | pytest fixture exported by `cratedb-toolkit`. 6 | 7 | https://pypi.org/project/cratedb-toolkit/ 8 | """ 9 | import subprocess 10 | from pprint import pprint 11 | 12 | SQL_STATEMENT = "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3;" 13 | 14 | 15 | def test_crash(cratedb_service): 16 | """ 17 | After provisioning a test instance of CrateDB, invoke `crash`. 18 | """ 19 | http_url = cratedb_service.get_http_url() 20 | command = f"time crash --hosts '{http_url}' --command '{SQL_STATEMENT}'" 21 | subprocess.check_call(command, shell=True) 22 | 23 | 24 | def test_sql(cratedb_service): 25 | """ 26 | After provisioning a test instance of CrateDB, invoke an SQL statement. 27 | """ 28 | results = cratedb_service.database.run_sql(SQL_STATEMENT, records=True) 29 | pprint(results) 30 | -------------------------------------------------------------------------------- /topic/chatbot/table-augmented-generation/workshop/conftest.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | import pytest 5 | import sqlalchemy as sa 6 | from pueblo.testing.notebook import generate_tests 7 | 8 | 9 | def pytest_generate_tests(metafunc): 10 | """ 11 | Generate pytest test case per Jupyter Notebook. 12 | """ 13 | here = Path(__file__).parent 14 | generate_tests(metafunc, path=here) 15 | 16 | 17 | @pytest.fixture(autouse=True) 18 | def reset_database_tables(): 19 | """ 20 | Before running a test case, reset relevant tables in database. 21 | """ 22 | 23 | connection_string = os.environ.get("CRATEDB_CONNECTION_STRING") 24 | 25 | engine = sa.create_engine(connection_string, echo=os.environ.get("DEBUG")) 26 | connection = engine.connect() 27 | 28 | reset_tables = [ 29 | "machine_manuals", 30 | "motor_readings", 31 | ] 32 | 33 | for table in reset_tables: 34 | connection.execute(sa.text(f"DROP TABLE IF EXISTS {table};")) 35 | -------------------------------------------------------------------------------- /topic/machine-learning/langchain/init.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS time_series_data; 2 | 3 | CREATE TABLE IF NOT EXISTS time_series_data ( 4 | timestamp TIMESTAMP, 5 | value DOUBLE, 6 | location STRING, 7 | sensor_id INT 8 | ); 9 | 10 | INSERT INTO time_series_data (timestamp, value, location, sensor_id) 11 | VALUES 12 | ('2023-09-14T00:00:00', 10.5, 'Sensor A', 1), 13 | ('2023-09-14T01:00:00', 15.2, 'Sensor A', 1), 14 | ('2023-09-14T02:00:00', 18.9, 'Sensor A', 1), 15 | ('2023-09-14T03:00:00', 12.7, 'Sensor B', 2), 16 | ('2023-09-14T04:00:00', 17.3, 'Sensor B', 2), 17 | ('2023-09-14T05:00:00', 20.1, 'Sensor B', 2), 18 | ('2023-09-14T06:00:00', 22.5, 'Sensor A', 1), 19 | ('2023-09-14T07:00:00', 18.3, 'Sensor A', 1), 20 | ('2023-09-14T08:00:00', 16.8, 'Sensor A', 1), 21 | ('2023-09-14T09:00:00', 14.6, 'Sensor B', 2), 22 | ('2023-09-14T10:00:00', 13.2, 'Sensor B', 2), 23 | ('2023-09-14T11:00:00', 11.7, 'Sensor B', 2); 24 | 25 | REFRESH TABLE time_series_data; 26 | -------------------------------------------------------------------------------- /topic/machine-learning/open-webui/init/init.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS time_series_data; 2 | 3 | CREATE TABLE IF NOT EXISTS time_series_data ( 4 | "timestamp" TIMESTAMP, 5 | value DOUBLE, 6 | location STRING, 7 | sensor_id INT 8 | ); 9 | 10 | INSERT INTO time_series_data ("timestamp", value, location, sensor_id) 11 | VALUES 12 | ('2023-09-14T00:00:00', 10.5, 'Sensor A', 1), 13 | ('2023-09-14T01:00:00', 15.2, 'Sensor A', 1), 14 | ('2023-09-14T02:00:00', 18.9, 'Sensor A', 1), 15 | ('2023-09-14T03:00:00', 12.7, 'Sensor B', 2), 16 | ('2023-09-14T04:00:00', 17.3, 'Sensor B', 2), 17 | ('2023-09-14T05:00:00', 20.1, 'Sensor B', 2), 18 | ('2023-09-14T06:00:00', 22.5, 'Sensor A', 1), 19 | ('2023-09-14T07:00:00', 18.3, 'Sensor A', 1), 20 | ('2023-09-14T08:00:00', 16.8, 'Sensor A', 1), 21 | ('2023-09-14T09:00:00', 14.6, 'Sensor B', 2), 22 | ('2023-09-14T10:00:00', 13.2, 'Sensor B', 2), 23 | ('2023-09-14T11:00:00', 11.7, 'Sensor B', 2); 24 | 25 | REFRESH TABLE time_series_data; 26 | -------------------------------------------------------------------------------- /topic/timeseries/conftest.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | import pytest 5 | import sqlalchemy as sa 6 | from pueblo.testing.notebook import generate_tests 7 | 8 | 9 | def pytest_generate_tests(metafunc): 10 | """ 11 | Generate pytest test case per Jupyter Notebook. 12 | """ 13 | here = Path(__file__).parent 14 | generate_tests(metafunc, path=here) 15 | 16 | 17 | @pytest.fixture(autouse=True) 18 | def reset_database_tables(): 19 | """ 20 | Before running a test case, reset relevant tables in database. 21 | """ 22 | 23 | connection_string = os.environ.get("CRATEDB_CONNECTION_STRING") 24 | 25 | engine = sa.create_engine(connection_string, echo=os.environ.get("DEBUG")) 26 | connection = engine.connect() 27 | 28 | reset_tables = [ 29 | "cities", 30 | "machine_data", 31 | "weather_data", 32 | "weather_stations", 33 | ] 34 | 35 | for table in reset_tables: 36 | connection.execute(sa.text(f"DROP TABLE IF EXISTS {table};")) 37 | -------------------------------------------------------------------------------- /by-language/python-pg8000/README.rst: -------------------------------------------------------------------------------- 1 | .. highlight: console 2 | 3 | ################################################# 4 | Connect to CrateDB and CrateDB Cloud using pg8000 5 | ################################################# 6 | 7 | 8 | ***** 9 | About 10 | ***** 11 | 12 | Example programs demonstrating CrateDB with pg8000, 13 | for the PostgreSQL protocol. 14 | 15 | 16 | ***** 17 | Setup 18 | ***** 19 | 20 | To start a CrateDB instance on your machine for evaluation purposes, invoke:: 21 | 22 | docker run --publish 4200:4200 --publish 5432:5432 --env CRATE_HEAP_SIZE=1g crate:latest -Cdiscovery.type=single-node 23 | 24 | Navigate to the example program directory, and install prerequisites:: 25 | 26 | # Acquire sources. 27 | git clone https://github.com/crate/cratedb-examples 28 | cd cratedb-examples 29 | python3 -m venv .venv 30 | source .venv/bin/activate 31 | pip install pg8000 32 | 33 | 34 | ******** 35 | Examples 36 | ******** 37 | 38 | Run an example program:: 39 | 40 | python basic.py 41 | 42 | -------------------------------------------------------------------------------- /operation/http-api-behind-nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | # Nginx configuration for hosting the CrateDB HTTP API endpoint on a subdirectory path. 2 | # Here: `/db`. 3 | 4 | daemon off; 5 | error_log /dev/stderr info; 6 | 7 | worker_processes 1; 8 | 9 | events { 10 | worker_connections 256; 11 | } 12 | 13 | http { 14 | keepalive_timeout 65; 15 | access_log /dev/stderr; 16 | 17 | server { 18 | listen 7070; 19 | server_name localhost; 20 | 21 | location /db/ { 22 | 23 | # Cut away the `/db` prefix and reverse-proxy requests to CrateDB on `localhost`. 24 | rewrite ^/db/(.*)$ /$1 break; 25 | proxy_pass http://localhost:4200/; 26 | 27 | # Obligatory configuration for setting appropriate HTTP headers. 28 | proxy_set_header Host $http_host; 29 | proxy_set_header X-Real-IP $remote_addr; 30 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 31 | # proxy_set_header X-Forwarded-Proto https; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /application/microsoft-ssis/ssis-cratedb-demo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34511.84 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{C9674DCB-5085-4A16-B785-4C70DD1589BD}") = "ssis-cratedb-demo", "ssis-cratedb-demo\ssis-cratedb-demo.dtproj", "{F5FAA1CD-14E9-4E6B-8389-784DA75AC8C9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Development|Default = Development|Default 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {F5FAA1CD-14E9-4E6B-8389-784DA75AC8C9}.Development|Default.ActiveCfg = Development 14 | {F5FAA1CD-14E9-4E6B-8389-784DA75AC8C9}.Development|Default.Build.0 = Development 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | GlobalSection(ExtensibilityGlobals) = postSolution 20 | SolutionGuid = {2FB11F7F-C2E1-4584-B8AE-07CF2EC637E8} 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-python/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "location": { 3 | "localtime": "2024-03-07 18:20", 4 | "country": "France", 5 | "localtime_epoch": 1709832024, 6 | "name": "Nonette", 7 | "lon": 3.28, 8 | "region": "Auvergne", 9 | "lat": 45.48, 10 | "tz_id": "Europe/Paris" 11 | }, 12 | "current": { 13 | "feelslike_c": 11, 14 | "uv": 3, 15 | "last_updated": "2024-03-07 18:15", 16 | "feelslike_f": 51.7, 17 | "wind_degree": 30, 18 | "last_updated_epoch": 1709831700, 19 | "is_day": 1, 20 | "precip_in": 0, 21 | "wind_dir": "NNE", 22 | "gust_mph": 12.1, 23 | "temp_c": 12, 24 | "pressure_in": 29.83, 25 | "gust_kph": 19.5, 26 | "temp_f": 53.6, 27 | "precip_mm": 0, 28 | "cloud": 0, 29 | "wind_kph": 6.8, 30 | "condition": { 31 | "code": 1000, 32 | "icon": "//cdn.weatherapi.com/weather/64x64/day/113.png", 33 | "text": "Sunny" 34 | }, 35 | "wind_mph": 4.3, 36 | "vis_km": 10, 37 | "humidity": 50, 38 | "pressure_mb": 1010, 39 | "vis_miles": 6 40 | } 41 | } -------------------------------------------------------------------------------- /testing/native/python-unittest/test_unittest.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using "cr8" test layers with CrateDB and unittest 3 | 4 | Build test harnesses around CrateDB using the `create_node` 5 | primitive exported by `cr8`. 6 | 7 | https://pypi.org/project/cr8/ 8 | """ 9 | import subprocess 10 | from unittest import TestCase 11 | 12 | from cr8.run_crate import create_node 13 | 14 | # Run a testing instance of CrateDB. 15 | # TODO: How to select a nightly release? 16 | cratedb_layer = create_node(version="latest-testing") 17 | 18 | SQL_STATEMENT = "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3;" 19 | 20 | 21 | def setUpModule(): 22 | cratedb_layer.start() 23 | 24 | 25 | def tearDownModule(): 26 | cratedb_layer.stop() 27 | 28 | 29 | class CrashTest(TestCase): 30 | 31 | def test_crash(self): 32 | """ 33 | After provisioning a test instance of CrateDB, invoke `crash`. 34 | """ 35 | http_url = cratedb_layer.http_url 36 | command = f"time crash --hosts '{http_url}' --command '{SQL_STATEMENT}'" 37 | subprocess.check_call(command, shell=True) 38 | -------------------------------------------------------------------------------- /topic/machine-learning/langchain/conversational_memory.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrate conversational memory with CrateDB. 3 | 4 | Synopsis:: 5 | 6 | # Install prerequisites. 7 | pip install -U -r requirements.txt 8 | 9 | # Start database. 10 | docker run --rm -it --publish=4200:4200 crate/crate:nightly 11 | 12 | # Run program. 13 | export CRATEDB_CONNECTION_STRING="crate://crate@localhost/?schema=doc" 14 | python conversational_memory.py 15 | """ 16 | import os 17 | from pprint import pprint 18 | 19 | from langchain_cratedb.chat_history import CrateDBChatMessageHistory 20 | 21 | 22 | CONNECTION_STRING = os.environ.get( 23 | "CRATEDB_CONNECTION_STRING", 24 | "crate://crate@localhost/?schema=doc" 25 | ) 26 | 27 | 28 | def main(): 29 | 30 | chat_history = CrateDBChatMessageHistory( 31 | session_id="test_session", 32 | connection=CONNECTION_STRING, 33 | ) 34 | chat_history.add_user_message("Hello") 35 | chat_history.add_ai_message("Hi") 36 | pprint(chat_history.messages) 37 | 38 | 39 | if __name__ == "__main__": 40 | main() 41 | -------------------------------------------------------------------------------- /application/ingestr/.env: -------------------------------------------------------------------------------- 1 | # Data source configuration (Kafka). 2 | export PORT_KAFKA_BROKER_EXTERNAL=9092 3 | export PORT_KAFKA_BROKER_INTERNAL=9094 4 | export PORT_KAFKA_ZOOKEEPER=2181 5 | 6 | # Data sink configuration (CrateDB). 7 | export CRATEDB_HOST=${CRATEDB_HOST:-cratedb} 8 | export CRATEDB_HTTP_PORT=${CRATEDB_HTTP_PORT:-4200} 9 | export CRATEDB_POSTGRESQL_PORT=${CRATEDB_POSTGRESQL_PORT:-5432} 10 | export CRATEDB_USERNAME=${CRATEDB_USERNAME:-crate} 11 | export CRATEDB_PASSWORD=${CRATEDB_PASSWORD:-crate} 12 | export CRATEDB_HTTP_SCHEME=${CRATEDB_HTTP_SCHEME:-http} 13 | 14 | # Data sink configuration (CrateDB Cloud). 15 | # export CRATEDB_HTTP_SCHEME=https 16 | # export CRATEDB_HOST=example.aks1.westeurope.azure.cratedb.net 17 | # export CRATEDB_USERNAME='admin' 18 | # export CRATEDB_PASSWORD='' 19 | 20 | # Needed by HTTPie. 21 | export CRATEDB_HTTP_URL_DOCKER="${CRATEDB_HTTP_SCHEME}://${CRATEDB_USERNAME}:${CRATEDB_PASSWORD}@${CRATEDB_HOST}:${CRATEDB_HTTP_PORT}" 22 | 23 | # Needed by Python's urllib. 24 | export CRATEDB_HTTP_URL_NOAUTH="${CRATEDB_HTTP_SCHEME}://localhost:${CRATEDB_HTTP_PORT}" 25 | -------------------------------------------------------------------------------- /application/metabase/test.py: -------------------------------------------------------------------------------- 1 | from metabase_rig import MetabaseRig 2 | 3 | pytest_plugins = ["docker_compose"] 4 | 5 | 6 | def test_api_sys_summits(session_scoped_container_getter): 7 | """ 8 | End-to-end test reading data from CrateDB through Metabase. 9 | """ 10 | rig = MetabaseRig("http://localhost:3000/") 11 | 12 | # Login to and optionally provision Metabase. 13 | try: 14 | rig.login() 15 | except: 16 | rig.setup() 17 | rig.login() 18 | 19 | # Acquire a database handle, optionally creating a database. 20 | db = rig.database("cratedb-testdrive") 21 | if not db.exists(): 22 | db.create() 23 | 24 | # Wait for the `sys` schema to become available. 25 | db.wait_schema("sys") 26 | 27 | # Validate a table exists in the `sys` schema. 28 | assert "sys.summits" in db.table_names(schema_name="sys") 29 | 30 | # Wait for the `sys.summits` table to become available. 31 | db.wait_table("sys", "summits") 32 | 33 | # Query the `sys.summits` table. 34 | data = db.query("summits") 35 | assert data["data"]["rows"][0][5] == "Mont Blanc" 36 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/src/main/docker/Dockerfile.native-micro: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. 3 | # It uses a micro base image, tuned for Quarkus native executables. 4 | # It reduces the size of the resulting container image. 5 | # Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. 6 | # 7 | # Before building the container image run: 8 | # 9 | # ./gradlew build -Dquarkus.package.type=native 10 | # 11 | # Then, build the image with: 12 | # 13 | # docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/code-with-quarkus . 14 | # 15 | # Then run the container using: 16 | # 17 | # docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus 18 | # 19 | ### 20 | FROM quay.io/quarkus/quarkus-micro-image:2.0 21 | WORKDIR /work/ 22 | RUN chown 1001 /work \ 23 | && chmod "g+rwX" /work \ 24 | && chown 1001:root /work 25 | COPY --chown=1001:root build/*-runner /work/application 26 | 27 | EXPOSE 8080 28 | USER 1001 29 | 30 | ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] 31 | -------------------------------------------------------------------------------- /application/apache-superset/data.sql: -------------------------------------------------------------------------------- 1 | -- https://github.com/crate/cratedb-datasets 2 | 3 | CREATE TABLE IF NOT EXISTS devices_readings ( 4 | "ts" TIMESTAMP WITH TIME ZONE, 5 | "device_id" TEXT, 6 | "battery" OBJECT(DYNAMIC) AS ( 7 | "level" BIGINT, 8 | "status" TEXT, 9 | "temperature" DOUBLE PRECISION 10 | ), 11 | "cpu" OBJECT(DYNAMIC) AS ( 12 | "avg_1min" DOUBLE PRECISION, 13 | "avg_5min" DOUBLE PRECISION, 14 | "avg_15min" DOUBLE PRECISION 15 | ), 16 | "memory" OBJECT(DYNAMIC) AS ( 17 | "free" BIGINT, 18 | "used" BIGINT 19 | ) 20 | ); 21 | 22 | CREATE TABLE IF NOT EXISTS devices_info ( 23 | "device_id" TEXT, 24 | "api_version" TEXT, 25 | "manufacturer" TEXT, 26 | "model" TEXT, 27 | "os_name" TEXT 28 | ); 29 | 30 | COPY "devices_readings" 31 | FROM 'https://cdn.crate.io/downloads/datasets/cratedb-datasets/cloud-tutorials/devices_readings.json.gz' 32 | WITH (compression = 'gzip'); 33 | 34 | COPY "devices_info" 35 | FROM 'https://cdn.crate.io/downloads/datasets/cratedb-datasets/cloud-tutorials/devices_info.json.gz' 36 | WITH (compression = 'gzip'); 37 | -------------------------------------------------------------------------------- /application/microsoft-ssis/ssis-cratedb-demo/ssis-cratedb-demo.dtproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Development 6 | 7 | 8 | false 9 | 10 | 11 | 12 | 13 | false 14 | true 15 | 16 | 17 | LastModifiedTime 18 | LastModifiedTime 19 | 2024-01-29T14:32:39.9079955Z 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/README-OCI.md: -------------------------------------------------------------------------------- 1 | # Using CrateDB with turbodbc (OCI) 2 | 3 | The [dockerfiles](./dockerfiles) folder includes Dockerfiles that exercise 4 | installing the turbodbc driver. They are handy if you can't install it 5 | on your machine. Follow the instructions how to build OCI images and how 6 | to invoke the `demo.py` program using them. 7 | 8 | ## Build 9 | 10 | Make the upcoming build more verbose. 11 | ```shell 12 | export BUILDKIT_PROGRESS=plain 13 | export COMPOSE_DOCKER_CLI_BUILD=1 14 | export DOCKER_BUILDKIT=1 15 | ``` 16 | 17 | Build images. 18 | ```shell 19 | docker build --tag local/turbodbc-demo-archlinux --file=dockerfiles/archlinux.Dockerfile . 20 | docker build --tag local/turbodbc-demo-centos --file=dockerfiles/centos.Dockerfile . 21 | docker build --tag local/turbodbc-demo-debian --file=dockerfiles/debian.Dockerfile . 22 | docker build --tag local/turbodbc-demo-opensuse --file=dockerfiles/opensuse.Dockerfile . 23 | ``` 24 | 25 | Invoke demo program. 26 | ```shell 27 | for OS in archlinux centos debian opensuse; do 28 | docker run --rm -it --volume=$(pwd):/src --network=host \ 29 | local/turbodbc-demo-${OS} python3 /src/demo.py 30 | done 31 | ``` 32 | -------------------------------------------------------------------------------- /.github/workflows/application-roapi.yml: -------------------------------------------------------------------------------- 1 | name: "ROAPI" 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/application-roapi.yml' 7 | - 'application/roapi/**' 8 | push: 9 | branches: [ main ] 10 | paths: 11 | - '.github/workflows/application-roapi.yml' 12 | - 'application/roapi/**' 13 | 14 | # Allow job to be triggered manually. 15 | workflow_dispatch: 16 | 17 | # Run job each night after CrateDB nightly has been published. 18 | schedule: 19 | - cron: '0 3 * * *' 20 | 21 | # Cancel in-progress jobs when pushing to the same branch. 22 | concurrency: 23 | cancel-in-progress: true 24 | group: ${{ github.workflow }}-${{ github.ref }} 25 | 26 | jobs: 27 | 28 | test: 29 | runs-on: ${{ matrix.os }} 30 | 31 | strategy: 32 | fail-fast: true 33 | matrix: 34 | os: [ 'ubuntu-latest' ] 35 | 36 | name: OS ${{ matrix.os }} 37 | steps: 38 | 39 | - name: Acquire sources 40 | uses: actions/checkout@v6 41 | 42 | - name: Validate application/roapi 43 | run: | 44 | # TODO: Generalize invocation into `ngr` test runner. 45 | cd application/roapi 46 | sh test.sh 47 | -------------------------------------------------------------------------------- /.github/workflows/application-pgpool.yml: -------------------------------------------------------------------------------- 1 | name: "Pgpool-II" 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/application-pgpool.yml' 7 | - 'application/pgpool/**' 8 | push: 9 | branches: [ main ] 10 | paths: 11 | - '.github/workflows/application-pgpool.yml' 12 | - 'application/pgpool/**' 13 | 14 | # Allow job to be triggered manually. 15 | workflow_dispatch: 16 | 17 | # Run job each night after CrateDB nightly has been published. 18 | schedule: 19 | - cron: '0 3 * * *' 20 | 21 | # Cancel in-progress jobs when pushing to the same branch. 22 | concurrency: 23 | cancel-in-progress: true 24 | group: ${{ github.workflow }}-${{ github.ref }} 25 | 26 | jobs: 27 | 28 | test: 29 | runs-on: ${{ matrix.os }} 30 | 31 | strategy: 32 | fail-fast: true 33 | matrix: 34 | os: [ 'ubuntu-latest' ] 35 | 36 | name: OS ${{ matrix.os }} 37 | steps: 38 | 39 | - name: Acquire sources 40 | uses: actions/checkout@v6 41 | 42 | - name: Validate application/pgpool 43 | run: | 44 | # TODO: Generalize invocation into `ngr` test runner. 45 | cd application/pgpool 46 | sh test.sh 47 | -------------------------------------------------------------------------------- /by-language/python-sqlalchemy/test.py: -------------------------------------------------------------------------------- 1 | import shlex 2 | import subprocess 3 | import pytest 4 | 5 | 6 | def run(command: str): 7 | subprocess.check_call(shlex.split(command)) 8 | 9 | 10 | def test_insert_efficient_multirow(): 11 | insert_records = 25_000 12 | cmd = f"time python insert_efficient.py cratedb multirow {insert_records}" 13 | run(cmd) 14 | 15 | 16 | def test_insert_efficient_batched(): 17 | insert_records = 50_000 18 | cmd = f"time python insert_efficient.py cratedb batched {insert_records}" 19 | run(cmd) 20 | 21 | 22 | def test_insert_efficient_unknown(capfd): 23 | cmd = "time python insert_efficient.py cratedb unknown 1000" 24 | with pytest.raises(subprocess.CalledProcessError): 25 | run(cmd) 26 | out, err = capfd.readouterr() 27 | assert "ValueError: Unknown variant: unknown" in err 28 | 29 | 30 | def test_sync_table(): 31 | cmd = "time python sync_table.py urllib3 psycopg" 32 | run(cmd) 33 | 34 | 35 | def test_async_table(): 36 | cmd = "time python async_table.py psycopg asyncpg" 37 | run(cmd) 38 | 39 | 40 | def test_async_streaming(): 41 | cmd = "time python async_streaming.py psycopg asyncpg" 42 | run(cmd) 43 | -------------------------------------------------------------------------------- /.github/workflows/application-ingestr.yml: -------------------------------------------------------------------------------- 1 | name: "Ingestr" 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/application-ingestr.yml' 7 | - 'application/ingestr/**' 8 | push: 9 | branches: [ main ] 10 | paths: 11 | - '.github/workflows/application-ingestr.yml' 12 | - 'application/ingestr/**' 13 | 14 | # Allow job to be triggered manually. 15 | workflow_dispatch: 16 | 17 | # Run job each night after CrateDB nightly has been published. 18 | schedule: 19 | - cron: '0 3 * * *' 20 | 21 | # Cancel in-progress jobs when pushing to the same branch. 22 | concurrency: 23 | cancel-in-progress: true 24 | group: ${{ github.workflow }}-${{ github.ref }} 25 | 26 | jobs: 27 | 28 | test: 29 | runs-on: ${{ matrix.os }} 30 | 31 | strategy: 32 | fail-fast: true 33 | matrix: 34 | os: [ "ubuntu-latest" ] 35 | 36 | name: OS ${{ matrix.os }} 37 | steps: 38 | 39 | - name: Acquire sources 40 | uses: actions/checkout@v6 41 | 42 | - name: Validate application/ingestr 43 | run: | 44 | # TODO: Generalize invocation into `ngr` test runner. 45 | cd application/ingestr 46 | bash test.sh 47 | -------------------------------------------------------------------------------- /topic/machine-learning/open-webui/init/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.13-slim-bookworm 2 | 3 | # Configure operating system. 4 | ENV DEBIAN_FRONTEND=noninteractive 5 | ENV TERM=linux 6 | 7 | RUN set -e \ 8 | && apt-get update \ 9 | && apt-get --yes install --no-install-recommends --no-install-suggests curl jq \ 10 | && rm -rf /var/lib/apt/lists/* 11 | 12 | # Install and configure `uv`. 13 | # Guidelines that have been followed. 14 | # - https://hynek.me/articles/docker-uv/ 15 | 16 | # Install the `uv` package manager. 17 | COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv 18 | COPY --from=ghcr.io/astral-sh/uv:latest /uvx /usr/local/bin/uvx 19 | 20 | # - Tell uv to byte-compile packages for faster application startups. 21 | # - Silence uv complaining about not being able to use hard links. 22 | # - Prevent uv from accidentally downloading isolated Python builds. 23 | # - Install packages into the system Python environment. 24 | ENV \ 25 | UV_COMPILE_BYTECODE=true \ 26 | UV_LINK_MODE=copy \ 27 | UV_PYTHON_DOWNLOADS=never \ 28 | UV_SYSTEM_PYTHON=true 29 | 30 | RUN uv pip install crash cratedb-mcp httpie 31 | 32 | RUN mkdir /app 33 | WORKDIR /app 34 | COPY .env *.sh *.json *.sql /app/ 35 | -------------------------------------------------------------------------------- /by-dataframe/polars/write_adbc.py: -------------------------------------------------------------------------------- 1 | """ 2 | Import a Parquet file into CrateDB using Polars and ADBC. 3 | 4 | FIXME: Will currently not work with CrateDB, as it uses `COPY FROM STDIN`. 5 | 6 | Install dependencies: 7 | 8 | pip install polars pyarrow adbc-driver-postgresql 9 | """ 10 | 11 | import polars as pl 12 | 13 | 14 | CRATEDB_URI = "postgresql://crate:crate@localhost:5432/?sslmode=disable" 15 | TABLE_NAME = "testdrive_polars" 16 | FILE_URI = "https://cdn.crate.io/downloads/datasets/cratedb-datasets/timeseries/yc.2019.07-tiny.parquet" 17 | 18 | 19 | def main(): 20 | df = pl.read_parquet(FILE_URI) 21 | 22 | df.write_database( 23 | engine="adbc", 24 | connection=CRATEDB_URI, 25 | table_name="testdrive_polars", 26 | if_table_exists="replace", 27 | ) 28 | print(f"Records written to database table: {TABLE_NAME}") # pragma: nocover 29 | 30 | # We can also write from other file types, polars have: 31 | 32 | # polars.read_database 33 | # polars.read_csv 34 | # polars.read_avro 35 | # polars.read_delta 36 | # polars.read_excel 37 | # polars.read_ods 38 | # polars.read_json 39 | # polars.read_ndjson 40 | 41 | 42 | if __name__ == "__main__": 43 | main() 44 | -------------------------------------------------------------------------------- /by-language/csharp-efcore/README.md: -------------------------------------------------------------------------------- 1 | # Npgsql Entity Framework Core provider for PostgreSQL with CrateDB 2 | 3 | ## About 4 | 5 | The file `BlogDemo.cs` includes a demonstration program written in [C#] which 6 | demonstrates the [Entity Framework Core] README code snippet of [efcore.pg], 7 | effectively a very basic usage scenario, with CrateDB. 8 | 9 | `efcore.pg` is built on top of [Npgsql - .NET Access to PostgreSQL]. 10 | 11 | ## Usage 12 | 13 | Start a CrateDB instance for evaluation purposes. 14 | ```shell 15 | docker run -it --rm --publish=4200:4200 --publish=5432:5432 crate:latest 16 | ``` 17 | 18 | Invoke example program. 19 | ```shell 20 | dotnet run 21 | ``` 22 | 23 | ## Tests 24 | 25 | Invoke software tests. 26 | ```shell 27 | dotnet test 28 | ``` 29 | 30 | Generate a Cobertura code coverage report. 31 | ```shell 32 | dotnet test --collect:"XPlat Code Coverage" 33 | ``` 34 | 35 | Invoke test cases selectively. 36 | ```shell 37 | dotnet test --filter BlogDemoTest 38 | ``` 39 | 40 | 41 | [C#]: https://en.wikipedia.org/wiki/C_Sharp_(programming_language) 42 | [efcore.pg]: https://github.com/npgsql/efcore.pg 43 | [Entity Framework Core]: https://learn.microsoft.com/en-gb/ef/core/ 44 | [Npgsql - .NET Access to PostgreSQL]: https://github.com/npgsql/npgsql 45 | -------------------------------------------------------------------------------- /by-language/python-connectorx/README.md: -------------------------------------------------------------------------------- 1 | # Connect to CrateDB and CrateDB Cloud using ConnectorX 2 | 3 | ## About 4 | 5 | [ConnectorX] enables you to load data from databases into Python in the 6 | fastest and most memory efficient way. 7 | 8 | ## Usage 9 | 10 | You can optionally accelerate the data loading using parallelism by 11 | specifying a partition column. 12 | ```python 13 | import connectorx as cx 14 | 15 | cx.read_sql( 16 | "postgresql://username:password@server:port/database", 17 | "SELECT * FROM lineitem", 18 | partition_on="l_orderkey", 19 | partition_num=10, 20 | ) 21 | ``` 22 | Please find more [usage examples] on the [ConnectorX documentation]. 23 | 24 | ## Status 25 | 26 | The example program `demo.py` in this folder demonstrates basic use 27 | by reading from the built-in `sys.summits` table. 28 | 29 | Please note many special data types have not been verified to work 30 | with CrateDB yet, or have been identified to not work yet. We are 31 | enumerating them within the [backlog] file. 32 | 33 | 34 | [backlog]: ./backlog.md 35 | [ConnectorX]: https://pypi.org/project/connectorx/ 36 | [ConnectorX documentation]: https://sfu-db.github.io/connector-x/ 37 | [usage examples]: https://sfu-db.github.io/connector-x/api.html#examples 38 | -------------------------------------------------------------------------------- /testing/native/python-unittest/README.md: -------------------------------------------------------------------------------- 1 | # Using "cr8" test layers with CrateDB and unittest 2 | 3 | [cr8] provides a subsystem to invoke throwaway instances of CrateDB 4 | for testing purposes. 5 | 6 | This folder contains example test cases demonstrating how to use the 7 | `create_node` utility function and the `CrateNode` class, exported 8 | by [cr8], within your Python unittest-based test cases. 9 | 10 | > [!TIP] 11 | > Please also refer to the header sections of each of the provided 12 | > example programs, to learn more about what's exactly inside. 13 | 14 | 15 | ## Run Tests 16 | 17 | Acquire the `cratedb-examples` repository, and install sandbox and 18 | prerequisites. 19 | ```shell 20 | git clone https://github.com/crate/cratedb-examples 21 | cd cratedb-examples 22 | python3 -m venv .venv 23 | source .venv/bin/activate 24 | pip install -r requirements.txt 25 | ``` 26 | 27 | Then, invoke the integration test cases. 28 | ```shell 29 | export TC_KEEPALIVE=true 30 | ngr test testing/native/python-unittest 31 | ``` 32 | 33 | Alternatively, you can change your working directory to the selected 34 | test case folder, and run `unittest` inside there. 35 | ```shell 36 | cd testing/native/python-unittest 37 | python -m unittest -vvv 38 | ``` 39 | 40 | 41 | [cr8]: https://pypi.org/project/cr8/ 42 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'io.quarkus' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | mavenLocal() 9 | } 10 | 11 | dependencies { 12 | implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") 13 | implementation 'io.quarkus:quarkus-hibernate-orm-panache' 14 | implementation 'io.quarkus:quarkus-jdbc-postgresql' 15 | implementation 'io.quarkus:quarkus-arc' 16 | implementation 'io.quarkus:quarkus-hibernate-orm' 17 | implementation 'io.quarkus:quarkus-jackson' // needed for json serializing 18 | testImplementation 'io.quarkus:quarkus-junit5' 19 | testImplementation 'org.testcontainers:cratedb:1.19.7' 20 | testImplementation "org.testcontainers:junit-jupiter:1.19.7" 21 | } 22 | 23 | group 'org.acme' 24 | version '1.0.0-SNAPSHOT' 25 | 26 | java { 27 | sourceCompatibility = JavaVersion.VERSION_21 28 | targetCompatibility = JavaVersion.VERSION_21 29 | } 30 | 31 | test { 32 | systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" 33 | } 34 | compileJava { 35 | options.encoding = 'UTF-8' 36 | options.compilerArgs << '-parameters' 37 | } 38 | 39 | compileTestJava { 40 | options.encoding = 'UTF-8' 41 | } 42 | -------------------------------------------------------------------------------- /by-language/elixir-postgrex/README.md: -------------------------------------------------------------------------------- 1 | # Connecting to CrateDB with Elixir 2 | 3 | ## About 4 | 5 | The file `test/basic_test.exs` includes a basic example program that uses 6 | the canonical PostgreSQL driver for Elixir, [Postgrex], to connect to 7 | CrateDB. 8 | 9 | ## Usage 10 | 11 | Start a CrateDB instance for evaluation purposes. 12 | ```shell 13 | docker run -it --rm --publish=4200:4200 --publish=5432:5432 crate:latest 14 | ``` 15 | 16 | Invoke example program. 17 | ```shell 18 | mix deps.get 19 | mix test --trace 20 | ``` 21 | 22 | ## Trivia 23 | 24 | This folder contains a minimal Elixir project using [Hex] and [Mix] 25 | for package management, and [ExUnit] for unit testing. 26 | 27 | [Hex] is [Elixir]'s package manager. 28 | 29 | > [Elixir] ships with a great set of tools to ease development. [Mix] is a 30 | > build tool that allows you to easily create projects, manage tasks, 31 | > run tests and more. 32 | > 33 | > [Mix] also integrates with the [Hex] package manager for dependency management 34 | > and hosting documentation for the whole ecosystem. 35 | > 36 | > -- https://elixir-lang.org/ 37 | 38 | 39 | [Elixir]: https://elixir-lang.org/ 40 | [ExUnit]: https://hexdocs.pm/ex_unit/ 41 | [Hex]: https://hex.pm/ 42 | [Mix]: https://hexdocs.pm/mix/Mix.html 43 | [Postgrex]: https://hexdocs.pm/postgrex/ 44 | -------------------------------------------------------------------------------- /framework/graphene/schema.py: -------------------------------------------------------------------------------- 1 | import graphene 2 | from graphene import relay 3 | from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType 4 | 5 | from models import Department as DepartmentModel 6 | from models import Employee as EmployeeModel 7 | from models import Role as RoleModel 8 | 9 | 10 | class Department(SQLAlchemyObjectType): 11 | class Meta: 12 | model = DepartmentModel 13 | interfaces = (relay.Node,) 14 | 15 | 16 | class Employee(SQLAlchemyObjectType): 17 | class Meta: 18 | model = EmployeeModel 19 | interfaces = (relay.Node,) 20 | 21 | 22 | class Role(SQLAlchemyObjectType): 23 | class Meta: 24 | model = RoleModel 25 | interfaces = (relay.Node,) 26 | 27 | 28 | class Query(graphene.ObjectType): 29 | node = relay.Node.Field() 30 | # Allow only single column sorting 31 | all_employees = SQLAlchemyConnectionField( 32 | Employee.connection, sort=Employee.sort_argument() 33 | ) 34 | # Allows sorting over multiple columns, by default over the primary key 35 | all_roles = SQLAlchemyConnectionField(Role.connection) 36 | # Disable sorting over this field 37 | all_departments = SQLAlchemyConnectionField(Department.connection, sort=None) 38 | 39 | 40 | schema = graphene.Schema(query=Query) 41 | -------------------------------------------------------------------------------- /application/ingestr/README.md: -------------------------------------------------------------------------------- 1 | # Use CrateDB with ingestr 2 | 3 | ## About 4 | 5 | [ingestr] is a command-line application that allows copying data 6 | from any source into any destination database. 7 | 8 | ## What's inside 9 | 10 | This folder includes runnable examples that use ingestr with CrateDB. 11 | They are also used as integration tests to ensure software components 12 | fit together well. 13 | 14 | - `.env`: Environment variable definitions 15 | - `kafka-compose.yml`: Service composition file for Kafka and CrateDB 16 | - `kafka-demo.xsh`: The demonstration program 17 | 18 | ## Prerequisites 19 | 20 | For executing the commands in this walkthrough, you need a working 21 | installation of Docker and Python. 22 | 23 | ## Synopsis 24 | 25 | ```shell 26 | ingestr ingest --yes \ 27 | --source-uri "kafka://?bootstrap_servers=localhost:9092&group_id=test_group&value_type=json&select=value" \ 28 | --source-table "demo" \ 29 | --dest-uri "cratedb://crate:crate@localhost:5432/?sslmode=disable" \ 30 | --dest-table "doc.kafka_demo" 31 | ``` 32 | 33 | ## Usage 34 | 35 | To start cycling without tearing down the backend stack each time, 36 | use the `KEEPALIVE` environment variable. 37 | ```shell 38 | export KEEPALIVE=true 39 | sh test.sh 40 | ``` 41 | 42 | 43 | [ingestr]: https://bruin-data.github.io/ingestr/ 44 | -------------------------------------------------------------------------------- /by-language/csharp-efcore/tests/BlogDemoTest.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using Microsoft.EntityFrameworkCore; 3 | using Npgsql; 4 | using Xunit; 5 | 6 | public class BlogDemoTest 7 | { 8 | public NpgsqlConnection GetConnection(string? connectionString) 9 | { 10 | var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString); 11 | // dataSourceBuilder.EnableDynamicJson(); 12 | using var dataSource = dataSourceBuilder.Build(); 13 | return dataSource.OpenConnection(); 14 | } 15 | 16 | [Fact] 17 | public void TestBlogDemo() 18 | { 19 | // Invoke example database workload. 20 | var blogDemo = new BlogDemo(); 21 | blogDemo.run(); 22 | 23 | // Validate database content. 24 | var conn = GetConnection(blogDemo.context.Database.GetConnectionString()); 25 | var cmd = new NpgsqlCommand("""SELECT * FROM testdrive."Blogs";""", conn); 26 | var reader = cmd.ExecuteReader(); 27 | 28 | var data = new DataTable(); 29 | data.Load(reader); 30 | 31 | // Check first record. 32 | var row = data.Rows[0]; 33 | Assert.NotNull(row["Id"]); 34 | Assert.Equal("FooBlog", row["Name"]); 35 | 36 | conn.Close(); 37 | conn.Dispose(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /by-language/java-jooq/src/generated/java/io/crate/demo/jooq/model/Keys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is generated by jOOQ. 3 | */ 4 | package io.crate.demo.jooq.model; 5 | 6 | 7 | import io.crate.demo.jooq.model.tables.Author; 8 | import io.crate.demo.jooq.model.tables.Book; 9 | import io.crate.demo.jooq.model.tables.records.AuthorRecord; 10 | import io.crate.demo.jooq.model.tables.records.BookRecord; 11 | 12 | import org.jooq.TableField; 13 | import org.jooq.UniqueKey; 14 | import org.jooq.impl.DSL; 15 | import org.jooq.impl.Internal; 16 | 17 | 18 | /** 19 | * A class modelling foreign key relationships and constraints of tables in the 20 | * default schema. 21 | */ 22 | @SuppressWarnings({ "all", "unchecked", "rawtypes" }) 23 | public class Keys { 24 | 25 | // ------------------------------------------------------------------------- 26 | // UNIQUE and PRIMARY KEY definitions 27 | // ------------------------------------------------------------------------- 28 | 29 | public static final UniqueKey CONSTRAINT_A = Internal.createUniqueKey(Author.AUTHOR, DSL.name("CONSTRAINT_A"), new TableField[] { Author.AUTHOR.ID }, true); 30 | public static final UniqueKey CONSTRAINT_2 = Internal.createUniqueKey(Book.BOOK, DSL.name("CONSTRAINT_2"), new TableField[] { Book.BOOK.ID }, true); 31 | } 32 | -------------------------------------------------------------------------------- /by-dataframe/spark/scala-http/README.md: -------------------------------------------------------------------------------- 1 | # Load Spark data frame into CrateDB using Scala and HTTP 2 | 3 | This example aims to demonstrate how a Spark data frame can be loaded into CrateDB using the CrateDB HTTP endpoint. 4 | 5 | It assumes there is a CrateDB instance running on localhost accepting connections with the default `crate` superuser, and it relies on the following table being created: 6 | 7 | .. code-block:: sql 8 | 9 | CREATE TABLE myschema.mytable ( 10 | examplefield1 TIMESTAMP, 11 | anotherfield geo_point, 12 | jsonpayload OBJECT 13 | ); 14 | 15 | When applicable for your environment, you may want to consider to replace `scalaj.http` with async calls like `akka.http` or `AsyncHttpClient`. 16 | You may also want to explore if connection pooling is useful in your environment, 17 | and if JDBC calls leveraging the PostgreSQL wire protocol are more convenient 18 | for your particular case. 19 | 20 | Saying this, note that this example uses [CrateDB's HTTP bulk operations] to ingest 21 | data, which is currently the most efficient way to do it. 22 | 23 | [CrateDB's HTTP bulk operations]: https://cratedb.com/docs/guide/performance/inserts/bulk.html 24 | 25 | You can run this example with [sbt]: 26 | 27 | .. code-block:: shell 28 | 29 | sbt run 30 | 31 | [sbt]: https://www.scala-sbt.org/download/ 32 | -------------------------------------------------------------------------------- /operation/testbench-yellowcab/README.rst: -------------------------------------------------------------------------------- 1 | ############################ 2 | CrateDB NYC Yellowcab import 3 | ############################ 4 | 5 | 6 | ***** 7 | About 8 | ***** 9 | 10 | Import a subset of the NYC Yellowcab data set from a gzipped CSV file on AWS S3 11 | into CrateDB. 12 | 13 | 14 | ***** 15 | Usage 16 | ***** 17 | 18 | :: 19 | 20 | curl https://raw.githubusercontent.com/crate/cratedb-examples/main/stacks/testbench-yellowcab/cratedb-import-nyc-yellowcab.sh | bash 21 | 22 | 23 | *** 24 | SQL 25 | *** 26 | 27 | The SQL statements used:: 28 | 29 | CREATE TABLE IF NOT EXISTS "nyc_taxi" 30 | ("congestion_surcharge" REAL, "dolocationid" INTEGER, "extra" REAL, "fare_amount" REAL, "improvement_surcharge" REAL, "mta_tax" REAL, "passenger_count" INTEGER, "payment_type" INTEGER, "pickup_datetime" TIMESTAMP WITH TIME ZONE, "pulocationid" INTEGER, "ratecodeid" INTEGER, "store_and_fwd_flag" TEXT, "tip_amount" REAL, "tolls_amount" REAL, "total_amount" REAL, "trip_distance" REAL, "vendorid" INTEGER) 31 | WITH ("column_policy" = 'dynamic', "number_of_replicas" = '0', "refresh_interval" = 10000); 32 | 33 | COPY "nyc_taxi" 34 | FROM 'https://s3.amazonaws.com/crate.sampledata/nyc.yellowcab/yc.2019.07.gz' 35 | WITH (compression = 'gzip'); 36 | 37 | REFRESH TABLE "nyc_taxi"; 38 | 39 | SELECT COUNT(*) FROM nyc_taxi; 40 | -------------------------------------------------------------------------------- /testing/testcontainers/python-unittest/test_unittest.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using "Testcontainers for Python" with CrateDB and unittest 3 | 4 | Build test harnesses around CrateDB using the `CrateDBTestAdapter` 5 | exported by `cratedb-toolkit`. 6 | 7 | https://pypi.org/project/cratedb-toolkit/ 8 | """ 9 | import subprocess 10 | from pprint import pprint 11 | from unittest import TestCase 12 | 13 | from cratedb_toolkit.testing.testcontainers.cratedb import CrateDBTestAdapter 14 | 15 | cratedb_layer = CrateDBTestAdapter() 16 | 17 | SQL_STATEMENT = "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3;" 18 | 19 | 20 | def setUpModule(): 21 | cratedb_layer.start() 22 | 23 | 24 | def tearDownModule(): 25 | cratedb_layer.stop() 26 | 27 | 28 | class CrashTest(TestCase): 29 | 30 | def test_crash(self): 31 | """ 32 | After provisioning a test instance of CrateDB, invoke `crash`. 33 | """ 34 | http_url = cratedb_layer.get_http_url() 35 | command = f"time crash --hosts '{http_url}' --command '{SQL_STATEMENT}'" 36 | subprocess.check_call(command, shell=True) 37 | 38 | def test_sql(self): 39 | """ 40 | After provisioning a test instance of CrateDB, invoke an SQL statement. 41 | """ 42 | results = cratedb_layer.database.run_sql(SQL_STATEMENT, records=True) 43 | pprint(results) 44 | -------------------------------------------------------------------------------- /framework/gradio/basic_sys_summits.py: -------------------------------------------------------------------------------- 1 | """ 2 | A basic Gradio 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://www.gradio.app/guides/connecting-to-a-database 8 | - https://www.gradio.app/docs/gradio/dataframe 9 | - https://cratedb.com/docs/sqlalchemy-cratedb/ 10 | """ 11 | import gradio as gr 12 | import pandas as pd 13 | 14 | # Connect to CrateDB on localhost. 15 | CRATEDB_SQLALCHEMY_URL = "crate://localhost:4200" 16 | 17 | # Connect to CrateDB Cloud. 18 | # CRATEDB_SQLALCHEMY_URL = "crate://admin:g_,8.F0fNbVSk0.*!n54S5c,@example.gke1.us-central1.gcp.cratedb.net:4200?ssl=true" 19 | 20 | 21 | def get_sys_summits(): 22 | """ 23 | Query the database using pandas. 24 | """ 25 | return pd.read_sql('SELECT * FROM "sys"."summits";', con=CRATEDB_SQLALCHEMY_URL) 26 | 27 | 28 | def get_dataframe(): 29 | """ 30 | Create a dataframe widget. 31 | """ 32 | df = get_sys_summits() 33 | return gr.DataFrame(df) 34 | 35 | 36 | # Define the Gradio interface. 37 | demo = gr.Interface( 38 | fn=get_dataframe, 39 | inputs=[], 40 | outputs=["dataframe"], 41 | title="Gradio with CrateDB Example", 42 | live=True, 43 | allow_flagging="never", 44 | ) 45 | 46 | 47 | if __name__ == "__main__": 48 | demo.launch() 49 | -------------------------------------------------------------------------------- /application/microsoft-ssis/README.md: -------------------------------------------------------------------------------- 1 | # Using SQL Server Integration Services with CrateDB 2 | 3 | ## About 4 | 5 | Microsoft [SQL Server Integration Services] (SSIS) is a component of the 6 | Microsoft SQL Server database software that can be used to perform a broad 7 | range of data migration tasks. [SSIS] is effectively a platform and framework 8 | for data integration and workflow applications. 9 | 10 | This folder includes a demo project which uses SSIS to read and write data from 11 | [CrateDB]. The file `Package.dtsx` defines a basic [Data Flow Task] pipeline to 12 | read data from the `"doc"."nyc_taxi"` table and write it into the 13 | `"doc"."nyc_taxi_target"` table, in order to verify connectivity. 14 | 15 | For connecting to CrateDB, SSIS uses the [ODBC] interface. More specifically, 16 | because CrateDB is compatible with PostgreSQL, the [psqlODBC - PostgreSQL ODBC 17 | driver]. 18 | 19 | 20 | [CrateDB]: https://github.com/crate/crate 21 | [Data Flow Task]: https://learn.microsoft.com/en-us/sql/integration-services/control-flow/data-flow-task 22 | [ODBC]: https://en.wikipedia.org/wiki/Odbc 23 | [psqlODBC - PostgreSQL ODBC driver]: https://odbc.postgresql.org/ 24 | [SQL Server Integration Services]: https://learn.microsoft.com/en-us/sql/integration-services/sql-server-integration-services 25 | [SSIS]: https://en.wikipedia.org/wiki/SQL_Server_Integration_Services 26 | -------------------------------------------------------------------------------- /testing/native/python-pytest/README.md: -------------------------------------------------------------------------------- 1 | # Using "pytest-cratedb" with CrateDB and pytest 2 | 3 | [pytest-cratedb] wraps the CrateDB test layer from [cr8], and provides 4 | a few pytest fixtures to conveniently make it accessible for test 5 | cases based on pytest. 6 | 7 | This folder contains example test cases demonstrating how to use the 8 | `crate`, `crate_cursor`, and `crate_cursor` pytest fixtures exported 9 | by [pytest-cratedb]. 10 | 11 | > [!TIP] 12 | > Please also refer to the header sections of each of the provided 13 | > example programs, to learn more about what's exactly inside. 14 | 15 | 16 | ## Run Tests 17 | 18 | Acquire the `cratedb-examples` repository, and install sandbox and 19 | prerequisites. 20 | ```shell 21 | git clone https://github.com/crate/cratedb-examples 22 | cd cratedb-examples 23 | python3 -m venv .venv 24 | source .venv/bin/activate 25 | pip install -r requirements.txt 26 | ``` 27 | 28 | Then, invoke the integration test cases. 29 | ```shell 30 | export TC_KEEPALIVE=true 31 | ngr test testing/native/python-pytest 32 | ``` 33 | 34 | Alternatively, you can change your working directory to the selected 35 | test case folder, and run `pytest` inside there. 36 | ```shell 37 | cd testing/native/python-pytest 38 | pytest 39 | ``` 40 | 41 | 42 | [cr8]: https://pypi.org/project/cr8/ 43 | [pytest-cratedb]: https://pypi.org/project/pytest-cratedb/ 44 | -------------------------------------------------------------------------------- /framework/records/test.py: -------------------------------------------------------------------------------- 1 | from example_basic import ( 2 | records_select_sys_summits, 3 | records_get_table_names, 4 | records_export_sys_summits_csv, 5 | records_export_sys_summits_pandas, 6 | ) 7 | from example_types import records_ddl_dml_dql, RECORD_OUT 8 | 9 | 10 | def test_sys_summits(): 11 | """ 12 | Read built-in data from CrateDB's `sys` table through `records`. 13 | """ 14 | data = records_select_sys_summits() 15 | assert data[0]["mountain"] == "Mont Blanc" 16 | 17 | 18 | def test_get_table_names(): 19 | data = records_get_table_names() 20 | assert "nodes" in data 21 | assert "shards" in data 22 | assert len(data) > 10 23 | 24 | 25 | def test_export_sys_summits_pandas(): 26 | data = records_export_sys_summits_pandas() 27 | assert list(data["mountain"]) == ["Mont Blanc", "Monte Rosa", "Dom"] 28 | 29 | 30 | def test_export_sys_summits_csv(): 31 | data = records_export_sys_summits_csv() 32 | assert "classification,coordinates,country" in data 33 | assert "Mont Blanc,4695,U-Savoy/Aosta" in data 34 | 35 | 36 | def test_ddl_dml_dql(): 37 | """ 38 | Validate an end-to-end lifecycle, defining a table, inserting data, and querying it. 39 | This example uses all data types supported by CrateDB. 40 | """ 41 | data = records_ddl_dml_dql() 42 | assert data[0].as_dict() == RECORD_OUT 43 | -------------------------------------------------------------------------------- /.github/workflows/framework-flink-kafka-java.yml: -------------------------------------------------------------------------------- 1 | name: "Apache Flink: Kafka to JDBC sink (Java)" 2 | 3 | on: 4 | pull_request: 5 | branches: ~ 6 | paths: 7 | - '.github/workflows/framework-flink-kafka-java.yml' 8 | - 'framework/flink/kafka-jdbcsink-java/**' 9 | - '/requirements.txt' 10 | push: 11 | branches: [ main ] 12 | paths: 13 | - '.github/workflows/framework-flink-kafka-java.yml' 14 | - 'framework/flink/kafka-jdbcsink-java/**' 15 | - '/requirements.txt' 16 | 17 | # Allow job to be triggered manually. 18 | workflow_dispatch: 19 | 20 | # Run job each night after CrateDB nightly has been published. 21 | schedule: 22 | - cron: '0 3 * * *' 23 | 24 | # Cancel in-progress jobs when pushing to the same branch. 25 | concurrency: 26 | cancel-in-progress: true 27 | group: ${{ github.workflow }}-${{ github.ref }} 28 | 29 | jobs: 30 | 31 | test: 32 | runs-on: ${{ matrix.os }} 33 | 34 | strategy: 35 | fail-fast: true 36 | matrix: 37 | os: [ "ubuntu-latest" ] 38 | 39 | name: OS ${{ matrix.os }} 40 | steps: 41 | 42 | - name: Acquire sources 43 | uses: actions/checkout@v6 44 | 45 | - name: Validate framework/flink/kafka-jdbcsink-java 46 | run: | 47 | # TODO: Generalize invocation into `ngr` test runner. 48 | cd framework/flink/kafka-jdbcsink-java 49 | bash test.sh 50 | -------------------------------------------------------------------------------- /testing/testcontainers/python-pytest/README.md: -------------------------------------------------------------------------------- 1 | # Using "Testcontainers for Python" with CrateDB and pytest 2 | 3 | [Testcontainers] is an open source framework for providing throwaway, 4 | lightweight instances of databases, message brokers, web browsers, or 5 | just about anything that can run in a Docker container. 6 | 7 | This folder contains example test cases demonstrating how to use the 8 | `cratedb_service` pytest fixture exported by [cratedb-toolkit]. 9 | 10 | > [!TIP] 11 | > Please also refer to the header sections of each of the provided 12 | > example programs, to learn more about what's exactly inside. 13 | 14 | 15 | ## Run Tests 16 | 17 | Acquire the `cratedb-examples` repository, and install sandbox and 18 | prerequisites. 19 | ```shell 20 | git clone https://github.com/crate/cratedb-examples 21 | cd cratedb-examples 22 | python3 -m venv .venv 23 | source .venv/bin/activate 24 | pip install -r requirements.txt 25 | ``` 26 | 27 | Then, invoke the integration test cases. 28 | ```shell 29 | export TC_KEEPALIVE=true 30 | ngr test testing/testcontainers/python-pytest 31 | ``` 32 | 33 | Alternatively, you can change your working directory to the selected 34 | test case folder, and run `pytest` inside there. 35 | ```shell 36 | cd testing/testcontainers/python-pytest 37 | pytest 38 | ``` 39 | 40 | 41 | [cratedb-toolkit]: https://pypi.org/project/cratedb-toolkit/ 42 | [Testcontainers]: https://testcontainers.org/ 43 | -------------------------------------------------------------------------------- /topic/autoscaling/README.md: -------------------------------------------------------------------------------- 1 | # Autoscaling 2 | 3 | ## Introduction 4 | 5 | Autoscaling is the process of scaling up and down your CrateDB Cluster 6 | on demand. 7 | 8 | ## About 9 | 10 | This Python program can be used to autoscale a CrateDB Cloud Cluster. 11 | 12 | The program monitors the number of shards that are on the nodes in the 13 | cluster. If that number crosses a threshold, a new node will be added 14 | to the database cluster. 15 | 16 | When the number of shards goes back down below another threshold, the 17 | cluster will be scaled-back, by decommissioning excess nodes again. 18 | 19 | For more depth and background on this please see the community post 20 | about autoscaling. 21 | > 22 | 23 | ## Usage 24 | 25 | Run a dedicated cluster in [CrateDB Cloud](https://console.cratedb.cloud/). 26 | 27 | ### Install 28 | 29 | The script uses a couple of Python libraries. Make sure you have installed those: 30 | 31 | ```shell 32 | pip install requests prometheus-client 33 | ``` 34 | 35 | ```shell 36 | git clone https://github.com/crate/cratedb-examples 37 | cd cratedb-examples/topic/autoscaling 38 | ``` 39 | 40 | ### Run 41 | 42 | ```shell 43 | export CRATEDB_CLOUD_API_KEY="" 44 | export CRATEDB_CLOUD_API_SECRET="" 45 | python autoscale.py --organization_id "" --cluster_id "" 46 | ``` -------------------------------------------------------------------------------- /by-dataframe/polars/one_db_to_another.py: -------------------------------------------------------------------------------- 1 | """ 2 | Thanks to Polars, we can seamlessly move data from one Polars' compatible 3 | database to another. 4 | """ 5 | 6 | import polars as pl 7 | 8 | 9 | def postgres_to_cratedb(table_name, pg_uri, cratedb_uri): 10 | """ 11 | Copies `table_name` from Postgres to CrateDB 12 | 13 | Note: 14 | When specifying the query for Postgres, you might need to specify the 15 | database name and schema, for example, `mydatabase.public.ny_taxi` and 16 | when can leave just 'ny_taxi' in the Crate part, creating the table in 17 | `doc.ny_taxi`. 18 | """ 19 | df = pl.read_database_uri(f"SELECT * FROM {table_name}", pg_uri, engine="adbc") 20 | df.write_database(table_name, cratedb_uri) 21 | 22 | 23 | def mysql_to_cratedb(table_name, mysql_uri, cratedb_uri): 24 | """Moves `table_name` from Postgres to CrateDB 25 | 26 | Note: 27 | You will need to install 'adbc-driver-mysql pyarrow' 28 | """ 29 | df = pl.read_database_uri(f"SELECT * FROM {table_name}", mysql_uri, engine="adbc") 30 | df.write_database(table_name, cratedb_uri) 31 | 32 | 33 | # At this point, you probably see the pattern, if polars can connect to it, we can write 34 | # to CrateDB! 35 | # 36 | # We can change the engine to `sqlalchemy` (or remote the parameter, since it's the default value) 37 | # meaning that any Database that has an SQLAlchemy driver can be used to read from. 38 | -------------------------------------------------------------------------------- /framework/flink/kafka-jdbcsink-java/.env: -------------------------------------------------------------------------------- 1 | # Software component versions. 2 | CONFLUENT_VERSION=7.9.0 3 | CRATEDB_VERSION=5.10.3 4 | FLINK_VERSION=1.20.1 5 | KCAT_VERSION=1.7.1 6 | 7 | # Flink service configuration. 8 | PORT_FLINK_JOBMANAGER=8081 9 | 10 | # Data source configuration (Kafka). 11 | PORT_KAFKA_BROKER_INTERNAL=9092 12 | PORT_KAFKA_BROKER_EXTERNAL=9094 13 | PORT_KAFKA_ZOOKEEPER=2181 14 | 15 | # Data sink configuration (CrateDB). 16 | CRATEDB_HOST=${CRATEDB_HOST:-cratedb} 17 | CRATEDB_HTTP_PORT=${CRATEDB_HTTP_PORT:-4200} 18 | CRATEDB_POSTGRESQL_PORT=${CRATEDB_POSTGRESQL_PORT:-5432} 19 | CRATEDB_USERNAME=${CRATEDB_USERNAME:-crate} 20 | CRATEDB_PASSWORD=${CRATEDB_PASSWORD:-} 21 | CRATEDB_HTTP_SCHEME=${CRATEDB_HTTP_SCHEME:-http} 22 | 23 | # Data sink configuration (CrateDB Cloud). 24 | # CRATEDB_HTTP_SCHEME=https 25 | # CRATEDB_HOST=example.aks1.westeurope.azure.cratedb.net 26 | # CRATEDB_USERNAME='admin' 27 | # CRATEDB_PASSWORD='' 28 | 29 | # Needs to be computed here. 30 | CRATEDB_HTTP_URL="${CRATEDB_HTTP_SCHEME}://${CRATEDB_USERNAME}:${CRATEDB_PASSWORD}@${CRATEDB_HOST}:${CRATEDB_HTTP_PORT}" 31 | 32 | # Options for acquiring the Flink job JAR file. 33 | # https://github.com/crate/cratedb-flink-jobs 34 | FLINK_JOB_JAR_VERSION=0.5 35 | FLINK_JOB_JAR_FILE=cratedb-flink-jobs-${FLINK_JOB_JAR_VERSION}.jar 36 | FLINK_JOB_JAR_URL=https://github.com/crate/cratedb-flink-jobs/releases/download/${FLINK_JOB_JAR_VERSION}/${FLINK_JOB_JAR_FILE} 37 | -------------------------------------------------------------------------------- /framework/dbt/basic/dbt_project.yml: -------------------------------------------------------------------------------- 1 | 2 | # Name your project! Project names should contain only lowercase characters 3 | # and underscores. A good package name should reflect your organization's 4 | # name or the intended use of these models 5 | name: 'testdrive_basic' 6 | version: '1.0.0' 7 | config-version: 2 8 | 9 | # This setting configures which "profile" dbt uses for this project. 10 | profile: 'cratedb_localhost' 11 | 12 | # These configurations specify where dbt should look for different types of files. 13 | # The `model-paths` config, for example, states that models in this project can be 14 | # found in the "models/" directory. You probably won't need to change these! 15 | model-paths: ["models"] 16 | analysis-paths: ["analyses"] 17 | test-paths: ["tests"] 18 | seed-paths: ["seeds"] 19 | macro-paths: ["macros"] 20 | snapshot-paths: ["snapshots"] 21 | 22 | clean-targets: # directories to be removed by `dbt clean` 23 | - "target" 24 | - "dbt_packages" 25 | 26 | 27 | # Configuring models 28 | # Full documentation: https://docs.getdbt.com/docs/configuring-models 29 | 30 | # In this example config, we tell dbt to build all models in the example/ 31 | # directory as views. These settings can be overridden in the individual model 32 | # files using the `{{ config(...) }}` macro. 33 | models: 34 | testdrive_basic: 35 | # Config indicated by + and applies to all files under models/example/ 36 | example: 37 | +materialized: view 38 | -------------------------------------------------------------------------------- /testing/testcontainers/python-unittest/README.md: -------------------------------------------------------------------------------- 1 | # Using "Testcontainers for Python" with CrateDB and unittest 2 | 3 | [Testcontainers] is an open source framework for providing throwaway, 4 | lightweight instances of databases, message brokers, web browsers, or 5 | just about anything that can run in a Docker container. 6 | 7 | This folder contains example test cases demonstrating how to use the 8 | `CrateDBTestAdapter` test layer utility exported by [cratedb-toolkit]. 9 | 10 | > [!TIP] 11 | > Please also refer to the header sections of each of the provided 12 | > example programs, to learn more about what's exactly inside. 13 | 14 | 15 | ## Run Tests 16 | 17 | Acquire the `cratedb-examples` repository, and install sandbox and 18 | prerequisites. 19 | ```shell 20 | git clone https://github.com/crate/cratedb-examples 21 | cd cratedb-examples 22 | python3 -m venv .venv 23 | source .venv/bin/activate 24 | pip install -r requirements.txt 25 | ``` 26 | 27 | Then, invoke the integration test cases. 28 | ```shell 29 | export TC_KEEPALIVE=true 30 | ngr test testing/testcontainers/python-unittest 31 | ``` 32 | 33 | Alternatively, you can change your working directory to the selected 34 | test case folder, and run `unittest` inside there. 35 | ```shell 36 | cd testing/testcontainers/python-unittest 37 | python -m unittest -vvv 38 | ``` 39 | 40 | 41 | [cratedb-toolkit]: https://pypi.org/project/cratedb-toolkit/ 42 | [Testcontainers]: https://testcontainers.org/ 43 | -------------------------------------------------------------------------------- /topic/machine-learning/mlflow/test.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import pytest 4 | 5 | from cratedb_toolkit.util.database import DatabaseAdapter 6 | from pueblo.testing.folder import str_list, list_python_files 7 | from pueblo.testing.notebook import generate_tests 8 | from pueblo.testing.snippet import pytest_module_function 9 | from testbook import testbook 10 | 11 | HERE = Path(__file__).parent 12 | 13 | 14 | @pytest.fixture() 15 | def cratedb() -> DatabaseAdapter: 16 | return DatabaseAdapter(dburi="crate://crate@localhost:4200") 17 | 18 | 19 | @pytest.fixture(scope="function", autouse=True) 20 | def db_init(cratedb): 21 | """ 22 | Initialize database. 23 | """ 24 | cratedb.run_sql("DROP TABLE IF EXISTS machine_data;") 25 | 26 | 27 | def pytest_generate_tests(metafunc): 28 | """ 29 | Generate pytest test case per Jupyter Notebook. 30 | """ 31 | here = Path(__file__).parent 32 | generate_tests(metafunc, path=here) 33 | 34 | 35 | def test_notebook(notebook): 36 | """ 37 | Execute Jupyter Notebook, one test case per .ipynb file. 38 | """ 39 | with testbook(notebook) as tb: 40 | tb.execute() 41 | 42 | 43 | @pytest.mark.parametrize("pyfile", str_list(list_python_files(HERE))) 44 | def test_file(request, pyfile: Path): 45 | """ 46 | From individual Python file, collect and wrap the `main` function into a test case. 47 | """ 48 | pytest_module_function(request, pyfile) 49 | -------------------------------------------------------------------------------- /by-language/python-turbodbc/backlog.rst: -------------------------------------------------------------------------------- 1 | ####################### 2 | python-turbodbc backlog 3 | ####################### 4 | 5 | Various items how this little code example can be improved. 6 | 7 | - [x] Provide basic example 8 | - [x] Insert multiple records using parameters 9 | - [x] Docs: Add installation on SUSE 10 | - [x] Provide example(s) for different operating systems (Linux, macOS) 11 | - [x] Using turbodbc 4 is not an option, see https://github.com/blue-yonder/turbodbc/issues/437 12 | - [x] Note turbodbc=5.0.1 should only require numpy>=2 in the build environment but should run also with e.g. numpy=1.26 13 | - [x] Let's use NumPy 2 across the board 14 | - [o] Docs: Drop a note about connecting with driver file vs. connecting via DSN 15 | - [o] Evaluate different ODBC drivers 16 | - [o] Provide an example scenario how to run it on Windows 17 | - [o] Exercise advanced NumPy and PyArrow options 18 | - [o] Exchange advanced CrateDB data types like ``OBJECT``, ``ARRAY``, and friends 19 | - [o] Use ``SSLmode = Yes`` to connect to CrateDB Cloud 20 | - [o] Explore other driver options at `Zabbix » Recommended UnixODBC settings for PostgreSQL`_ 21 | - [o] Check out https://github.com/dirkjonker/sqlalchemy-turbodbc 22 | - [o] Check out https://docs.devart.com/odbc/postgresql/centos.htm 23 | 24 | 25 | .. _Zabbix » Recommended UnixODBC settings for PostgreSQL: https://www.zabbix.com/documentation/current/en/manual/config/items/itemtypes/odbc_checks/unixodbc_postgresql 26 | -------------------------------------------------------------------------------- /by-language/python-dbapi/README.rst: -------------------------------------------------------------------------------- 1 | .. highlight: console 2 | 3 | ######################################################## 4 | Connect to CrateDB and CrateDB Cloud using Python DB API 5 | ######################################################## 6 | 7 | 8 | ***** 9 | About 10 | ***** 11 | 12 | Example programs demonstrating CrateDB's DB API adapter, 13 | for the HTTP protocol. 14 | 15 | 16 | ***** 17 | Setup 18 | ***** 19 | 20 | To start a CrateDB instance on your machine for evaluation purposes, invoke:: 21 | 22 | docker run -it --rm --publish=4200:4200 --publish=5432:5432 crate:latest 23 | 24 | Navigate to example program directory, and install prerequisites:: 25 | 26 | # Acquire sources. 27 | git clone https://github.com/crate/cratedb-examples 28 | cd cratedb-examples 29 | python3 -m venv .venv 30 | source .venv/bin/activate 31 | 32 | Then, invoke the integration test cases:: 33 | 34 | ngr test by-language/python-dbapi 35 | 36 | 37 | ******** 38 | Examples 39 | ******** 40 | 41 | Run an example program:: 42 | 43 | time python select_basic.py 44 | time python insert_basic.py 45 | 46 | .. TIP:: 47 | 48 | For more information, please refer to the header sections of each of the 49 | provided example programs. 50 | 51 | 52 | ***** 53 | Tests 54 | ***** 55 | 56 | To test the accompanied example programs all at once, invoke the software tests:: 57 | 58 | pytest 59 | 60 | 61 | .. _CrateDB: https://github.com/crate/crate 62 | -------------------------------------------------------------------------------- /topic/serverless/azure-eventhub/Azure Function/function_app.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import json 4 | import logging 5 | 6 | import azure.functions as func 7 | 8 | from enrichment import transform 9 | from cratedb_writer import CrateDBWriter 10 | from value_cache import ValueCache 11 | 12 | 13 | app = func.FunctionApp() 14 | 15 | 16 | @app.event_hub_message_trigger( 17 | arg_name="event", 18 | event_hub_name="demo-event-ce", 19 | connection="EVENT_HUB_CONNECTION_STRING", 20 | ) 21 | def enrich_events(event: func.EventHubEvent): 22 | crate_db = CrateDBWriter( 23 | { 24 | "readings": os.getenv("READING_TABLE"), 25 | "errors": os.getenv("ERROR_TABLE"), 26 | }, 27 | os.getenv("HOST"), 28 | os.getenv("DB_USER", None), 29 | os.getenv("DB_PASSWORD", None), 30 | ) 31 | 32 | try: 33 | if event is None: 34 | return 35 | insert_value_cache = ValueCache() 36 | raw_events = json.loads(event.get_body().decode("utf-8")) 37 | 38 | for event_ in raw_events: 39 | raw_event = event_ 40 | transform(raw_event, insert_value_cache) 41 | 42 | crate_db.insert_values(insert_value_cache) 43 | except Exception as e: 44 | # when any exception occurred, the function must exit unsuccessfully for events to be retried 45 | logging.error(f"error: {e}") 46 | sys.exit(1) 47 | -------------------------------------------------------------------------------- /by-language/r/basic_rpostgresql.r: -------------------------------------------------------------------------------- 1 | # Install driver on demand. 2 | # RPostgreSQL: R Interface to the 'PostgreSQL' Database System 3 | # https://cran.r-project.org/web/packages/RPostgreSQL/ 4 | 5 | # Optionally install the PostgreSQL library. 6 | if (!requireNamespace("RPostgreSQL", quietly = TRUE)) { 7 | install.packages("RPostgreSQL", repos="https://cran.r-project.org") 8 | } 9 | 10 | # Load the DBI and PostgreSQL libraries. 11 | library(DBI) 12 | library(RPostgreSQL) 13 | drv <- RPostgreSQL::PostgreSQL() 14 | 15 | # Open a database connection, where `dbname` is the name of the CrateDB schema. 16 | conn <- dbConnect(drv, 17 | host = "localhost", 18 | port = 5432, 19 | user = "crate", 20 | password = "crate", 21 | dbname = "doc", 22 | ) 23 | on.exit(DBI::dbDisconnect(conn), add = TRUE) 24 | 25 | # Invoke a basic select query. 26 | res <- dbGetQuery(conn, "SELECT mountain, region, height FROM sys.summits ORDER BY height DESC LIMIT 10;") 27 | print(res) 28 | 29 | # Delete testdrive table when needed. 30 | if (dbExistsTable(conn, "r")) { 31 | dbRemoveTable(conn, "r") 32 | } 33 | 34 | # Basic I/O. 35 | res <- dbGetQuery(conn, "CREATE TABLE IF NOT EXISTS r (id INT PRIMARY KEY, data TEXT);") 36 | res <- dbGetQuery(conn, "INSERT INTO r (id, data) VALUES (42, 'foobar');") 37 | res <- dbGetQuery(conn, "REFRESH TABLE r;") 38 | res <- dbGetQuery(conn, "SELECT * FROM r;") 39 | print(res) 40 | -------------------------------------------------------------------------------- /by-language/java-jooq/build.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * A demo application using CrateDB with jOOQ and the PostgreSQL JDBC driver. 3 | */ 4 | 5 | buildscript { 6 | repositories { 7 | mavenCentral() 8 | } 9 | } 10 | 11 | plugins { 12 | id 'application' 13 | id 'com.adarshr.test-logger' version '4.0.0' 14 | id 'idea' 15 | id 'java' 16 | } 17 | 18 | repositories { 19 | mavenCentral() 20 | mavenLocal() 21 | } 22 | 23 | dependencies { 24 | implementation 'org.jooq:jooq:3.20.10' 25 | implementation 'org.jooq:jooq-meta:3.20.10' 26 | implementation 'org.postgresql:postgresql:42.7.8' 27 | implementation 'org.slf4j:slf4j-api:2.0.17' 28 | implementation 'org.slf4j:slf4j-simple:2.0.17' 29 | testImplementation 'junit:junit:4.13.2' 30 | } 31 | 32 | java { 33 | toolchain { 34 | languageVersion = JavaLanguageVersion.of(21) 35 | } 36 | } 37 | 38 | jar { 39 | archiveBaseName = 'cratedb-demo-java-jooq' 40 | archiveVersion = '0.0.1-SNAPSHOT' 41 | } 42 | 43 | application { 44 | mainClass = 'io.crate.demo.jooq.Application' 45 | } 46 | 47 | sourceSets { 48 | main { 49 | java.srcDirs += [ 50 | "src/generated/java", 51 | "src/main/java", 52 | ] 53 | } 54 | } 55 | 56 | test { 57 | dependsOn 'cleanTest' 58 | } 59 | 60 | // Activate jOOQ code generation add-on. 61 | apply from: 'jooq.gradle' 62 | 63 | idea.module.inheritOutputDirs = true 64 | compileJava.dependsOn processResources 65 | -------------------------------------------------------------------------------- /framework/dlt/pokemon.py: -------------------------------------------------------------------------------- 1 | """data load tool (dlt) — the open-source Python library for data loading 2 | 3 | How to create a data loading pipeline with dlt and CrateDB in 3 seconds: 4 | 5 | 0. Configure `cratedb` destination in `.dlt/secrets.toml`. 6 | ```toml 7 | [destination.cratedb.credentials] 8 | host = "localhost" 9 | port = 5432 10 | username = "crate" 11 | password = "" 12 | ``` 13 | 14 | 1. Write a pipeline script 15 | >>> import dlt 16 | >>> from dlt.sources.helpers import requests 17 | >>> dlt.run( 18 | ... data=requests.get("https://pokeapi.co/api/v2/pokemon/").json()["results"], 19 | ... destination="cratedb", 20 | ... dataset_name="doc", 21 | ... table_name="pokemon") 22 | 23 | 2. Run your pipeline script 24 | > $ python pokemon.py 25 | 26 | 3. See and query your data with autogenerated Streamlit app 27 | > $ dlt pipeline dlt_pokemon show 28 | 29 | Or start with our pipeline template with sample PokeAPI (pokeapi.co) data loaded to bigquery 30 | 31 | > $ dlt init pokemon bigquery 32 | 33 | For more detailed info, see https://dlthub.com/docs/intro 34 | """ 35 | 36 | 37 | def main(): 38 | import dlt 39 | import dlt_cratedb 40 | from dlt.sources.helpers import requests 41 | 42 | dlt.run( 43 | data=requests.get("https://pokeapi.co/api/v2/pokemon/").json()["results"], 44 | destination="cratedb", 45 | dataset_name="doc", 46 | table_name="pokemon") 47 | 48 | 49 | if __name__ == "__main__": 50 | main() 51 | -------------------------------------------------------------------------------- /framework/graphene/database.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import create_engine 2 | from sqlalchemy.ext.declarative import declarative_base 3 | from sqlalchemy.orm import scoped_session, sessionmaker 4 | 5 | engine = create_engine("crate://localhost:4200") 6 | db_session = scoped_session( 7 | sessionmaker(autocommit=False, autoflush=False, bind=engine) 8 | ) 9 | Base = declarative_base() 10 | Base.query = db_session.query_property() 11 | 12 | 13 | def init_db(): 14 | # import all modules here that might define models so that 15 | # they will be registered properly on the metadata. Otherwise 16 | # you will have to import them first before calling init_db() 17 | from models import Department, Employee, Role 18 | 19 | Base.metadata.drop_all(bind=engine) 20 | Base.metadata.create_all(bind=engine) 21 | 22 | # Create the fixtures 23 | engineering = Department(name="Engineering") 24 | db_session.add(engineering) 25 | hr = Department(name="Human Resources") 26 | db_session.add(hr) 27 | 28 | manager = Role(name="manager") 29 | db_session.add(manager) 30 | engineer = Role(name="engineer") 31 | db_session.add(engineer) 32 | 33 | peter = Employee(name="Peter", department=engineering, role=engineer) 34 | db_session.add(peter) 35 | roy = Employee(name="Roy", department=engineering, role=engineer) 36 | db_session.add(roy) 37 | tracy = Employee(name="Tracy", department=hr, role=manager) 38 | db_session.add(tracy) 39 | db_session.commit() 40 | -------------------------------------------------------------------------------- /application/roapi/roapi.Dockerfile: -------------------------------------------------------------------------------- 1 | # Temporarily build ROAPI for CrateDB, until an obligatory 2 | # improvement is included into an official release. 3 | # https://github.com/roapi/roapi/pull/416 4 | 5 | # Source: https://github.com/roapi/roapi/blob/main/Dockerfile 6 | 7 | ARG RUST_VER=1.86.0-bookworm 8 | 9 | FROM rust:${RUST_VER} AS foundation 10 | 11 | RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash 12 | RUN cargo binstall trunk 13 | 14 | # Add WebAssembly target for UI build. 15 | RUN rustup target add wasm32-unknown-unknown 16 | 17 | # Install cmake for snmalloc. 18 | RUN apt-get update \ 19 | && apt-get install --no-install-recommends -y cmake 20 | 21 | FROM foundation AS builder 22 | 23 | RUN cargo install --locked --git https://github.com/roapi/roapi.git --rev 4d649d78 --jobs default --bins roapi --features database 24 | RUN cargo install --list 25 | 26 | # Assemble the final image 27 | FROM debian:bookworm-slim 28 | LABEL org.opencontainers.image.source=https://github.com/roapi/roapi 29 | 30 | RUN apt-get update \ 31 | && apt-get install -y libssl-dev ca-certificates \ 32 | && rm -rf /var/lib/apt/lists/* 33 | 34 | # Use `roapi` program from custom build. 35 | COPY --from=builder /usr/local/cargo/bin/roapi /usr/local/bin/roapi 36 | 37 | # Use test data from vanilla image. 38 | COPY --from=ghcr.io/roapi/roapi:latest /test_data /test_data 39 | 40 | EXPOSE 8080 41 | ENTRYPOINT ["roapi"] 42 | -------------------------------------------------------------------------------- /by-language/java-qa/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | io.crate.qa2 5 | jdbc-qa 6 | jar 7 | 1.0-SNAPSHOT 8 | jdbc-qa 9 | http://maven.apache.org 10 | 11 | 12 | org.hamcrest 13 | hamcrest 14 | 3.0 15 | 16 | 17 | org.postgresql 18 | postgresql 19 | 42.7.8 20 | 21 | 22 | io.crate 23 | crate-testing 24 | 0.12.1 25 | test 26 | 27 | 28 | junit 29 | junit 30 | 4.13.2 31 | test 32 | 33 | 34 | 35 | UTF-8 36 | 11 37 | 11 38 | 39 | 40 | -------------------------------------------------------------------------------- /framework/graphene/models.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, DateTime, ForeignKey, BigInteger, String, func 2 | from sqlalchemy.orm import backref, relationship 3 | from sqlalchemy_cratedb.support import patch_autoincrement_timestamp 4 | 5 | from database import Base 6 | 7 | patch_autoincrement_timestamp() 8 | 9 | 10 | class Department(Base): 11 | __tablename__ = "department" 12 | id = Column(BigInteger, primary_key=True, autoincrement=True) 13 | name = Column(String) 14 | 15 | 16 | class Role(Base): 17 | __tablename__ = "roles" 18 | id = Column(BigInteger, primary_key=True, autoincrement=True) 19 | name = Column(String) 20 | 21 | 22 | class Employee(Base): 23 | __tablename__ = "employee" 24 | id = Column(BigInteger, primary_key=True, autoincrement=True) 25 | name = Column(String) 26 | # Use default=func.now() to set the default hiring time 27 | # of an Employee to be the current time when an 28 | # Employee record was created 29 | hired_on = Column(DateTime, default=func.now()) 30 | department_id = Column(BigInteger, ForeignKey("department.id")) 31 | role_id = Column(BigInteger, ForeignKey("roles.id")) 32 | # Use cascade='delete,all' to propagate the deletion of a Department onto its Employees 33 | department = relationship( 34 | Department, backref=backref("employees", uselist=True, cascade="delete,all") 35 | ) 36 | role = relationship( 37 | Role, backref=backref("roles", uselist=True, cascade="delete,all") 38 | ) 39 | -------------------------------------------------------------------------------- /by-language/java-jooq/src/test/java/io/crate/demo/jooq/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package io.crate.demo.jooq; 2 | 3 | import org.jooq.DSLContext; 4 | import org.jooq.impl.DSL; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | import java.sql.SQLException; 10 | 11 | import static io.crate.demo.jooq.model.Tables.AUTHOR; 12 | 13 | public class ApplicationTest { 14 | 15 | /** 16 | * Run demo application example with generated code, and verify it works. 17 | */ 18 | @Test 19 | public void testExampleWithGeneratedCode() throws SQLException, IOException { 20 | 21 | // Invoke example. 22 | Application app = new Application(); 23 | app.exampleWithGeneratedCode(); 24 | 25 | // Check number of records. 26 | DSLContext db = app.getDSLContext(); 27 | int count = db.fetchCount(DSL.selectFrom(AUTHOR)); 28 | Assert.assertEquals(count, 3); 29 | } 30 | 31 | /** 32 | * Run demo application example with generated code, and verify it works. 33 | */ 34 | @Test 35 | public void testExampleWithDynamicSchema() throws SQLException, IOException { 36 | 37 | // Invoke example. 38 | Application app = new Application(); 39 | app.exampleWithDynamicSchema(); 40 | 41 | // Check number of records. 42 | DSLContext db = app.getDSLContext(); 43 | int count = db.fetchCount(DSL.selectFrom("book")); 44 | Assert.assertEquals(count, 2); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/src/main/java/io/crate/CrateDBJsonJdbcType.java: -------------------------------------------------------------------------------- 1 | package io.crate; 2 | 3 | import org.hibernate.dialect.Dialect; 4 | import org.hibernate.metamodel.mapping.EmbeddableMappingType; 5 | import org.hibernate.metamodel.spi.RuntimeModelCreationContext; 6 | import org.hibernate.sql.ast.spi.SqlAppender; 7 | import org.hibernate.type.SqlTypes; 8 | import org.hibernate.type.descriptor.jdbc.AggregateJdbcType; 9 | import org.hibernate.type.descriptor.jdbc.JsonJdbcType; 10 | 11 | /** 12 | * custom type for crate json 13 | * 14 | * @author mackerl 15 | */ 16 | public class CrateDBJsonJdbcType extends JsonJdbcType { 17 | 18 | public static final CrateDBJsonJdbcType JSON_INSTANCE = new CrateDBJsonJdbcType(null); 19 | 20 | public CrateDBJsonJdbcType(EmbeddableMappingType embeddableMappingType) { 21 | super(embeddableMappingType); 22 | } 23 | 24 | @Override 25 | public int getDdlTypeCode() { 26 | return SqlTypes.JSON; 27 | } 28 | 29 | @Override 30 | public AggregateJdbcType resolveAggregateJdbcType(EmbeddableMappingType mappingType, 31 | String sqlType, 32 | RuntimeModelCreationContext creationContext) { 33 | return new CrateDBJsonJdbcType(mappingType); 34 | } 35 | 36 | @Override 37 | public void appendWriteExpression(String writeExpression, SqlAppender appender, Dialect dialect) { 38 | appender.append(writeExpression); 39 | } 40 | } -------------------------------------------------------------------------------- /application/records/example.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Using `records` with CrateDB: Basic usage. 4 | # 5 | # pip install --upgrade records sqlalchemy-cratedb 6 | # 7 | # A few basic operations using the `records` program with CrateDB. 8 | # 9 | # - https://pypi.org/project/records/ 10 | 11 | # Define database connection URL, suitable for CrateDB on localhost. 12 | # For CrateDB Cloud, use `crate://:@`. 13 | export DATABASE_URL="crate://" 14 | 15 | # Basic query, tabular output. 16 | records "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3" 17 | 18 | # Query with parameters. 19 | records "SELECT * FROM sys.summits WHERE region ILIKE :region" region="ortler%" 20 | 21 | # Export data. 22 | # Supported formats: csv tsv json yaml html xls xlsx dbf latex ods 23 | records "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3" csv 24 | records "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3" json 25 | records "SELECT * FROM sys.summits LIMIT 42" html > "${TMPDIR}/sys_summits.html" 26 | records "SELECT * FROM sys.summits LIMIT 42" ods > "${TMPDIR}/sys_summits.ods" 27 | records "SELECT * FROM sys.summits LIMIT 42" xlsx > "${TMPDIR}/sys_summits.xlsx" 28 | 29 | # Insert data. 30 | records "DROP TABLE IF EXISTS testdrive.example" 31 | records "CREATE TABLE testdrive.example (data OBJECT(DYNAMIC))" 32 | records "INSERT INTO testdrive.example (data) VALUES (:data)" data='{"temperature": 42.42, "humidity": 84.84}' 33 | records "REFRESH TABLE testdrive.example" 34 | records "SELECT * FROM testdrive.example" 35 | -------------------------------------------------------------------------------- /.github/workflows/ml-open-webui.yml: -------------------------------------------------------------------------------- 1 | name: "Open WebUI" 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/ml-open-webui.yml' 7 | - 'topic/machine-learning/open-webui/**' 8 | push: 9 | branches: [ main ] 10 | paths: 11 | - '.github/workflows/ml-open-webui.yml' 12 | - 'topic/machine-learning/open-webui/**' 13 | 14 | # Allow job to be triggered manually. 15 | workflow_dispatch: 16 | 17 | # Run job each night after CrateDB nightly has been published. 18 | #schedule: 19 | # - cron: '0 3 * * *' 20 | 21 | # Cancel in-progress jobs when pushing to the same branch. 22 | concurrency: 23 | cancel-in-progress: true 24 | group: ${{ github.workflow }}-${{ github.ref }} 25 | 26 | jobs: 27 | 28 | test: 29 | runs-on: ${{ matrix.os }} 30 | 31 | strategy: 32 | fail-fast: true 33 | matrix: 34 | os: [ "ubuntu-latest" ] 35 | 36 | name: OS ${{ matrix.os }} 37 | 38 | env: 39 | OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} 40 | 41 | steps: 42 | 43 | - name: Acquire sources 44 | uses: actions/checkout@v6 45 | 46 | - name: Validate topic/machine-learning/open-webui 47 | run: | 48 | # TODO: Generalize invocation into `ngr` test runner. 49 | 50 | # Invoke software stack. 51 | cd topic/machine-learning/open-webui 52 | docker compose up --detach 53 | 54 | # Invoke validation payload. 55 | # TODO: Currently does not work on GHA. 56 | # docker compose run --rm test 57 | -------------------------------------------------------------------------------- /by-language/r/basic_rpostgres.r: -------------------------------------------------------------------------------- 1 | # Install driver on demand. 2 | # RPostgres: C++ Interface to PostgreSQL 3 | # https://cran.r-project.org/web/packages/RPostgres/ 4 | 5 | # Optionally install the PostgreSQL library. 6 | if (!requireNamespace("RPostgres", quietly = TRUE)) { 7 | install.packages("RPostgres", repos="https://cran.r-project.org") 8 | } 9 | 10 | # Load the DBI and PostgreSQL libraries. 11 | library(DBI) 12 | library(RPostgres) 13 | drv <- Postgres() 14 | 15 | # Open a database connection, where `dbname` is the name of the CrateDB schema. 16 | conn <- dbConnect(drv, 17 | host = "localhost", 18 | port = 5432, 19 | sslmode = "disable", 20 | user = "crate", 21 | password = "crate", 22 | dbname = "doc", 23 | ) 24 | on.exit(DBI::dbDisconnect(conn), add = TRUE) 25 | 26 | # Invoke a basic select query. 27 | res <- dbGetQuery(conn, "SELECT mountain, region, height FROM sys.summits ORDER BY height DESC LIMIT 10;") 28 | print(res) 29 | 30 | # Delete testdrive table when needed. 31 | if (dbExistsTable(conn, "r")) { 32 | dbRemoveTable(conn, "r") 33 | } 34 | 35 | # Basic I/O. 36 | res <- dbSendQuery(conn, "CREATE TABLE r (id INT PRIMARY KEY, data TEXT);") 37 | dbClearResult(res) 38 | res <- dbSendQuery(conn, "INSERT INTO r (id, data) VALUES (42, 'foobar');") 39 | dbClearResult(res) 40 | res <- dbSendQuery(conn, "REFRESH TABLE r;") 41 | dbClearResult(res) 42 | res <- dbGetQuery(conn, "SELECT * FROM r;") 43 | print(res) 44 | -------------------------------------------------------------------------------- /testing/testcontainers/java/src/test/java/io/crate/example/testing/TestManual.java: -------------------------------------------------------------------------------- 1 | package io.crate.example.testing; 2 | 3 | import io.crate.example.testing.utils.TestingHelpers; 4 | import org.junit.Test; 5 | import org.testcontainers.cratedb.CrateDBContainer; 6 | import org.testcontainers.utility.DockerImageName; 7 | 8 | import java.io.IOException; 9 | import java.sql.SQLException; 10 | 11 | import static io.crate.example.testing.utils.TestingHelpers.assertResults; 12 | 13 | 14 | /** 15 | * Function-scoped testcontainer instance with manual setup/teardown. 16 | * 17 | */ 18 | public class TestManual { 19 | 20 | @Test 21 | public void testReadSummits() throws SQLException, IOException { 22 | // Run CrateDB nightly. 23 | DockerImageName image = TestingHelpers.nameFromLabel("nightly"); 24 | try (CrateDBContainer cratedb = new CrateDBContainer(image)) { 25 | cratedb.start(); 26 | 27 | // Get JDBC URL to CrateDB instance. 28 | String connectionUrl = cratedb.getJdbcUrl(); 29 | System.out.printf("Connecting to %s%n", connectionUrl); 30 | 31 | // Invoke example test. 32 | Application app = new Application(connectionUrl); 33 | var results = app.querySummitsTable(); 34 | assertResults(results); 35 | 36 | // Tear down CrateDB. 37 | cratedb.stop(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/src/main/java/io/crate/MyApplication.java: -------------------------------------------------------------------------------- 1 | package io.crate; 2 | 3 | import java.util.List; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.fasterxml.jackson.databind.ObjectMapper; 9 | 10 | import io.quarkus.arc.Unremovable; 11 | import io.quarkus.runtime.Quarkus; 12 | import io.quarkus.runtime.ShutdownEvent; 13 | import io.quarkus.runtime.StartupEvent; 14 | import jakarta.enterprise.context.ApplicationScoped; 15 | import jakarta.enterprise.event.Observes; 16 | import jakarta.enterprise.inject.Produces; 17 | 18 | @ApplicationScoped 19 | public class MyApplication { 20 | private static final Logger log = LoggerFactory.getLogger(MyApplication.class); 21 | 22 | void onStart(@Observes StartupEvent event) { 23 | log.info("starting the crate demo application."); 24 | 25 | MyEntity.populateWithData(1); 26 | 27 | List data = MyEntity.listAll(); 28 | 29 | log.info("Print populated data"); 30 | 31 | for (MyEntity entity : data) { 32 | log.info(entity.toString()); 33 | } 34 | } 35 | 36 | void onStop(@Observes ShutdownEvent event) { 37 | log.info("i have done my duty and may lay my head to rest."); 38 | } 39 | 40 | @Produces 41 | @Unremovable // Prevent quarkus from optimizing ObjectMapper away 42 | public ObjectMapper objectMapper() { 43 | return new ObjectMapper(); 44 | } 45 | 46 | public static void main(String[] args) { 47 | Quarkus.run(args); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /by-language/java-quarkus-panache/src/test/java/io/crate/test/CrateDBTestResource.java: -------------------------------------------------------------------------------- 1 | package io.crate.test; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.testcontainers.cratedb.CrateDBContainer; 7 | import org.testcontainers.utility.DockerImageName; 8 | 9 | import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; 10 | 11 | public class CrateDBTestResource implements QuarkusTestResourceLifecycleManager { 12 | 13 | private CrateDBContainer cratedb; 14 | 15 | @Override 16 | public Map start() { 17 | startContainer(); 18 | 19 | Map conf = new HashMap<>(); 20 | conf.put("quarkus.datasource.jdbc.url", cratedb.getJdbcUrl()); 21 | conf.put("quarkus.datasource.username", cratedb.getUsername()); 22 | conf.put("quarkus.datasource.password", cratedb.getPassword()); 23 | conf.put("quarkus.datasource.db-kind", "postgresql"); 24 | conf.put("quarkus.hibernate-orm.dialect", "io.crate.CrateDbDialect"); 25 | return conf; 26 | } 27 | 28 | @Override 29 | public void stop() { 30 | cratedb.stop(); 31 | } 32 | 33 | private void startContainer() { 34 | // Run CrateDB latest. 35 | DockerImageName image = dockerImageLatest(); 36 | cratedb = new CrateDBContainer(image); 37 | cratedb.start(); 38 | } 39 | 40 | public static DockerImageName dockerImageLatest() { 41 | return DockerImageName.parse("crate:latest").asCompatibleSubstituteFor("crate"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /application/metabase/docker-compose.yml: -------------------------------------------------------------------------------- 1 | networks: 2 | metanet-demo: 3 | driver: bridge 4 | 5 | services: 6 | 7 | # Metabase 8 | # https://www.metabase.com/docs/latest/installation-and-operation/running-metabase-on-docker#example-docker-compose-yaml-file 9 | metabase: 10 | image: metabase/metabase:v0.48.3 11 | container_name: metabase 12 | hostname: metabase 13 | volumes: 14 | - /dev/urandom:/dev/random:ro 15 | ports: 16 | - 3000:3000 17 | networks: 18 | - metanet-demo 19 | healthcheck: 20 | test: curl --fail -I http://localhost:3000/api/health || exit 1 21 | interval: 15s 22 | timeout: 5s 23 | retries: 5 24 | 25 | # CrateDB 26 | # https://github.com/crate/crate 27 | cratedb: 28 | image: crate/crate:nightly 29 | container_name: cratedb 30 | hostname: cratedb 31 | ports: 32 | - 4200:4200 33 | - 5432:5432 34 | networks: 35 | - metanet-demo 36 | healthcheck: 37 | # https://github.com/crate/docker-crate/pull/151/files 38 | test: curl --max-time 25 http://localhost:4200 || exit 1 39 | interval: 30s 40 | timeout: 30s 41 | 42 | # Wait for all defined services to be fully available by probing their health 43 | # status, even when using `docker compose up --detach`. 44 | # https://marcopeg.com/2019/docker-compose-healthcheck/ 45 | wait: 46 | image: dadarek/wait-for-dependencies 47 | depends_on: 48 | metabase: 49 | condition: service_healthy 50 | cratedb: 51 | condition: service_healthy 52 | -------------------------------------------------------------------------------- /by-dataframe/polars/test.py: -------------------------------------------------------------------------------- 1 | import shlex 2 | import subprocess 3 | import pytest 4 | import sqlalchemy as sa 5 | 6 | 7 | DBURI = "crate://localhost:4200" 8 | 9 | 10 | def run(command: str): 11 | subprocess.check_call(shlex.split(command)) 12 | 13 | 14 | def test_read_pg(): 15 | cmd = "time python read_pg.py" 16 | run(cmd) 17 | 18 | 19 | def test_read_sqlalchemy(): 20 | cmd = "time python read_sqlalchemy.py" 21 | run(cmd) 22 | 23 | 24 | @pytest.mark.skip 25 | def test_write_adbc(reset_table): 26 | cmd = "time python write_adbc.py" 27 | run(cmd) 28 | assert get_table_cardinality() == 20 29 | 30 | 31 | def test_write_sqlalchemy(reset_table): 32 | cmd = "time python write_sqlalchemy.py" 33 | run(cmd) 34 | assert get_table_cardinality() == 20 35 | 36 | 37 | @pytest.fixture 38 | def reset_table(): 39 | """Drop database tables used for testing.""" 40 | engine = get_engine() 41 | with engine.connect() as conn: 42 | conn.exec_driver_sql("DROP TABLE IF EXISTS testdrive_polars;") 43 | 44 | 45 | def get_engine(): 46 | """Provide an SQLAlchemy `engine` instance.""" 47 | return sa.create_engine(DBURI) 48 | 49 | 50 | def get_table_cardinality(): 51 | """Get number of records in table used for testing.""" 52 | engine = get_engine() 53 | with engine.connect() as conn: 54 | conn.exec_driver_sql("REFRESH TABLE testdrive_polars;") 55 | result = conn.exec_driver_sql("SELECT COUNT(*) FROM testdrive_polars;") 56 | table_size = result.scalar_one() 57 | return table_size 58 | -------------------------------------------------------------------------------- /by-language/java-jooq/src/generated/java/io/crate/demo/jooq/model/DefaultSchema.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is generated by jOOQ. 3 | */ 4 | package io.crate.demo.jooq.model; 5 | 6 | 7 | import io.crate.demo.jooq.model.tables.Author; 8 | import io.crate.demo.jooq.model.tables.Book; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | import org.jooq.Catalog; 14 | import org.jooq.Table; 15 | import org.jooq.impl.SchemaImpl; 16 | 17 | 18 | /** 19 | * This class is generated by jOOQ. 20 | */ 21 | @SuppressWarnings({ "all", "unchecked", "rawtypes" }) 22 | public class DefaultSchema extends SchemaImpl { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | /** 27 | * The reference instance of 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> getTables() { 56 | return Arrays.asList( 57 | Author.AUTHOR, 58 | Book.BOOK 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /.github/workflows/operation-compose-ssl.yml: -------------------------------------------------------------------------------- 1 | name: "Compose: CrateDB with SSL" 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/operation-compose-ssl.yml' 7 | - 'operation/compose/ssl/**' 8 | - '/requirements.txt' 9 | push: 10 | branches: [ main ] 11 | paths: 12 | - '.github/workflows/operation-compose-ssl.yml' 13 | - 'operation/compose/ssl/**' 14 | - '/requirements.txt' 15 | 16 | # Allow job to be triggered manually. 17 | workflow_dispatch: 18 | 19 | # Run job each night after CrateDB nightly has been published. 20 | schedule: 21 | - cron: '0 3 * * *' 22 | 23 | # Cancel in-progress jobs when pushing to the same branch. 24 | concurrency: 25 | cancel-in-progress: true 26 | group: ${{ github.workflow }}-${{ github.ref }} 27 | 28 | jobs: 29 | test: 30 | name: " 31 | Python ${{ matrix.python-version }} 32 | on ${{ matrix.os }}" 33 | runs-on: ${{ matrix.os }} 34 | strategy: 35 | fail-fast: false 36 | matrix: 37 | os: [ 'ubuntu-latest' ] 38 | python-version: [ '3.13' ] 39 | 40 | env: 41 | UV_SYSTEM_PYTHON: true 42 | 43 | steps: 44 | 45 | - name: Acquire sources 46 | uses: actions/checkout@v6 47 | 48 | - name: Set up Python 49 | uses: actions/setup-python@v6 50 | with: 51 | python-version: ${{ matrix.python-version }} 52 | 53 | - name: Set up uv 54 | uses: astral-sh/setup-uv@v7 55 | 56 | - name: Validate operation/compose/ssl 57 | run: | 58 | cd operation/compose/ssl 59 | make test 60 | -------------------------------------------------------------------------------- /.github/workflows/lang-r.yml: -------------------------------------------------------------------------------- 1 | name: R 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/lang-r.yml' 7 | - 'by-language/r/**' 8 | - '/requirements.txt' 9 | push: 10 | branches: [ main ] 11 | paths: 12 | - '.github/workflows/lang-r.yml' 13 | - 'by-language/r/**' 14 | - '/requirements.txt' 15 | 16 | # Allow job to be triggered manually. 17 | workflow_dispatch: 18 | 19 | # Run job each night after CrateDB nightly has been published. 20 | schedule: 21 | - cron: '0 3 * * *' 22 | 23 | # Cancel in-progress jobs when pushing to the same branch. 24 | concurrency: 25 | cancel-in-progress: true 26 | group: ${{ github.workflow }}-${{ github.ref }} 27 | 28 | jobs: 29 | 30 | test: 31 | name: " 32 | CrateDB: ${{ matrix.cratedb-version }} 33 | on ${{ matrix.os }}" 34 | runs-on: ${{ matrix.os }} 35 | strategy: 36 | fail-fast: false 37 | matrix: 38 | os: [ 'ubuntu-latest' ] 39 | cratedb-version: [ 'nightly' ] 40 | 41 | services: 42 | cratedb: 43 | image: crate/crate:${{ matrix.cratedb-version }} 44 | ports: 45 | - 4200:4200 46 | - 5432:5432 47 | env: 48 | CRATE_HEAP_SIZE: 4g 49 | 50 | steps: 51 | 52 | - name: Acquire sources 53 | uses: actions/checkout@v6 54 | 55 | - name: Set up uv 56 | uses: astral-sh/setup-uv@v7 57 | 58 | - name: Install R 59 | uses: r-lib/actions/setup-r@v2 60 | 61 | - name: Validate by-language/r 62 | run: | 63 | uv run --with=pueblo ngr test by-language/r 64 | -------------------------------------------------------------------------------- /.github/workflows/lang-rust-postgres.yml: -------------------------------------------------------------------------------- 1 | name: Rust Postgres 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/lang-rust-postgres.yml' 7 | - 'by-language/rust-postgres/**' 8 | - '/requirements.txt' 9 | push: 10 | branches: [ main ] 11 | paths: 12 | - '.github/workflows/lang-rust-postgres.yml' 13 | - 'by-language/rust-postgres/**' 14 | - '/requirements.txt' 15 | 16 | # Allow job to be triggered manually. 17 | workflow_dispatch: 18 | 19 | # Run job each night after CrateDB nightly has been published. 20 | schedule: 21 | - cron: '0 3 * * *' 22 | 23 | # Cancel in-progress jobs when pushing to the same branch. 24 | concurrency: 25 | cancel-in-progress: true 26 | group: ${{ github.workflow }}-${{ github.ref }} 27 | 28 | jobs: 29 | 30 | test: 31 | name: " 32 | CrateDB: ${{ matrix.cratedb-version }} 33 | on ${{ matrix.os }}" 34 | runs-on: ${{ matrix.os }} 35 | strategy: 36 | fail-fast: false 37 | matrix: 38 | os: [ 'ubuntu-latest' ] 39 | cratedb-version: [ 'nightly' ] 40 | 41 | services: 42 | cratedb: 43 | image: crate/crate:${{ matrix.cratedb-version }} 44 | ports: 45 | - 4200:4200 46 | - 5432:5432 47 | env: 48 | CRATE_HEAP_SIZE: 4g 49 | 50 | steps: 51 | 52 | - name: Acquire sources 53 | uses: actions/checkout@v6 54 | 55 | - name: Set up uv 56 | uses: astral-sh/setup-uv@v7 57 | 58 | - name: Validate by-language/rust-postgres 59 | run: | 60 | uv run --with=pueblo ngr test by-language/rust-postgres 61 | -------------------------------------------------------------------------------- /by-language/go-pgx/bulk_operations.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "math/rand" 8 | "os" 9 | "strconv" 10 | 11 | "github.com/jackc/pgx/v5" 12 | ) 13 | 14 | func submitDdl(ctx context.Context, conn *pgx.Conn, ddl string) error { 15 | 16 | sql, err := os.ReadFile("setup.sql") 17 | if err != nil { 18 | log.Fatal(err) 19 | } 20 | 21 | commandTag, err := conn.Exec(ctx, string(sql)) 22 | if err != nil { 23 | log.Fatal(err) 24 | } 25 | fmt.Println(commandTag) 26 | return nil 27 | } 28 | 29 | func runBulkOperations(connStr string) { 30 | 31 | fmt.Println("# runBulkOperations") 32 | 33 | num_batches := 20 34 | batch_size := 500 35 | 36 | ctx := context.Background() 37 | conn, err := pgx.Connect(ctx, connStr) 38 | if err != nil { 39 | log.Fatal(err) 40 | } 41 | 42 | err = submitDdl(ctx, conn, "foo") 43 | if err != nil { 44 | log.Fatal(err) 45 | } 46 | 47 | _, err = conn.Prepare(ctx, "ps1", "INSERT INTO go_users (id, name, value) VALUES ($1, $2, $3)") 48 | if err != nil { 49 | log.Fatal(err) 50 | } 51 | 52 | for b := 0; b < num_batches; b++ { 53 | fmt.Println("batch " + strconv.Itoa(b)) 54 | 55 | batch := &pgx.Batch{} 56 | for x := 0; x < batch_size; x++ { 57 | id := b*x + x 58 | username := "user_" + strconv.Itoa(b) + "_" + strconv.Itoa(x) 59 | batch.Queue("ps1", id, username, rand.Float32()) 60 | } 61 | 62 | br := conn.SendBatch(ctx, batch) 63 | _, err := br.Exec() 64 | if err != nil { 65 | log.Fatal(err) 66 | } 67 | err = br.Close() 68 | if err != nil { 69 | log.Fatal(err) 70 | } 71 | } 72 | 73 | fmt.Println() 74 | 75 | } 76 | -------------------------------------------------------------------------------- /application/records/README.md: -------------------------------------------------------------------------------- 1 | # Verify the `records` program with CrateDB 2 | 3 | Records: SQL for Humans™ 4 | 5 | ## About 6 | 7 | This folder includes software integration tests for verifying 8 | that the [Records] Python program works well together with [CrateDB]. 9 | 10 | Records is a very simple, but powerful, library for making raw SQL 11 | queries to most relational databases. It uses [SQLAlchemy]. 12 | 13 | Records is intended for report-style exports of database queries, and 14 | has not yet been optimized for extremely large data dumps. 15 | 16 | ## What's Inside 17 | 18 | - `example.sh`: A few examples that read CrateDB's `sys.summits` table 19 | using the `records` program. A single example that inserts data into 20 | a column using CrateDB's `OBJECT` column. 21 | 22 | ## Install 23 | 24 | Set up sandbox and install packages. 25 | ```bash 26 | pip install uv 27 | uv venv .venv 28 | source .venv/bin/activate 29 | uv pip install -r requirements.txt 30 | ``` 31 | 32 | ## Synopsis 33 | Install packages. 34 | ```shell 35 | pip install --upgrade records sqlalchemy-cratedb 36 | ``` 37 | Define database connection URL, suitable for CrateDB on localhost. 38 | For CrateDB Cloud, use `crate://:@`. 39 | ```shell 40 | export DATABASE_URL="crate://" 41 | ``` 42 | Invoke query. 43 | ```shell 44 | records "SELECT * FROM sys.summits WHERE region ILIKE :region" region="ortler%" 45 | ``` 46 | 47 | ## Tests 48 | 49 | Run integration tests. 50 | ```bash 51 | sh test.sh 52 | ``` 53 | 54 | 55 | [CrateDB]: https://cratedb.com/database 56 | [Records]: https://pypi.org/project/records/ 57 | [SQLAlchemy]: https://www.sqlalchemy.org/ 58 | -------------------------------------------------------------------------------- /.github/workflows/ml-llm.yml: -------------------------------------------------------------------------------- 1 | name: "llm" 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/ml-llm.yml' 7 | - 'topic/machine-learning/llm/**' 8 | push: 9 | branches: [ main ] 10 | paths: 11 | - '.github/workflows/ml-llm.yml' 12 | - 'topic/machine-learning/llm/**' 13 | 14 | # Allow job to be triggered manually. 15 | workflow_dispatch: 16 | 17 | # Run job each night after CrateDB nightly has been published. 18 | # schedule: 19 | # - cron: '0 3 * * *' 20 | 21 | # Cancel in-progress jobs when pushing to the same branch. 22 | concurrency: 23 | cancel-in-progress: true 24 | group: ${{ github.workflow }}-${{ github.ref }} 25 | 26 | jobs: 27 | 28 | test: 29 | runs-on: ${{ matrix.os }} 30 | 31 | strategy: 32 | fail-fast: true 33 | matrix: 34 | os: [ "ubuntu-latest" ] 35 | 36 | env: 37 | ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} 38 | OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} 39 | UV_SYSTEM_PYTHON: 1 40 | UV_BREAK_SYSTEM_PACKAGES: 1 41 | 42 | name: OS ${{ matrix.os }} 43 | steps: 44 | 45 | - name: Acquire sources 46 | uses: actions/checkout@v6 47 | 48 | - name: Set up Python 49 | uses: actions/setup-python@v6 50 | with: 51 | python-version: "3.13" 52 | 53 | - name: Install uv 54 | uses: astral-sh/setup-uv@v7 55 | 56 | - name: Validate topic/machine-learning/llm 57 | run: | 58 | # TODO: Generalize invocation into `ngr` test runner. 59 | cd topic/machine-learning/llm 60 | uv pip install -r requirements.txt 61 | uvx xonsh test.xsh 62 | -------------------------------------------------------------------------------- /testing/testcontainers/java/src/test/java/io/crate/example/testing/TestClassScope.java: -------------------------------------------------------------------------------- 1 | package io.crate.example.testing; 2 | 3 | import io.crate.example.testing.utils.TestingHelpers; 4 | import org.junit.jupiter.api.Test; 5 | import org.testcontainers.cratedb.CrateDBContainer; 6 | import org.testcontainers.junit.jupiter.Container; 7 | import org.testcontainers.junit.jupiter.Testcontainers; 8 | 9 | import java.io.IOException; 10 | import java.sql.SQLException; 11 | 12 | import static io.crate.example.testing.utils.TestingHelpers.assertResults; 13 | 14 | 15 | /** 16 | * Class-scoped testcontainer instance with JUnit 5. 17 | *

18 | * The extension finds all fields that are annotated with @Container and calls their container 19 | * lifecycle methods (methods on the Startable interface). 20 | * Containers declared as static fields will be shared between test methods. 21 | *

22 | *

23 | * 24 | *

25 | */ 26 | @Testcontainers 27 | public class TestClassScope { 28 | 29 | @Container 30 | public static CrateDBContainer cratedb = new CrateDBContainer(TestingHelpers.nameFromLabel("5.10")); 31 | 32 | @Test 33 | public void testReadSummits() throws SQLException, IOException { 34 | 35 | // Get JDBC URL to CrateDB instance. 36 | String connectionUrl = cratedb.getJdbcUrl(); 37 | System.out.printf("Connecting to %s%n", connectionUrl); 38 | 39 | // Invoke example test. 40 | Application app = new Application(connectionUrl); 41 | var results = app.querySummitsTable(); 42 | assertResults(results); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /by-language/java-jooq/src/generated/java/io/crate/demo/jooq/model/DefaultCatalog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is generated by jOOQ. 3 | */ 4 | package io.crate.demo.jooq.model; 5 | 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import org.jooq.Constants; 11 | import org.jooq.Schema; 12 | import org.jooq.impl.CatalogImpl; 13 | 14 | 15 | /** 16 | * This class is generated by jOOQ. 17 | */ 18 | @SuppressWarnings({ "all", "unchecked", "rawtypes" }) 19 | public class DefaultCatalog extends CatalogImpl { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | /** 24 | * The reference instance of DEFAULT_CATALOG 25 | */ 26 | public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog(); 27 | 28 | /** 29 | * The schema DEFAULT_SCHEMA. 30 | */ 31 | public final DefaultSchema DEFAULT_SCHEMA = DefaultSchema.DEFAULT_SCHEMA; 32 | 33 | /** 34 | * No further instances allowed 35 | */ 36 | private DefaultCatalog() { 37 | super(""); 38 | } 39 | 40 | @Override 41 | public final List getSchemas() { 42 | return Arrays.asList( 43 | DefaultSchema.DEFAULT_SCHEMA 44 | ); 45 | } 46 | 47 | /** 48 | * A reference to the 3.17 minor release of the code generator. If this 49 | * doesn't compile, it's because the runtime library uses an older minor 50 | * release, namely: 3.17. You can turn off the generation of this reference 51 | * by specifying /configuration/generator/generate/jooqVersionReference 52 | */ 53 | private static final String REQUIRE_RUNTIME_JOOQ_VERSION = Constants.VERSION_3_17; 54 | } 55 | --------------------------------------------------------------------------------