https://delta.io logo
s

Srinivas Maganti

08/24/2023, 12:26 PM
Hi guys. I am trying to convert tables columns names upper case to lower case . For that i am using below code. for table in table_list:     spark.sql(f'''ALTER TABLE {table}         SET TBLPROPERTIES (         'delta.columnMapping.mode' = 'name',         'delta.minReaderVersion' = '1',         'delta.minWriterVersion' = '2')''')     print(table)     col_list=spark.table(table).columns     if len(col_list) > 0 :         for col in col_list:             spark.sql(f'''ALTER TABLE {table} RENAME COLUMN {col} to {col+'_tmp'} ''')             spark.sql(f'''ALTER TABLE {table} RENAME COLUMN {col+'_tmp'} to {col.lower()} ''') I am getting below error in sometimes if i rerun its working fine. AnalysisException: org.apache.hadoop.hive.ql.metadata.HiveException: at least one column must be specified for the table Can anyone help me out here why i am getting above error. Thanks
i

Itagyba Abondanza Kuhlmann

08/24/2023, 11:45 PM
Did you try something like:
Copy code
(spark.read.table(...)
  .withColumnRenamed("dateOfBirth", "birthDate")
  .write
  .mode("overwrite")
  .option("overwriteSchema", "true")
  .saveAsTable(...)
)
j

Jesper Gomes

09/27/2023, 9:23 AM
Hi @Srinivas Maganti. I'm experiencing something similar. Did you find a solution/explanation?