HDFS(一)增删改查操作

HDFS之增删改查操作

零、启动集群,Web查看hdfs系统

1.搭建过程:https://blog.csdn.net/qq_31316733/article/details/108386424

hadoop11 192.168.1.11
hadoop12 192.168.1.12
hadoop13 192.168.1.13
hadoop11 hadoop12 hadoop13
HDFS NameNode DataNode DataNode SecondaryNameNode DataNode
YARN NodeManager ResourceManager NodeManager NodeManager

2.Web端查看hdfs系统

namenode:http://hadoop11:9870 #查看hdfs文件系统

resourcemanager:http://hadoop12:8088

JobHistory:http://hadoop11:19888/jobhistory

一、Shell操作:linux本地–>hdfs系统

1.增

#剪切:linux-->hdfs
hadoop fs  -moveFromLocal  [linux路径下文件]  [hdfs系统路径]
#复制:linux-->hdfs
hadoop fs -copyFromLocal [linux路径下文件]  [hdfs系统路径]
hadoop fs -put [linux路径下文件]  [hdfs系统路径]
#追加内容到末尾:linux-->hdfs
hadoop fs -appendToFile [linux路径下文件]  [hdfs系统路径]
#复制:hdfs-->hdfs
hadoop fs -cp [hdfs系统路径] [hdfs系统路径]
#新建目录:hdfs
hadoop fs -mkdir -p [hdfs系统路径]
#从hdfs下载到linux本地:hdfs-->linux
hadoop fs -copyToLocal [hdfs系统路径] [linux系统路径]
hadoop fs -get [hdfs系统路径] [linux系统路径]
#3)从hdfs下载到linux本地多个文件,并执行合并操作
hadoop fs -getmerge [hdfs系统路径下多个文件] [linux系统路径]
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Iceberg是一个开源的表格管理库,可以将数据存储在云存储中,如Hadoop HDFS、Amazon S3等,并提供了增删改查的功能。而Flink是一个开源的流处理框架,可以处理实时数据流。 要在Flink中使用Iceberg进行增删改查操作,需要使用Iceberg的Flink集成库。以下是一些示例代码来说明如何进行增删改查操作: 1. 创建Iceberg表: ```java import org.apache.flink.table.catalog.CatalogTable; import org.apache.flink.table.catalog.GenericInMemoryCatalog; import org.apache.iceberg.flink.CatalogLoader; import org.apache.iceberg.flink.TableLoader; import org.apache.iceberg.flink.TableLoaderOptions; import org.apache.iceberg.Table; import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.types.Types; // 创建一个内存catalog GenericInMemoryCatalog catalog = new GenericInMemoryCatalog("my_catalog"); // 创建一个表格 CatalogTable table = new CatalogTable( TableSchema.builder() .field("id", DataTypes.INT()) .field("name", DataTypes.STRING()) .build(), CatalogTableOptions.builder() .withCatalogTableType(CatalogTableType.MANAGED) .build() ); // 注册表格到catalog catalog.createTable(new ObjectPath("default", "my_table"), table, false); // 加载catalog和table CatalogLoader catalogLoader = CatalogLoader.hive("my_catalog"); TableLoader tableLoader = TableLoader.fromCatalog(catalogLoader); Table table = tableLoader.load(TableIdentifier.of("default", "my_table")); // 添加数据到表格 DataFile file = DataFiles.builder(table.spec()) .withInputFile(new Path("/path/to/data.parquet")) .withFormat(FileFormat.PARQUET) .build(); table.newAppend().appendFile(file).commit(); // 查询表格数据 table.newScan().project("id", "name").asEnumerable().forEach(row -> { System.out.println(row.get(0) + " " + row.get(1)); }); // 删除表格 table.delete(); ``` 2. 查询Iceberg表: ```java import org.apache.flink.table.api.Table; import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; import org.apache.iceberg.flink.CatalogLoader; import org.apache.iceberg.flink.TableLoaderOptions; import org.apache.iceberg.Table; import org.apache.iceberg.catalog.TableIdentifier; // 创建StreamTableEnvironment StreamTableEnvironment tEnv = StreamTableEnvironment.create(env); // 加载catalog和table CatalogLoader catalogLoader = CatalogLoader.hive("my_catalog"); TableLoaderOptions options = new TableLoaderOptions(); options.setTableIdentifier(TableIdentifier.of("default", "my_table")); Table table = TableLoader.fromCatalog(catalogLoader, options).load(); // 将Iceberg表格注册为Flink表 tEnv.createTemporaryView("my_table", table); // 查询表格数据 Table result = tEnv.sqlQuery("SELECT id, name FROM my_table WHERE id > 100"); result.toRetractStream(Row.class).print(); ``` 3. 修改Iceberg表: ```java import org.apache.iceberg.Schema; import org.apache.iceberg.Table; import org.apache.iceberg.types.Types; // 加载catalog和table CatalogLoader catalogLoader = CatalogLoader.hive("my_catalog"); TableLoaderOptions options = new TableLoaderOptions(); options.setTableIdentifier(TableIdentifier.of("default", "my_table")); Table table = TableLoader.fromCatalog(catalogLoader, options).load(); // 修改表格Schema Schema schema = new Schema( Types.NestedField.optional(1, "id", Types.IntegerType.get()), Types.NestedField.optional(2, "name", Types.StringType.get()), Types.NestedField.optional(3, "age", Types.IntegerType.get()) ); table.updateSchema().addColumn("age", Types.IntegerType.get()).commit(); // 修改表格数据 table.newUpdate() .set("age", 30) .where("id = 1") .commit(); ``` 这些示例代码演示了如何在Flink中使用Iceberg进行增删改查操作。你可以根据自己的需求来调整代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值