Coder Social home page Coder Social logo

Comments (3)

zero323 avatar zero323 commented on June 6, 2024 1

@FurcyPin I am going to close it with #163 - you encounter any similar cases, please let me know.

from pyspark-stubs.

zero323 avatar zero323 commented on June 6, 2024

That's a valid point, thank you for reporting.

Related:

from pyspark-stubs.

zero323 avatar zero323 commented on June 6, 2024

For simple unary and binary ((Column, Column) => Column) functions we can identify possible mismatches like this:

from operator import attrgetter, itemgetter
import re

from py4j.protocol import Py4JError
import requests
from toolz.curried import (
    filter, groupby, itemfilter, map, mapcat, pipe, sorted, valfilter, valmap
)
from toolz.functoolz import compose

from pyspark.sql import functions
from pyspark.sql.utils import ParseException

url = (
    "https://raw.githubusercontent.com/apache/spark/"
    "v2.4.3/sql/core/src/main/scala/org/apache/spark/sql/functions.scala"
)
func_pattern = re.compile("^\s*def ([\w_]+)\(([, :\w]*?)\): Column")
argtype_pattern = re.compile("[\w_]+: (\w+)")

def is_candidate(types):
    pref = pipe(types, map(itemgetter(slice(0, 2))), set)
    return (
        (("Column", ) in pref and ("String", ) not in pref) or
        (("Column", "Column") in pref and ("String", "String") not in pref)
    )


def takes_string(item):
    name, types = item
    try:
        f = getattr(functions, name)
        if ("Column", "Column") in types:
            f("foo", "bar")
        else:
            f("foo")
        # Successfully applied string
        return False
    # Incorrect arity
    except TypeError:
        return False
    # No such function in PySpark
    except AttributeError:
        return False
    except ParseException:
        return False
    # Doesn't take String as the first argument
    except Py4JError:
        return True

pipe(
    requests.get(url).text.splitlines(),
    mapcat(func_pattern.findall),
    sorted,
    groupby(itemgetter(0)),
    valmap(compose(
        set,
        map(compose(tuple, argtype_pattern.findall)),
        map(itemgetter(1))
    )),
    valfilter(is_candidate),
    itemfilter(takes_string),
    list
)

which gives in 2.4.3:

['abs',
 'array_repeat',
 'ascii',
 'base64',
 'bitwiseNOT',
 'lower',
 'ltrim',
 'rtrim',
 'trim',
 'unbase64',
 'upper']

but excluding array_repeat (which is a different beast), these are already fixed in 3.0.0.pre0 (master).

from pyspark-stubs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.