2017-02-02 4 views
0

하이브의 테이블에서 일부 텍스트 분석을 수행 할 때 pyspark를 사용하고 있습니다. 나는이 수출됩니다 경우가스파크 데이터 프레임을 하이브 데이터베이스로 내보낼 때 Java 힙 공간 오류가 발생했습니다.

INFO FileOutputCommitter: FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 
Exception in thread "stdout writer for python" 17/02/02 15:18:44 ERROR Utils: Uncaught exception in thread stdout writer for python 
java.lang.OutOfMemoryError: Java heap space 

난 상관 없어 날이 오류를 제공, 나는 그것을 내보내려고 나는 그러나

words_data.show(2) 

을 할 수

from pyspark.sql import SQLContext, Row, HiveContext 
from pyspark.sql.functions import col, udf, StringType 
from pyspark.sql.types import * 
from pyspark import SparkContext 
hc = HiveContext(sc) 
df=hc.sql("select * from table1") 
def cleaning_text(sentence): 
    sentence=sentence.lower() 
    sentence=re.sub('\'',' ',sentence) 
    cleaned=' '.join([w for w in cleaned.split() if not len(w)<=2 ]) 
    return cleaned 

org_val=udf(cleaning_text,StringType()) 
data=df.withColumn("cleaned",org_val(df.text)) 

data_1=data.select('uniqueid','cleaned','parsed')#2630789 #2022395 
tokenizer = Tokenizer(inputCol="cleaned", outputCol="words") 
wordsData = tokenizer.transform(data_1) 

hc.sql("SET spark.sql.hive.convertMetastoreParquet=false") 
hc.sql("create table table2 (uniqueid string, cleaned string, parsed string)") 
wordsData.insertInto('table2') 

다음 코드를 사용하여 텍스트 파일로도.

답변

0

기본적으로 드라이버 메모리가 1g 인이 스파크 셸에서이 스크립트를 실행하고있었습니다.

내가 스파크 쉘이

0

테이블에 삽입하는 동안 하이브 테이블에 쓰고있는 hiveContext에 insert 문을 써야합니다.

hc.sql("SET spark.sql.hive.convertMetastoreParquet=false") hc.sql("create table table2 (uniqueid string, cleaned string, parsed string)") wordsData.registerTempTable("tb1") val df1 = hc.sql("insert into table table2 select * from tb1")

위의 사람은 일을하거나 당신에게 만족하지 않을 경우 직접 saveAsTable

을 (테이블이 이미 원하는 스키마에 생성되어 있는지 확인) 할 수있는 아래를 시도하지 않는 경우 wordsData.write.mode("append").saveAsTable("sample_database.sample_tablename") 위의 코드를 시도하여 오류가 발생하면 여기에 오류를 붙여 넣으십시오. 더 도움을 드리겠습니다.

+0

'17/02/02 16시 49분 47초은 MemoryManager 경고 내 문제를 해결

pyspark --driver-memory 10g 

을 시작하는 동안 아래 문을 실행하여 변경 : 총 할당은 95.00 %를 초과 (948,830,208 바이트) 29 개의 작성자에 대해 행 그룹 크기를 24.38 %로 조정 17/02/02 16:50:17 오류 Utils : 파이썬의 스레드 stdout 작성자에서 캐치되지 않는 예외 java.lang.OutOfMemoryError : Java 힙 공간 '이것은 생성 된 오류입니다. –