Skip to content

Commit

Permalink
chore(datafusion): clean up more unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Oct 26, 2023
1 parent cc6870c commit 4c51d1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 57 deletions.
63 changes: 7 additions & 56 deletions ibis/backends/datafusion/compiler/values.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import functools
import math
import operator
from typing import Any

Expand Down Expand Up @@ -99,6 +98,12 @@ def translate_val(op, **_):
ops.MinRank: "rank",
ops.CumeDist: "cume_dist",
ops.NthValue: "nth_value",
ops.Cot: "cot",
ops.Atan2: "atan2",
ops.Radians: "radians",
ops.Degrees: "degrees",
ops.NullIf: "nullif",
ops.Pi: "pi",
}

for _op, _name in _simple_ops.items():
Expand Down Expand Up @@ -263,16 +268,6 @@ def _de_morgan_law(logical_op: sg.exp.Expression):
return None


@translate_val.register(ops.And)
def and_(op, *, left, right, **_):
return sg.and_(left, right)


@translate_val.register(ops.Or)
def or_(op, *, left, right, **_):
return sg.or_(left, right)


@translate_val.register(ops.Ceil)
@translate_val.register(ops.Floor)
def ceil_floor(op, *, arg, **_):
Expand Down Expand Up @@ -351,49 +346,19 @@ def negate(op, *, arg, **_):
return -paren(arg)


@translate_val.register(ops.Atan2)
def atan2(op, *, left, right, **_):
return F.atan(left / right)


@translate_val.register(ops.Cot)
def cot(op, *, arg, **_):
return 1.0 / F.tan(arg)


@translate_val.register(ops.Radians)
def radians(op, *, arg, **_):
return arg * sg.exp.convert(math.pi) / sg.exp.convert(180)


@translate_val.register(ops.Degrees)
def degrees(op, *, arg, **_):
return arg * sg.exp.convert(180) / sg.exp.convert(math.pi)


@translate_val.register(ops.Coalesce)
def coalesce(op, *, arg, **_):
return F.coalesce(*arg)


@translate_val.register(ops.NullIf)
def nullif(op, *, arg, null_if_expr, **_):
return F.nullif(arg, null_if_expr)


@translate_val.register(ops.Log)
def log(op, *, arg, base, **_):
return F.log(base, arg)


@translate_val.register(ops.Pi)
def pi(op, **_):
return sg.exp.convert(math.pi)


@translate_val.register(ops.E)
def e(op, **_):
return sg.exp.convert(math.e)
return F.exp(1)


@translate_val.register(ops.ScalarUDF)
Expand Down Expand Up @@ -472,52 +437,38 @@ def string_join(op, *, sep, arg, **_):

@translate_val.register(ops.ExtractFragment)
def _(op, *, arg, **_):
if isinstance(arg, sg.exp.Alias): # ignore the aliases inside a function
arg = arg.this
return F.extract_url_field(arg, "fragment")


@translate_val.register(ops.ExtractProtocol)
def extract_protocol(op, *, arg, **_):
if isinstance(arg, sg.exp.Alias): # ignore the aliases inside a function
arg = arg.this
return F.extract_url_field(arg, "scheme")


@translate_val.register(ops.ExtractAuthority)
def extract_authority(op, *, arg, **_):
if isinstance(arg, sg.exp.Alias): # ignore the aliases inside a function
arg = arg.this
return F.extract_url_field(arg, "netloc")


@translate_val.register(ops.ExtractPath)
def extract_path(op, *, arg, **_):
if isinstance(arg, sg.exp.Alias): # ignore the aliases inside a function
arg = arg.this
return F.extract_url_field(arg, "path")


@translate_val.register(ops.ExtractHost)
def extract_host(op, *, arg, **_):
if isinstance(arg, sg.exp.Alias): # ignore the aliases inside a function
arg = arg.this
return F.extract_url_field(arg, "hostname")


@translate_val.register(ops.ExtractQuery)
def extract_query(op, *, arg, key, **_):
if isinstance(arg, sg.exp.Alias): # ignore the aliases inside a function
arg = arg.this
if key is not None:
return F.extract_query_param(arg, key)
return F.extract_query(arg)


@translate_val.register(ops.ExtractUserInfo)
def extract_user_info(op, *, arg, **_):
if isinstance(arg, sg.exp.Alias): # ignore the aliases inside a function
arg = arg.this
return F.extract_user_info(arg)


Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ def test_substr_with_null_values(backend, alltypes, df):
)
def test_parse_url(con, result_func, expected):
url = "http://user:[email protected]:80/docs/books/tutorial/index.html?name=networking#DOWNLOADING"
expr = result_func(ibis.literal(url).name("url"))
expr = result_func(ibis.literal(url))
result = con.execute(expr)
assert result == expected

Expand Down

0 comments on commit 4c51d1b

Please sign in to comment.