spark-dataframe

When to use Spark DataFrame/Dataset API and when to use plain RDD?

百般思念 提交于 2019-12-19 17:13:27
问题 Spark SQL DataFrame/Dataset execution engine has several extremely efficient time & space optimizations (e.g. InternalRow & expression codeGen). According to many documentations, it seems to be a better option than RDD for most distributed algorithms. However, I did some sourcecode research and am still not convinced. I have no doubt that InternalRow is much more compact and can save large amount of memory. But execution of algorithms may not be any faster saving predefined expressions.

When to use Spark DataFrame/Dataset API and when to use plain RDD?

 ̄綄美尐妖づ 提交于 2019-12-19 17:12:31
问题 Spark SQL DataFrame/Dataset execution engine has several extremely efficient time & space optimizations (e.g. InternalRow & expression codeGen). According to many documentations, it seems to be a better option than RDD for most distributed algorithms. However, I did some sourcecode research and am still not convinced. I have no doubt that InternalRow is much more compact and can save large amount of memory. But execution of algorithms may not be any faster saving predefined expressions.

How to write into PostgreSQL hstore using Spark Dataset

折月煮酒 提交于 2019-12-19 08:31:31
问题 I'm trying to write a Spark Dataset into an existent postgresql table (can't change the table metadata like column types). One of the columns of this table is of type HStore and it's causing trouble. I see the following exception when I launch the write (here the original map is empty which when escaped gives an empty string): Caused by: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO part_d3da09549b713bbdcd95eb6095f929c8 (.., "my_hstore_column", ..) VALUES (..,'',..) was aborted.

Converting RDD[org.apache.spark.sql.Row] to RDD[org.apache.spark.mllib.linalg.Vector]

こ雲淡風輕ζ 提交于 2019-12-19 05:47:38
问题 I am relatively new to Spark and Scala. I am starting with the following dataframe (single column made out of a dense Vector of Doubles): scala> val scaledDataOnly_pruned = scaledDataOnly.select("features") scaledDataOnly_pruned: org.apache.spark.sql.DataFrame = [features: vector] scala> scaledDataOnly_pruned.show(5) +--------------------+ | features| +--------------------+ |[-0.0948337274182...| |[-0.0948337274182...| |[-0.0948337274182...| |[-0.0948337274182...| |[-0.0948337274182...| +----

Spark job restarted after showing all jobs completed and then fails (TimeoutException: Futures timed out after [300 seconds])

≯℡__Kan透↙ 提交于 2019-12-18 17:29:21
问题 I'm running a spark job. It shows that all of the jobs were completed: however after couple of minutes the entire job restarts, this time it will show all jobs and tasks were completed too, but after couple of minutes it will fail. I found this exception in the logs: java.util.concurrent.TimeoutException: Futures timed out after [300 seconds] So this happens when I'm trying to join 2 pretty big tables: one of 3B rows, and the second is 200M rows, when I run show(100) on the resulting

Spark cosine distance between rows using Dataframe

◇◆丶佛笑我妖孽 提交于 2019-12-18 17:25:49
问题 I have to compute a cosine distance between each rows but I have no idea how to do it using Spark API Dataframes elegantly. The idea is to compute similarities for each rows(items) and take top 10 similarities by comparing their similarities between rows. --> This is need for Item-Item Recommender System. All that I've read about it is referred to computing similarity over columns Apache Spark Python Cosine Similarity over DataFrames May someone say is it possible to compute a cosine distance

run spark as java web application

烂漫一生 提交于 2019-12-18 17:08:33
问题 I have used Spark ML and was able to get reasonable accuracy in prediction for my business problem The data is not huge and I was able to transform the input ( basically a csv file ) using stanford NLP and run Naive Bayes for prediction in my local machine. I want to run this prediction service like a simple java main program or along with a simple MVC web application Currently I run my prediction using the spark-submit command ? Instead , can I create spark context and data frames from my

Scala: Spark SQL to_date(unix_timestamp) returning NULL

别说谁变了你拦得住时间么 提交于 2019-12-18 17:02:46
问题 Spark Version: spark-2.0.1-bin-hadoop2.7 Scala: 2.11.8 I am loading a raw csv into a DataFrame. In csv, although the column is support to be in date format, they are written as 20161025 instead of 2016-10-25. The parameter date_format includes string of column names that need to be converted to yyyy-mm-dd format. In the following code, I first loaded the csv of Date column as StringType via the schema , and then I check if the date_format is not empty, that is there are columns that need to

How can I write a parquet file using Spark (pyspark)?

蹲街弑〆低调 提交于 2019-12-18 12:57:09
问题 I'm pretty new in Spark and I've been trying to convert a Dataframe to a parquet file in Spark but I haven't had success yet. The documentation says that I can use write.parquet function to create the file. However, when I run the script it shows me: AttributeError: 'RDD' object has no attribute 'write' from pyspark import SparkContext sc = SparkContext("local", "Protob Conversion to Parquet ") # spark is an existing SparkSession df = sc.textFile("/temp/proto_temp.csv") # Displays the content

Spark-SQL : How to read a TSV or CSV file into dataframe and apply a custom schema?

我只是一个虾纸丫 提交于 2019-12-18 12:08:28
问题 I'm using Spark 2.0 while working with tab-separated value (TSV) and comma-separated value (CSV) files. I want to load the data into Spark-SQL dataframes, where I would like to control the schema completely when the files are read. I don't want Spark to guess the schema from the data in the file. How would I load TSV or CSV files into Spark SQL Dataframes and apply a schema to them? 回答1: Below is a complete Spark 2.0 example of loading a tab-separated value (TSV) file and applying a schema. I