You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Extracting data from nested structures often leads to complex, error-prone code with multiple checks and conditionals. Consider this traditional approach:"
130
+
]
131
+
},
132
+
{
133
+
"cell_type": "code",
134
+
"execution_count": 14,
135
+
"id": "69ff114d",
128
136
"metadata": {},
137
+
"outputs": [],
129
138
"source": [
130
-
"Have you ever wanted to match complex data types and extract their information? \n",
139
+
"def get_youngest_pet(pet_info):\n",
140
+
" if isinstance(pet_info, list) and len(pet_info) == 2:\n",
"The code below uses structural pattern matching to extract ages from the matching data structure. "
221
+
"Python 3.10's pattern matching provides a more declarative and readable way to handle complex data structures, reducing the need for nested conditionals and type checks."
Copy file name to clipboardExpand all lines: Chapter5/SQL.ipynb
+113Lines changed: 113 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1023,6 +1023,119 @@
1023
1023
"source": [
1024
1024
"[Link to sql-metadata](https://github.com/macbre/sql-metadata)."
1025
1025
]
1026
+
},
1027
+
{
1028
+
"cell_type": "markdown",
1029
+
"id": "055e3474",
1030
+
"metadata": {},
1031
+
"source": [
1032
+
"### SQLGlot: Write Once, Run Anywhere SQL"
1033
+
]
1034
+
},
1035
+
{
1036
+
"cell_type": "code",
1037
+
"execution_count": null,
1038
+
"id": "8d257860",
1039
+
"metadata": {
1040
+
"tags": [
1041
+
"hide-cell"
1042
+
]
1043
+
},
1044
+
"outputs": [],
1045
+
"source": [
1046
+
"!pip install \"sqlglot[rs]\""
1047
+
]
1048
+
},
1049
+
{
1050
+
"cell_type": "markdown",
1051
+
"id": "49d7f225",
1052
+
"metadata": {},
1053
+
"source": [
1054
+
"SQL dialects vary across databases, making it challenging to port queries between different database systems.\n",
1055
+
"\n",
1056
+
"SQLGlot addresses this by providing a parser and transpiler supporting 21 dialects. This enables automatic SQL translation between systems, eliminating the need for manual query rewrites."
1057
+
]
1058
+
},
1059
+
{
1060
+
"cell_type": "code",
1061
+
"execution_count": 6,
1062
+
"id": "72644346",
1063
+
"metadata": {},
1064
+
"outputs": [],
1065
+
"source": [
1066
+
"import sqlglot"
1067
+
]
1068
+
},
1069
+
{
1070
+
"cell_type": "markdown",
1071
+
"id": "733ad01f",
1072
+
"metadata": {},
1073
+
"source": [
1074
+
"Convert a DuckDB-specific date formatting query into an equivalent query in Hive SQL:"
<h2><spanclass="section-number">2.10.2. </span>Structural Pattern Matching in Python 3.10<aclass="headerlink" href="#structural-pattern-matching-in-python-3-10" title="Permalink to this heading">#</a></h2>
590
-
<p>Have you ever wanted to match complex data types and extract their information?</p>
591
-
<p>Python 3.10 allows you to do exactly that with the <codeclass="docutils literal notranslate"><spanclass="pre">match</span></code> statement and the <codeclass="docutils literal notranslate"><spanclass="pre">case</span></code> statements.</p>
592
-
<p>The code below uses structural pattern matching to extract ages from the matching data structure.</p>
591
+
<p>Extracting data from nested structures often leads to complex, error-prone code with multiple checks and conditionals. Consider this traditional approach:</p>
<p>Python 3.10’s pattern matching provides a more declarative and readable way to handle complex data structures, reducing the need for nested conditionals and type checks.</p>
0 commit comments