Skip to content

Commit 647928b

Browse files
committed
📄 Add (database): DDL file for weather table in SQL
1 parent ed33f0f commit 647928b

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

‎assets/sql/ddl/weather.sql

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
CREATE TABLE weather (
2+
id SERIAL PRIMARY KEY,
3+
date DATE NOT NULL UNIQUE,
4+
min_temp FLOAT,
5+
max_temp FLOAT,
6+
rainfall FLOAT,
7+
humidity_9am INTEGER,
8+
humidity_3pm INTEGER,
9+
temp_9am FLOAT,
10+
temp_3pm FLOAT,
11+
current_temp FLOAT,
12+
current_humidity INTEGER,
13+
current_weather_description VARCHAR,
14+
created_by VARCHAR(50) NOT NULL DEFAULT current_user,
15+
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT current_timestamp,
16+
updated_by VARCHAR(50),
17+
updated_at TIMESTAMP WITH TIME ZONE,
18+
CONSTRAINT weather_date_check CHECK (date <= CURRENT_DATE),
19+
CONSTRAINT weather_min_max_temp_check CHECK (min_temp <= max_temp),
20+
CONSTRAINT weather_temp_9am_range_check CHECK (temp_9am BETWEEN -273.15 AND 100.0),
21+
CONSTRAINT weather_temp_3pm_range_check CHECK (temp_3pm BETWEEN -273.15 AND 100.0),
22+
CONSTRAINT weather_current_temp_range_check CHECK (current_temp BETWEEN -273.15 AND 100.0),
23+
CONSTRAINT weather_min_temp_range_check CHECK (min_temp BETWEEN -273.15 AND 100.0),
24+
CONSTRAINT weather_max_temp_range_check CHECK (max_temp BETWEEN -273.15 AND 100.0),
25+
CONSTRAINT weather_max_rainfall_check CHECK (rainfall <= 1000.0),
26+
CONSTRAINT weather_created_by_check CHECK (created_at <= CURRENT_TIMESTAMP),
27+
CONSTRAINT weather_updated_by_check CHECK (updated_at IS NULL OR updated_at <= CURRENT_TIMESTAMP)
28+
);
29+
30+
COMMENT ON TABLE weather IS 'Table storing weather data including historical and current weather details';
31+
COMMENT ON COLUMN weather.id IS 'ID of the table';
32+
COMMENT ON COLUMN weather.date IS 'Date for the record about the weather';
33+
COMMENT ON COLUMN weather.min_temp IS 'Minimum temperature of the day';
34+
COMMENT ON COLUMN weather.max_temp IS 'Maximum temperature of the day';
35+
COMMENT ON COLUMN weather.rainfall IS 'Rainfall in millimeters';
36+
COMMENT ON COLUMN weather.humidity_9am IS 'Humidity percentage at 9 AM';
37+
COMMENT ON COLUMN weather.humidity_3pm IS 'Humidity percentage at 3 PM';
38+
COMMENT ON COLUMN weather.temp_9am IS 'Temperature at 9 AM';
39+
COMMENT ON COLUMN weather.temp_3pm IS 'Temperature at 3 PM';
40+
COMMENT ON COLUMN weather.current_temp IS 'Current temperature from the API';
41+
COMMENT ON COLUMN weather.current_humidity IS 'Current humidity percentage from the API';
42+
COMMENT ON COLUMN weather.current_weather_description IS 'Current weather description from the API';
43+
COMMENT ON COLUMN weather.created_by IS 'User that created the record';
44+
COMMENT ON COLUMN weather.created_at IS 'Datetime when the record was created';
45+
COMMENT ON COLUMN weather.updated_by IS 'Last user that updated the record';
46+
COMMENT ON COLUMN weather.updated_at IS 'Last timestamp when the record was updated';

‎pipeline/engineering/transformation.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
from pipeline.core.decorators import benchmark, with_logging
6-
from pipeline.exceptions.exceptions import DataQualityException
76
from pipeline.models.weather import Weather
87
from pipeline.schemas.api.weather import APIWeather, CurrentWeather
98
from pipeline.schemas.files.weather import CSVWeather
@@ -22,14 +21,6 @@ def transform_data(csv_weather: CSVWeather, api_weather: APIWeather) -> Weather:
2221
:rtype: Weather
2322
"""
2423
current_weather: CurrentWeather = api_weather.current
25-
if not (
26-
csv_weather.min_temp <= current_weather.temp <= csv_weather.max_temp
27-
):
28-
raise DataQualityException(
29-
f"Current temperature {current_weather.temp} is outside the range"
30-
f" of min_temp {csv_weather.min_temp} and max_temp"
31-
f" {csv_weather.max_temp}"
32-
)
3324
weather: Weather = Weather(
3425
date=csv_weather.date,
3526
min_temp=csv_weather.min_temp,

0 commit comments

Comments
 (0)