国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

實(shí)驗(yàn)三:熟悉常用的HBase操作

這篇具有很好參考價(jià)值的文章主要介紹了實(shí)驗(yàn)三:熟悉常用的HBase操作。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

完整原版實(shí)驗(yàn)報(bào)告word文件:實(shí)驗(yàn)三:熟悉常用的HBase操作

—————————————————————————————————

"大數(shù)據(jù)技術(shù)原理與應(yīng)用"課程實(shí)驗(yàn)報(bào)告

題目:實(shí)驗(yàn)三:熟悉常用的HBase操作

姓名:朱小凡

日期:2022/3/29

1、實(shí)驗(yàn)環(huán)境:

設(shè)備名稱(chēng) LAPTOP-9KJS8HO6

處理器 Intel? Core? i5-10300H CPU @ 2.50GHz 2.50 GHz

機(jī)帶 RAM 16.0 GB (15.8 GB 可用)

主機(jī)操作系統(tǒng) Windows 10 家庭中文版

虛擬機(jī)操作系統(tǒng) ubuntukylin-16.04

Hadoop 版本 3.1.3

JDK 版本 1.8

Java IDE:Eclipse

系統(tǒng)類(lèi)型 64 位操作系統(tǒng), 基于 x64 的處理器

筆和觸控 沒(méi)有可用于此顯示器的筆或觸控輸入

2、實(shí)驗(yàn)內(nèi)容與完成情況:

1.編程實(shí)現(xiàn)以下指定功能,并用 Hadoop提供的 HBase Shell
命令完成相同任務(wù)

(1) 列出 HBase所有的表的相關(guān)信息,例如表名。

a.Shell命令

HBase Shell:List

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖1.列出表名

b.java命令

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.*;

import org.apache.hadoop.hbase.client.*;

