BIEE Hello World式的例子

這篇文章提供了一個Hello World式的例子,講述如何創建一個最簡單的BIEE資料庫。本文使用的示例數據可以在從此鏈接下載:http://www.zw1840.com

目錄

創建資料庫

創建物理模型

創建邏輯模型

創建展現模型

保存資料庫

配置 Oracle BI Server 使用新資料庫

Oracle Answer中定義查詢

參考

創建資料庫

BIEE的資料庫(Repository)是一個後綴名爲rpd的物理文件,其中存儲了三類元數據:數據源物理模型,邏輯模型,以及展現模型。Oracle BI Server是資料庫的使用者:在前端,BI Server通過ODBC將資料庫中的邏輯模型及展現模型提供給Oracle BI Presentation Server;在後端,BI Server通過各種適配器訪問與資料庫中物理模型對應的數據源[1]。資料庫rpd文件存儲在 $OBIEE_HOME/server/Repository 目錄裏。

 

首先,我使用BIEE Administration Tool創建一個名爲zw1840的新資料庫。

 

 

 

點“保存”按鈕後,可以看到Administration Tool打開了一個空資料庫。資料庫的編輯窗口分爲三欄,從右至左依次爲:

 

Ÿ       Physical:定義數據源的類型和連接方式,還有數據源物理表結構,字段數據類型,物理表的主外鍵之類的信息。[2]

Ÿ       Business Model and Mapping:定義邏輯模型,以及邏輯模型與物理模型間的映射關係。[3]

Ÿ       Presentation:定義展現模型。展現模型中的一個Catalog對應Oracle Answer中的一個Subject Area[4]

 

創建物理模型

物理模型可以手工創建,但是最簡單的方法是從源數據庫中直接導入。通過菜單 File/Import/from Database 開始導入。

 

 

在“Select Data Source”對話框中設置導入元數據時使用的數據源連接信息。

 

 

    在“Import”對話框裏可以選擇需要導入的數據庫對象,此對話框可以根據對象類型篩選樹形列出的數據庫對象。我的習慣是爲所有數據庫表建立視圖,使用視圖的好處是:如果數據庫發生了變化只需要修改視圖定義,BIEE中的修改工作可以減少很多。因此在“Import”對話框我只選擇導入視圖對象。在這個例子中,我首先導入消費記錄事實表(V_FINANCE_EXPENSE)和家庭成員維表(V_COMMON_MEMBER)。

 

 

    在第一次導入物理模型時,還需要設定BI Server進行數據查詢時使用的連接信息

 

 

注意上面設置了兩次連接信息,一次在“Select Data Source”對話框,此處的連接信息是供Administration Tool導入元數據用的;另一次在“Connection Pool”對話框,此處的連接信息是供BI Server進行數據查詢時使用的。如果你的Administration ToolBI Server裝在不同的機器上則需要在兩臺機器上分別配置Oracle TNS

 

現在,在“Physical”窗口可以看到剛纔導入的物理模型了。

 

 

Database節點(TNS_VZW1840_ORADB10G)上使用右鍵菜單“Physical Diagram/Object(s) and All Joins”可以查看數據源的物理模型圖。

 

 

 

接下來要定義各物理表的主鍵。雙擊V_COMMON_MEMBER表,在“Physical Table”對話框的“Keys”頁上點“New”按鈕,選擇MEMBER_ID字段作爲主鍵。使用同樣的方法將V_FINANCE_EXPENSE表的CONSUME_ID字段定義爲主鍵。

 

 

 

最後定義物理表之間的外鍵。雙擊V_FINANCE_EXPENSE表,在“Physical Table”窗口的“Foreign Keys”頁上點“New”按鈕,設定V_COMMON_MEMBER表的MEMBER_ID字段爲V_FINANCE_EXPENSEMEMBER_ID字段的外鍵。

 

 

再次查看物理模型圖你會發現兩個表之間建立了1..N的引用關係。

 

創建邏輯模型

將整個Physical SchemaZW1840”拖到“Business Model and Mapping”窗口。

 

 

Administrator Tool提供了一個偷懶的工具,可以自動地修改邏輯表和邏輯字段的名稱,完成去掉下劃線、首字母大寫之類的工作,不過這個功能對於國內項目意義不大。感興趣的話可以試試“Tools/Utilities”中的“Rename Wizard”。我用這個工具修改了邏輯模型、邏輯表及字段的名稱。

 

 

