Skip to content

Commit f1d4142

Browse files
authored
Fixed catalog import error to Hive 2.2 and 2.3 for Hive Metastore Migration tool (#172)
* Added default value to IS_REWRITE_COLUMN if it's present in TBLS table.
1 parent 14e230e commit f1d4142

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

utilities/Hive_metastore_migration/src/hive_metastore_migration.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ def export_to_metastore(self):
15031503
self.write_table(table_name="SKEWED_STRING_LIST_VALUES", df=self.ms_skewed_string_list_values)
15041504
self.write_table(table_name="SKEWED_COL_VALUE_LOC_MAP", df=self.ms_skewed_col_value_loc_map)
15051505
self.write_table(table_name="SORT_COLS", df=self.ms_sort_cols)
1506-
self.write_table(table_name="TBLS", df=self.ms_tbls)
1506+
self._write_tbls_table(table_name="TBLS", df=self.ms_tbls)
15071507
self.write_table(table_name="TABLE_PARAMS", df=self.ms_table_params)
15081508
self.write_table(table_name="PARTITION_KEYS", df=self.ms_partition_keys)
15091509
self.write_table(table_name="PARTITIONS", df=self.ms_partitions)
@@ -1533,6 +1533,19 @@ def _write_dbs_table(self, table_name, df) -> None:
15331533
df = df.withColumn("CTLG_NAME", lit("hive"))
15341534
self.write_table(table_name=table_name, df=df)
15351535

1536+
def _write_tbls_table(self, table_name, df) -> None:
1537+
"""
1538+
Handling IS_REWRITE_ENABLED column in TBLS table which does not accept null.
1539+
Context:
1540+
- HIVE-14496 added `IS_REWRITE_ENABLED` column to Hive 2.2.0, and it doesn't accept null until HIVE-18046 (Hive 3.0.0)
1541+
"""
1542+
1543+
source_df = self.read_table(table_name=table_name)
1544+
for col in [i.jsonValue() for i in source_df.schema]:
1545+
if col["name"] == "IS_REWRITE_ENABLED":
1546+
df = df.withColumn("IS_REWRITE_ENABLED", lit(0))
1547+
self.write_table(table_name=table_name, df=df)
1548+
15361549

15371550
def get_output_dir(output_dir_parent):
15381551
if not output_dir_parent:

0 commit comments

Comments
 (0)