[英]How to use Timestamp from PostgreSQL in Mondrian 4 Schema?
在我的事實表(來自PostgreSQL)中,我有一個像這樣的時間戳:
2016-07-01
如何使用此時間戳顯示年/月/季/日維度? 一個Mondrian 4模式示例將很有幫助。
我不想使用額外的時間表或類似的東西。 只是時間戳記。
我找到了解決此要求的方法。
該問題包括三個不同的問題
如下所述,我解決了所有三個問題,但是在我看來,這些解決方案都不是完美的,因此,如果您有任何改進建議,請在下面的評論中告訴我。 下面描述的所有內容都是針對元模型版本4.0和PostgreSQL數據庫的。
我找不到集成的解決方案,因此我制定了自己的解決方案。 在Mondrian架構中,您可以為表定義計算列。
<Table name="sales" schema="reporting">
<ColumnDefs>
<CalculatedColumnDef name='store2'>
<ExpressionView>
<SQL dialect='generic'>
<Column name='store'/>
</SQL>
</ExpressionView>
</CalculatedColumnDef>
</ColumnDefs>
</Table>
蒙德里安總是以某種方式使用generic
作為方言,因此使用postgres
作為方言不起作用。 通過<Column name='column'/>
您可以使用同一表的列值。 在上面的示例中,它是sales
表的store
列。
我們可以使用相同的方法為時間戳之外的每個子字段添加年,月,...列。
對於季度,它看起來像這樣:
<CalculatedColumnDef name='quarter'>
<ExpressionView>
<SQL dialect='generic'>
'Q' || EXTRACT(QUARTER FROM <Column name='date'/>)
</SQL>
</ExpressionView>
</CalculatedColumnDef>
現在,您只需要為所需的每個子字段執行此操作。 PostgreSQL支持的所有子字段: PostgreSQL-日期/時間函數EXTRACT
沒有定義表的維在mondrian模式中是不可能的。 有人會認為該架構將假設事實表為默認表,而mondrian架構則不會。
mondrian文檔中未說明如何解決此問題。 但這就像為DimensionLinks
使用其他鏈接一樣簡單。
使用此鏈接(其中xy
應該是尺寸名稱):
<FactLink dimension="xy"/>
在這一點上,這真讓Mondrian感到困惑。 只有1、2和一個層次結構維度,Mondrian崩潰並說:
尺寸'xy'; 省略定義的鍵,該鍵僅對具有單個屬性的退化尺寸有效。
這對我來說沒有任何意義,解決方案也沒有任何意義。
只需將一個key
添加到維度和相應的鍵屬性即可。 不知道為什么!
Mondrian文檔確實建議使用維類型TIME
和相應的屬性levelType
。
在文檔之外:
由於與MDX時間相關的功能,在Mondrian模式中對基於年/月/周/日的時間維度進行了不同的編碼
對我來說,這根本沒有什么區別,但是我仍然將其包括在我的維度中:
<Dimension name='Time' key="Timestamp" type="TIME">
<Attributes>
<Attribute name='Timestamp' table='sales' keyColumn='slice_date' hasHierarchy="false"/>
<Attribute name='Year' table='sales' keyColumn='year' levelType="TimeYears" hasHierarchy='false'/>
<Attribute name='Quarter' table='sales' keyColumn='quarter' levelType="TimeQuarters" hasHierarchy='false'/>
<Attribute name='Month' table='sales' keyColumn='month' levelType="TimeMonths" hasHierarchy='false'/>
<Attribute name='Day' table='sales' keyColumn='day' levelType="TimeWeeks" hasHierarchy='false'/>
<Attribute name='Week' table='sales' keyColumn='week' levelType="TimeDays" hasHierarchy='false'/>
<Attribute name='Day of Week' table='sales' keyColumn='dayOfWeek' levelType="TimeWeeks" hasHierarchy='false'/>
</Attributes>
<Hierarchies>
<Hierarchy name='Monthly'>
<Level attribute='Year'/>
<Level attribute='Quarter'/>
<Level attribute='Month'/>
</Hierarchy>
<Hierarchy name='Weekly'>
<Level attribute='Year'/>
<Level attribute='Week'/>
<Level attribute='Day of Week'/>
</Hierarchy>
</Hierarchies>
</Dimension>
現在,您只需在帶有2.中描述的鏈接的多維數據集中使用此維度:
<Dimensions>
<Dimension source="Time"/>
</Dimensions>
我希望這對其他人有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.