public class test1 {

public static Configuration configuration;

public static Connection connection;

public static Admin admin;

/**

* @param args

* 建立連接

*/

public static void init(){

configuration = HBaseConfiguration.create();

configuration.set(“hbase.rootdir”, “hdfs://localhost:9000/hbase”);

try{

connection = ConnectionFactory.createConnection(configuration);

admin = connection.getAdmin();

}catch(IOException e){

e.printStackTrace();

}

}

//關(guān)閉連接

public static void close(){

try{

if(admin != null){

admin.close();

}

if(null != connection){

connection.close();

}

}catch(IOException e){

e.printStackTrace();

}

}

/*

* 查看已有表

* @throws IOException

*/

public static void listTables() throws IOException{

init();

@SuppressWarnings(“deprecation”)

HTableDescriptor hTableDescriptors [] = admin.listTables();

for(HTableDescriptor hTableDescriptor : hTableDescriptors){

System.out.println(hTableDescriptor.getNameAsString());

}

close();

}

public static void main(String[] args) {

// TODO Auto-generated method stub

test1 t = new test1();

try{

System.out.println(“以下為Hbase數(shù)據(jù)庫(kù)中所存的表信息”);

t.listTables();

}catch (IOException e){

e.printStackTrace();

}

}

}

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖2.列出表名(java)

(2)在終端打印出指定的表的所有記錄數(shù)據(jù)。

a.Shell命令

scan ‘student’

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖3.打印指定表數(shù)據(jù)

b.java代碼

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.*;

import org.apache.hadoop.hbase.client.*;

import java.io.IOException;

import java.util.Scanner;

public class Test_2 {

public static Configuration configuration;

public static Connection connection;

public static Admin admin;

/**

* @param args

*/

//建立連接

public static void init(){

configuration = HBaseConfiguration.create();

configuration.set(“hbase.rootdir”,“hdfs://localhost:9000/hbase”);

try{

connection = ConnectionFactory.createConnection(configuration);

admin = connection.getAdmin();

}catch (IOException e){

e.printStackTrace();

}

}

//關(guān)閉連接

public static void close(){

try{

if(admin != null){

admin.close();

}

if(null != connection){

connection.close();

}

}catch (IOException e){

e.printStackTrace();

}

}

/**

* 根據(jù)表名查找表信息

*/

public static void getData(String tableName)throws IOException{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Scan scan = new Scan();

ResultScanner scanner = table.getScanner(scan);

for(Result result:scanner)

{

showCell((result));

}

close();

}

/**

* 格式化輸出

* @param result

*/

public static void showCell(Result result){

Cell[] cells = result.rawCells();

for(Cell cell:cells){

System.out.println(“RowName(行鍵):”+new
String(CellUtil.cloneRow(cell))+" ");

System.out.println(“Timetamp(時(shí)間戳):”+cell.getTimestamp()+" ");

System.out.println(“column Family(列簇):”+new
String(CellUtil.cloneFamily(cell))+" ");

System.out.println(“column Name(列名):”+new
String(CellUtil.cloneQualifier(cell))+" ");

System.out.println(“value:(值)”+new
String(CellUtil.cloneValue(cell))+" ");

System.out.println();

}

}

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

Test_2 t =new Test_2();

System.out.println(“請(qǐng)輸入要查看的表名”);

Scanner scan = new Scanner(System.in);

String tableName=scan.nextLine();

System.out.println(“信息如下:”);

t.getData(tableName);

}

}

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖4.打印指定表數(shù)據(jù)(java)

(3)向已經(jīng)創(chuàng)建好的表添加和刪除指定的列族或列。

a.Shell命令

put ‘student’,‘95001’,‘Sname’,‘LiYing’

put ‘student’,‘95001’,‘Ssex’,‘male’

put ‘student’,‘95001’,‘Sage’,‘22’

put ‘student’,‘95001’,‘Sdept’,‘CS’

put ‘student’,‘95001’,‘course:math’,‘80’

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖5.添加或刪除指定列族或列

b.java代碼

import java.io.IOException;

import java.util.Scanner;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.Cell;

import org.apache.hadoop.hbase.CellUtil;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.hbase.client.Admin;

import org.apache.hadoop.hbase.client.Connection;

import org.apache.hadoop.hbase.client.ConnectionFactory;

import org.apache.hadoop.hbase.client.Delete;

import org.apache.hadoop.hbase.client.Put;

import org.apache.hadoop.hbase.client.Result;

import org.apache.hadoop.hbase.client.ResultScanner;

import org.apache.hadoop.hbase.client.Scan;

import org.apache.hadoop.hbase.client.Table;

public class Test_3 {

public static Configuration configuration;

public static Connection connection;

public static Admin admin;

//建立連接

public static void init(){

configuration = HBaseConfiguration.create();

configuration.set(“hbase.rootdir”,“hdfs://localhost:9000/hbase”);

try{

connection = ConnectionFactory.createConnection(configuration);

admin = connection.getAdmin();

}catch (IOException e){

e.printStackTrace();

}

}

//關(guān)閉連接

public static void close(){

try{

if(admin != null){

admin.close();

}

if(null != connection){

connection.close();

}

}catch (IOException e){

e.printStackTrace();

}

}

/**

* 向某一行的某一列插入數(shù)據(jù)

* @param tableName 表名

* @param rowKey 行鍵

* @param colFamily 列族名

* @param col 列名(如果其列族下沒(méi)有子列,此參數(shù)可為空)

* @param val 值

* @throws IOException

*/

public static void insertRow(String tableName,String rowKey,String
colFamily,String col,String val) throws IOException {

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Put put = new Put(rowKey.getBytes());

put.addColumn(colFamily.getBytes(), col.getBytes(), val.getBytes());

table.put(put);

table.close();

close();

}

/**

* 根據(jù)表名查找表信息

*/

public static void getData(String tableName)throws IOException{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Scan scan = new Scan();

ResultScanner scanner = table.getScanner(scan);

for(Result result:scanner)

{

showCell((result));

}

close();

}

/**

* 格式化輸出

* @param result

*/

public static void showCell(Result result){

Cell[] cells = result.rawCells();

for(Cell cell:cells){

System.out.println(“RowName(行鍵):”+new
String(CellUtil.cloneRow(cell))+" ");

System.out.println(“Timetamp(時(shí)間戳):”+cell.getTimestamp()+" ");

System.out.println(“column Family(列簇):”+new
String(CellUtil.cloneFamily(cell))+" ");

System.out.println(“column Name(列名):”+new
String(CellUtil.cloneQualifier(cell))+" ");

System.out.println(“value:(值)”+new
String(CellUtil.cloneValue(cell))+" ");

System.out.println();

}

}

/**

* 刪除數(shù)據(jù)

* @param tableName 表名

* @param rowKey 行鍵

* @param colFamily 列族名

* @param col 列名

* @throws IOException

*/

public static void deleteRow(String tableName,String rowKey,String
colFamily,String col) throws IOException {

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Delete delete = new Delete(rowKey.getBytes());

boolean flag2 =true;

while(flag2)

{

System.out.println(“請(qǐng)輸入你的選擇 1-刪除列族的所有數(shù)據(jù)
2-指定列的數(shù)據(jù)”);

Scanner scanner=new Scanner(System.in);

String chooseString = scanner.nextLine();

switch (chooseString) {

case “1”:

{

//刪除指定列族的所有數(shù)據(jù)

delete.addFamily(colFamily.getBytes());

table.delete(delete);

table.close();

close();

break;

}

case “2”:

{

//刪除指定列的數(shù)據(jù)

delete.addColumn(colFamily.getBytes(), col.getBytes());

table.delete(delete);

table.close();

close();

break;

}

default:

{

System.out.println(" 你的輸入有誤 !?。?");

table.close();

close();

break;

}

}

System.out.println(" 你要繼續(xù)操作嗎? 是-true 否-false ");

flag2=scanner.nextBoolean();

}

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Test_3 t =new Test_3();

boolean flag =true;

while(flag)

{

System.out.println(“------------向已經(jīng)創(chuàng)建好的表中添加和刪除指定的列簇或列--------------------”);

System.out.println(" 請(qǐng)輸入您要進(jìn)行的操作 1- 添加 2-刪除 ");

Scanner scan = new Scanner(System.in);

String choose1=scan.nextLine();

switch (choose1) {

case “1”:

{

System.out.println(“請(qǐng)輸入要添加的表名”);

String tableName=scan.nextLine();

System.out.println(“請(qǐng)輸入要添加的表的行鍵”);

String rowKey=scan.nextLine();

System.out.println(“請(qǐng)輸入要添加的表的列簇”);

String colFamily=scan.nextLine();

System.out.println(“請(qǐng)輸入要添加的表的列名”);

String col=scan.nextLine();

System.out.println(“請(qǐng)輸入要添加的值”);

String val=scan.nextLine();

try {

t.insertRow(tableName, rowKey, colFamily, col, val);

System.out.println(“插入成功:”);

t.getData(tableName);

} catch (IOException e) {

// TODO Auto-generated catch block

e.getMessage();

}

break;

}

case “2”:

{

System.out.println(“請(qǐng)輸入要?jiǎng)h除的表名”);

String tableName=scan.nextLine();

System.out.println(“請(qǐng)輸入要?jiǎng)h除的表的行鍵”);

String rowKey=scan.nextLine();

System.out.println(“請(qǐng)輸入要?jiǎng)h除的表的列簇”);

String colFamily=scan.nextLine();

System.out.println(“請(qǐng)輸入要?jiǎng)h除的表的列名”);

String col=scan.nextLine();

try {

System.out.println(“----------------------表的原本信息如下---------------------”);

t.getData(tableName);

System.out.println(“____________________________正在執(zhí)行刪除操作…\n”);

t.deleteRow(tableName, rowKey, colFamily, col);

System.out.println(“____________________________刪除成功_______________\n”);

System.out.println(“---------------------刪除后
表的信息如下---------------------”);

t.getData(tableName);

} catch (IOException e) {

// TODO Auto-generated catch block

e.getMessage();

}

break;

}

default:

{

System.out.println(" 你的操作有誤 ?。?! ");

break;

}

}

System.out.println(" 你要繼續(xù)操作嗎? 是-true 否-false ");

flag=scan.nextBoolean();

}

