Posts

Showing posts with the label apache-spark

Separating application logs in Logback from Spark Logs in log4j

Image
Clash Royale CLAN TAG #URR8PPP Separating application logs in Logback from Spark Logs in log4j I have a Scala Maven project using that uses Spark, and I am trying implement logging using Logback. I am compiling my application to a jar, and deploying to an EC2 instance where the Spark distribution is installed. My pom.xml includes dependencies for Spark and Logback as follows: <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.7</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_${scala.binary.version}</artifactId> ...

scala: select column where not contains elements into dataframe

Image
Clash Royale CLAN TAG #URR8PPP scala: select column where not contains elements into dataframe I have this ligne of code that should create a dataframe from list of columns that not contain a string. I tried this but it doesn't work: val exemple = hiveObj.sql("show tables in database").select("tableName")!==="ABC".collect() By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

text similarity distinct method using spark?

Image
Clash Royale CLAN TAG #URR8PPP text similarity distinct method using spark? I want to get a text similarity distinct method on 200 million differnent sentences using spark .Suppose I have 4 sentence that is ["Hi I heard about Spark","Hi I heard about Spark World", "Logistic regression models ","Logistic regression goodmodels "] I hope get the reuslt is ["Hi I heard about Spark", "Logistic regression models] Since the first sentence is similar to second sentence and the third sentence is similar to the 4th sentence arrorcding to Levenshtein distance:https://rosettacode.org/wiki/Levenshtein_distance How to achieve it efficiently using spark? Because the data is 200 million, I am hesitate to do cartesian By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your con...

Save Spark dataframe as dynamic partitioned table in Hive

Image
Clash Royale CLAN TAG #URR8PPP Save Spark dataframe as dynamic partitioned table in Hive I have a sample application working to read from csv files into a dataframe. The dataframe can be stored to a Hive table in parquet format using the method df.saveAsTable(tablename,mode) . df.saveAsTable(tablename,mode) The above code works fine, but I have so much data for each day that i want to dynamic partition the hive table based on the creationdate(column in the table). is there any way to dynamic partition the dataframe and store it to hive warehouse. Want to refrain from Hard-coding the insert statement using hivesqlcontext.sql(insert into table partittioin by(date)....) . hivesqlcontext.sql(insert into table partittioin by(date)....) Question can be considered as an extension to :How to save DataFrame directly to Hive? any help is much appreciated. 4 Answers 4 I believe it works something like this: df...

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...

Spark - Why is it necessary to collect() to the driver node before printing an RDD? Can it not be done in parallel?

Image
Clash Royale CLAN TAG #URR8PPP Spark - Why is it necessary to collect() to the driver node before printing an RDD? Can it not be done in parallel? I was reading about how to print RDDs in Spark (I'm using Java), and it seems like most people just collect() (if the RDD is small enough) and use forall(println), or something like that. Is it not possible to print in parallel? Why do we have to collect the data onto the driver node in order to print? collect() I was thinking maybe it's because we can't use System.out in parallel, but I feel like that's not it. And furthermore, I'm not quite sure how one would even distribute the data and print parallelly, in terms of code. One approach I was thinking of was to do a mappartitions that doesn't do anything useful in terms of mapping, but it iterates through the partition and prints its contents. By clicking "Post Your Answer", you acknowledg...

Unable to create temp file for insert values in hive

Image
Clash Royale CLAN TAG #URR8PPP Unable to create temp file for insert values in hive I have installed hive 1.2 in a Linux server and started metastore successfully when I am inserting data in a table I am getting below error.Please suggest some solution. /oradata_iscsi/hive/bin>hive ls: cannot access /oradata_iscsi/spark/lib/spark-assembly-*.jar: No such file or directory Logging initialized using configuration in jar:file:/oradata_iscsi/hive/lib/hive-common-1.2.0.jar!/hive-log4j.properties hive> Insert into test values(1); FAILED: SemanticException [Error 10293]: Unable to create temp file for insert values File /tmp/hive/ora12c/6a9e3ee7-620f-476c-939c-64a49c6a0a7e/_tmp_space.db/Values__Tmp__Table__1/data_file could only be replicated to 0 nodes instead of minReplication (=1). There are 1 datanode(s) running and no node(s) are excluded in this operation. at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:1559) at...

join streaming and static dataframes does nothing

Image
Clash Royale CLAN TAG #URR8PPP join streaming and static dataframes does nothing So I'm trying to setup a stream from Kafka, and then add columns from a table to that dataframe based on a matching id in the kafka message and table. I've got two separate files, the first one calls a method in streamKafka_ASH to setup the stream and then it prints out the contents. val query = streamKafka_ASH.setupStream(spark, bootstrapservers,zkPath, topics, zkHosts, consumerGroup, batchIntervalSeconds.toInt, autoOffset, checkpointDir) .writeStream .outputMode("append") .format("console") .trigger(ProcessingTime(intervalMs = batchIntervalSeconds.toInt * 1000)) .start() query.awaitTermination() And here is the code in streamKafka_ASH.setupStream(...) val marketingTrackingSchema = new StructType() .add("id", StringType) .add("device", StringType) .add("type", StringType) .add(...

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...