Skip to content

featurebyte.TimestampSchema

class TimestampSchema(
*,
format_string: Optional[str]=None,
is_utc_time: Optional[bool]=None,
timezone: Union[TimeZoneName, TimeZoneColumn, NoneType]=None
)

Description

Schema for a timestamp column. To be embedded within a ColumnSpec

Parameters

  • format_string: Optional[str]
    Format string for the timestamp column represented as a string. This format is specific to the underlying database and is used to parse the timestamp values.

    - Databricks (Spark SQL): (example: "yyyy-MM-dd HH:mm:ss")
    Spark SQL Date and Timestamp Functions

    - Snowflake: (example: "YYYY-MM-DD HH24:MI:SS")
    Snowflake Date and Time Formats

    - BigQuery: (example: "%Y-%m-%d %H:%M:%S")
    BigQuery Date and Time Functions
    If the timestamp column is not of type string, format_string is not required and should not be provided.

  • is_utc_time: Optional[bool]
    Whether the timestamp values are in UTC (True) or local time (False)

  • timezone: Union[TimeZoneName, TimeZoneColumn, NoneType]
    Specifies the time zone information, which must conform to the
    International Time Zone Database
    (commonly known as the IANA Time Zone Database or tz database). The default value is None, which assumes "Etc/UTC". You can also provide a TimeZoneColumn to reference a dataset column containing time zone data.

Examples

Example 1: Basic UTC Timestamp (BigQuery)

utc_timestamp = fb.TimestampSchema(
    is_utc_time=True, format_string="%Y-%m-%dT%H:%M:%SZ", timezone="Etc/UTC"
)
Example 2: Local Time with Specific Timezone (Databricks)

local_timestamp = fb.TimestampSchema(
    is_utc_time=False, format_string="yyyy-MM-dd HH:mm:ss", timezone="America/New_York"
)

Example 3: Local Time with Timezone Offset Column (Snowflake)

offset_timestamp = fb.TimestampSchema(
    is_utc_time=False,
    format_string="YYYY-MM-DD HH24:MI:SS",
    timezone=fb.TimeZoneColumn(column_name="timezone_offset", type="offset"),
)

Example 4: UTC Year-Month Timestamp (BigQuery)

year_month_timestamp = fb.TimestampSchema(
    is_utc_time=True, format_string="%Y-%m", timezone="Etc/UTC"
)

See Also