feat(spark-lesson): spark实验五部分内容,添加新的 Spark RDD 操作示例

- 新增了 6 个 Spark RDD 操作示例程序
- 包括求平均分、低于 60 分的成绩、最低2 个成绩、二次排序等操作
- 示例程序展示了 Spark RDD 的基本操作和常用算子的使用方法
This commit is contained in:
2025-04-20 14:42:17 +08:00
parent 630e102a52
commit 2840970cb0
7 changed files with 313 additions and 9 deletions

View File

@@ -11,8 +11,9 @@ import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Arrays;
public class task_DML_select {
public static void main(String[] args) throws Exception {
@@ -27,7 +28,11 @@ public class task_DML_select {
Table table = conn.getTable(TableName.valueOf("ideaPro_space:students"));
scanRows(table);
// scanRows(table);
// getKeyValue(table,"000000");
getFamily(table);
// 关闭连接
table.close();
@@ -40,20 +45,20 @@ public class task_DML_select {
*
* @param table
*/
public static void getKeyValue(Table table) throws IOException {
public static void getKeyValue(Table table,String rowKey) throws IOException {
String rowKey = "000010";
// String rowKey = "000010";
Get getParam = new Get(Bytes.toBytes(rowKey));
getParam.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("age"));
getParam.addColumn(Bytes.toBytes("extra_info"), Bytes.toBytes("salary"));
Result result = table.get(getParam);
byte[] value = result.getValue(Bytes.toBytes("base_info"), Bytes.toBytes("age"));
byte[] value = result.getValue(Bytes.toBytes("extra_info"), Bytes.toBytes("salary"));
int age = Bytes.toInt(value);
String age = Bytes.toString(value);
System.out.println(age);
@@ -70,10 +75,10 @@ public class task_DML_select {
*/
public static void getFamily(Table table) throws IOException {
String rowKey = "000010";
String rowKey = "000000";
Get getParam = new Get(Bytes.toBytes(rowKey));
getParam.addFamily(Bytes.toBytes("base_info"));
getParam.addFamily(Bytes.toBytes("extra_info"));
Result result = table.get(getParam);
CellScanner cellScanner = result.cellScanner();