System.out.println(" 程序已退出! ");

}

}

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖5.添加或刪除指定列族或列(java)

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖6.添加或刪除指定列族或列(java)

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖7.添加或刪除指定列族或列(java)

(4)清空指定的表的所有記錄數(shù)據(jù)。

a.Shell命令

truncate ‘student’

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖8.清空指定表的所有記錄

b.java代碼

import java.io.IOException;

import java.util.Scanner;

import java.util.ArrayList;

import java.util.List;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.Cell;

import org.apache.hadoop.hbase.CellUtil;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.HColumnDescriptor;

import org.apache.hadoop.hbase.HTableDescriptor;

import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.hbase.client.Admin;

import org.apache.hadoop.hbase.client.Connection;

import org.apache.hadoop.hbase.client.ConnectionFactory;

import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.Result;

import org.apache.hadoop.hbase.client.ResultScanner;

import org.apache.hadoop.hbase.client.Scan;

import org.apache.hadoop.hbase.client.Table;

import org.apache.hadoop.hbase.util.Bytes;

public class Test_4 {

public static Configuration configuration;

public static Connection connection;

public static Admin admin;

/**

* @param args

*/

//建立連接

public static void init(){

configuration = HBaseConfiguration.create();

configuration.set(“hbase.rootdir”,“hdfs://localhost:9000/hbase”);

try{

connection = ConnectionFactory.createConnection(configuration);

admin = connection.getAdmin();

}catch (IOException e){

e.printStackTrace();

}

}

//關(guān)閉連接

public static void close(){

try{

if(admin != null){

admin.close();

}

if(null != connection){

connection.close();

}

}catch (IOException e){

e.printStackTrace();

}

}

/**

* 清空制定的表的所有記錄數(shù)據(jù)

* @param args

* @throws IOException

*/

public static void clearRows(String tableName) throws IOException{

init();

// HBaseAdmin admin1=new HBaseAdmin(configuration);

// HTableDescriptor tDescriptor
=admin1.getTableDescriptor(Bytes.toBytes(tableName));//讀取了之前表的表名
列簇等信息,然后再進(jìn)行刪除操作。
總思想是先將原表結(jié)構(gòu)保留下來(lái),然后進(jìn)行刪除,再重新依據(jù)保存的信息重新創(chuàng)建表。

//備份表列族名

TableName tablename=TableName.valueOf(tableName);

HTableDescriptor tDescriptor = new

HTableDescriptor(TableName.valueOf(tableName));

Table table = connection.getTable(TableName.valueOf(tableName));

Scan scan = new Scan();

ResultScanner scanner = table.getScanner(scan);

List<String> cloFamily = new ArrayList<String>();

for(Result result:scanner)

{

Cell[] cells = result.rawCells();

for(Cell cell:cells){

// System.out.println(“column Family(列簇):”+new
String(CellUtil.cloneFamily(cell))+" ");

cloFamily.add(new String(CellUtil.cloneFamily(cell)));

}

}

//刪除表

admin.disableTable(tablename);

admin.deleteTable(tablename);

//重新建表

// HTableDescriptor tDescriptor = new

// HTableDescriptor(TableName.valueOf(tableName));

// tDescriptor.addFamily(new HColumnDescriptor(“name”));

for(String cf : cloFamily)

{

tDescriptor.addFamily(new HColumnDescriptor(cf));

}

admin.createTable(tDescriptor);

close();

}

/**

* 根據(jù)表名查找表信息

*/

public static void getData(String tableName)throws IOException{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Scan scan = new Scan();

ResultScanner scanner = table.getScanner(scan);

for(Result result:scanner)

{

showCell((result));

}

close();

}

/**

* 格式化輸出

* @param result

*/

public static void showCell(Result result){

Cell[] cells = result.rawCells();

for(Cell cell:cells){

System.out.println(“RowName(行鍵):”+new
String(CellUtil.cloneRow(cell))+" ");

System.out.println(“Timetamp(時(shí)間戳):”+cell.getTimestamp()+" ");

System.out.println(“column Family(列簇):”+new
String(CellUtil.cloneFamily(cell))+" ");

System.out.println(“column Name(列名):”+new
String(CellUtil.cloneQualifier(cell))+" ");

System.out.println(“value:(值)”+new
String(CellUtil.cloneValue(cell))+" ");

System.out.println();

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

Test_4 test_4=new Test_4();

Scanner scan = new Scanner(System.in);

System.out.println(“請(qǐng)輸入要清空的表名”);

String tableName=scan.nextLine();

try {

System.out.println(“表原來(lái)的信息:”);

test_4.getData(tableName);

test_4.clearRows(tableName);

System.out.println(“表已清空:”);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖9.清空指定表的所有記錄(java)

(5)統(tǒng)計(jì)表的行數(shù)

a.Shell命令

count ‘s1’

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖10.統(tǒng)計(jì)表的行數(shù)

b.java代碼

import java.io.IOException;

import java.util.Scanner;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.hbase.client.Admin;

import org.apache.hadoop.hbase.client.Connection;

import org.apache.hadoop.hbase.client.ConnectionFactory;

import org.apache.hadoop.hbase.client.Result;

import org.apache.hadoop.hbase.client.ResultScanner;

import org.apache.hadoop.hbase.client.Scan;

import org.apache.hadoop.hbase.client.Table;

public class Test_5 {

public static Configuration configuration;

public static Connection connection;

public static Admin admin;

//建立連接

public static void init(){

configuration = HBaseConfiguration.create();

configuration.set(“hbase.rootdir”,“hdfs://localhost:9000/hbase”);

try{

connection = ConnectionFactory.createConnection(configuration);

admin = connection.getAdmin();

}catch (IOException e){

e.printStackTrace();

}

}

//關(guān)閉連接

public static void close(){

try{

if(admin != null){

admin.close();

}

if(null != connection){

connection.close();

}

}catch (IOException e){

e.printStackTrace();

}

}

public static void countRows (String tableName) throws IOException

{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Scan scan = new Scan();

ResultScanner scanner =table.getScanner(scan);

int num = 0;

for(Result result = scanner.next();result!=null;result=scanner.next())

{

num++;

}

System.out.println(“行數(shù):”+num);

scanner.close();

close();

}

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

Test_5 test_5=new Test_5();

Scanner scan = new Scanner(System.in);

System.out.println(“請(qǐng)輸入要統(tǒng)計(jì)行數(shù)的表名”);

String tableName=scan.nextLine();

test_5.countRows(tableName);

}

}

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖11.統(tǒng)計(jì)表的行數(shù)(java)

2.HBase數(shù)據(jù)庫(kù)操作

(1)現(xiàn)有以下關(guān)系型數(shù)據(jù)庫(kù)中的表和數(shù)據(jù)(見(jiàn)表A-1~表A-3),要求將其轉(zhuǎn)換為適合于HBase存儲(chǔ)的表并插人數(shù)據(jù)。

a.創(chuàng)建學(xué)生表

create ‘student’,‘S_No’,‘S_Name’,‘S_Sex’,‘S_Age’

插入數(shù)據(jù):

插入shell命令

第一行數(shù)據(jù) put ‘Student’,‘s001’,‘S_No’,‘2015001’?
put ‘Student’,‘s001’,‘S_Name’,‘Zhangsan’?
put ‘Student’,‘s001’,‘S_Sex’,‘male’?
put ‘Student’,‘s001’,‘S_Age’,‘23’?
第二行數(shù)據(jù) put ‘Student’,‘s002’,‘S_No’,‘2015002’?
put ‘Student’,‘s002’,‘S_Name’,‘Mary’?
put ‘Student’,‘s002’,‘S_Sex’,‘female’?
put ‘Student’,‘s002’,‘S_Age’,‘22’?
第三行數(shù)據(jù) put ‘Student’,‘s003’,‘S_No’,‘2015003’?
put ‘Student’,‘s003’,‘S_Name’,‘Lisi’?
put ‘Student’,‘s003’,‘S_Sex’,‘male’?
put ‘Student’,‘s003’,‘S_Age’,‘24’

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖12.創(chuàng)建學(xué)生表

b.創(chuàng)建選課表

create ‘Course’,‘C_No’,‘C_Name’,‘C_Credit’

創(chuàng)建Course表

±----------------------------------±----------------------------------+
| | 插入shell命令 |
第一行數(shù)據(jù) put ‘Course’,‘c001’,‘C_No’,‘123001’
put ‘Course’,‘c001’,‘C_Name’,‘Math’
put ‘Course’,‘c001’,‘C_Credit’,‘2.0’

第二行數(shù)據(jù) put ‘Course’,‘c002’,‘C_No’,‘123002’
put ‘Course’,‘c002’,‘C_Name’,‘Computer Science’
put ‘Course’,‘c002’,‘C_Credit’,‘5.0’

第三行數(shù)據(jù) put ‘Course’,‘c003’,‘C_No’,‘123003’
put ‘Course’,‘c003’,‘C_Name’,‘English’
put ‘Course’,‘c003’,‘C_Credit’,‘3.0’

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖13.創(chuàng)建課程表

c.創(chuàng)建選課表

create ‘SC’,‘SC_Sno’,‘SC_Cno’,‘SC_Score’

插入數(shù)據(jù):

±----------------------------------±----------------------------------+
| | 插入shell命令 |
+=+=+
第一行數(shù)據(jù) put ‘SC’,‘sc001’,‘SC_Sno’,‘2015001’
put ‘SC’,‘sc001’,‘SC_Cno’,‘123001’
put ‘SC’,‘sc001’,‘SC_Score’,‘86’

第二行數(shù)據(jù) put ‘SC’,‘sc002’,‘SC_Sno’,‘2015001’
put ‘SC’,‘sc002’,‘SC_Cno’,‘123003’
put ‘SC’,‘sc002’,‘SC_Score’,‘69’

第三行數(shù)據(jù) put ‘SC’,‘sc003’,‘SC_Sno’,‘2015002’
put ‘SC’,‘sc003’,‘SC_Cno’,‘123002’
put ‘SC’,‘sc003’,‘SC_Score’,‘77’

第四行數(shù)據(jù) put ‘SC’,‘sc004’,‘SC_Sno’,‘2015002’
put ‘SC’,‘sc004’,‘SC_Cno’,‘123003’
put ‘SC’,‘sc004’,‘SC_Score’,‘99’

第五行數(shù)據(jù) put ‘SC’,‘sc005’,‘SC_Sno’,‘2015003’
put ‘SC’,‘sc005’,‘SC_Cno’,‘123001’
put ‘SC’,‘sc005’,‘SC_Score’,‘98’

第六行數(shù)據(jù) put ‘SC’,‘sc006’,‘SC_Sno’,‘2015003’
put ‘SC’,‘sc006’,‘SC_Cno’,‘123002’
put ‘SC’,‘sc006’,‘SC_Score’,‘95’

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖13.創(chuàng)建選課表

2.請(qǐng)編程實(shí)現(xiàn)以下功能

1.createTable(String tableName, String[] fields)

創(chuàng)建表,參數(shù) tableName 為表的名稱(chēng),字符串?dāng)?shù)組 fields 為存儲(chǔ)記錄各個(gè)字段名稱(chēng)的數(shù)組。要求當(dāng) HBase 已經(jīng)存在名為 tableName
的表的時(shí)候,先刪除原有的表,然后再創(chuàng)建新的表。

2.addRecord(String tableName, String row, String[] fields,
String[] values)

向表 tableName、行 row(用 S_Name 表示)和字符串?dāng)?shù)組 fields
指定的單元格中添加對(duì)應(yīng)的數(shù)據(jù) values。其中,fields
中每個(gè)元素如果對(duì)應(yīng)的列族下還有相應(yīng)的列限定符的話(huà),用"columnFamily:column"表示。例如,同時(shí)向"Math"、“Computer
Science”、"English"三列添加成績(jī)時(shí),字符串?dāng)?shù)組 fields 為{“Score:Math”,
“Score:Computer Science”, “Score:English”},數(shù)組

