Skip to content

Commit a531128

Browse files
authored
Merge branch 'main' into missing_expr
2 parents 28577f8 + 5a7f638 commit a531128

File tree

4 files changed

+359
-10
lines changed

4 files changed

+359
-10
lines changed

python/datafusion/__init__.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
except ImportError:
2727
import importlib_metadata
2828

29+
from datafusion.col import col, column
30+
2931
from . import functions, object_store, substrait, unparser
3032

3133
# The following imports are okay to remain as opaque to the user.
@@ -95,16 +97,6 @@
9597
]
9698

9799

98-
def column(value: str) -> Expr:
99-
"""Create a column expression."""
100-
return Expr.column(value)
101-
102-
103-
def col(value: str) -> Expr:
104-
"""Create a column expression."""
105-
return Expr.column(value)
106-
107-
108100
def literal(value) -> Expr:
109101
"""Create a literal expression."""
110102
return Expr.literal(value)

python/datafusion/col.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""Col class."""
19+
20+
from datafusion.expr import Expr
21+
22+
23+
class Col:
24+
"""Create a column expression.
25+
26+
This helper class allows an extra syntax of creating columns using the __getattr__
27+
method.
28+
"""
29+
30+
def __call__(self, value: str) -> Expr:
31+
"""Create a column expression."""
32+
return Expr.column(value)
33+
34+
def __getattr__(self, value: str) -> Expr:
35+
"""Create a column using attribute syntax."""
36+
# For autocomplete to work with IPython
37+
if value.startswith("__wrapped__"):
38+
return getattr(type(self), value)
39+
40+
return Expr.column(value)
41+
42+
43+
col: Col = Col()
44+
column: Col = Col()
45+
__all__ = ["col", "column"]

python/datafusion/expr.py

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from typing import TYPE_CHECKING, Any, ClassVar, Optional
2626

27+
import functions as F
2728
import pyarrow as pa
2829

2930
try:
@@ -661,6 +662,294 @@ def over(self, window: Window) -> Expr:
661662
)
662663
)
663664

665+
def asin(self) -> Expr:
666+
"""Returns the arc sine or inverse sine of a number."""
667+
return F.asin(self)
668+
669+
def array_pop_back(self) -> Expr:
670+
"""Returns the array without the last element."""
671+
return F.array_pop_back(self)
672+
673+
def reverse(self) -> Expr:
674+
"""Reverse the string argument."""
675+
return F.reverse(self)
676+
677+
def bit_length(self) -> Expr:
678+
"""Returns the number of bits in the string argument."""
679+
return F.bit_length(self)
680+
681+
def array_length(self) -> Expr:
682+
"""Returns the length of the array."""
683+
return F.array_length(self)
684+
685+
def array_ndims(self) -> Expr:
686+
"""Returns the number of dimensions of the array."""
687+
return F.array_ndims(self)
688+
689+
def to_hex(self) -> Expr:
690+
"""Converts an integer to a hexadecimal string."""
691+
return F.to_hex(self)
692+
693+
def array_dims(self) -> Expr:
694+
"""Returns an array of the array's dimensions."""
695+
return F.array_dims(self)
696+
697+
def from_unixtime(self) -> Expr:
698+
"""Converts an integer to RFC3339 timestamp format string."""
699+
return F.from_unixtime(self)
700+
701+
def array_empty(self) -> Expr:
702+
"""Returns a boolean indicating whether the array is empty."""
703+
return F.array_empty(self)
704+
705+
def sin(self) -> Expr:
706+
"""Returns the sine of the argument."""
707+
return F.sin(self)
708+
709+
def log10(self) -> Expr:
710+
"""Base 10 logarithm of the argument."""
711+
return F.log10(self)
712+
713+
def initcap(self) -> Expr:
714+
"""Set the initial letter of each word to capital.
715+
716+
Converts the first letter of each word in ``string`` to uppercase and the remaining
717+
characters to lowercase.
718+
"""
719+
return F.initcap(self)
720+
721+
def list_distinct(self) -> Expr:
722+
"""Returns distinct values from the array after removing duplicates.
723+
724+
This is an alias for :py:func:`array_distinct`.
725+
"""
726+
return F.list_distinct(self)
727+
728+
def iszero(self) -> Expr:
729+
"""Returns true if a given number is +0.0 or -0.0 otherwise returns false."""
730+
return F.iszero(self)
731+
732+
def array_distinct(self) -> Expr:
733+
"""Returns distinct values from the array after removing duplicates."""
734+
return F.array_distinct(self)
735+
736+
def arrow_typeof(self) -> Expr:
737+
"""Returns the Arrow type of the expression."""
738+
return F.arrow_typeof(self)
739+
740+
def length(self) -> Expr:
741+
"""The number of characters in the ``string``."""
742+
return F.length(self)
743+
744+
def lower(self) -> Expr:
745+
"""Converts a string to lowercase."""
746+
return F.lower(self)
747+
748+
def acos(self) -> Expr:
749+
"""Returns the arc cosine or inverse cosine of a number.
750+
751+
Returns:
752+
--------
753+
Expr
754+
A new expression representing the arc cosine of the input expression.
755+
"""
756+
return F.acos(self)
757+
758+
def ascii(self) -> Expr:
759+
"""Returns the numeric code of the first character of the argument."""
760+
return F.ascii(self)
761+
762+
def sha384(self) -> Expr:
763+
"""Computes the SHA-384 hash of a binary string."""
764+
return F.sha384(self)
765+
766+
def isnan(self) -> Expr:
767+
"""Returns true if a given number is +NaN or -NaN otherwise returns false."""
768+
return F.isnan(self)
769+
770+
def degrees(self) -> Expr:
771+
"""Converts the argument from radians to degrees."""
772+
return F.degrees(self)
773+
774+
def cardinality(self) -> Expr:
775+
"""Returns the total number of elements in the array."""
776+
return F.cardinality(self)
777+
778+
def sha224(self) -> Expr:
779+
"""Computes the SHA-224 hash of a binary string."""
780+
return F.sha224(self)
781+
782+
def asinh(self) -> Expr:
783+
"""Returns inverse hyperbolic sine."""
784+
return F.asinh(self)
785+
786+
def flatten(self) -> Expr:
787+
"""Flattens an array of arrays into a single array."""
788+
return F.flatten(self)
789+
790+
def exp(self) -> Expr:
791+
"""Returns the exponential of the argument."""
792+
return F.exp(self)
793+
794+
def abs(self) -> Expr:
795+
"""Return the absolute value of a given number.
796+
797+
Returns:
798+
--------
799+
Expr
800+
A new expression representing the absolute value of the input expression.
801+
"""
802+
return F.abs(self)
803+
804+
def btrim(self) -> Expr:
805+
"""Removes all characters, spaces by default, from both sides of a string."""
806+
return F.btrim(self)
807+
808+
def md5(self) -> Expr:
809+
"""Computes an MD5 128-bit checksum for a string expression."""
810+
return F.md5(self)
811+
812+
def octet_length(self) -> Expr:
813+
"""Returns the number of bytes of a string."""
814+
return F.octet_length(self)
815+
816+
def cosh(self) -> Expr:
817+
"""Returns the hyperbolic cosine of the argument."""
818+
return F.cosh(self)
819+
820+
def radians(self) -> Expr:
821+
"""Converts the argument from degrees to radians."""
822+
return F.radians(self)
823+
824+
def sqrt(self) -> Expr:
825+
"""Returns the square root of the argument."""
826+
return F.sqrt(self)
827+
828+
def character_length(self) -> Expr:
829+
"""Returns the number of characters in the argument."""
830+
return F.character_length(self)
831+
832+
def tanh(self) -> Expr:
833+
"""Returns the hyperbolic tangent of the argument."""
834+
return F.tanh(self)
835+
836+
def atan(self) -> Expr:
837+
"""Returns inverse tangent of a number."""
838+
return F.atan(self)
839+
840+
def rtrim(self) -> Expr:
841+
"""Removes all characters, spaces by default, from the end of a string."""
842+
return F.rtrim(self)
843+
844+
def atanh(self) -> Expr:
845+
"""Returns inverse hyperbolic tangent."""
846+
return F.atanh(self)
847+
848+
def list_dims(self) -> Expr:
849+
"""Returns an array of the array's dimensions.
850+
851+
This is an alias for :py:func:`array_dims`.
852+
"""
853+
return F.list_dims(self)
854+
855+
def sha256(self) -> Expr:
856+
"""Computes the SHA-256 hash of a binary string."""
857+
return F.sha256(self)
858+
859+
def factorial(self) -> Expr:
860+
"""Returns the factorial of the argument."""
861+
return F.factorial(self)
862+
863+
def acosh(self) -> Expr:
864+
"""Returns inverse hyperbolic cosine."""
865+
return F.acosh(self)
866+
867+
def floor(self) -> Expr:
868+
"""Returns the nearest integer less than or equal to the argument."""
869+
return F.floor(self)
870+
871+
def ceil(self) -> Expr:
872+
"""Returns the nearest integer greater than or equal to argument."""
873+
return F.ceil(self)
874+
875+
def list_length(self) -> Expr:
876+
"""Returns the length of the array.
877+
878+
This is an alias for :py:func:`array_length`.
879+
"""
880+
return F.list_length(self)
881+
882+
def upper(self) -> Expr:
883+
"""Converts a string to uppercase."""
884+
return F.upper(self)
885+
886+
def chr(self) -> Expr:
887+
"""Converts the Unicode code point to a UTF8 character."""
888+
return F.chr(self)
889+
890+
def ln(self) -> Expr:
891+
"""Returns the natural logarithm (base e) of the argument."""
892+
return F.ln(self)
893+
894+
def tan(self) -> Expr:
895+
"""Returns the tangent of the argument."""
896+
return F.tan(self)
897+
898+
def array_pop_front(self) -> Expr:
899+
"""Returns the array without the first element."""
900+
return F.array_pop_front(self)
901+
902+
def cbrt(self) -> Expr:
903+
"""Returns the cube root of a number."""
904+
return F.cbrt(self)
905+
906+
def sha512(self) -> Expr:
907+
"""Computes the SHA-512 hash of a binary string."""
908+
return F.sha512(self)
909+
910+
def char_length(self) -> Expr:
911+
"""The number of characters in the ``string``."""
912+
return F.char_length(self)
913+
914+
def list_ndims(self) -> Expr:
915+
"""Returns the number of dimensions of the array.
916+
917+
This is an alias for :py:func:`array_ndims`.
918+
"""
919+
return F.list_ndims(self)
920+
921+
def trim(self) -> Expr:
922+
"""Removes all characters, spaces by default, from both sides of a string."""
923+
return F.trim(self)
924+
925+
def cos(self) -> Expr:
926+
"""Returns the cosine of the argument."""
927+
return F.cos(self)
928+
929+
def sinh(self) -> Expr:
930+
"""Returns the hyperbolic sine of the argument."""
931+
return F.sinh(self)
932+
933+
def empty(self) -> Expr:
934+
"""This is an alias for :py:func:`array_empty`."""
935+
return F.empty(self)
936+
937+
def ltrim(self) -> Expr:
938+
"""Removes all characters, spaces by default, from the beginning of a string."""
939+
return F.ltrim(self)
940+
941+
def signum(self) -> Expr:
942+
"""Returns the sign of the argument (-1, 0, +1)."""
943+
return F.signum(self)
944+
945+
def log2(self) -> Expr:
946+
"""Base 2 logarithm of the argument."""
947+
return F.log2(self)
948+
949+
def cot(self) -> Expr:
950+
"""Returns the cotangent of the argument."""
951+
return F.cot(self)
952+
664953

665954
class ExprFuncBuilder:
666955
def __init__(self, builder: expr_internal.ExprFuncBuilder) -> None:

0 commit comments

Comments
 (0)