Forum

This topic contains 0 replies, has 1 voice, and was last updated by  Avikumar 2 years, 9 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1270 Reply

    Avikumar
    Participant

    The following file contains employeedata table.

    /tab1/employeedata/file1

    id, name, dept, yoj
    1, gopal, TP, 2012
    2, kiran, HR, 2012
    3, kaleel,SC, 2013
    4, Prasanth, SC, 2013
    The above data is partitioned into two files using year.

    /tab1/employeedata/2012/file2

    1, gopal, TP, 2012
    2, kiran, HR, 2012
    /tab1/employeedata/2013/file3

    3, kaleel,SC, 2013
    4, Prasanth, SC, 2013

    Adding a Partition:

    We can add partitions to a table by altering the table. Let us assume we have a table called employee with fields such as Id, Name, Salary, Designation, Dept, and yoj.

    Syntax:
    ALTER TABLE table_name ADD [IF NOT EXISTS] PARTITION partition_spec
    [LOCATION ‘location1’] partition_spec [LOCATION ‘location2’] …;

    partition_spec:
    : (p_column = p_col_value, p_column = p_col_value, …)
    The following query is used to add a partition to the employee table.

    hive> ALTER TABLE employee
    > ADD PARTITION (year=’2013’)
    > location ‘/2012/part2012’;

    Renaming a Partition:
    The syntax of this command is as follows.

    ALTER TABLE table_name PARTITION partition_spec RENAME TO PARTITION partition_spec;
    The following query is used to rename a partition:

    hive> ALTER TABLE employee PARTITION (year=’1203’)
    > RENAME TO PARTITION (Yoj=’1203’);

    Dropping a Partition:
    The following syntax is used to drop a partition:

    ALTER TABLE table_name DROP [IF EXISTS] PARTITION partition_spec, PARTITION partition_spec,…;
    The following query is used to drop a partition:

    hive> ALTER TABLE employee DROP [IF EXISTS]
    > PARTITION (year=’1203’);

Viewing 1 post (of 1 total)
Reply To: Hive – Partitioning
Your information:




cf22

Your Name (required)

Your Email (required)

Subject

Phone No

Your Message

Cart

  • No products in the cart.