()
| 3918 | |
| 3919 | |
| 3920 | def create_sample_expressions(): |
| 3921 | # We need a schema for substrait conversion |
| 3922 | schema = pa.schema([pa.field("i64", pa.int64()), pa.field( |
| 3923 | "foo", pa.struct([pa.field("bar", pa.string())]))]) |
| 3924 | |
| 3925 | # Creates a bunch of sample expressions for testing |
| 3926 | # serialization and deserialization. The expressions are categorized |
| 3927 | # to reflect certain nuances in Substrait conversion. |
| 3928 | a = pc.scalar(1) |
| 3929 | b = pc.scalar(1.1) |
| 3930 | c = pc.scalar(True) |
| 3931 | d = pc.scalar("string") |
| 3932 | e = pc.scalar(None) |
| 3933 | f = pc.scalar({'a': 1}) |
| 3934 | g = pc.scalar(pa.scalar(1)) |
| 3935 | h = pc.scalar(np.int64(2)) |
| 3936 | j = pc.scalar(False) |
| 3937 | k = pc.scalar(0) |
| 3938 | |
| 3939 | # These expression consist entirely of literals |
| 3940 | literal_exprs = [a, b, c, d, e, g, h, j, k] |
| 3941 | |
| 3942 | # These expressions include at least one function call |
| 3943 | exprs_with_call = [a == b, a != b, a > b, c & j, c | j, ~c, d.is_valid(), |
| 3944 | a + b, a - b, a * b, a / b, pc.negate(a), |
| 3945 | pc.add(a, b), pc.subtract(a, b), pc.divide(a, b), |
| 3946 | pc.multiply(a, b), pc.power(a, a), pc.sqrt(a), |
| 3947 | pc.exp(b), pc.cos(b), pc.sin(b), pc.tan(b), |
| 3948 | pc.acos(b), pc.atan(b), pc.asin(b), pc.atan2(b, b), |
| 3949 | pc.sinh(a), pc.cosh(a), pc.tanh(a), |
| 3950 | pc.asinh(a), pc.acosh(b), pc.atanh(k), |
| 3951 | pc.abs(b), pc.sign(a), pc.bit_wise_not(a), |
| 3952 | pc.bit_wise_and(a, a), pc.bit_wise_or(a, a), |
| 3953 | pc.bit_wise_xor(a, a), pc.is_nan(b), pc.is_finite(b), |
| 3954 | pc.coalesce(a, b), |
| 3955 | a.cast(pa.int32(), safe=False)] |
| 3956 | |
| 3957 | # These expressions test out various reference styles and may include function |
| 3958 | # calls. Named references are used here. |
| 3959 | exprs_with_ref = [pc.field('i64') > 5, pc.field('i64') == 5, |
| 3960 | pc.field('i64') == 7, |
| 3961 | pc.field(('foo', 'bar')) == 'value', |
| 3962 | pc.field('foo', 'bar') == 'value'] |
| 3963 | |
| 3964 | # Similar to above but these use numeric references instead of string refs |
| 3965 | exprs_with_numeric_refs = [pc.field(0) > 5, pc.field(0) == 5, |
| 3966 | pc.field(0) == 7, |
| 3967 | pc.field((1, 0)) == 'value', |
| 3968 | pc.field(1, 0) == 'value'] |
| 3969 | |
| 3970 | # Expressions that behave uniquely when converting to/from substrait |
| 3971 | special_cases = [ |
| 3972 | f, # Struct literals lose their field names |
| 3973 | a.isin([1, 2, 3]), # isin converts to an or list |
| 3974 | pc.field('i64').is_null() # pyarrow always specifies a FunctionOptions |
| 3975 | # for is_null which, being the default, is |
| 3976 | # dropped on serialization |
| 3977 | ] |
no test coverage detected