values 存儲(chǔ)這三門(mén)課的成績(jī)。

3.scanColumn(String tableName, String column)

瀏覽表 tableName 某一列的數(shù)據(jù),如果某一行記錄中該列數(shù)據(jù)不存在,則返回 null。要求當(dāng)參數(shù) column 為某一列族名稱(chēng)時(shí),如果底下有若干個(gè)列限定符,則要列出每個(gè)列限定符代表的列的數(shù)據(jù);當(dāng)參數(shù) column
為某一列具體名稱(chēng)(例如"Score:Math")時(shí),只需要列出該列的數(shù)據(jù)。

4.modifyData(String tableName, String row, String column)

修改表 tableName,行 row(可以用學(xué)生姓名 S_Name 表示),列 column
指定的單元格的數(shù)據(jù)。

5.deleteRow(String tableName, String row)

刪除表 tableName 中 row 指定的行的記錄。

java代碼:

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Scanner;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.Cell;

import org.apache.hadoop.hbase.CellUtil;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.HColumnDescriptor;

import org.apache.hadoop.hbase.HTableDescriptor;

import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.hbase.client.Admin;

import org.apache.hadoop.hbase.client.Connection;

import org.apache.hadoop.hbase.client.ConnectionFactory;

import org.apache.hadoop.hbase.client.Delete;

