сделано ДЗ "значения по умолчанию"

This commit is contained in:
Dmitry Medvedev
2026-10-20 00:50:22 +05:00
parent 54bd4595ea
commit 71b3042b43
@@ -0,0 +1,189 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "669999d9",
"metadata": {},
"source": [
"Задача 1. Лог запуска процесса\n",
"Напиши функцию log_job_start, которая принимает:\n",
" job_name\n",
" level=\"INFO\"\n",
" env=\"dev\"\n",
"Функция должна выводить строку:\n",
" [INFO] Job load_users started in dev"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "2af8c0ea",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[INFO] Job load_users started in dev\n"
]
}
],
"source": [
"def log_job_start(job_name, level = \"INFO\", env = \"dev\"):\n",
" print(f\"[{level}] {job_name} load_users started in {env}\")\n",
"\n",
"log_job_start(\"Job\")"
]
},
{
"cell_type": "markdown",
"id": "60ce459d",
"metadata": {},
"source": [
"Задача 2. Подключение к источнику\n",
"Напиши функцию connect_source, которая принимает:\n",
" source_name\n",
" host=\"localhost\"\n",
" port=5432\n",
" user=\"etl_user\"\n",
"Функция должна возвращать словарь с настройками подключения."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d73d7ab5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'source_name': 'dwh', 'host': 'localhost', 'port': 5432, 'user': 'etl_user'} <class 'dict'>\n"
]
}
],
"source": [
"def connect_source(source_name, host = \"localhost\", port = 5432, user = \"etl_user\"):\n",
" connecting_configuration = {\n",
" \"source_name\" : source_name,\n",
" \"host\" : host,\n",
" \"port\" : port,\n",
" \"user\" : user\n",
" }\n",
" return connecting_configuration"
]
},
{
"cell_type": "markdown",
"id": "e667db79",
"metadata": {},
"source": [
"Задача 3. Построение SELECT-запроса\n",
"Напиши функцию build_select_query, которая принимает:\n",
" table_name\n",
" columns=None\n",
"Логика:\n",
" если columns=None, функция должна вернуть:\n",
" SELECT * FROM table_name\n",
" если список колонок передан, собрать их через запятую."
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "4b710ebe",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'SELECT id, user_id, email FROM orders'"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def build_select_query(table_name, columns = None):\n",
" if columns is None:\n",
" return f\"SELECT * FROM {table_name}\"\n",
" else:\n",
" columns_str = \", \".join(columns)\n",
" return f\"SELECT {columns_str} FROM {table_name}\"\n",
"\n",
"build_select_query(\"orders\")\n",
"build_select_query(\"orders\", [\"id\", \"user_id\", \"email\"])\n"
]
},
{
"cell_type": "markdown",
"id": "ba059bd5",
"metadata": {},
"source": [
"Задача 4. Проверка обязательных полей\n",
"Напиши функцию validate_row, которая принимает:\n",
" row — словарь;\n",
" required_fields=None\n",
"Логика:\n",
" если required_fields=None, использовать [\"id\"];\n",
" проверить, есть ли все нужные поля;\n",
" если какого-то поля нет, вернуть строку:\n",
" Missing field: email\n",
" если всё хорошо, вернуть:\n",
" Row is valid"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ceb7c30b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Row is valid'"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def validate_row(row, required_fields = None):\n",
" if required_fields is None:\n",
" required_fields = [\"id\"]\n",
" for field in required_fields:\n",
" if field not in required_fields:\n",
" return f\"Missing field: {field}\"\n",
" else:\n",
" return \"Row is valid\""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}