Skip to content

Commit 2157bc0

Browse files
Merge pull request #196 from trxvorr/feature/mariadb-adapter
feat: implement MariaDB adapter
2 parents 484040b + 8ff7929 commit 2157bc0

8 files changed

Lines changed: 722 additions & 1 deletion

File tree

docsite/docs/connectors/mariadb.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
# MariaDB
6+
7+
`intugle` integrates with MariaDB, allowing you to read data from your tables and views.
8+
9+
## Installation
10+
11+
To use `intugle` with MariaDB, you must install the optional dependencies:
12+
13+
```bash
14+
pip install "intugle[mariadb]"
15+
```
16+
17+
This installs the `mariadb` (MariaDB Connector/Python) and `sqlglot` libraries.
18+
19+
:::warning Linux Dependencies
20+
On Linux, the MariaDB Connector/Python requires the MariaDB C Connector dependencies to be installed on your system.
21+
For example, on Ubuntu/Debian:
22+
```bash
23+
sudo apt-get install libmariadb3 libmariadb-dev
24+
```
25+
On CentOS/RHEL:
26+
```bash
27+
sudo yum install mariadb-connector-c-devel
28+
```
29+
Please refer to the [MariaDB Connector/Python documentation](https://mariadb.com/docs/server/connect/programming-languages/python/install/#installing-mariadb-connector-python) for more details.
30+
:::
31+
32+
## Configuration
33+
34+
To connect to your MariaDB database, you must provide connection credentials in a `profiles.yml` file at the root of your project. The adapter looks for a top-level `mariadb:` key.
35+
36+
**Example `profiles.yml`:**
37+
38+
```yaml
39+
mariadb:
40+
host: <your_mariadb_host>
41+
port: 3306 # Default MariaDB port
42+
user: <your_username>
43+
password: <your_password>
44+
database: <your_database_name>
45+
```
46+
47+
## Usage
48+
49+
### Reading Data from MariaDB
50+
51+
To include a MariaDB table or view in your `SemanticModel`, define it in your input dictionary with `type: "mariadb"` and use the `identifier` key to specify the object name.
52+
53+
:::caution Important
54+
The dictionary key for your dataset (e.g., `"CUSTOMERS"`) must exactly match the table or view name specified in the `identifier`.
55+
:::
56+
57+
```python
58+
from intugle import SemanticModel
59+
60+
datasets = {
61+
"CUSTOMERS": {
62+
"identifier": "CUSTOMERS", # Must match the key above
63+
"type": "mariadb"
64+
},
65+
"ORDERS_VIEW": {
66+
"identifier": "ORDERS_VIEW", # Can be a view
67+
"type": "mariadb"
68+
}
69+
}
70+
71+
# Initialize the semantic model
72+
sm = SemanticModel(datasets, domain="E-commerce")
73+
74+
# Build the model as usual
75+
sm.build()
76+
```
77+
78+
### Materializing Data Products
79+
80+
When you use the `DataProduct` class with a MariaDB connection, the resulting data product can be materialized as a new **table** or **view** directly within your target database.
81+
82+
```python
83+
from intugle import DataProduct
84+
85+
etl_model = {
86+
"name": "top_customers",
87+
"fields": [
88+
{"id": "CUSTOMERS.customer_id", "name": "customer_id"},
89+
{"id": "CUSTOMERS.name", "name": "customer_name"},
90+
]
91+
}
92+
93+
dp = DataProduct()
94+
95+
# Materialize as a view (default)
96+
dp.build(etl_model, materialize="view")
97+
98+
# Materialize as a table
99+
dp.build(etl_model, materialize="table")
100+
```

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ mysql = [
7979
"sqlglot>=27.20.0",
8080
]
8181

82+
mariadb = [
83+
"mariadb>=1.1.10",
84+
"sqlglot>=27.20.0",
85+
]
86+
8287
oracle = [
8388
"oracledb>=2.0.0",
8489
"sqlglot>=27.20.0",

src/intugle/adapters/factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def is_safe_plugin_name(plugin_name: str) -> bool:
3333
"intugle.adapters.types.databricks.databricks",
3434
"intugle.adapters.types.postgres.postgres",
3535
"intugle.adapters.types.mysql.mysql",
36+
"intugle.adapters.types.mariadb.mariadb",
3637
"intugle.adapters.types.sqlserver.sqlserver",
3738
"intugle.adapters.types.sqlite.sqlite",
3839
"intugle.adapters.types.oracle.oracle",

src/intugle/adapters/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ def get_dataset_data_type() -> type:
2121

2222
from intugle.adapters.types.databricks.models import DatabricksConfig
2323
from intugle.adapters.types.duckdb.models import DuckdbConfig
24+
from intugle.adapters.types.mariadb.models import MariaDBConfig
2425
from intugle.adapters.types.oracle.models import OracleConfig
2526
from intugle.adapters.types.postgres.models import PostgresConfig
2627
from intugle.adapters.types.snowflake.models import SnowflakeConfig
2728
from intugle.adapters.types.sqlite.models import SqliteConfig
2829
from intugle.adapters.types.sqlserver.models import SQLServerConfig
2930

30-
DataSetData = pd.DataFrame | DuckdbConfig | SnowflakeConfig | DatabricksConfig | PostgresConfig | SQLServerConfig | SqliteConfig | OracleConfig
31+
DataSetData = pd.DataFrame | DuckdbConfig | SnowflakeConfig | DatabricksConfig | PostgresConfig | SQLServerConfig | SqliteConfig | OracleConfig | MariaDBConfig
3132
else:
3233
# At runtime, this is dynamically determined
3334
DataSetData = Any

src/intugle/adapters/types/mariadb/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)