import org.apache.hadoop.hbase.client.Put;

import org.apache.hadoop.hbase.client.Result;

import org.apache.hadoop.hbase.client.ResultScanner;

import org.apache.hadoop.hbase.client.Scan;

import org.apache.hadoop.hbase.client.Table;

import org.apache.hadoop.hbase.util.Bytes;

public class Test_Two {

public static Configuration configuration;

public static Connection connection;

public static Admin admin;

//建立連接

public static void init(){

configuration = HBaseConfiguration.create();

configuration.set(“hbase.rootdir”,“hdfs://localhost:9000/hbase”);

try{

connection = ConnectionFactory.createConnection(configuration);

admin = connection.getAdmin();

}catch (IOException e){

e.printStackTrace();

}

}

//關(guān)閉連接

public static void close(){

try{

if(admin != null){

admin.close();

}

if(null != connection){

connection.close();

}

}catch (IOException e){

e.printStackTrace();

}

}

/**

*
建表。參數(shù)tableName為表的名稱(chēng),字符串?dāng)?shù)組fields為存儲(chǔ)記錄各個(gè)域名稱(chēng)的數(shù)組。

* 要求當(dāng)HBase已經(jīng)存在名為tableName的表時(shí),先刪除原有的表,然后再

* 創(chuàng)建新的表 field:列族

* @param myTableName 表名

* @param colFamily 列族名

* @throws IOException

*/

public static void createTable(String tableName,String[] fields)
throws IOException {

init();

TableName tablename = TableName.valueOf(tableName);

if(admin.tableExists(tablename)){

System.out.println(“表已存在,將執(zhí)行刪除原表,重建新表!”);

admin.disableTable(tablename);

admin.deleteTable(tablename);//刪除原來(lái)的表

}

// HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName);

HTableDescriptor hTableDescriptor = new

HTableDescriptor(TableName.valueOf(tableName));

for(String str:fields){

HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(str);

hTableDescriptor.addFamily(hColumnDescriptor);

}

admin.createTable(hTableDescriptor);

System.out.println(“表已創(chuàng)建成功”);

close();

}

/**

* 向表 tableName、行 row(用 S_Name 表示)和字符串?dāng)?shù)組 fields
指定的單元格中

* 添加對(duì)應(yīng)的數(shù)據(jù) values。

* 其中,fields 中每個(gè)元素如果對(duì)應(yīng)的列族下還有相應(yīng)的列限定符的話(huà),

* 用"columnFamily:column"表示。

* 例如,同時(shí)向"Math"、“Computer Science”、"English"三列添加成績(jī)時(shí),

* 字符串?dāng)?shù)組 fields 為{“Score:Math”, “Score:Computer Science”,
“Score:English”},

* 數(shù)組values 存儲(chǔ)這三門(mén)課的成績(jī)。

*/

public static void addRecord(String tableName,String rowKey,String
[]fields,String [] values) throws IOException {

init();

Table table = connection.getTable(TableName.valueOf(tableName));

for (int i = 0; i < fields.length; i++) {

Put put = new Put(rowKey.getBytes());

String [] cols = fields[i].split(“:”);

if(cols.length==1)

{

put.addColumn(cols[0].getBytes(), “”.getBytes(),
values[i].getBytes());//因?yàn)楫?dāng)輸入的是單列族,split僅讀出一個(gè)字符字符串,即cols僅有一個(gè)元素

}

else {

put.addColumn(cols[0].getBytes(), cols[1].getBytes(),
values[i].getBytes());

}

table.put(put);

}

table.close();

close();

}

/**

* 根據(jù)表名查找表信息

*/

public static void getData(String tableName)throws IOException{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Scan scan = new Scan();

ResultScanner scanner = table.getScanner(scan);

for(Result result:scanner)

{

showCell((result));

}

close();

}

/**

* 格式化輸出

* @param result

*/

public static void showCell(Result result){

Cell[] cells = result.rawCells();

for(Cell cell:cells){

System.out.println(“RowName(行鍵):”+new
String(CellUtil.cloneRow(cell))+" ");

System.out.println(“Timetamp(時(shí)間戳):”+cell.getTimestamp()+" ");

System.out.println(“column Family(列簇):”+new
String(CellUtil.cloneFamily(cell))+" ");

System.out.println(“column Name(列名):”+new
String(CellUtil.cloneQualifier(cell))+" ");

System.out.println(“value:(值)”+new
String(CellUtil.cloneValue(cell))+" ");

System.out.println();

}

}

/**

* 瀏覽表 tableName 某一列的數(shù)據(jù),如果某一行記錄中該列數(shù)據(jù)不存在,則返回
null。

* 要求當(dāng)參數(shù) column
為某一列族名稱(chēng)時(shí),如果底下有若干個(gè)列限定符,則要列出每個(gè)列限定符代表的列的數(shù)據(jù);

* 當(dāng)參數(shù) column
為某一列具體名稱(chēng)(例如"Score:Math")時(shí),只需要列出該列的數(shù)據(jù)。

* @param tableName

* @param column

* @throws IOException

*/

public static void scanColumn (String tableName,String column) throws
IOException

{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Scan scan = new Scan();

String [] cols = column.split(“:”);

if(cols.length==1)

{

scan.addFamily(Bytes.toBytes(column));

}

else {

scan.addColumn(Bytes.toBytes(cols[0]),Bytes.toBytes(cols[1]));

}

ResultScanner scanner = table.getScanner(scan);

for (Result result = scanner.next(); result !=null;result =
scanner.next()) {

showCell(result);

}

table.close();

close();

}

/**

* 修改表 tableName,行 row(可以用學(xué)生姓名 S_Name 表示),列 column
指定的單元格的數(shù)據(jù)。

* @throws IOException

*/

public static void modifyData(String tableName,String rowKey,String
column,String value) throws IOException

{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Put put = new Put(rowKey.getBytes());

String [] cols = column.split(“:”);

if(cols.length==1)

{

put.addColumn(column.getBytes(),“”.getBytes() ,
value.getBytes());//qualifier:列族下的列名

}

else {

put.addColumn(cols[0].getBytes(),cols[1].getBytes() ,
value.getBytes());//qualifier:列族下的列名

}

table.put(put);

table.close();

close();

}

/**

* 刪除表 tableName 中 row 指定的行的記錄。

* @throws IOException

*/

public static void deleteRow(String tableName,String rowKey) throws
IOException

{

init();

Table table = connection.getTable(TableName.valueOf(tableName));

Delete delete = new Delete(rowKey.getBytes());

table.delete(delete);

table.close();

close();

}

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

Test_Two test_Two = new Test_Two();

boolean flag =true;

while(flag)

{

System.out.println(“------------------------------------------------提供以下功能----------------------------------------------”);

System.out.println(" 1- createTable(創(chuàng)建表 ,提供表名、列族名) ");

System.out.println(" 2-addRecord (向已知表名、行鍵、列簇的表添加值)
");

System.out.println(" 3- ScanColumn(瀏覽表 某一列的數(shù)據(jù)) ");

System.out.println(" 4- modifyData(修改某表
某行,某一列,指定的單元格的數(shù)據(jù)) ");

System.out.println(" 5- deleteRow(刪除 某表 某行的記錄) ");

System.out.println(“------------------------------------------------------------------------------------------------------------------”);

Scanner scan = new Scanner(System.in);

String choose1=scan.nextLine();

switch (choose1) {

case “1”:

{

System.out.println(“請(qǐng)輸入要?jiǎng)?chuàng)建的表名”);

String tableName=scan.nextLine();

System.out.println(“請(qǐng)輸入要?jiǎng)?chuàng)建的表的列族個(gè)數(shù)”);

int Num=scan.nextInt();

String [] fields = new String[Num];

System.out.println(“請(qǐng)輸入要?jiǎng)?chuàng)建的表的列族”);

