velocity-python 0.0.67__py3-none-any.whl → 0.0.68__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
velocity/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = version = "0.0.67"
1
+ __version__ = version = "0.0.68"
2
2
 
3
3
  from . import aws
4
4
  from . import db
@@ -143,47 +143,56 @@ class TableHelper:
143
143
  """
144
144
  Extracts the 'bare' column name from a SQL expression.
145
145
 
146
- This version intelligently detects window functions like ROW_NUMBER() OVER(ORDER BY x)
147
- and returns the actual column used inside ORDER BY.
146
+ Supports:
147
+ - Aliases (AS ...)
148
+ - Window functions (OVER(... ORDER BY ...))
149
+ - CAST(... AS ...)
150
+ - CASE WHEN ... THEN ... ELSE ... END
151
+ - Nested function calls
152
+ - Grabs column from inside expressions (e.g. PLAID_ERROR from SUM(CASE...))
148
153
 
149
154
  Args:
150
- sql_expression (str): Complex SQL expression (may include OVER, CAST, CASE, etc.)
155
+ sql_expression (str): SQL expression (SELECT column) string.
151
156
 
152
157
  Returns:
153
- str or None: Inferred base column name, like "amount", "a.email", or "*"
158
+ str or None: Extracted column name or None if undetectable.
154
159
  """
155
- import re
156
-
157
160
  expr = sql_expression.replace('"', "").strip()
158
161
 
159
- # Step 1: Remove alias
162
+ # Remove trailing alias
160
163
  expr = re.sub(r"(?i)\s+as\s+\w+$", "", expr).strip()
161
164
 
162
- # Step 2: Pull column from ORDER BY inside OVER()
163
- over_match = re.search(r"(?i)OVER\s*\(\s*ORDER\s+BY\s+([^)\s]+)", expr)
165
+ # If OVER clause: extract column inside ORDER BY
166
+ over_match = re.search(r"(?i)OVER\s*\(\s*ORDER\s+BY\s+([^\s,)]+)", expr)
164
167
  if over_match:
165
- column = over_match.group(1).strip(",")
166
- return column
167
-
168
- # Step 3: Strip CAST(x AS type)
169
- expr = re.sub(r"(?i)CAST\s*\((.*?)\s+AS\s+[^\)]+\)", r"\1", expr)
170
-
171
- # Step 4: Strip CASE WHEN ... THEN ... ELSE ... END
172
- expr = re.sub(
173
- r"(?i)CASE\s+WHEN\s+(.*?)\s+THEN\s+.*?\s+(ELSE\s+.*?)?END", r"\1", expr
174
- )
168
+ return over_match.group(1)
169
+
170
+ # Remove CAST(... AS ...)
171
+ while re.search(r"(?i)CAST\s*\(([^()]+?)\s+AS\s+[^\)]+\)", expr):
172
+ expr = re.sub(r"(?i)CAST\s*\(([^()]+?)\s+AS\s+[^\)]+\)", r"\1", expr)
173
+
174
+ # Remove CASE WHEN ... THEN ... ELSE ... END, keep just the WHEN part
175
+ while re.search(
176
+ r"(?i)CASE\s+WHEN\s+(.+?)\s+THEN\s+.+?(?:\s+ELSE\s+.+?)?\s+END", expr
177
+ ):
178
+ expr = re.sub(
179
+ r"(?i)CASE\s+WHEN\s+(.+?)\s+THEN\s+.+?(?:\s+ELSE\s+.+?)?\s+END",
180
+ r"\1",
181
+ expr,
182
+ )
175
183
 
176
- # Step 5: Remove nested function calls
177
- while re.search(r"\b\w+\s*\([^()]*\)", expr):
178
- expr = re.sub(r"\b\w+\s*\(([^()]*)\)", r"\1", expr)
184
+ # Unwrap function calls (SUM(...), MAX(...), etc.)
185
+ while re.search(r"\b\w+\s*\(([^()]+)\)", expr):
186
+ expr = re.sub(r"\b\w+\s*\(([^()]+)\)", r"\1", expr)
179
187
 
180
- # Step 6: Keep only first expression if comma-separated
188
+ # If multiple columns, take the first
181
189
  if "," in expr:
182
190
  expr = expr.split(",")[0].strip()
183
191
 
184
- # Step 7: Match column-like patterns
185
- pattern = r"^([a-zA-Z_][\w]*\.\*|\*|[a-zA-Z_][\w]*(?:\.[a-zA-Z_][\w]*)?)$"
186
- match = re.search(pattern, expr)
192
+ # Extract column name (basic or dotted like table.col or *)
193
+ match = re.search(
194
+ r"\b([a-zA-Z_][\w]*\.\*|\*|[a-zA-Z_][\w]*(?:\.[a-zA-Z_][\w]*)?)\b", expr
195
+ )
187
196
  return match.group(1) if match else None
