Home > OS >  Databricks - alter complex data type in hive table
Databricks - alter complex data type in hive table

Time:01-20

I have a delta table which is partitioned with below structure in Databricks

  |--Name
  |--Group
    |--Computer
    |  |--C
    |  |--Java
    |--Biology
    |--Commerce
  |--Date 

I am trying to add a new struct field under Group.Computer.

Expected Schema:

  |--Name
  |--Group
    |--Computer
    |  |--C
    |  |--Java
    |  |--Python
    |--Biology
    |--Commerce
  |--Date 

I am trying to do this using below alter command

ALTER TABLE <TABLE_NAME> CHANGE COLUMN GROUP GROUP STRUCT<COMPUTER:STRUCT<C:STRING, JAVA:STRING, PYTHON STRING>,BIOLOGY:STRING, COMMERCE:STRING>

But i get an error like below:

cannot update spark_catalog.table_name field computer type:update a struct by updating its fields;

How to alter complex data types of existing table in databricks?

CodePudding user response:

You need to add it as a column but using the fully-qualified name in dotted notation - Databricks SQL doc explicitly says about it:

alter table <TABLE_NAME> add column group.computer.cobol string
  • Related