Search

Wednesday 26 April 2023

How to create / register and drop a UDF in Databricks Spark using Python

Below is an example of how to create and drop a UDF in Python using Databricks:

Creating a UDF:

from pyspark.sql.functions import udf
from pyspark.sql.types import IntegerType
# Define the function you want to use in your UDF
def multiply_by_two(x):
    return x * 2
# Create the UDF using the function you defined
multiply_by_two_udf = udf(multiply_by_two, IntegerType())
# Register the UDF so it can be used in your Spark SQL queries
spark.udf.register("multiply_by_two", multiply_by_two_udf)


Dropping a UDF:

# Unregister the UDF so it can no longer be used in your Spark SQL queries
spark.catalog.dropTempView("multiply_by_two")

Note that in the above examples, we're using spark to access the SparkSession object, which is the entry point to using Spark functionality. If you're running this code in a Databricks notebook, the SparkSession object is automatically created for you.

Tuesday 25 April 2023

SUBSTRING_INDEX function in Databricks Spark

SUBSTRING_INDEX is a string manipulation function that can be used in Databricks, which is a cloud-based big data processing platform based on Apache Spark.

The SUBSTRING_INDEX function allows you to extract a substring from a string by specifying a delimiter and the number of occurrences of the delimiter to consider from the left or right of the string. The syntax for the function is as follows:

SUBSTRING_INDEX(string, delimiter, count)

Where:
string: the input string to extract the substring from.
delimiter: the delimiter used to split the input string.
count: the number of occurrences of the delimiter to consider. If count is positive, the function will extract the substring from the left of the string, starting from the beginning. If count is negative, the function will extract the substring from the right of the string, starting from the end.
Here is an example usage of SUBSTRING_INDEX in Databricks:

%sql
SELECT SUBSTRING_INDEX('www.example.com', '.', 2)

This would return the output www.example as it extracts the first two occurrences of the delimiter "." from the left of the input string "www.example.com".

Sunday 9 April 2023

Adobe Premiere Error - The code execution cannot proceed because MFPlat.dll not found

Error Message on Windows 10/11 when running Adobe Premiere Pro for the first time - The code execution cannot proceed because MFPlat.dll not found. Reinstalling the program may fix this problem. 


Fix - Go to Optional features > Add a feature > Media Feature Pack


Restart PC after installation.

Thursday 6 April 2023

Install ADB Faastboot USB Drivers Xiaomi on Windows, Debloat via ADB

1. Download the ADB, Fastboot and Drivers - 15 seconds ADB Installer from the following link:

https://forum.xda-developers.com/t/official-tool-windows-adb-fastboot-and-drivers-15-seconds-adb-installer-v1-4-3.2588979/

2. Check if your device is detected
adb devices

3. List all installed packages:
adb shell cmd package list packages
4. To remove a package, use the following command (replace the package name):
Adb shell pm uninstall -k --user 0 com.life.breathing