188
197
 
189
198
  def are_parentheses_balanced(self, expression):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: velocity-python
3
- Version: 0.0.67
3
+ Version: 0.0.68
4
4
  Summary: A rapid application development library for interfacing with data storage
5
5
  Author-email: Paul Perez <pperez@codeclubs.org>
6
6
  Project-URL: Homepage, https://codeclubs.org/projects/velocity
@@ -1,4 +1,4 @@
1
- velocity/__init__.py,sha256=sWlnhF2G6SCos7NBlC2zOtN-FNPGuLbB3yeepfiHMtY,88
1
+ velocity/__init__.py,sha256=RG-xG6jwuUUVOz7GYfyRuXiVYUh4Tkvg0MRxwhH8HZ8,88
2
2
  velocity/aws/__init__.py,sha256=GBTEr02whnCH3TG-BWCpUC3KfHY3uNxD21g0OvsVJnc,598
3
3
  velocity/aws/handlers/__init__.py,sha256=xnpFZJVlC2uoeeFW4zuPST8wA8ajaQDky5Y6iXZzi3A,172
4
4
  velocity/aws/handlers/context.py,sha256=UIjNR83y2NSIyK8HMPX8t5tpJHFNabiZvNgmmdQL3HA,1822
@@ -24,7 +24,7 @@ velocity/db/servers/sqlite.py,sha256=X210a5pENT9PiVK7f16fxXzFwEsq8fSe58Vouv2xqlk
24
24
  velocity/db/servers/sqlite_reserved.py,sha256=-xmjl-Hgu6lKqkCAXq_6U8_aJX6gvaMgLMLdCt-Ej7o,3006
25
25
  velocity/db/servers/sqlserver.py,sha256=0uGLEWRXiUhrOVTpEA1zvaKq1mcfiaCDp9r7gX-N71g,29914
26
26
  velocity/db/servers/sqlserver_reserved.py,sha256=3LGQYU0qfvk6AbKety96gbzzfLbZ0dNHDPLxKGvvi4Q,4596
27
- velocity/db/servers/tablehelper.py,sha256=-sb9RAj8OUZTuoNQehc1ALxowk11gb3IUCxdaT6Aua4,10735
27
+ velocity/db/servers/tablehelper.py,sha256=Z6fpzewuCmrZ98Lk5OKu_nhpBpeX_OLnSCyqr1KdxRk,11054
28
28
  velocity/db/servers/postgres/__init__.py,sha256=SRqTRrhHkueEzGScG82KVveXC9mfNm6t4XylSCObkXQ,546
29
29
  velocity/db/servers/postgres/operators.py,sha256=A2T1qFwhzPl0fdXVhLZJhh5Qfx-qF8oZsDnxnq2n_V8,389
30
30
  velocity/db/servers/postgres/reserved.py,sha256=5tKLaqFV-HrWRj-nsrxl5KGbmeM3ukn_bPZK36XEu8M,3648
@@ -41,8 +41,8 @@ velocity/misc/tools.py,sha256=_bGneHHA_BV-kUonzw5H3hdJ5AOJRCKfzhgpkFbGqIo,1502
41
41
  velocity/misc/conv/__init__.py,sha256=MLYF58QHjzfDSxb1rdnmLnuEQCa3gnhzzZ30CwZVvQo,40
42
42
  velocity/misc/conv/iconv.py,sha256=d4_BucW8HTIkGNurJ7GWrtuptqUf-9t79ObzjJ5N76U,10603
43
43
  velocity/misc/conv/oconv.py,sha256=h5Lo05DqOQnxoD3y6Px_MQP_V-pBbWf8Hkgkb9Xp1jk,6032
44
- velocity_python-0.0.67.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
45
- velocity_python-0.0.67.dist-info/METADATA,sha256=7BQY5psmqQwrVwTGLl3pI2D_mPmcsqZFT9yd-zvpV5k,8541
46
- velocity_python-0.0.67.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
47
- velocity_python-0.0.67.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
48
- velocity_python-0.0.67.dist-info/RECORD,,
44
+ velocity_python-0.0.68.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
45
+ velocity_python-0.0.68.dist-info/METADATA,sha256=hZEB2oLJnPxM4jt42JBv2XVAIDqDY7TZnYEguFQi_DU,8541
46
+ velocity_python-0.0.68.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
47
+ velocity_python-0.0.68.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
48
+ velocity_python-0.0.68.dist-info/RECORD,,