-- Analytical fact table: market_bars
-- OHLCV bar data for tracked symbols.
-- Partitioned by dt (date) on MinIO.
-- Path: s3://stonks-lakehouse/warehouse/market_bars/dt={yyyy-mm-dd}/part-*.parquet
-- Requirements: 2.1, 9.4, 9.5, 10.1
-- Design ref: Section 7 (lake.market_bars)

CREATE TABLE IF NOT EXISTS lakehouse.stonks.market_bars (
    ticker        VARCHAR,
    open_price    DOUBLE,
    high_price    DOUBLE,
    low_price     DOUBLE,
    close_price   DOUBLE,
    volume        BIGINT,
    vwap          DOUBLE,
    trade_count   BIGINT,
    bar_timestamp TIMESTAMP(6) WITH TIME ZONE,
    bar_interval  VARCHAR,
    source        VARCHAR,
    dt            DATE
) WITH (
    format = 'PARQUET',
    partitioned_by = ARRAY['dt'],
    external_location = 's3a://stonks-lakehouse/warehouse/market_bars/'
);
