OpenMetadata icon indicating copy to clipboard operation
OpenMetadata copied to clipboard

feat: Add metadata flag to identify Hive partition keys

Open m0hitbansal opened this issue 8 months ago • 23 comments

Right now, the Hive connector mixes partition keys (like year or country in the folder path) with the actual data columns inside the files. It’s annoying because you can't tell which columns are for filtering/partitioning and which ones are just regular data. This makes it hard to write efficient queries or know how the table is actually organized.

Describe the solution you'd like Make the connector "smart" enough to label partition keys. When I look at the table schema, it should clearly show which columns are partitions. Ideally, it should prevent users from accidentally trying to update a partition key like a normal piece of data.

m0hitbansal avatar Mar 24 '26 05:03 m0hitbansal

hi sir I’ve reviewed the issue and have an idea for the fix. I’d like to work on this. Please assign it to me.

jatinmasaram avatar Apr 04 '26 10:04 jatinmasaram

@m0hitbansal I would like to work on this issue. Can you please assign it to me?

Priyanshubhartistm avatar Apr 06 '26 16:04 Priyanshubhartistm

@m0hitbansal I have pushed a pr please review I would like to work on this issue please assign me

Esvanth avatar Apr 07 '26 22:04 Esvanth

@m0hitbansal I have pushed a pr please review I would like to work on this issue please assign me

Esvanth avatar Apr 08 '26 12:04 Esvanth

Hi @m0hitbansal @harshach ! I'd like to take this on — could you assign it to me? Thanks!

david-mamani avatar Apr 09 '26 02:04 david-mamani

hi @harshach and @TeddyCr, i would like to work on this. Please assign it to me

siddhiguptas avatar Apr 10 '26 04:04 siddhiguptas

Hi @m0hitbansal 👋

I'd like to work on this issue.

My approach: Implement get_table_partition_details() in HiveSource that parses DESCRIBE FORMATTED output to extract partition columns, with a robust section-exit parser and metastore-connection awareness to avoid false positives. Will include unit tests covering all edge cases.

Requesting assignment. Starting work now!

mohitjeswani01 avatar Apr 11 '26 10:04 mohitjeswani01

I'd love to work on this

Uche44 avatar Apr 15 '26 20:04 Uche44

Hi @m0hitbansal , it would be helpful for devs to RCA, if u could provide any screenshot or screen recording of this issue. @PubChimps I would like to contribute to resolve this issue if get assigned.

jaya6400 avatar Apr 16 '26 07:04 jaya6400

Hi, I'd like to work on this issue. can i get assigned?

shogun444 avatar Apr 16 '26 08:04 shogun444

Hi @m0hitbansal @ulixius9 👋

I'd like to work on issue #26712.

My Approach:

Implement get_table_partition_details() in HiveSource with a production-grade DESCRIBE FORMATTED parser that:

  • Correctly exits the partition section when the next section header is encountered — preventing false positives like Database:, Owner:, Location: being picked up as partition keys
  • Handles metastore connection (MySQL/Postgres) as a separate path by querying the metastore PARTITION_KEYS table directly instead of running DESCRIBE FORMATTED against a non-Hive engine
  • Gracefully falls back with a warning if partition detection fails — zero impact on existing ingestion
  • Includes complete unit tests covering: tables with partitions, tables without partitions, metastore connection path, parser section-exit correctness, and failure fallback

I have studied the existing Copilot review comments on PR #27029 and #27278 and my implementation directly addresses all flagged issues.

Requesting assignment. Starting work now!

Yashsainani123 avatar Apr 16 '26 10:04 Yashsainani123

Hi @m0hitbansal and @PubChimps

