Scarica Temporal and Spatial Databases: Understanding Time Domain, Granularity, and Calendars - Pr e più Appunti in PDF di Basi di Dati solo su Docsity! Temporal and Spatial Databases Chapter 2: Time Domain and Calendars J. Gamper ◮ Time domain ◮ Time granularity ◮ Calendars ◮ Modeling instants, periods, and intervals ◮ Now TSDB 2008/09 J. Gamper 1/19 Time Domain ◮ Time domain/ontology ◮ Specifies the basic building blocks of time ◮ Time is generally modeled as an arbitrary set of instants/points with an imposed partial order, e.g., (N, <) ◮ Additional axioms introduce more refined models of time ◮ Structure of time ◮ Linear time ◮ Time advances from past to future in a step-by-step fashion ◮ Branching time (possible future or hypothetical model) ◮ Time is linear from the past to now, where it then divides into several time lines ◮ Along any future path, additional branches may exist ◮ Structure is a tree rooted at now TSDB 2008/09 J. Gamper 2/19 Time Granularity ◮ Granularity: Intuitively, a discrete unit of measure for a temporal datum that supports a user-friendly representation of time, e.g., ◮ birthdates are typically measured at granularity of days ◮ business appointments to granularity of hours ◮ train schedules to granularity of minutes ◮ Mixed granularities are of basic importance to modeling “real-world” temporal data ◮ Mixing granularities create problems ◮ What are the semantics of operations with operands at differing granularities? ◮ How to convert from one granularity to another? ◮ How expensive is maintaining and querying times at different granularities? TSDB 2008/09 J. Gamper 5/19 Time Granularity . . . ◮ Example: Airline flight database FlightDepartures Flight# Time 53 ’1994-11-20 14:38’ 200 ’1994-11-25 14:34’ 653 ’1994-11-27 12:38’ 658 ’1994-11-30 10:03’ Vactions Vaction Time Labor Day ’[1994-09-01, 1994-09-03]’ Thanksgiving ’[1994-11-24, 1994-11-28]’ Christmas ’[1994-12-24, 1994-12-26]’ ◮ Data are stored at different granularities ◮ Flight departures are recorded at granularity of minutes ◮ Vactions are stored at granularity of days, each tuple storing a period of days ◮ Query: Which flights leave during the Thanksgiving vaction? SELECT * FROM Vacations, FlightDepartures WHERE Vacation = ’Thanksgiving’ AND Vacations.Time OVERLAPS FlightDepartures.Time ◮ Problems ◮ Query processor needs to know the relationships between minutes and days! ◮ Why is overlaps evaluated at granularity of days rather than minutes? TSDB 2008/09 J. Gamper 6/19 Time Granularity . . . ◮ Granularity: More formally, a partitioning of the time-line (chronons) into a finite set of segments, called granules. ◮ The partitioning scheme of a granularity is specified by ◮ the length (or size) of each granule and ◮ an anchor point, where the partitioning begins ◮ The timeline is partitioned into granules, each the size of the partitioning length, beginning from the anchor point, and extending forwards and backwards ◮ The granules are labeled with their distance from the anchor point. TSDB 2008/09 J. Gamper 7/19 Calendars . . . ◮ Calendars incorporate the cultural, legal, and even business orientation of the user to define the time values that are of interest, e.g., ◮ Gregorian calendar ◮ Business calendar ◮ Useful calendar for tax or payroll applications ◮ Days are the same as in the Gregorian calendar, but the Business calendar has a five day (work) week ◮ The Business calendar year is divided into four quarters (Fall, Winter, Spring, Summer) ◮ For tax purposes, the Business calendar year starts with the Fall quarter ◮ Astronomy calendar ◮ A year has 365.25 days ◮ A century is precisely 36525 days long ◮ Origin is noon on January 1, 4713 B.C. ◮ The Gregorian calendar date “June 24, 1994” is 2449527.5 in the Astronomy calendar TSDB 2008/09 J. Gamper 10/19 Lattice of Granularities ◮ Within a calendar, granularities are related in the sense that one granularity may be a finer parititioning of another ◮ e.g., days are a finer partitioning of months or weeks ◮ weeks are not a finer partitioning of months TSDB 2008/09 J. Gamper 11/19 Lattice of Granularities . . . ◮ With respect to finer partitioning, a set of granularities forms a lattice. ◮ The top element, ⊤, is the maximal granularity of, i.e., the entire time-line ◮ The bottom element, ⊥, is the granularity of time-line clock (chronons) TSDB 2008/09 J. Gamper 12/19 Cast Function ◮ Cast function cast(T ,G ) ◮ Convert a timestamp T into granularity level G ◮ Uses the mappings between different granularities ◮ Examples cast( ’1994-06-01’, century) = ’20’ cast( ’1994-06-01’, year) = ’1994’ cast( ’1994-06-01’, month) = ’1994-06’ cast( ’1994-06-01’, day) = ’1994-06-01’ cast( ’1994-06-01’, hour) = ’1994-06-01 00’ cast( ’1994-06-01’, minute) = ’1994-06-01 00:00’ ◮ Conversion from coarser to finer granularity ◮ The cast function always chooses the first granule from the set of granules corresponding to the coarser timestamp ◮ This avoids indeterminate results ◮ Scale function is similar, but produces an indeterminate result (a set of granules) when converting from a coarser to a finer granularity. TSDB 2008/09 J. Gamper 15/19 Instants, Periods, and Intervals in a Discrete TM ◮ Modeling Instants ◮ An instant is a point on the time line which is modeled by an instant timestamp that stores the number of a granule ◮ An instant timestamp records that an instant is located sometime during that particular granule ◮ The exact instant represented by an instant timestamp is never precisely known; only the granule during which it is located is known. ◮ Two instants represented by the same granule might be different ◮ An instant is a point on a time-line, whereas a granule is a (short) segment of a time-line ◮ We assume that (time-line lock) chronons, which are the smallest possible granule, are still bigger than instants. ◮ Distinction between chronons and instants captures the reality of measurements ◮ All mesaurements are imprecise with respect to instants ◮ We simply cannot measure individual instants: instants are “too small”. TSDB 2008/09 J. Gamper 16/19 Instants, Periods, and Intervals in a Discrete TM . . . ◮ Modeling Periods ◮ A period is a duration of time that is anchored between two instants and is modeled by a period timestamp ◮ A period timestamp is the composition of two instant timestamps, where the start timestamp precedes or is equal to the end timestamp. ◮ We assume that the starting and ending timestamp are at the same granularity level TSDB 2008/09 J. Gamper 17/19