更改表列名称拼写格式Hadoop

时间:2019-03-24 17:51:47

标签: hadoop hive hdfs parquet

我的桌子上有a,b,c列。 hdfs上的数据存储为实木复合地板,即使该实木复合地板已经使用a,b,c模式编写,也可以更改特定的列名吗?

3 个答案:

答案 0 :(得分:0)

尝试使用ALTER TABLE

desc p;

+-------------------------+------------+----------+--+
|        col_name         | data_type  | comment  |
+-------------------------+------------+----------+--+
| category_id             | int        |          |
| category_department_id  | int        |          |
| category_name           | string     |          |
+-------------------------+------------+----------+--+

alter table p change column category_id id int

desc p;
+-------------------------+------------+----------+--+
|        col_name         | data_type  | comment  |
+-------------------------+------------+----------+--+
| id                      | int        |          |
| category_department_id  | int        |          |
| category_name           | string     |          |
+-------------------------+------------+----------+--+

答案 1 :(得分:0)

循环读取文件 用更改的列名创建一个新的df 在附加模式下在另一个目录中写入新的df 将这个新目录移动到读取目录


cmd=['hdfs', 'dfs', '-ls', OutDir]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for i in process.communicate():
 if i:
    for j in i.decode('utf-8').strip().split():
       if j.endswith('snappy.parquet'):
          print('reading file ',j)
          mydf  = spark.read.format("parquet").option("inferSchema","true")\
          .option("header", "true")\
          .load(j)
          print('df built on bad file ')
          mydf.createOrReplaceTempView("dtl_rev")
          ssql="""select old-name AS new_name,
          old_col AS new_col from dtl_rev"""
          newdf=spark.sql(ssql)
          print('df built on renamed file ')
          aggdf.write.format("parquet").mode("append").save(newdir)

答案 2 :(得分:0)

我们无法在现有文件中重命名列名,镶木地板将架构存储在数据文件中, 我们可以使用以下命令检查架构 实木复合地板工具架构part-m-00000.parquet

我们必须将备份备份到临时表中并重新记录历史数据。

相关问题