Skip to content

Commit b455b02

Browse files
authored
Fixed date and date-time types convert rules (#4)
1 parent 43219e9 commit b455b02

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

pydantic_glue/handler.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def dispatch(v: dict[str, Any]) -> str:
1818
return handle_array(v)
1919

2020
if t == "string":
21+
if v.get("format") == "date-time":
22+
return "timestamp"
23+
if v.get("format") == "date":
24+
return "date"
2125
return "string"
2226

2327
if t == "boolean":

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "pydantic-glue"
33
keywords = ["pydantic", "glue", "athena", "types", "convert"]
4-
version = "0.2.1"
4+
version = "0.3.0"
55
description = "Convert pydantic model to aws glue schema for terraform"
66
authors = ["Serhii Dimchenko <[email protected]>"]
77
readme = "README.md"

tests/unit/test_convert.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import json
23
from typing import Optional, Union
34

@@ -33,6 +34,22 @@ class A(BaseModel):
3334
assert convert(json.dumps(A.model_json_schema())) == expected
3435

3536

37+
def test_single_date_column():
38+
class A(BaseModel):
39+
modifiedOn: datetime.date
40+
41+
expected = [("modifiedOn", "date")]
42+
assert convert(json.dumps(A.model_json_schema())) == expected
43+
44+
45+
def test_single_datetime_column():
46+
class A(BaseModel):
47+
modifiedOn: datetime.datetime
48+
49+
expected = [("modifiedOn", "timestamp")]
50+
assert convert(json.dumps(A.model_json_schema())) == expected
51+
52+
3653
def test_multiple_string_column():
3754
class A(BaseModel):
3855
hey: str

0 commit comments

Comments
 (0)