create alias if not exists hdfs_set_owner as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.*;
import java.net.*;
@CODE
Boolean hdfs_set_owner(String uri, String user,
String path, String owner, String group)
throws Exception
{
if( uri == null ){
throw new Exception("uri is not specified.");
}
if( user == null ){
throw new Exception("user is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( owner == null ){
throw new Exception("owner is not specified.");
}
if( group == null ){
throw new Exception("group is not specified.");
}
FileSystem fs = FileSystem.get(
URI.create(uri), new Configuration(), user);
fs.setOwner(new Path(path), owner, group);
return new Boolean(true);
}
$$
実行例
select
hdfs_set_owner('hdfs://192.168.1.81:9000/', 'hadoop',
'/opt/hadoop-data/test.txt', 'test', 'testgroup')
;
※以下のjarをCLASSPATH環境変数に追加
hadoop-common-0.21.0.jar
hadoop-hdfs-0.21.0.jar
log4j-1.2.15.jar
○動作環境
JDK6 Update22, Hadoop 0.21.0, H2 Database 1.2.147 (2010-11-21)
○関連情報
・CentOS5.5にHadoop0.21.0をインストールする
http://serverarekore.blogspot.com/2010/10/centos55hadoop0210.html
・H2 Databaseに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