Administrator Tool 將按照物理模型的結構原樣創建邏輯模型,自動將物理表的主鍵作爲邏輯表的主鍵,同時創建邏輯表中的邏輯連接(Logical Join)。Server Administration Guide 文檔建議在邏輯模型中不要建立邏輯外鍵(Logical Foreign Key),而應使用邏輯連接[5]

 

Business Model節點(Finance)上使用右鍵菜單“Business Model Diagram/Whole Model”可以查看邏輯模型圖。

 

 

 

注意Administrator Tool自動創建的邏輯連接,雙擊可以打開“Logical Join”對話框查看邏輯連接的詳細情況。

 

 

我感覺Administrator Tool自動創建的邏輯連接(Relationship_2004:3161206517091)中,連接方式“Inner”還有“Member Dim”表的Cardinality0,1”不正確,修改爲“Left Outer”和“1”。

 

Server Administration Guide 文檔建議邏輯模型中不要設置Driving選項[6]

 

對於邏輯事實表的度量字段,需要設定其默認的聚合方法。“Expense Fact”表的“Amount”字段爲度量值,雙擊此字段,在“Logical Column”對話框的“Aggregation”頁將其默認聚合方法設置爲“SUM”。[7]

 

 

再看邏輯模型,“Amount”字段的圖標發生了變化。

 

 

爲了實現鑽取功能,需要在邏輯模型內創建維度。BIEE中的維度(Dimension)與Oracle數據庫中的DIMENSION對象概念類似,其中包含層級(Level)以及由各層級構成的層次結構(Hierarchy)。維度所包含的邏輯列必須來自同一個邏輯表[8]

 

我對示例數據的分析需求是:要按家庭成員維度彙總消費金額,還要從家庭成員下鑽到消費明細描述。由於消費明細描述位於消費事實表(V_FINANCE_EXPENSE)中,因此我需要改造邏輯表Member Dim,在其中添加消費明細字段。

 

將物理模型V_FINANCE_EXPENSE表的CONSUME_IDDESCR列拖到邏輯模型的Member Dim表下。

 

 

    此時邏輯表Member Dim有兩個邏輯表來源(Logical Table Source),Member Id Member Name來自V_FINANCE_EXPENSEConsume Id Descr 來自 V_COMMON_MEMBER。雙擊邏輯表來源可以打開“Logical Table Source”對話框,在“Column Mapping”頁可以查看邏輯列與物理表的映射關係。

 

從物理模型向邏輯模型拖放字段時,邏輯表來源是根據物理字段所在的物理表自動地建立的。按我的理解,Member Id/Member Name以及Consume Id/Descr來自同一物理數據源的兩張物理表,可以使用同一個邏輯表來源。我需要在邏輯表來源中設定物理表間的關聯關係,並重新映射邏輯字段。

 

刪除邏輯表來源V_FINANCE_EXPENS,雙擊V_COMMON_MEMBER開始編輯Member Dim的邏輯表來源。

 

首先設定Member Dim內邏輯字段所需的物理表,以及表間的關聯關係。(我不確定是否一定要這樣做,物理表間的關聯在物理模型中已經設置了,爲什麼這裏還要做一遍?)

 

 

    之後定義邏輯字段與物理字段間的映射關係。

 

 

由於將Consume Id加入了邏輯表Member Dim,因此Member Dim的邏輯主鍵不再是Member Id,應改爲Consume Id。刪除原來的邏輯主鍵,使用Consume Id創建新的邏輯主鍵。

 

經過重新整理的Member Dim是醬子的:

 

 

現在可以依據邏輯表Member Dim創建維度了。

 

 

