Saiku的基本使用介紹(這里都是使用Admin用戶登錄系統)
1、啟動安裝好的Saiku ( ./start-saiku.sh ) ,瀏覽器使用訪問系統 http://localhost:8080 ,然后使用 admin admin 登錄系統
2、 登錄系統后,首先點擊 A ,進入管理控制平台(添加數據源信息)
2.1 根據需要連接的數據源信息中的數據(本文中連接Mysql數據庫),編寫對應的schame文件,(這里schame文件的配置了兩個cube ,第一個是一張表一個cube配置,第二個是雙表對應一個cube)
<Dimension> 標簽定義維度信息
<Hierarchy> 標簽 定義層次信息
<Level>標簽中定義具體的列信息 (對應數據庫中的 字段名)
<Measure> 標簽定義度量信息 注意度量信息中指定的字段需為數據類型,需要進行運算
<Schema> 標簽定義當前文件在saiku中的數據源信息名稱
<Cube> 標簽定義數據信息(可以理解為用於展示數據的名稱)
<Table> 標簽 定義數據庫中的表名
一個Schame文件中可以配置多個Cube,
一個Cube 中可以配置多個Dimension ,多個Table,多個Measure
一個Dimension中可以配置多個Level信息
MDX的數據類型:String Numeric Integer Boolean Time Timestamp (在配置中使用datatype字段指定)
report.xml 文件內容如下:
<?xml version="1.0" encoding="UTF-8"?> <Schema name="report"> <!-- 測試數據量 --> <Cube name="測試數據量1w"> <Table name="rs_testdata" /> <Dimension name="序號" foreignKey="ID" > <Hierarchy hasAll="true" primaryKey="ID" allMemberName="序號" > <Level name="序號" column="ID" uniqueMembers="true" /> </Hierarchy> </Dimension> <Dimension name="SEQ" foreignKey="ID" > <Hierarchy hasAll="true" primaryKey="ID" allMemberName="SEQ" > <Level name="SEQ" column="seq" uniqueMembers="true" /> </Hierarchy> </Dimension> <Dimension name="姓名" foreignKey="ID" > <Hierarchy hasAll="true" primaryKey="ID" allMemberName="姓名" > <Level name="姓名" column="name" uniqueMembers="true" /> </Hierarchy> </Dimension> <Measure name="序號" column="ID" aggregator="sum" /> </Cube> <!-- 匯總數據表 summaryKpi --> <Cube name="SummaryKpi匯總數據"> <Table name="rs_kpisummary_data" /> <Dimension name="序號" foreignKey="ID" > <Hierarchy hasAll="true" primaryKey="ID" allMemberName="序號" > <Level name="序號" column="ID" uniqueMembers="true" /> </Hierarchy> </Dimension> <Dimension name="維度" foreignKey="kpiKey" ><!-- 這里的foreignKey指的是rs_kpisummary_data表中的kpiKey--> <Hierarchy hasAll="true" allMemberName="維度信息" primaryKey="kpiKey" primaryKeyTable="rs_kpisummary_template"> <!--這里的primaryKey指的是rs_kpisummary_template表中的kpiKey--> <Table name="rs_kpisummary_template" /> <Level name="部門" table="rs_kpisummary_template" column="department" nameColumn="department" uniqueMembers="false" ></Level> <Level name="類別" table="rs_kpisummary_template" column="kpiType" nameColumn="kpiType" uniqueMembers="false" ></Level> <Level name="序號" table="rs_kpisummary_template" column="kpiSeqno" nameColumn="kpiSeqno" uniqueMembers="false" ></Level> <Level name="指標名稱" table="rs_kpisummary_template" column="kpiName" nameColumn="kpiName" uniqueMembers="false" ></Level> <Level name="指標說明" table="rs_kpisummary_template" column="kpiDesc" nameColumn="kpiDesc" uniqueMembers="false" ></Level> <Level name="備註" table="rs_kpisummary_template" column="remarks" nameColumn="remarks" uniqueMembers="false" ></Level> <Level name="達標率" table="rs_kpisummary_template" column="rate" nameColumn="rate" uniqueMembers="false" ></Level> <Level name="指標明細區分字段A" table="rs_kpisummary_template" column="kpiKey" nameColumn="kpiKey" uniqueMembers="false" ></Level> </Hierarchy> </Dimension> <Dimension name="統計日期" foreignKey="ID" > <Hierarchy hasAll="true" primaryKey="ID" allMemberName="統計日期" > <Level name="統計日期" table="rs_kpisummary_data" column="countdate" type='Date' uniqueMembers="false" /> </Hierarchy> </Dimension> <Measure name="周完成量" table="rs_kpisummary_data" column="weekFinishNum" datatype="Integer" aggregator="sum" /> <Measure name="周總量" table="rs_kpisummary_data" column="weekTotalNum" datatype="Integer" aggregator="sum" /> <Measure name="周KPI" table="rs_kpisummary_data" column="weekKPI" datatype="Numeric" aggregator="sum" /> <Measure name="月完成量" table="rs_kpisummary_data" column="monthFinishNum" datatype="Integer" aggregator="sum" /> <Measure name="月總量" table="rs_kpisummary_data" column="monthFinishNum" datatype="Integer" aggregator="sum" /> <Measure name="月KPI" table="rs_kpisummary_data" column="monthKPI" datatype="Numeric" aggregator="sum" /> </Cube> </Schema>
2.2 將編寫的report.xml文件上傳到saiku,上傳步驟 :
1. 選中 add Schame
2. 選中剛剛編寫的report.xml
3. 點擊上傳(Upload)
2.3 添加數據源信息:
輸入數據庫相關信息,如果是第一次使用記得將對應的數據庫驅動包放入 saiku的lib目錄下 ( saiku-latest\saiku-server\tomcat\webapps\saiku\WEB-INF\lib )
3、 新建查詢 ,開始使用saiku展示數據
前面兩個是saiku自帶的元數據信息
report: 就是我們配置的Schame中的數據信息
report目錄下的數據就是我們配置的Cube信息
3.1 選中配置好的Cube SummaryKpi匯總數據
3.2 界面分析:簡單的操作方法是通過拖拽指標信息以及維度信息實現數據的展示,請注意每個數據只能被拖到一個展示框哦!
(比如:序號拖拽為列信息,就不能再把序號拖拽為行信息了,如果需要序號變為行則必須將列下方的序號刪除 再次重新拖拽)
3.3 以圖表的形式展示數據效果如圖:
3.4 指標相關信息分析: 右擊指標,效果如圖:(可一 一點擊進行試驗)
Columns | Measures : 先展示列數據,然后將指標信息在列數據后展示 (指標信息以列數據格式展示)
Measures| Columns: 先展示指標信息數據,然后將列信息數據在指標數據后展示 (指標信息以列數據格式展示)
Rows | Measures : 先展示行數據,然后將指標信息在行數據后展示 (指標信息以行數據格式展示)
Columns | Rows: 先展示指標信息數據,然后將行數據信息在指標數據后展示 (指標信息以行數據格式展示)
Reset Deafult: 回復為默認的數據展示形式 (Columns | Measures )
3.5 查看當前數據的匯總計算數據信息:(點擊右側的圖標,再點擊一次會恢復到之前的Table數據)
3.6 對數據進行篩選:(行數據 以及 列數據 中 的每一項數據都可以使用此方法進行篩選)
3.6.1 篩選數據查詢使用示例:
1 輸入查詢關鍵字 : 保
2 點擊 Pre-Filter on Server 然后就會得到查詢結果
4. 數據篩選示例:
1 選定數據添加到右側 Used members
2 (可選) 設置參數名 sectionParam
3 點擊OK
數據篩選之后的效果:
Parameter 參數使用效果:
5 添加指標信息:
1 點擊指標右側的添加
2. 填寫彈出框中的數據信息
Name : 指標名稱
Formula : 對指標或者維度進行計算的 MDX表達式
5.1 添加新指標示例:
此表達式的含義: 判斷維度信息 部門 所對應的值中是包含 新業務 這三個字,如果包含 新指標中的 部門判斷值則為 新單,如果不包含 部門判斷值則為 非新單。
IIf(Logic_Expresssion,value1,value2) : 這是一個If判斷,如果前面的表達式為真,則取第一個值 value1,如果表達式的結果為false ,則取第二個值 value2.
Instr(String1,String2) : 這個函數用來判斷字符串的包含關系,String1表示比較的字符串,String2是被比較的字符串。(這里是判斷String1中是否包含String2字符串,返回的是下標信息),結果大於0 表示包含,否則就表示不包含。
IIf(Instr([維度].[維度].[部門].CurrentMember.Name,"新業務")>0,"新單","非新單")
ps: 記得 Dimension 選擇 Measures
添加新指標后的效果:
以上就是saiku的基本操作啦,接下來更深層次的操作待后期研究,最后我們編輯好一個文件后要記得保存哦!
6 保存數據文件
1. 點擊保存標
2. 選中存儲目錄 datasources
3. 輸入保存的文件名 save
4. 點擊 save
查看我們保存的數據信息:
Saiku數據顯示格式問題1: null值顯示控制
默認顯示為 #null
可通過修改配置文件 mondrain.properties 文件,讓列數據為空時顯示需要的數據
文件路徑: saiku-server\tomcat\webapps\saiku\WEB-INF\classes\mondrain.properties
## 注意這是部分配置信息
###############################################################################
# Property that determines how a null member value is represented in the
# result output.
# AS 2000 shows this as empty value
# AS 2005 shows this as "(null)" value
#
#mondrian.olap.NullMemberRepresentation=#null
修改之后的文件為:
## 注意這是部分配置信息
###############################################################################
# Property that determines how a null member value is represented in the
# result output.
# AS 2000 shows this as empty value
# AS 2005 shows this as "(null)" value
#
mondrian.olap.NullMemberRepresentation=
然后重新啟動Saiku ,再查看數據就會發現所有為null的數據信息都會不顯示任何內容。