sqlframe 1.8.0__py3-none-any.whl → 1.10.0__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.
sqlframe/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.8.0'
16
- __version_tuple__ = version_tuple = (1, 8, 0)
15
+ __version__ = version = '1.10.0'
16
+ __version_tuple__ = version_tuple = (1, 10, 0)
sqlframe/base/column.py CHANGED
@@ -229,7 +229,7 @@ class Column:
229
229
  return Column(op)
230
230
 
231
231
  def unary_op(self, klass: t.Callable, **kwargs) -> Column:
232
- return Column(klass(this=self.column_expression, **kwargs))
232
+ return Column(klass(this=exp.Paren(this=self.column_expression), **kwargs))
233
233
 
234
234
  @property
235
235
  def is_alias(self):
@@ -1424,3 +1424,99 @@ def bit_length_from_length(col: ColumnOrName) -> Column:
1424
1424
  col_func = get_func_from_session("col")
1425
1425
 
1426
1426
  return Column(expression.Length(this=col_func(col).expression)) * lit(8)
1427
+
1428
+
1429
+ def any_value_always_ignore_nulls(
1430
+ col: ColumnOrName, ignoreNulls: t.Optional[t.Union[bool, Column]] = None
1431
+ ) -> Column:
1432
+ from sqlframe.base.functions import any_value
1433
+
1434
+ if not ignoreNulls:
1435
+ logger.warning("Nulls are always ignored when using `ANY_VALUE` on this engine")
1436
+ return any_value(col)
1437
+
1438
+
1439
+ def any_value_ignore_nulls_not_supported(
1440
+ col: ColumnOrName, ignoreNulls: t.Optional[t.Union[bool, Column]] = None
1441
+ ) -> Column:
1442
+ from sqlframe.base.functions import any_value
1443
+
1444
+ if ignoreNulls:
1445
+ logger.warning("Ignoring nulls is not supported in this dialect")
1446
+ return any_value(col)
1447
+
1448
+
1449
+ def current_user_from_session_user() -> Column:
1450
+ return Column(expression.Anonymous(this="SESSION_USER"))
1451
+
1452
+
1453
+ def extract_convert_to_var(field: ColumnOrName, source: ColumnOrName) -> Column:
1454
+ from sqlframe.base.functions import extract
1455
+
1456
+ field = expression.Var(this=Column.ensure_col(field).alias_or_name) # type: ignore
1457
+ return extract(field, source) # type: ignore
1458
+
1459
+
1460
+ def left_cast_len(str: ColumnOrName, len: ColumnOrName) -> Column:
1461
+ from sqlframe.base.functions import left
1462
+
1463
+ len = Column.ensure_col(len).cast("integer")
1464
+ return left(str, len)
1465
+
1466
+
1467
+ def right_cast_len(str: ColumnOrName, len: ColumnOrName) -> Column:
1468
+ from sqlframe.base.functions import right
1469
+
1470
+ len = Column.ensure_col(len).cast("integer")
1471
+ return right(str, len)
1472
+
1473
+
1474
+ def position_cast_start(
1475
+ substr: ColumnOrName, str: ColumnOrName, start: t.Optional[ColumnOrName] = None
1476
+ ) -> Column:
1477
+ from sqlframe.base.functions import position
1478
+
1479
+ start = Column.ensure_col(start).cast("integer") if start else None
1480
+ return position(substr, str, start)
1481
+
1482
+
1483
+ def position_as_strpos(
1484
+ substr: ColumnOrName, str: ColumnOrName, start: t.Optional[ColumnOrName] = None
1485
+ ) -> Column:
1486
+ substr_func = get_func_from_session("substr")
1487
+ lit = get_func_from_session("lit")
1488
+
1489
+ if start:
1490
+ str = substr_func(str, start)
1491
+ column = Column.invoke_anonymous_function(str, "STRPOS", substr)
1492
+ if start:
1493
+ return column + start - lit(1)
1494
+ return column
1495
+
1496
+
1497
+ def to_number_using_to_double(col: ColumnOrName, format: ColumnOrName) -> Column:
1498
+ return Column.invoke_anonymous_function(col, "TO_DOUBLE", format)
1499
+
1500
+
1501
+ def try_element_at_zero_based(col: ColumnOrName, extraction: ColumnOrName) -> Column:
1502
+ from sqlframe.base.functions import try_element_at
1503
+
1504
+ lit = get_func_from_session("lit")
1505
+ index = Column.ensure_col(extraction)
1506
+ if isinstance(index.expression, expression.Literal) and index.expression.is_number:
1507
+ index = index - lit(1)
1508
+ return try_element_at(col, index)
1509
+
1510
+
1511
+ def to_unix_timestamp_include_default_format(
1512
+ timestamp: ColumnOrName,
1513
+ format: t.Optional[ColumnOrName] = None,
1514
+ ) -> Column:
1515
+ from sqlframe.base.functions import to_unix_timestamp
1516
+
1517
+ lit = get_func_from_session("lit")
1518
+
1519
+ if not format:
1520
+ format = lit("%Y-%m-%d %H:%M:%S")
1521
+
1522
+ return to_unix_timestamp(timestamp, format)