Questions tagged [user-defined-functions]

A function provided by the user of a program or an environment most often for spreadsheet type applications or database applications. Use [custom-functions-excel] for Excel and [custom-function] for Google sheets. Specify a programming language tag as well: [google-apps-script], [javascript], [sql], [tsql], etc. as well as a tag for the application: [excel], [google-spreadsheet], [sql-server] etc.

In the context of a programming language or an environment, a User Defined Function (UDF) is a function that is created by a user to perform a specific task (as opposed to a function that is intrinsic to the environment, built into the programming language or environment).

Spreadsheet applications like Excel and Google Sheets calls these "custom functions".

Microsoft also uses the term User Defined Functions with . The tag may also be applicable. See What is the need for user-defined functions in SQL Server?

Use:

4875 questions
1
vote
1 answer

Convert multiple columns in pyspark dataframe into one dictionary

I have created a PySpark DataFrame like this one: ''' df = spark.createDataFrame([ ('v', 3, 'a'), ('d', 2, 'b'), ('q', 9, 'c')], ["c1", "c2", "c3"] ) df.show() c1 | c2 | c3 v | 3 | a d | 2 | b q | 9 | c I want to create…
1
vote
0 answers

Update a pyspark Delta Table using a python boolean function

so I have a delta table that I want to update based on a condition of two column values combined; i.e. delta_table.update( condition=is_eligible(col("name"), col("age")) set={"pension_eligible": lit("yes")} ) I'm aware that I can do…
1
vote
0 answers

Comparing the json data types at runtime using Jackson and Scala

I have an incoming JSON data that looks like below: {"id":"1000","premium":29999,"eventTime":"2021-12-22 00:00:00"} Now, I have created a class that will accept this record and will check whether the data type of the incoming record is according to…
1
vote
0 answers

Convert a MS SQL Function to MySQL referencing an assembly created by Yaddress

Yaddress.net created a user-defined function for use with MS SQL that appears to integrate with their address correction service. I know the setup script doesn't work with MySQL, but I don't know enough about MySQL to know if it can work with MySQL.…
1
vote
1 answer

How to user define filtering parameters in R?

I need some help with user defined functions or a similar method that lets me define filtering and use it repeatedly. I have a DF that i need to filter in to many smaller DF-s, Some of the filtering logic i need to reuse and change from time to…
Picataro
  • 151
  • 6
1
vote
1 answer

ReturnType of Pandas UDF varies per input. How to deal? - Pyspark

I've written a pandas UDF that returns the value of a column where another column has its max value @F.pandas_udf("string") def belonging_to_max_udf(value_of: pd.Series, where_this_is_max: pd.Series) -> str : mx = where_this_is_max.max() if not…
Rens
  • 177
  • 9
1
vote
1 answer

Loop through a table in a CLR UDF C#

I need to write a CLR UDF that reads data from a table and loops through it, but most important storing data in double arrays (the table has only double values), afterwards I will use a math library to compute some things... I have been searching…
edgarmtze
  • 24,683
  • 80
  • 235
  • 386
1
vote
1 answer

In PostgreSQL can an immutable function access a table in its code?

I am writing a PostgreSQL function. I want to write an immutable function. The following is an excerpt from a PostgreSQL manual. IMMUTABLE indicates that the function cannot modify the database and always returns the same result when given the same…
1
vote
2 answers

Union two or more tables, when you don't know the number of tables you are merging

I am working with MS SQL 2005. I have defined a tree structure as: 1 |\ 2 3 /|\ 4 5 6 I have made a SQL-function Subs(id), that gets the id, and returns the subtree table. So, Subs(3) will return 4 rows with 3,4,5,6, while Subs(2) will…
Stavros
  • 5,802
  • 13
  • 32
  • 45
1
vote
0 answers

java.lang.InternalError: Malformed class name in zeppelin paragraph

I write a UDF and use it in sql in a spark paragraph like this: import java.security.MessageDigest spark.udf.register("covertMd5", (input: String) => { if (input == null || input.size == 0) null else { if (input.startsWith("_"))…
1
vote
1 answer

Pyspark : Model Loading multiple times with udf

Trying to apply udf on a large csv file that makes a model prediction based on some conditions, but for some reason the model is being loaded multiple number of times. Below is a sample snippet of how the flow looks like: # main.py loads…
1
vote
1 answer

Access jQuery user defined function within said function via sub function

I was wondering how I could access the jQuery custom function within a sub function which is defined through an object. Observe: (function($){ var methods = { init : function ( options ) { // getting the variable "data". …
nderjung
  • 1,607
  • 4
  • 17
  • 38
1
vote
1 answer

How can I use this Java function in Scala in a UDF?

I have created a UDF in Scala (that im using with Spark btw) in order to get as a parameter a string and output a BeiderMorseEncoder string. I am using the org.apache.commons.codec.language.bm.BeiderMorseEncoder Java function from Apache…
mamonu
  • 392
  • 3
  • 19
1
vote
1 answer

Failed to execute user defined function in Spark-Scala

Below is the UDF to convert multivalued column into map. def convertToMapFn (c: String): Map[String,String] = { val str = Option(c).getOrElse(return Map[String, String]()) val arr = str.split(",") val l = arr.toList val regexPattern =…
SanjanaSanju
  • 261
  • 2
  • 18
1
vote
0 answers

euclidean distance between two dataframes

I have two dataframes. For simplicity assume, they each have only one entry +--------------------+ | entry | +--------------------+ |[0.34, 0.56, 0.87] …
A.M.
  • 1,757
  • 5
  • 22
  • 41