2016-08-12 3 views
0

내 코드는 다음과 같습니다의 PrintWriter 대신 HDFS 경로에 이중 슬래시의 한 슬래시를 고려하고있다

val df = sqlContext.read 
     .format("com.databricks.spark.xml") 
     .option("rowTag", header) 
     .load("/input/du3_init.dat") 
val dfCI2 = df.select("CI2") 
dfCI2.printSchema() 
val path="hdfs://nameservice/user/CI2_Schema" 
new PrintWriter(path) { write(dfCI2.schema.treeString);close} 

내가 스파크에서 실행, 내가

Exception in thread "main" java.io.FileNotFoundException: hdfs:/nameservice/user/CI2_Schema (No such file or directory) 
     at java.io.FileOutputStream.open(Native Method) 
     at java.io.FileOutputStream.<init>(FileOutputStream.java:221) 
     at java.io.FileOutputStream.<init>(FileOutputStream.java:110) 

하나의 슬래시를 얻고 것은에 존재 hdfs 경로는 예외로 표시됩니다. 이 문제를 해결하는 방법? 미리 감사드립니다.

+0

'PrintWriter'는'hdfs : //'또는'ftp : //'를 가진 네트워크 경로를 이해하지 못합니다. 그것은 로컬 파일 시스템과 함께 작동합니다. 그리고 로컬 파일 시스템 경로는'a/b/c' 형식입니다. –

답변

1

hdfs에 쓰려면 PrintWriter을 사용할 수 없습니다. PrintWriter는 hdfs:// 또는 ftp:// 인 네트워크 경로를 이해하지 못합니다. 로컬 파일 시스템에서 작동합니다.

hdfs 구성 양식 스파크 컨텍스트를 가져 와서 hdfs에 쓸 수 있습니다.

import org.apache.hadoop.fs.FileSystem 
import java.io.BufferedOutputStream 


val hdfsConf = sparkContext.hadoopConfiguration 

val fileSystem: FileSystem = FileSystem.get(hdfsConf) 

val filePath = "hdfs://nameservice1/user/dhdpbankcrtbtch/CIW2_Schema" 

val hdfsFileOS: FSDataOutputStream = fileSystem.create(new Path(filePath)); 

// create a buffered output stream using the FSDataOutputStream 
val bos = new BufferedOutputStream(hdfsFileOS) 

bos.write(dfCIW2.schema.treeString.toBytes("utf-8")) 

bos.close() 
+0

Sarvesh 대단히 감사합니다. – Sibikrish

관련 문제