既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
private String name;
private String studentName;
private Integer studentAge;
}
/**
* HBabse 测试类
/
public class HBaseTest {
/*
* 获取连接对象
* @return
* @throws IOException
*/
private static Connection connection = null;
/**
* 日志类
*/
private static final Logger LOGGER = LoggerFactory.getLogger(HBaseTest.class);
/**
* 获取连接
* @return
* @throws IOException
*/
public static Connection getConnection() throws IOException {
Configuration configuration = HBaseConfiguration.create();
configuration.set(“hbase.zookeeper.property.clientPort”,“2181”);
configuration.set(“hbase.zookeeper.quorum”,“192.168.64.128,192.168.64.130,192.168.64.131,192.168.64.133”);
configuration.set(“hbase.master”,“192.168.64.128:16010”);
synchronized(HBaseTest.class){
if(null==connection){
connection = ConnectionFactory.createConnection(configuration);
}
}
return connection;
}
/**
* 创建表
* @param tableName
* @param cols
* @throws IOException
*/
public static void createTable(String tableName,String [] cols) throws IOException {
TableName name = TableName.valueOf(tableName);
Admin admin = getConnection().getAdmin();
if(admin.tableExists(name)){
System.out.println(“表已经存在”);
}else {
TableDescriptorBuilder.ModifyableTableDescriptor descriptor = (TableDescriptorBuilder.ModifyableTableDescriptor) TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName)).build();
for(String col: cols){
ColumnFamilyDescriptor columnDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(col.getBytes()).build();
descriptor.setColumnFamily(columnDescriptor);
}
admin.createTable(descriptor);
}
}
/**
* 插入数据
* @param tableName
* @param student
* @throws IOException
*/
public static void insert(String tableName, StudentBean student) throws IOException {
Table table = getConnection().getTable(TableName.valueOf(tableName));
Put put = new Put((“stu”+student.getStudentNo()).getBytes());
put.addColumn(“stu_name”.getBytes(),“student_name”.getBytes(),student.getStudentName().getBytes());
put.addColumn(“stu_name”.getBytes(),“name”.getBytes(),student.getStudentName().getBytes());
put.addColumn(“stu_age”.getBytes(),“student_age”.getBytes(),(“”+student.getStudentAge()).getBytes());
table.put(put);
}
public static List getColumnFamilyNames(String tableName) throws IOException {
Table table = getConnection().getTable(TableName.valueOf(tableName));
TableDescriptor tableDescriptor = table.getDescriptor();
List columnFamilyNames = new ArrayList<>();
for(ColumnFamilyDescriptor columnFamilyDescriptor :tableDescriptor.getColumnFamilies()){
columnFamilyNames.add(columnFamilyDescriptor.getNameAsString());
}
return columnFamilyNames;
}
public static Set getFamilyNames(String tableName) throws IOException {
Table table = getConnection().getTable(TableName.valueOf(tableName));
TableDescriptor descriptor = table.getDescriptor();
Set<byte[]> familySet = descriptor.getColumnFamilyNames();
Set familyNameSet = familySet.stream().map(byteValue -> Bytes.toString(byteValue)).collect(Collectors.toSet());
return familyNameSet;
}
public static List getAllData(String tableName) throws IOException {
Table descriptor = getConnection().getTable(TableName.valueOf(tableName));
Scan scan = new Scan();
scan.setStartRow(“stu1”.getBytes());
scan.setStopRow(“stu1000”.getBytes());
scan.addColumn(“stu_name”.getBytes(),“student_name”.getBytes());
ResultScanner results = descriptor.getScanner(scan);
List studentBeans = new ArrayList<>();
for(Result result: results){
if(!result.isEmpty()){
StudentBean studentBean = new StudentBean();
String rowKey = new String(result.getRow());
int studentNo = Integer.parseInt(rowKey.substring(3));
studentBean.setStudentNo(studentNo);
for(Cell cell: result.rawCells()){
String name = Bytes.toString(cell.getQualifierArray(),cell.getQualifierOffset(),cell.getQualifierLength());
String value = Bytes.toString(cell.getValueArray(),cell.getValueOffset(),cell.getValueLength());
if(name.equals(“student_name”)){
studentBean.setStudentName(value);
}
if(name.equals(“student_age”)){
studentBean.setStudentAge(Integer.parseInt(value));
}
if(name.equals(“name”)){
studentBean.setName(value);
}
}
studentBeans.add(studentBean);
}
}
return studentBeans;
}
public static StudentBean getRowByRowKey(String tableName,Integer rowKey) throws IOException {
StudentBean studentBean = new StudentBean();
studentBean.setStudentNo(rowKey);
Get get = new Get((“stu”+rowKey).getBytes());
Table table = getConnection().getTable(TableName.valueOf(tableName));
if(!get.isCheckExistenceOnly()){
Result result = table.get(get);
for(Cell cell: result.rawCells()){
String name = Bytes.toString(cell.getQualifierArray(),cell.getQualifierOffset(),cell.getQualifierLength());
String value = Bytes.toString(cell.getValueArray(),cell.getValueOffset(),cell.getValueLength());
if(name.equals(“student_name”)){
studentBean.setStudentName(value);
}
if(name.equals(“student_age”)){
studentBean.setStudentAge(Integer.parseInt(value));
}
}
}
return studentBean;
}
public static void updateTable(String tableName) throws IOException {
HTable table = (HTable)getConnection().getTable(TableName.valueOf(tableName));
Put put = new Put(“stu-1”.getBytes());
put.addColumn(“stu_name”.getBytes(),“name”.getBytes(),UUID.randomUUID().toString().getBytes());
table.put(put);
table.clearRegionCache();
}
public void deteleTable(String tableName) throws IOException {
Table table = getConnection().getTable(TableName.valueOf(tableName));
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
95%以上大数据知识点,真正体系化!**
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新