-1
이 글에서는 쉘 스크립트를 사용하여 hbase 테이블을 만드는 방법을 설명합니다.hbase 명령을 실행하기위한 쉘 스크립트 - hbase 테이블 만들기
이 글에서는 쉘 스크립트를 사용하여 hbase 테이블을 만드는 방법을 설명합니다.hbase 명령을 실행하기위한 쉘 스크립트 - hbase 테이블 만들기
정의 테이블 이름 :
declare -a table_names=("Table_1;['t1']" "Table_2;['t1','t2']")
'된 table_1'는 TABLE_NAME
'T1'인 column_family입니다.
대하여 반복 각 테이블 기준
for i in "${table_names[@]}"
do
done
';'은 나. 여기서 첫 번째 값은 테이블 이름 & 두 번째 값은 열 패밀리이 될 것입니다.
set -- "$i"
IFS=";"; declare -a table_name_info=($*)
테이블이 존재하는지 확인하십시오. & 결과를 로그 파일에 저장하십시오.
echo "exists '${table_name_info[0]}'" | hbase shell > log 2>&1
"표 존재 함"메시지를 검색하십시오. 존재할 경우 상태는 0으로 리턴됩니다. 상태가 0이면 표가 이미 있습니다.
cat log | grep -q 'Table '${table_name_info[0]}' does exist'
if [ $? = 0 ]; then
## log message
else
## write script to create a table
fi
여기에 전체 스크립트 코드 찾기 :
hbase_shell_script.sh을
#!/bin/sh
echo "Running the <$0> file"
## table names
declare -a table_names=("Table_1;['t1']" "Table_2;['t1','t2']")
function tableExists {
echo "Table <$1> already exists."
}
function createTable {
echo "Table <$1> does not exist."
echo "Creating the Table <$1>"
echo "create '$1', $2" | hbase shell > log 2>&1
cat log | grep -q '0 row(s) in'
if [ $? = 0 ]; then
echo "Table <$1> created successfully."
else
echo "Table <$1> is not created."
fi
}
## iterating table names and checking table already exists. if does not exist creating table.
for i in "${table_names[@]}"
do
## splitting the table based on ';'. First argument will be 'table_name' and second argument will be 'column_families'
set -- "$i"
IFS=";"; declare -a table_name_info=($*)
echo ""
echo "Checking the table <${table_name_info[0]}> exists or not"
echo ""
echo "exists '${table_name_info[0]}'" | hbase shell > log 2>&1
cat log | grep -q 'Table '${table_name_info[0]}' does exist'
if [ $? = 0 ]; then
tableExists ${table_name_info[0]}
else
createTable ${table_name_info[0]} ${table_name_info[1]}
fi
done
## deleting the log file.
rm -rf log
echo ""
echo "done."
exit