/* Scanner scanner = new Scanner(System.in); scanner.next
如不是全局,即會(huì)記得上一次輸出。相同地址讀入值時(shí)*/

for(int i=0;i< fields.length;i++)

{

/*BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));

fields[i] = in.readLine();*/

/*fields[i]=scan.next(); 因?yàn)橹皼](méi)有輸入過(guò),所以可以讀入新值*/

scan = new Scanner(System.in);

fields[i]=scan.nextLine();

}

System.out.println(“正在執(zhí)行創(chuàng)建表的操作”);

test_Two.createTable(tableName,fields);

break;

}

case “2”:

{

System.out.println(“請(qǐng)輸入要添加數(shù)據(jù)的表名”);

String tableName=scan.nextLine();

System.out.println(“請(qǐng)輸入要添加數(shù)據(jù)的表的行鍵”);

String rowKey=scan.nextLine();

System.out.println(“請(qǐng)輸入要添加數(shù)據(jù)的表的列的個(gè)數(shù)”);

int num =scan.nextInt();

String fields[]=new String[num];

System.out.println(“請(qǐng)輸入要添加數(shù)據(jù)的表的列信息 共”+num+“條信息”);

for(int i=0;i< fields.length;i++)

{

BufferedReader in3= new BufferedReader(new
InputStreamReader(System.in));

fields[i] = in3.readLine();

/*fields[i]=scan.next(); 因?yàn)橹皼](méi)有輸入過(guò),所以可以讀入新值*/

}

System.out.println(“請(qǐng)輸入要添加的數(shù)據(jù)信息 共”+num+“條信息”);

String values[]=new String[num];

for(int i=0;i< values.length;i++)

{

BufferedReader in2 = new BufferedReader(new
InputStreamReader(System.in));

values[i] = in2.readLine();

}

System.out.println(“原表信息”);

test_Two.getData(tableName);

System.out.println(“正在執(zhí)行向表中添加數(shù)據(jù)的操作…\n”);

test_Two.addRecord(tableName, rowKey, fields, values);

System.out.println(“\n添加后的表的信息…”);

test_Two.getData(tableName);

break;

}

case “3”:

{

System.out.println(“請(qǐng)輸入要查看數(shù)據(jù)的表名”);

String tableName=scan.nextLine();

System.out.println(“請(qǐng)輸入要查看數(shù)據(jù)的列名”);

String column=scan.nextLine();

System.out.println(“查看的信息如下:…\n”);

test_Two.scanColumn(tableName, column);

break;

}

case “4”:

{

System.out.println(“請(qǐng)輸入要修改數(shù)據(jù)的表名”);

String tableName=scan.nextLine();

System.out.println(“請(qǐng)輸入要修改數(shù)據(jù)的表的行鍵”);

String rowKey=scan.nextLine();

System.out.println(“請(qǐng)輸入要修改數(shù)據(jù)的列名”);

String column=scan.nextLine();

System.out.println("請(qǐng)輸入要修改的數(shù)據(jù)信息 ");

String value=scan.nextLine();

System.out.println(“原表信息如下:…\n”);

test_Two.getData(tableName);

System.out.println(“正在執(zhí)行向表中修改數(shù)據(jù)的操作…\n”);

test_Two.modifyData(tableName, rowKey, column, value);

System.out.println(“\n修改后的信息如下:…\n”);

test_Two.getData(tableName);

break;

}

