feat(historical): durable Postgres-backed historical_sales + repoint Superset dashboard (no Trino downtime)
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
DROP TABLE IF EXISTS public.historical_sales;
|
||||||
|
CREATE TABLE public.historical_sales (
|
||||||
|
order_id bigint, order_date date, order_year int, region text,
|
||||||
|
product_category text, channel text, quantity int,
|
||||||
|
unit_price double precision, amount double precision
|
||||||
|
);
|
||||||
|
INSERT INTO public.historical_sales
|
||||||
|
SELECT s,
|
||||||
|
DATE '2019-01-01' + ((s*7)%2190),
|
||||||
|
EXTRACT(YEAR FROM (DATE '2019-01-01' + ((s*7)%2190)))::int,
|
||||||
|
(ARRAY['EMEA','AMER','APAC','LATAM'])[(s%4)+1],
|
||||||
|
(ARRAY['Servers','Storage','Networking','Laptops','Services'])[(s%5)+1],
|
||||||
|
(ARRAY['Direct','Partner','Online'])[(s%3)+1],
|
||||||
|
(1+(s%50))::int,
|
||||||
|
round((100+(s%9000)*0.5)::numeric,2)::double precision,
|
||||||
|
round(((1+(s%50))*(100+(s%9000)*0.5))::numeric,2)::double precision
|
||||||
|
FROM generate_series(1,25000) s;
|
||||||
|
SELECT order_year, count(*), round(sum(amount)::numeric,0) FROM public.historical_sales GROUP BY order_year ORDER BY 1;
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
from superset.app import create_app
|
||||||
|
|
||||||
|
app = create_app()
|
||||||
|
with app.app_context():
|
||||||
|
from superset import db
|
||||||
|
from superset.connectors.sqla.models import SqlaTable
|
||||||
|
from superset.models.core import Database
|
||||||
|
|
||||||
|
t = db.session.query(SqlaTable).filter_by(table_name="historical_sales").first()
|
||||||
|
pg = (
|
||||||
|
db.session.query(Database)
|
||||||
|
.filter(Database.database_name.like("%PostgreSQL Sales%"))
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
t.database_id = pg.id
|
||||||
|
t.schema = "public"
|
||||||
|
db.session.commit()
|
||||||
|
try:
|
||||||
|
t.fetch_metadata()
|
||||||
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
print("fetch_metadata warn:", str(e)[:200])
|
||||||
|
print("repointed dataset", t.id, "-> db", pg.id, pg.database_name,
|
||||||
|
"schema", t.schema, "cols", [c.column_name for c in t.columns])
|
||||||
Reference in New Issue
Block a user