首先定義Member維度的層次結構,由上至下依次爲Member TotalMemberDetail。之後將邏輯字段放入相應的層次。與維度對應的邏輯表的主鍵必須放在最低層(Detail[9] Grand Total層(Member Total)內不添加邏輯字段[10]Member維度的結構如下:

 

 

我還需要對每個層次進行設置,包括層次的元素數,以及層次的層鍵。

 

關於元素數的規則有:Grand Total層的元素數這隻能爲1;其他層次的元素數先設定一個大於1的數吧(具體規則還沒搞清楚)。

 

層鍵爲邏輯層元素的唯一組合,層鍵確定了鑽取時的查詢路徑。層鍵的屬性中可以設定此層鍵是否用於下鑽,選擇了“Use for drilldown”後此層鍵在Oracle Answer中才可用於下鑽。[11]

 

Member 層的層鍵設置如下:

 

 

 

 

 

Detail層的設置與Member層類似。

 

 

 

 

創建展現模型

將整個Business ModelZW1840”拖到“Presentation”窗口,Administrator Tool 將按照邏輯模型的結構原樣創建展現模型。

 

 

展現模型的目錄被稱爲Presentation Catalog,也就是在 Oracle Answer 中看到的Subject Area。在展現模型中,所有不希望業務用戶看到的字段可以刪掉,例如所有ID字段。經過修改後展現模型變成了這個樣子:

 

 

至此大功告成,Hello BIEE 資料庫設計完畢。

保存資料庫

每次保存資料庫文件時你都會看到提示

 

 

這是Administrator Tool在檢查資料庫的完整性,你可以根據提示檢查有問題的模型設置。一個新建的簡單資料庫不會有太多完整性問題,但第一次保存時你一定會看到這個警告:

 

 

新創建的資料庫Administrator密碼爲空,我們可以使用“Manage/Security”菜單打開“Security Manager”設置密碼。

 

 

雙擊Administrator 用戶設置密碼。在這還可以順便把“Logging Level”設爲“2”。[12]

 

配置Oracle BI Server使用新資料庫

修改Oracle BI Server的配置文件 $OBIEE_HOME/server/Config/NQSConfig.INI,找到“[ REPOSITORY ]”部分,指定新建的資料庫文件:

 

[ REPOSITORY ]

REP_ZW1840 = zw1840.rpd, DEFAULT;

 

現在啓動BIEE的三個服務Oracle BI Java HostOracle BI Presentation ServerOracle BI Server,並啓動BIEEOC4J

Oracle Answer中定義查詢

登錄BIEE,用戶/密碼爲當前NQSConfig.INI文件所使用的資料庫中包含的用戶/密碼。進入 AnswerBIEEAd Hoc 工具)就可以在Subject Area中看到剛纔定義的Expense Analysis啦。

 

 

選擇Subject Area打開查詢界面,單擊列名將列添加到查詢窗格(Selection Pane),CTRL+單擊列名將列添加到過濾器(Filters)。

 

 

Member Name 可以下鑽到消費明細

 

 

 

能下鑽,怎麼才能上鑽呢?我還沒有找到,向各位請教。

參考

[1] Deployment Guide p11

The Oracle Business Intelligence Server is a stand-alone process that maintains the logical data model which it provides to BI Presentation Services via ODBC. Metadata is maintained for the data model in a local proprietary file called the repository file (rpd). On the back-end, the BI Server connects to customer data stores via data source adaptors.

[2] Server Administration Guide p55

The Physical layer of the Administration Tool defines the data sources to which the Oracle BI Server submits queries and the relationships between physical databases and other data sources that are used to process multiple data source queries.

[3] Server Administration Guide p109

The Business Model and Mapping layer of the Administration Tool defines the business, or logical, model of the data and specifies the mapping between the business model and the physical layer schemas.

[4] Server Administration Guide p143

The Presentation layer provides a way to present customized views of a business model to users. Presentation Catalogs in the Presentation layer (called Subject Area in Oracle Answers) are seen as business models by Oracle BI Presentation Services users. They appear as catalogs to client tools that use the Oracle BI Server as an ODBC data source.

[5] Server Administration Guide p138

Logical foreign key joins might be needed if the Oracle BI Server is to be used as an ODBC data source for certain third-party query and reporting tools. Typically, you should not create logical foreign keys. This capability is in the Administration Tool to provide compatibility with previous releases.

[6] Server Administration Guide p140

CAUTION: Use extreme caution in deciding whether to specify a driving table. Driving tables are used for query optimization only under rare circumstances and when the driving table is extremely small (fewer than 1000 rows). Choosing a driving table incorrectly can lead to severe performance degradation.

[7] Server Administration Guide p115

Setting Default Levels of Aggregation for Measure Columns

[8] Server Administration Guide p125

In a business model, a dimension represents a hierarchical organization of logical columns (attributes) belonging to a single logical dimension table.

[9] Server Administration Guide p129

NOTE: The logical column(s) comprising the logical key of a dimension table must be associated with the lowest level of the dimension.

[10] Server Administration Guide p127

Grand total level

[11] Server Administration Guide p127

Level keys

[12] Server Administration Guide p215

Setting a Logging Level

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章