LIB CONNECT TO 'CustomSQL:Snowflake_example.com';
Section DirectQuery;
C:
Select C_NATIONKEY, Sum(C_ACCTBAL) as C_SUM from tpch1.customer group by C_NATIONKEY;
R:
SELECT R_REGIONKEY, R_NAME from tpch1.region;
N:
SELECT N_REGIONKEY, N_NAME, N_NATIONKEY from tpch1.nation;
Create Relationship Between R, N Matching R_REGIONKEY With N_REGIONKEY;
Create Relationship
Between Outer Joined N, Inner Joined C On
(coalesce([N_NATIONKEY], -1) = coalesce([C_NATIONKEY], -1));
LIB CONNECT TO 'CustomSQL:Snowflake_example.com';
// DMM created model portion includes Orders table.
IMPORT LIVE 'ModelName@obj://DirectQueryModel.Main';
Section DirectQuery;
C: Select C_CUSTKEY, C_ACCTBAL from tpch1.customer;
Create Relationship Between ORDERS, C on (O_CUSTKEY = C_CUSTKEY);
範例: 透過自訂 SQL 表格建構 Direct Query 資料模型
在此範例中,透過自訂 SQL 表格 C 建構 Direct Query 資料模型,這具有重新命名的欄位 C_KEY 和 C_BAL。接下來,IMPORT LIVE 會從 DirectQueryModel.main 新增在 資料模型管理員 中建立的資料模型。此資料模型包含表格「訂單」,並在該模型中有 Orders 和 Customer 之間的現有關係。然後,會捨棄 Customers 和 Orders 之間的現有關係,並定義 Orders 和 C 之間的新關係。
LIB CONNECT TO 'CustomSQL:Snowflake_example.com';
Section DirectQuery;
C: Select C_CUSTKEY as C_KEY, C_ACCTBAL as C_BAL from tpch1.customer;
// DMM created model portion includes Orders table.
IMPORT LIVE 'ModelName@obj://DirectQueryModel.Main';
// This relationship was defined using DMM between ORDERS and CUSTOMER, but I want to define my own.
Drop Relationship Between ORDERS, CUSTOMER;
Create Relationship Between ORDERS, C on (O_CUSTKEY = C_KEY);
LIB CONNECT TO 'CustomSQL:Snowflake_example.com';
Section DirectQuery;
LET MULT=100;
T1: SELECT PS_AVAILQTY AS C, SUM(PS_SUPPLYCOST) * $(MULT) AS S FROM "TPCH.01"."PARTSUPP" GROUP BY C;
IMPORT LIVE 'ModelName@obj://DirectQueryModel.Main';
section DirectQuery;
let Aggr1 = 1;
let Aggr2 = 0;
[GROUPS]:
SELECT 0 as GROUP_CODE, 'NONE' as "GROUP"
UNION ALL
SELECT 1 as GROUP_CODE, 'ORDERSTATUS' as "GROUP"
UNION ALL
SELECT 2 as GROUP_CODE, 'ORDERPRIORITY' as "GROUP"
;
[ORDERS_AGGREGATIONS]:
SELECT 'BY ORDERSTATUS' as "GROUP_NAME",
"O_ORDERSTATUS" as "ORDERS_GROUP",
sum("O_TOTALPRICE") as "ORDERS_GROUP_TOTAL_PRICE"
FROM "TEST1"."TPCH.01"."ORDERS"
WHERE '$(=min({<GROUP_CODE={0,1}>}[GROUP_CODE]))' = '1'
GROUP BY 1,2
UNION ALL
SELECT 'BY ORDERPRIORITY' as "GROUP_NAME",
"O_ORDERPRIORITY" as "ORDERS_GROUP",
sum("O_TOTALPRICE") as "ORDERS_GROUP_TOTAL_PRICE"
FROM "TEST1"."TPCH.01"."ORDERS"
WHERE '$(=min({<GROUP_CODE={0,2}>}[GROUP_CODE]))' = '2'
GROUP BY 1,2;
;
[ORDERS_AGGREGATIONS_VARS]:
SELECT 'BY ORDERSTATUS' as "GROUP_NAME_V",
"O_ORDERSTATUS" as "ORDERS_GROUP_V",
sum("O_TOTALPRICE") as "ORDERS_GROUP_TOTAL_PRICE_V"
FROM "TEST1"."TPCH.01"."ORDERS"
WHERE $(=Aggr1) = 1
GROUP BY 1,2
UNION ALL
SELECT 'BY ORDERPRIORITY' as "GROUP_NAME_V",
"O_ORDERPRIORITY" as "ORDERS_GROUP_V",
sum("O_TOTALPRICE") as "ORDERS_GROUP_TOTAL_PRICE_V"
FROM "TEST1"."TPCH.01"."ORDERS"
WHERE $(=Aggr2) = 1
GROUP BY 1,2;
;