# EWAH to DLT Mapping Reference

## Concept Mapping

| EWAH Concept | dlt Equivalent |
|--------------|----------------|
| `extract_strategy: full_refresh` | `write_disposition: "replace"` |
| `extract_strategy: incremental` | `write_disposition: "merge"` + `incremental` |
| `extract_strategy: subsequent` | `write_disposition: "merge"` + `incremental` |
| `primary_key` | `primary_key` in resource config |
| `data_from` / `data_until` | `incremental` cursor in endpoint config |
| Airflow connection | dlt secrets (`dlt.secrets.value`) |
| Hook pagination | `paginator` in endpoint config |
| `get_cleaner_callables()` | `add_map()` transformer or inline processing |

## Pagination Mapping

### EWAH Cursor Pagination

```python
"paginator": {
    "type": "cursor",
    "cursor_path": "meta.next_cursor",
    "cursor_param": "cursor",
}
```

### EWAH Offset Pagination

```python
"paginator": {
    "type": "offset",
    "limit": 100,
    "offset_param": "start",
    "limit_param": "limit",
    "total_path": "meta.total",
}
```

### EWAH Link Header Pagination

```python
"paginator": "header_link"
```

## Incremental Loading Mapping

### EWAH

```python
# In operator
data_from = context["data_interval_start"]
data_until = context["data_interval_end"]
```

### dlt

```python
{
    "name": "orders",
    "endpoint": {
        "path": "v1/orders",
        "params": {
            "updated_since": "{incremental.start_value}",
        },
        "incremental": {
            "cursor_path": "updated_at",
            "initial_value": "2024-01-01T00:00:00Z",
        },
    },
    "primary_key": "id",
    "write_disposition": "merge",
}
```

## Authentication Mapping

### EWAH API Key

```python
# In hook
headers = {"Authorization": f"Bearer {self.api_token}"}
```

### dlt API Key

```python
"auth": {
    "type": "api_key",
    "name": "Authorization",
    "api_key": f"Bearer {api_token}",
    "location": "header",
}
```

### OAuth

For EWAH hooks with token refresh logic, use dlt's built-in OAuth2 support:

```python
from dlt.sources.helpers.rest_client.auth import OAuth2ClientCredentials
```

## Write Disposition Decision Tree

```
Is data immutable (e.g., events, logs)?
├── Yes → write_disposition: "append"
└── No → Can records be updated?
    ├── Yes → write_disposition: "merge" (requires primary_key)
    └── No → write_disposition: "replace"
```