I’ve analyzed the requirements for identifying Hive partition keys and reviewed the existing PRs (#27029 and #27278). I’d like to take this on with a focus on making the detection robust across different environments.

My proposed approach:

Parser Logic: Implement a refined DESCRIBE FORMATTED parser in HiveSource that strictly identifies the # Partition Information section to avoid false positives from other metadata headers (like Owner or Location).

Metastore Support: Ensure compatibility for users connecting directly to the metastore (MySQL/Postgres) by querying PARTITION_KEYS where available.

Validation: Add unit tests covering partitioned vs. non-partitioned tables to ensure zero regression for existing ingestion workflows.

I'm ready to start immediately. Could you please assign this to me?

aksharagupta082007 avatar Apr 16 '26 14:04 aksharagupta082007

Hi! I'd like to work on this issue. Could you please assign it to me? I'm participating in the hackathon (Apr 17–26) and this fits well with my connector work. Thanks! @m0hitbansal

rajattiwari-stack avatar Apr 16 '26 17:04 rajattiwari-stack

Hi, I’d like to work on this issue. I’ll start working on it.

Sushantd07 avatar Apr 18 '26 19:04 Sushantd07

Hi @m0hitbansal

I went through the issue and also noticed there is an active PR (#27029) addressing this.

The idea of introducing a metadata flag to distinguish Hive partition keys from regular columns makes a lot of sense, especially for improving query clarity and preventing incorrect updates.

If there’s still room for contribution, I’d be happy to help with:

  • Adding/expanding test coverage for partition key identification
  • Validating edge cases (e.g., nested partitions or missing metadata)
  • Improving API/schema representation for better usability

Please let me know if I can contribute alongside the existing work. Happy to assist

pooja-bhavani avatar Apr 19 '26 18:04 pooja-bhavani

Hi @m0hitbansal @harshach @TeddyCr,

I'd like to work on this issue. I've done a thorough analysis of the problem, the existing codebase, and the two open PRs (#27029 and #27278). Here's my understanding and proposed approach:

Problem: The Hive connector currently mixes partition keys (e.g., year, country in HDFS folder paths) with regular data columns in the schema. Users can't distinguish which columns are for partitioning vs. actual data, making it hard to write efficient queries or understand table organization.

Proposed Approach — Hybrid Strategy:

I plan to modify ingestion/src/metadata/ingestion/source/database/hive/metadata.py with a two-tier detection strategy:

Tier 1 — Direct Metastore Query (primary, high accuracy): Query the PARTITION_KEYS table in the Hive metastore directly, joined with TBLS and DBS to identify partition columns by table/schema name. This handles both MySQL and Postgres metastore backends with database-agnostic identifier quoting (backticks for MySQL, double-quotes for Postgres).

# Pseudocode
query = """
  SELECT pk.PKEY_NAME
  FROM PARTITION_KEYS pk
  JOIN TBLS tbl ON pk.TBL_ID = tbl.TBL_ID
  JOIN DBS db ON tbl.DB_ID = db.DB_ID
  WHERE db.NAME = :schema AND tbl.TBL_NAME = :table_name
  ORDER BY pk.INTEGER_IDX
"""

Tier 2 — DESCRIBE FORMATTED Fallback (if metastore not directly accessible): Parse DESCRIBE FORMATTED <schema>.<table> output with a strict state machine — enter partition section on # Partition Information header, extract column names, and exit on the next section header (e.g., # Detailed Table Information). This avoids false positives from other metadata headers.

Integration with OpenMetadata Model: Build TablePartition objects using PartitionColumnDetails and attach them to the table entity:

TablePartition(
    partition_columns=[
        PartitionColumnDetails(column_name="year", interval_type=PartitionIntervalTypes.YEARLY),
        PartitionColumnDetails(column_name="country", interval_type=None),
    ]
)

Error Handling:

  • If metastore query fails → fallback to DESCRIBE FORMATTED with a warning log
  • If both fail → return None, log a debug message, and continue ingestion (never break existing workflows)

Testing Plan:

  • Unit tests for metastore query construction (MySQL + Postgres quoting)
  • Unit tests for DESCRIBE FORMATTED parser (correct section detection, edge cases)
  • Tests for tables with no partitions, single partition, multiple partitions
  • Fallback logic tests (metastore fail → DESCRIBE succeed, both fail → graceful None)

I have experience with Python async programming, REST APIs, and database connectors. I've studied both PRs #27029 and #27278 to understand what's been tried and where the review comments point to improvements. I can deliver a clean, well-tested PR.

Could you please assign this to me? Thank you!

yubarajDas avatar Apr 20 '26 08:04 yubarajDas

@m0hitbansal @PubChimps

Hi! I'd love to work on this issue and would like to get assigned to it. 🙋

I have gone through the issue description carefully and I'm confident I can tackle it effectively. I'm actively contributing to OpenMetadata and this looks like a great fit for me.

Could you please assign this issue to me? Thank you! 🚀

manavmax avatar Apr 20 '26 18:04 manavmax

Hi @harshach @m0hitbansal — I'd like to pick up another ingestion-framework issue before the hackathon ends.

I see #27029 and #27278 were opened for this but didn't land. Happy to take a fresh pass if this is still open.

Proposed approach (two-tier, similar in spirit to yubarajDas's earlier comment):

  1. Primary — direct metastore query. For users whose connection points at the Hive metastore backend (MySQL/Postgres), query PARTITION_KEYS joined with TBLS and DBS to get partition columns with correct ordering (INTEGER_IDX). Handles quoting differences between MySQL (backticks) and Postgres (double-quotes).

  2. Fallback — DESCRIBE FORMATTED parser. For HiveServer2 connections where the metastore isn't directly reachable, parse DESCRIBE FORMATTED <schema>.<table> with a strict state machine: enter on # Partition Information, exit on the next # section header. This is the part earlier PRs tripped on — false positives from Owner: / Location: lines.

  3. Model mapping. Build TablePartition with PartitionColumnDetails per column and attach to the table entity during ingestion.

  4. Graceful degradation. Any failure logs a warning and returns None — never breaks existing ingestion for users without partitioned tables.

Tests: partitioned and non-partitioned tables, multi-column partitions, both metastore backends (quoting), parser section-exit correctness, and the fallback path when the metastore query fails.

I'll review the review comments on #27029 and #27278 before writing anything so I don't repeat the same mistakes. Timeline: draft PR within 2 days of assignment.

Could you assign this to me?

abhay-codes07 avatar Apr 20 '26 20:04 abhay-codes07

Hi @m0hitbansal @harshach — I've opened PR #27731 with a clean implementation of the partition key flag.

What's in the PR:

  • _get_partition_column_names(): strict state-machine parser for DESCRIBE FORMATTED output — enters on # Partition Information, exits on the next #-prefixed section header to avoid false positives from Owner:/Location: rows.
  • get_columns now attaches is_partition_column=True to partition key columns. Non-partitioned tables get False — no regression.
  • get_table_partition_details() in HiveSource builds a TablePartition with PartitionColumnDetails per key using PartitionIntervalTypes.COLUMN_VALUE. Returns (False, None) gracefully on failure.
  • 8 unit tests in TestHivePartitionKeyFlag covering all edge cases.

Could you please assign this issue to me? Thank you!

Reet24-del avatar Apr 25 '26 10:04 Reet24-del

hi, can i work on this issue?

tazsq avatar Apr 28 '26 11:04 tazsq