Posts

Showing posts with the label pyspark

Save each row in Spark Dataframe into different file

Image
Clash Royale CLAN TAG #URR8PPP Save each row in Spark Dataframe into different file I construct a spark DataFrame using with the following structure: root |-- tickers: string (nullable = true) |-- name: string (nullable = true) |-- price: array (nullable = true) | |-- element: map (containsNull = true) | | |-- key: string | | |-- value: map (valueContainsNull = true) | | | |-- key: string | | | |-- value: string (valueContainsNull = true) I want to save each object in price into a separate JSON/CSV file and have each saved file using the corresponding name string as filename. Is there a way to implement this in a Python environment? price name The most relevant solution I find is to repartition the dataframe into patitions of number of "rows" in dataframe, and use .write.csv() (see https://stackoverflow.com/a/49890590/6158414). But this doesn't fit my need to save "rows" into separate files with different filenames. .w...

Increasing spark stack size to prevent stackoverflow error in Jupyter Notebook in Windows 10

Increasing spark stack size to prevent stackoverflow error in Jupyter Notebook in Windows 10 from pyspark import SparkContext from pyspark.sql import SparkSession spark = SparkSession.builder.appName('ose') .master("local[*]") .config("spark.executor.extraJavaOptions", "??") .config('spark.driver.extraJavaOptions',"??") .config('spark.executor.memory', '8g') .config('spark.driver.memory', '8g') .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer") .getOrCreate() I am not sure what values I should pass to the ?? arguments in the jupyter notebook to increase spark stack size to prevent the java.lang.StackOverflowError ? ?? java.lang.StackOverflowError Does the spark.executor.memory clash with spark.executor.extraJavaOptions ? spark.executor.memory spark.executor.extraJavaOptions In the documentation for spark.driver.extraJavaOptions Note: In client mode, thi...