case “5”:

{

System.out.println(“請(qǐng)輸入要?jiǎng)h除指定行的表名”);

String tableName=scan.nextLine();

System.out.println(“請(qǐng)輸入要?jiǎng)h除指定行的行鍵”);

String rowKey=scan.nextLine();

System.out.println(“原表信息如下:…\n”);

test_Two.getData(tableName);

System.out.println(“正在執(zhí)行向表中刪除數(shù)據(jù)的操作…\n”);

test_Two.deleteRow(tableName, rowKey);

System.out.println(“\n刪除后的信息如下:…\n”);

test_Two.getData(tableName);

break;

}

default:

{

System.out.println(" 你的操作有誤 ?。?! ");

break;

}

}

System.out.println(" 你要繼續(xù)操作嗎? 是-true 否-false ");

flag=scan.nextBoolean();

}

System.out.println(" 程序已退出! ");

}

}

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖14.創(chuàng)建表功能(java)

實(shí)驗(yàn)三:熟悉常用的HBase操作

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖15.增加記錄功能(java)

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖16.瀏覽表功能(java)

實(shí)驗(yàn)三:熟悉常用的HBase操作

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖17.修改表功能(java)

實(shí)驗(yàn)三:熟悉常用的HBase操作

圖18.刪除表功能(java)

3、出現(xiàn)的問(wèn)題:

1、安裝HBase2.2.2并測(cè)試HBase版本的時(shí)候遇到

錯(cuò)誤: 找不到或無(wú)法加載主類(lèi)
org.apache.hadoop.hbase.util.GetJavaProperty

實(shí)驗(yàn)三:熟悉常用的HBase操作

2、用java寫(xiě)清空數(shù)據(jù)表的時(shí)候遇到報(bào)錯(cuò):

Table should have at least one column family. Set
hbase.table.sanity.checks to false at conf or table descriptor if you
want to bypass sanity checks

實(shí)驗(yàn)三:熟悉常用的HBase操作

3、按照教材寫(xiě)java代碼時(shí),遇到一個(gè)錯(cuò)誤實(shí)驗(yàn)三:熟悉常用的HBase操作

Multiple markers at this line

- The type HTableDescriptor is deprecated

- The constructor HTableDescriptor(String) is

undefined

4、解決方案:

1、問(wèn)題原因是:因?yàn)?Hbase 沒(méi)有將其自身的依賴(lài)包添加到 classpath
配置路徑所以才會(huì)導(dǎo)致找不到自身主類(lèi)的報(bào)錯(cuò)。

查看了博客:https://blog.csdn.net/weixin_45702261/article/details/120587547?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~Rate-1.pc_relevant_antiscanv2&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~Rate-1.pc_relevant_antiscanv2&utm_relevant_index=1

進(jìn)入/usr/local/hbase/conf/hbase-env文件,將最后一行不允許注釋?zhuān)瑔?wèn)題得到解決

實(shí)驗(yàn)三:熟悉常用的HBase操作

2、錯(cuò)誤的原因是:創(chuàng)建Hbase數(shù)據(jù)表時(shí)至少要有一個(gè)列族名,而清空數(shù)據(jù)表的java代碼其實(shí)是刪除了整個(gè)數(shù)據(jù)表再重新建一個(gè)有著原表列族名的空表,此時(shí)要先將原表的列族名用String數(shù)組備份,再重新建表的時(shí)候依次重新添加列族名即可,代碼如下:

實(shí)驗(yàn)三:熟悉常用的HBase操作

3、教材的Hbase版本較老,我使用的的是HBase2.2.2版本較新,那一句的語(yǔ)法API已經(jīng)修改了,用HTableDescriptor
hTableDescriptor =new HTableDescriptor(TableName.valueOf(tableName));

代替HTableDescriptor hTableDescriptor = new
HTableDescriptor(tableName);即可。
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-403227.html

