Skip to content

Conversation

Copy link

Copilot AI commented Jan 24, 2026

Hive throws WRONG_COMMAND_FOR_OBJECT_TYPE when attempting DROP TABLE on a VIEW during cleanup after check_timestamps fails.

Root Cause

In apply_mapping, when output_file is None:

  • Hive creates a VIEW via create_materialized_view (line 229-232)
  • Other engines create a TABLE via create_table (line 234)

The exception handler unconditionally used DROP TABLE, which fails for Hive VIEWs.

Changes

src/chronify/time_series_mapper_base.py:149-152

Detect engine type and use appropriate DROP command:

if output_file is None:
    if engine.name == "hive":
        conn.execute(text(f"DROP VIEW {to_schema.name}"))
    else:
        conn.execute(text(f"DROP TABLE {to_schema.name}"))

Matches existing pattern in the finally block (line 156-157) and elsewhere in the codebase.

Original prompt

The CI job is failing on Hive when attempting to DROP TABLE on an object that is actually a VIEW, resulting in the error:

org.apache.hive.service.cli.HiveSQLException:Error running query: [WRONG_COMMAND_FOR_OBJECT_TYPE] ...is a VIEW. Use DROP VIEW instead. SQLSTATE: 42809

This occurs during cleanup when a mapped table or intermediate table needs to be dropped after check_timestamps fails. Specifically, in Hive SQL, 'DROP TABLE' only works on tables, not views. The code base currently issues DROP TABLE regardless of whether the object is a table or a view.

To fix:

  • Detect if the object to be dropped is a VIEW or a TABLE when using Hive.
  • Use 'DROP VIEW IF EXISTS ' for views, and 'DROP TABLE IF EXISTS ' for tables.
  • This logic should be applied wherever such cleanup or rollback happens (likely in time_series_mapper_base or similar code used for mapping/cleanup after failures).
  • Optionally, refactor common drop logic into a utility function.
  • Add/adjust tests if needed to exercise both view and table dropping in Hive context.

References:

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 24, 2026 00:30
Co-authored-by: lixiliu <36629962+lixiliu@users.noreply.github.com>
Co-authored-by: lixiliu <36629962+lixiliu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix DROP TABLE command for Hive views Fix Hive cleanup error: use DROP VIEW when check_timestamps fails Jan 24, 2026
Copilot AI requested a review from lixiliu January 24, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants