Skip to content

Executing statements in Hive

Use Hive.execute(...) to execute DDL and DML operations.

Syntax support

This method supports any query syntax supported by Hive, like:

  • ✅︎ CREATE TABLE ..., CREATE VIEW ..., and so on
  • ✅︎ LOAD DATA ..., and so on
  • ✅︎ ALTER ...
  • ✅︎ INSERT INTO ... SELECT ..., and so on
  • ✅︎ DROP TABLE ..., DROP VIEW ..., and so on
  • ✅︎ MSCK REPAIR TABLE ..., and so on
  • ✅︎ other statements not mentioned here
  • SET ...; SELECT ...; - multiple statements not supported

Warning

Actually, query should be written using SparkSQL syntax, not HiveQL.

Examples

from onetl.connection import Hive

hive = Hive(...)

hive.execute("DROP TABLE schema.table")
hive.execute(
    """
    CREATE TABLE schema.table (
        id NUMBER,
        key VARCHAR,
        value DOUBLE
    )
    PARTITION BY (business_date DATE)
    STORED AS orc
    """
)

Details

Execute DDL or DML statement. support hooks

Added in 0.2.0

Parameters:

  • statement (str) –

    Statement to be executed.