到了這里,關(guān)于實(shí)驗(yàn)三:熟悉常用的HBase操作的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 熟悉常用的HBase操作

    熟悉常用的HBase操作

    理解HBase在Hadoop體系結(jié)構(gòu)中的角色; 熟練使用HBase操作常用的Shell命令; 操作系統(tǒng):Linux Hadoop版本:3.1.3 HBase版本:2.2.2 JDK版本:1.8 1.用Hadoop提供的HBase Shell命令實(shí)現(xiàn)以下指定功能: 準(zhǔn)備工作: 啟動(dòng)hbash: 進(jìn)入shell: (1)列出HBase所有的表的相關(guān)信息,例如表名; (2)在終端打

    2023年04月17日
    瀏覽(21)
  • 實(shí)驗(yàn)2熟悉常用的HDFS操作

    實(shí)驗(yàn)2熟悉常用的HDFS操作

    (1)理解HDFS在Hadoop體系結(jié)構(gòu)中的角色; (2)熟練使用HDFS操作常用的Shell命令; (3)熟悉HDFS操作常用的Java API。 (1)操作系統(tǒng):Linux; (2)Hadoop版本:2.7.4 ; (3)JDK版本1.8; (4)Java IDE:eclipse ?。 (一)編程實(shí)現(xiàn)以下功能,并利用Hadoop提供的Shell命令完成相同任務(wù):

    2023年04月18日
    瀏覽(25)
  • 大數(shù)據(jù)實(shí)驗(yàn) 實(shí)驗(yàn)二:熟悉HDFS常用操作

    大數(shù)據(jù)實(shí)驗(yàn) 實(shí)驗(yàn)二:熟悉HDFS常用操作

    附件中有word版本的實(shí)驗(yàn)報(bào)告 理解HDFS在Hadoop體系結(jié)構(gòu)中的角色。 熟練使用HDFS操作常用的Shell命令。 熟悉HDFS操作常用的Java API。 Oracle VM VirtualBox虛擬機(jī) 系統(tǒng)版本centos7 JDK1.8版本 Hadoop-3.1.3 Windows11 Java IDE:IDEA 1.向HDFS中上傳任意文本文件,如果指定的文件在HDFS中已經(jīng)存在,由用戶(hù)

    2024年04月12日
    瀏覽(27)
  • 大數(shù)據(jù)編程實(shí)驗(yàn)二:熟悉常用的HDFS操作

    大數(shù)據(jù)編程實(shí)驗(yàn)二:熟悉常用的HDFS操作

    實(shí)驗(yàn)?zāi)康?1、理解HDFS在Hadoop體系結(jié)構(gòu)中的角色 2、熟悉使用HDFS操作常用的Shell命令 3、熟悉HDFS操作常用的Java API 實(shí)驗(yàn)平臺(tái) 1、操作系統(tǒng):Windows 2、Hadoop版本:3.1.3 3、JDK版本:1.8 4、Java IDE:IDEA 前期:一定要先啟動(dòng)hadoop ? 1、編程實(shí)現(xiàn)以下功能,并利用Hadoop提供的Shell命令完成相

    2024年02月08日
    瀏覽(27)
  • 大數(shù)據(jù) | 實(shí)驗(yàn)一:大數(shù)據(jù)系統(tǒng)基本實(shí)驗(yàn) | 熟悉常用的HDFS操作

    大數(shù)據(jù) | 實(shí)驗(yàn)一:大數(shù)據(jù)系統(tǒng)基本實(shí)驗(yàn) | 熟悉常用的HDFS操作

    1 )理解 HDFS 在 Hadoop 體系結(jié)構(gòu)中的角色。 2 )熟練使用 HDFS 操作常用的 shell 命令。 3 )熟悉 HDFS 操作常用的 Java API。 1 )操作系統(tǒng):Linux; 2 )Hadoop 版本:3.2.2; 3 )JDK 版本:1.8; 4 )Java IDE:Eclipse。 編程實(shí)現(xiàn) 以下功能,并利用 Hadoop 提供的 Shell 命令 完成相同任務(wù) 1)向

    2024年02月02日
    瀏覽(24)
  • 云計(jì)算 熟悉常用的LINUX操作和hadoop部署相關(guān)操作 實(shí)驗(yàn)報(bào)告

    云計(jì)算 熟悉常用的LINUX操作和hadoop部署相關(guān)操作 實(shí)驗(yàn)報(bào)告

    《云計(jì)算系統(tǒng)架構(gòu)及應(yīng)用》實(shí)驗(yàn)報(bào)告 題目: 熟悉常用的LINUX操作和hadoop部署相關(guān)操作 姓名 日期 實(shí)驗(yàn)環(huán)境:? 操作系統(tǒng):Linux Hadoop版本:2.7.3 實(shí)驗(yàn)內(nèi)容與完成情況: (一)熟悉常用的Linux 操作 請(qǐng)按要求上機(jī)實(shí)踐如下linux基本命令。 cd命令:切換目錄 (1)切換到目錄 /usr/lo

    2024年02月05日
    瀏覽(18)
  • 大數(shù)據(jù)技術(shù)原理及應(yīng)用課實(shí)驗(yàn)2 :熟悉常用的HDFS操作

    大數(shù)據(jù)技術(shù)原理及應(yīng)用課實(shí)驗(yàn)2 :熟悉常用的HDFS操作

    實(shí)驗(yàn)2 ?熟悉常用的HDFS操作 目錄 實(shí)驗(yàn)2 ?熟悉常用的HDFS操作 一、實(shí)驗(yàn)?zāi)康?二、實(shí)驗(yàn)平臺(tái) 三、實(shí)驗(yàn)步驟(每個(gè)步驟下均需有運(yùn)行截圖) (一)編程實(shí)現(xiàn)以下功能,并利用Hadoop提供的Shell命令完成相同任務(wù): (1)向HDFS中上傳任意文本文件,如果指定的文件在HDFS中已經(jīng)存在,則

    2024年04月14日
    瀏覽(36)
  • 熟悉常用的HDFS操作(大數(shù)據(jù)技術(shù)原理與應(yīng)用-第三章實(shí)驗(yàn))

    熟悉常用的HDFS操作(大數(shù)據(jù)技術(shù)原理與應(yīng)用-第三章實(shí)驗(yàn))

    首先啟動(dòng)Hadoop,命令如下: 在終端輸入如下命令,查看 hdfs dfs 總共支持哪些操作: 上述命令執(zhí)行后,會(huì)顯示如下的結(jié)果: 如果顯示 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable ,說(shuō)明環(huán)境變量 JAVA_LIBRARY_PATH 并未定義,首

    2024年02月01日
    瀏覽(20)
  • 實(shí)驗(yàn)二、熟悉常用的HDFS操作(HDFS JavaAPI之讀取/上傳/刪除文件)

    實(shí)驗(yàn)二、熟悉常用的HDFS操作(HDFS JavaAPI之讀取/上傳/刪除文件)

    理解HDFS在Hadoop體系結(jié)構(gòu)中的角色 熟練使用HDFS操作常用的shell命令 熟悉HDFS操作常用的Java API 操作系統(tǒng):CentOS 8 Hadoop版本:3.3.1 jdk版本:1.8 Java IDE:Eclipse 1. 使用Hadoop命令操作分布式文件系統(tǒng)。 新建目錄 在本地和hadoop中分別創(chuàng)建文件夾: 在本地創(chuàng)建目錄: Hadoop創(chuàng)建目錄: 上

    2023年04月08日
    瀏覽(29)
  • 實(shí)驗(yàn)六:熟悉Hive的基本操作

    由于CSDN上傳md文件總是會(huì)使圖片失效 完整的實(shí)驗(yàn)文檔地址如下: https://download.csdn.net/download/qq_36428822/85709631?spm=1001.2014.3001.5501 題目:實(shí)驗(yàn)六:熟悉Hive的基本操作 姓名:小豬豬 日期:2022/5/15 設(shè)備名稱(chēng) LAPTOP-9KJS8HO6 處理器 Intel? Core? i5-10300H CPU @ 2.50GHz 2.50 GHz 機(jī)帶 RAM 16.0 GB (1

    2024年02月08日
    瀏覽(27)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包