Chapter 9. Schema Design
Hive looks and acts like a relational database. Users have a familiar nomenclature such as tables and columns, as well as a query language that is remarkably similar to SQL dialects they have used before. However, Hive is implemented and used in ways that are very different from conventional relational databases. Often, users try to carry over paradigms from the relational world that are actually Hive anti-patterns. This section highlights some Hive patterns you should use and some anti-patterns you should avoid.
Table-by-Day
Table-by-day is a pattern where a table
named supply is appended with a
timestamp such as supply_2011_01_01,
supply_2011_01_02, etc. Table-by-day is
an anti-pattern in the database world, but due to common implementation
challenges of ever-growing data sets, it is still widely used:
hive>CREATETABLEsupply_2011_01_02(idint,partstring,quantityint);hive>CREATETABLEsupply_2011_01_03(idint,partstring,quantityint);hive>CREATETABLEsupply_2011_01_04(idint,partstring,quantityint);hive>....loaddata...hive>SELECTpart,quantitysupply_2011_01_02>UNIONALL>SELECTpart,quantityfromsupply_2011_01_03>WHEREquantity<4;
With Hive, a partitioned table should be used instead. Hive uses
expressions in the WHERE clause to
select input only from the partitions needed for the query. This query
will run efficiently, and it is clean and easy on the eyes:
hive>CREATETABLEsupply(idint,partstring,quantityint)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access