티스토리 뷰

Sqoop2 를 이용해서 Oracle to HDFS 로 데이터를 전송할 때,
HDFS 파일이 생성된다. 이 때 파일명은 sequene 하게 만들어지는 듯 한데. 이를 원하는 파일명 하나로 생성할 수 있을까?

일단 Job을 하나 생성해서 돌려보면 아래와 같이 파일이 생성된다.
(아래 예제는 uMON WKLOG_USER 테이블의 하루치 데이터를 옮긴 것이다.)


sqoop-connector-hdfs 컴포넌트에서 관련 코드를 확인이 가능하다.



HdfsConnector 관련 클래스는 위와 같다.
실제로 HdfsWriter 클래스들이 HDFS 파일을 쓰게되며, 그 filename은 HdfsLoader에서 결정한다.

코드를 상세히 살펴보자.

HdfsTestWriter

@Override
public void initialize(Path filepath, Configuration conf, CompressionCodec codec) throws IOException {
FileSystem fs = filepath.getFileSystem(conf);

DataOutputStream filestream = fs.create(filepath, false);
if (codec != null) {
filewriter = new BufferedWriter(new OutputStreamWriter(
codec.createOutputStream(filestream, codec.createCompressor()),
Charsets.UTF_8));
} else {
filewriter = new BufferedWriter(new OutputStreamWriter(
filestream, Charsets.UTF_8));
}
}
HdfsSequenceWriter

@SuppressWarnings("deprecation")
public void initialize(Path filepath, Configuration conf, CompressionCodec codec) throws IOException {
if (codec != null) {
filewriter = SequenceFile.createWriter(filepath.getFileSystem(conf),
conf, filepath, Text.class, NullWritable.class,
SequenceFile.CompressionType.BLOCK, codec);
} else {
filewriter = SequenceFile.createWriter(filepath.getFileSystem(conf),
conf, filepath, Text.class, NullWritable.class, SequenceFile.CompressionType.NONE);
}

text = new Text();
}

Writer 클래스는 initialize 때 전달받은 filepath 값을 가공하지 않고 그대로 사용하고 있다.

HdfsLoader 클래스를 살펴보자.

HdfsLoader

@Override
public void load(LoaderContext context, LinkConfiguration linkConfiguration,
ToJobConfiguration toJobConfig) throws Exception {

...

String filename = directoryName + "/" + UUID.randomUUID() + getExtension(toJobConfig,codec);

try {
Path filepath = new Path(filename);

GenericHdfsWriter filewriter = getWriter(toJobConfig);

filewriter.initialize(filepath, conf, codec);

...

} catch (IOException e) {
...
}

}

filename 생성시 UUID.randomUUID() 값을 붙여서 생성하는 것을 확인할 수 있다.
이는 HDFS 내에서 파일명 충돌을 막기 위함으로 생각된다.



결론은 Sqoop을 이용하여 HDFS 파일을 생성할 때는 사용자가 임의로 지정할 수 없다.
(단, 확장자는 변경 가능. Codec 설정을 사용할 때만)

만약 파일명을 조절하고자 한다면, HdfsLoader와 GenericHdfsWriter를 별도로 구현해야할 것으로 보인다.

'BigData > Sqoop' 카테고리의 다른 글

Sqoop의 개념  (0) 2015.04.10
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함