{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Defining your own ColumnMeta attributes\n", "\n", "In this notebook, we will see how to define your own `ColumnMeta` attributes. This is useful when you want to add some metadata to your columns that are not already defined in the `ColumnMeta` class." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': {'comment': 'Identifies the person', 'primary_key': True},\n", " 'name': {},\n", " 'age': {}}" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from dataclasses import dataclass\n", "from typing import Annotated\n", "from pyspark.sql.types import LongType, StringType\n", "from typedspark import ColumnMeta, Schema\n", "from typedspark._core.column import Column\n", "\n", "\n", "@dataclass\n", "class MyColumnMeta(ColumnMeta):\n", " primary_key: bool = False\n", "\n", "\n", "class Persons(Schema):\n", " id: Annotated[\n", " Column[LongType],\n", " MyColumnMeta(\n", " comment=\"Identifies the person\",\n", " primary_key=True,\n", " ),\n", " ]\n", " name: Column[StringType]\n", " age: Column[LongType]\n", "\n", "\n", "Persons.get_metadata()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "typedspark", "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.11.2" } }, "nbformat": 4, "nbformat_minor": 2 }