Skip to content

Commit 075f17c

Browse files
authored
Merge pull request #3 from dlt-hub/feat/replace-decimal-by-float
replace Decimal by float
2 parents 8752108 + 1f3aae2 commit 075f17c

4 files changed

Lines changed: 782 additions & 598 deletions

File tree

app/models.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Optional, List
66

77
from pydantic import BaseModel
8-
from decimal import Decimal
98
from datetime import datetime
109

1110

@@ -21,7 +20,7 @@ class Customer(BaseModel):
2120
class Supply(BaseModel):
2221
id: str
2322
name: str
24-
cost: Decimal
23+
cost: float
2524
perishable: bool
2625
sku: str
2726

@@ -37,22 +36,22 @@ class Order(BaseModel):
3736
customer_id: str
3837
store_id: str
3938
ordered_at: datetime
40-
subtotal: Decimal
41-
tax_paid: Decimal
42-
order_total: Decimal
39+
subtotal: float
40+
tax_paid: float
41+
order_total: float
4342
items: Optional[List[Item]]
4443

4544

4645
class Product(BaseModel):
4746
sku: str
4847
name: str
4948
type: str
50-
price: Decimal
49+
price: float
5150
description: str
5251

5352

5453
class Store(BaseModel):
5554
id: str
5655
name: str
5756
opened_at: datetime
58-
tax_rate: Decimal
57+
tax_rate: float

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ dependencies = [
1515
dev = [
1616
"ruff>=0.11.2",
1717
"pytest>=8.3.5",
18-
"dlt==1.8.1",
18+
"dlt==1.17.1",
1919
"pyarrow>=16.0.0",
2020
]

tests/test_dlt_extraction.py

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from app.main import app
1414

1515
from dlt.sources.rest_api import rest_api_source
16-
from dlt.common.destination.dataset import SupportsReadableDataset
1716

1817
from tests.utils import EXPECTED_TABLES_COUNTS_JANUARY_2017
1918

@@ -31,9 +30,7 @@ def send(self, prepared_request, **kwargs):
3130
)
3231

3332

34-
def row_counts(
35-
dataset: SupportsReadableDataset, tables: list[str] = None
36-
) -> dict[str, int]:
33+
def row_counts(dataset: dlt.Dataset, tables: list[str] = None) -> dict[str, int]:
3734
counts = dataset.row_counts(table_names=tables).arrow().to_pydict()
3835
return {t: c for t, c in zip(counts["table_name"], counts["row_count"])}
3936

@@ -135,3 +132,113 @@ def test_live_jaffle_shop():
135132
"orders": 3303, # 3303 orders in january 2017
136133
"orders__items": 5072,
137134
}
135+
136+
137+
def test_expected_columns_schema():
138+
"""
139+
This tests extracts the full dataset with the dlt rest_api source
140+
"""
141+
source = rest_api_source(
142+
{
143+
"client": {
144+
"base_url": "http://localhost:8000/api/v1",
145+
"paginator": {
146+
"type": "header_link",
147+
},
148+
"session": FastAPISession(app),
149+
},
150+
"resources": [
151+
"customers",
152+
"products",
153+
"stores",
154+
"supplies",
155+
# orders includes items
156+
# we only load orders for january 2017
157+
{
158+
"name": "orders",
159+
"endpoint": {
160+
"path": "orders",
161+
"params": {
162+
"page_size": 1000,
163+
"start_date": "2017-01-01",
164+
"end_date": "2017-01-31",
165+
},
166+
},
167+
},
168+
],
169+
},
170+
)
171+
pipeline = dlt.pipeline(
172+
pipeline_name="rest_api_example",
173+
destination=duckdb(credentials="test.db"),
174+
dataset_name="rest_api_data",
175+
dev_mode=True,
176+
)
177+
pipeline.run(source)
178+
179+
expected_table_columns = {
180+
"customers": {
181+
"id": {"name": "id", "data_type": "text", "nullable": True},
182+
"name": {"name": "name", "data_type": "text", "nullable": True},
183+
},
184+
"products": {
185+
"sku": {"name": "sku", "data_type": "text", "nullable": True},
186+
"name": {"name": "name", "data_type": "text", "nullable": True},
187+
"type": {"name": "type", "data_type": "text", "nullable": True},
188+
"price": {"name": "price", "data_type": "double", "nullable": True},
189+
"description": {
190+
"name": "description",
191+
"data_type": "text",
192+
"nullable": True,
193+
},
194+
},
195+
"stores": {
196+
"id": {"name": "id", "data_type": "text", "nullable": True},
197+
"name": {"name": "name", "data_type": "text", "nullable": True},
198+
"opened_at": {
199+
"name": "opened_at",
200+
"data_type": "timestamp",
201+
"nullable": True,
202+
},
203+
"tax_rate": {"name": "tax_rate", "data_type": "double", "nullable": True},
204+
},
205+
"supplies": {
206+
"id": {"name": "id", "data_type": "text", "nullable": True},
207+
"name": {"name": "name", "data_type": "text", "nullable": True},
208+
"cost": {"name": "cost", "data_type": "double", "nullable": True},
209+
"perishable": {"name": "perishable", "data_type": "bool", "nullable": True},
210+
"sku": {"name": "sku", "data_type": "text", "nullable": True},
211+
},
212+
"orders": {
213+
"id": {"name": "id", "data_type": "text", "nullable": True},
214+
"customer_id": {
215+
"name": "customer_id",
216+
"data_type": "text",
217+
"nullable": True,
218+
},
219+
"store_id": {"name": "store_id", "data_type": "text", "nullable": True},
220+
"ordered_at": {
221+
"name": "ordered_at",
222+
"data_type": "timestamp",
223+
"nullable": True,
224+
},
225+
"subtotal": {"name": "subtotal", "data_type": "double", "nullable": True},
226+
"tax_paid": {"name": "tax_paid", "data_type": "double", "nullable": True},
227+
"order_total": {
228+
"name": "order_total",
229+
"data_type": "double",
230+
"nullable": True,
231+
},
232+
},
233+
"orders__items": {
234+
"id": {"name": "id", "data_type": "text", "nullable": True},
235+
"order_id": {"name": "order_id", "data_type": "text", "nullable": True},
236+
"sku": {"name": "sku", "data_type": "text", "nullable": True},
237+
},
238+
}
239+
240+
for expected_table_name, expected_columns in expected_table_columns.items():
241+
table = pipeline.default_schema.tables[expected_table_name]
242+
table_columns = table["columns"]
243+
for expected_col_name, expected_col in expected_columns.items():
244+
assert table_columns[expected_col_name] == expected_col

0 commit comments

Comments
 (0)