|
| 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 | +``` |
0 commit comments