How can i write a dimension with snow flake schema ? . Details below - olap

There are three tables -
1) Student - My fact Table (References Addresses with FK ADDRESS_ID
2) Addresses - This table Contains FK COUNTRY_ID references COUNTRY
3) Country - this has a NAME COLUMN which i would display. (PK IDENTIFIER)
I have written this but Not Sure if it is Correct
Basically i want to join Student (FACT TABLE) to COUNTRY
Consosts of Fact --- Def .. then this
<Dimension foreignKey="ADDRESS_ID" name="COUNTRY">
<Hierarchy name="COUNTRY NAME" hasAll="true" primaryKey="IDENTIFIER" primaryKeyTable="ADDRESSES">
<Join leftKey="IDENTIFIER" rightKey="IDENTIFIER">
<Table name="ADDRESSES" >
</Table>
<Table name="COUNTRIES" >
</Table>
</Join>
<Level name="Country Name" visible="true" table="COUNTRIES" column="NAME" nameColumn="NAME" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>

You haven't made the join correctly. I'm going to assume your relational schema looks like this:
.-STUDENT-------.
| IDENTIFIER PK | .-ADDRESSES-----.
| ADDRESS_ID FK |----| IDENTIFIER PK | .-COUNTRIES-----.
| COUNTRY_ID FK |----| IDENTIFIER PK |
| NAME |
The JOIN element needs to make a join between the lowest-granularity dimension table ADDRESS and the next level up (COUNTRY). The keys that join these tables are COUNTRY_ID (for ADDRESS) and IDENTIFIER (COUNTRY). leftKey then needs to be set to COUNTRY_ID.
Also, you're using the Level's nameColumn attribute, but this is actually used to set the level's own name, not the member names. I would remove this. In all you'd en up with something looking like this:
<Dimension foreignKey="ADDRESS_ID" name="COUNTRY">
<Hierarchy name="COUNTRY NAME" hasAll="true" primaryKey="IDENTIFIER" primaryKeyTable="ADDRESSES">
<Join leftKey="COUNTRY_ID" rightKey="IDENTIFIER">
<Table name="ADDRESSES" >
</Table>
<Table name="COUNTRIES" >
</Table>
</Join>
<Level name="Country Name" visible="true" table="COUNTRIES" column="NAME">
</Level>
</Hierarchy>
</Dimension>

Related

map single source schema element to multiple element with attribute

I have a source schema as follows:
Users
Id
Name
Department
and destination schema as follows:
Employee
Name
Number
number_type(attribute)
I need to do the following mapping
Name ---> Name
Id ---> Number (number_type = "Id")
Department_no --> Number (number_type = "dept")
I need to map both Id and department number i.e. 2 elements to 1 element i.e. Number in dest schema but for both attribute value should be different.
Input
<Users>
<Id>123</Id>
<Name>abc</Name>
<Department_no>456</Department_no>
</Users>
Output:
<Employee>
<Name>abc</Name>
<Number number_type = "Id">123</Number>
<Number number_type = "dept">456</Number>
</Employee>
How can I achieve in BizTalk or what could be the inline XSLT for the same?
You nearly have it
Name ---> Name
Id ---> Number
Department --> Number
Then also link both Id & Department to a looping functoid that goes to Number
Plus to do the attributes there are some things you can try such as
Id ---> number_type
Department --> number_type
But click on the links select Copy Name instead of the Copy Text value.
From an input
<ns0:Root xmlns:ns0="http://Scratch.SO55049939Input">
<Users>
<Id>Id_0</Id>
<Name>Name_0</Name>
<Department>Department_0</Department>
</Users>
</ns0:Root>
You will get output
<ns0:Root xmlns:ns0="http://Scratch.SO55049939output">
<Employee>
<Name>Name_0</Name>
<Number number_type="Id">Id_0</Number>
<Number number_type="Department">Department_0</Number>
</Employee>
</ns0:Root>

I am trying to fetch data kept in a table's column with datatype <XMLTYPE>. I have to get all field names with values using procedure/ query

<record>
<field>
<fieldName>employee id</fieldName>
<fieldValue>2000001</fieldValue>
</field>
<field>
<fieldName>employee name</fieldName>
<fieldValue>pankaj kumar</fieldValue>
</field>
</record>
The data extracted should be like this:
employee id | employee name
2000001 | pankaj kumar
CREATE TABLE houses(
HOUSE_ID NUMBER(4),
house_add XMLTYPE,
HOUSE_NAME VARCHAR2(35)
);
Inserting the value in the table;
INSERT INTO houses VALUES
(100, XMLType('<house whNo="100">
<Building>Owned</Building>
</house>'), 'housename1');
To fech :-
SELECT house_add FROM HOUSES W;
o/p:-<house whNo="100"> <BUILDING>OWNED</BUILDING> </house>
To fetch Building detail:-
SELECT
w.house_add.extract('/house/Building/text()').getStringVal() "Building"
FROM HOUSES W;
o/p:-Owned
For your case:-
WITH T AS
(select xmltype('<?xml version = "1.0"?>
<record>
<FIELD>
<Field Name="employee id" fieldValue="2000001"/>
</FIELD>
<FIELD>
<Field Name="employee name" fieldValue="pankajkumar"/>
</FIELD>
</record>
') XML FROM DUAL
)
SELECT Y.NAME, Y.VALUE
FROM T ,
XMLTABLE('/record/FIELD/Field'
PASSING T.XML
COLUMNS NAME VARCHAR2(20) PATH '#Name',
VALUE VARCHAR2(20) PATH '#fieldValue'
)Y
output:-
NAme Value
employee id 2000001
employee name pankajkumar
This will help you !!

Mondrian parent-child hierarchy not working

Some issues to make mondrian work with a parent-child hierarchy.
My table structure is as follows (simplified, as the Category table is actually a MPTT):
RESPONSE QUESTION CATEGORY
-------------- ------------------- ----------
id ¡---> identifier (String) ¡---> id <---¡
question_id ___| category_id _____| parent_id _|
value (Measure) title name_en
My closure table is a simple setup: child_id, parent_id, distance (with the primary key being the tuple (child_id, parent_id) ).
My cube's schema is as follows:
<Cube cache="true"
defaultMeasure="Value" enabled="true" name="mycube">
<Table name="response" schema="public"/>
<Dimension foreignKey="question_id" name="Category">
<Hierarchy allMemberName="All Categories" hasAll="true"
primaryKey="identifier" primaryKeyTable="question">
<Join leftKey="category_id" rightKey="id">
<Table name="question"/>
<Table name="category"/>
</Join>
<!-- works fine with the category itself: <Level column="name" type="String" name="Category Name" table="category" uniqueMembers="true"/> -->
<Level column="id" name="Category ID"
nameColumn="name_en" nullParentValue="NULL"
parentColumn="parent_id" table="category"
type="Numeric" uniqueMembers="true">
<!-- type="Numeric" ordinalColumn="lft" parentColumn="parent_id" nullParentValue="NULL" -->
<Closure childColumn="child_id" parentColumn="parent_id">
<Table name="category_closure"/>
</Closure>
</Level>
</Hierarchy>
</Dimension>
<Measure aggregator="avg" caption="Value"
column="actual_value" formatString="#,###.00" name="Value"/>
</Cube>
Now, based on the mondrian FoodMart test pages, I have set up a simple jsp pages for my cube, which I want to use as a starting point for my tests. It has the following MDX:
select {[Measures].[Value]} ON COLUMNS,
{( [Category] )} ON ROWS
from [mycube]
The result it shows at first is "All Categories". When I try to drill down or hierarchize in the Categories, it returns nothing but [All Categories]. I have tried also with Descendants() to no avail.
Equally, when I try to list the members of Categories, it returns nothing.
I see that in the background it runs a query as follows to start the drilling down:
05/12/13 23:53:10,967 postgres: [3-1] LOG: execute : select
"category"."id" as "c0", "category"."name_en" as "c1" from "question"
as "question", "category" as "category" where "question"."category_id"
= "category"."id" and "category"."parent_id" IS NULL group by "category"."id", "category"."name_en" order by "category"."id" ASC
NULLS LAST
Obviously this query has an empty result because it joins question with root-level categories whilst only the leaves of my tree are attached some Questions.
It also shows that the closure table is not used here.
Any clue on what I can do to fix this?
Thanks ahead
lai
Following a few experiments, I shall conclude that my use case is probably not supported by Mondrian.
Here is the test I did to come to this conclusion:
- ensure I have 3 levels in my tree (level 0->2)
- create a fake question related to a root category (i.e. whose parent_id = NULL)
- create a response attached to this fake question
- at this stage, only level 0 and level 2 Category records have questions and responses related to them
- go ahead with a query
Here is the result I got in the logs:
14:37:09,082 WARN [SqlTupleReader] The level [Category].[Name] makes
use of the 'parentColumn' attribute, but a parent member for key 3 is
missing. This can be due to the usage of the NativizeSet MDX function
with a list of members form a parent-child hierarchy that doesn't
include all parent members in its definition. Using NativizeSet with a
parent-child hierarchy requires the parent members to be included in
the set, or the hierarchy cannot be properly built natively.
"key 3" relates to one of my level-2 records i.e. tree leaves (similar messages show for the other level-2 records).
Conclusion: not supported :-(
Enclosing the "working" schema below:
<Schema name="Foo">
<Cube name="Foo" caption="Cube to report on the Foo quizz dimensions" visible="true" defaultMeasure="Rating" cache="true" enabled="true">
<Table name="response" schema="public">
</Table>
<Dimension type="StandardDimension" visible="true" foreignKey="question_id" highCardinality="false" name="Category">
<Hierarchy name="Category" visible="true" hasAll="false" allMemberName="All Categories" primaryKey="identifier" primaryKeyTable="question">
<Join leftKey="category_id" rightKey="id">
<Table name="question" schema="public">
</Table>
<Table name="category" schema="public">
</Table>
</Join>
<Level name="Name" visible="true" table="category" column="id" nameColumn="name" ordinalColumn="tree_id" parentColumn="parent_id" nullParentValue="NULL" type="String" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
</Level>
</Hierarchy>
</Dimension>
<Measure name="Ratings" column="actual_value" formatString="#,###.00" aggregator="avg" caption="Ratings">
</Measure>
</Cube>
</Schema>

Query to output content of AllXml column of ELMAH_Error sql server table

I am having trouble writing query so that I can query the content of AllXml column inside Elmah_Error table.
How can I list out all the item nodes as an output of the query.
How could I write query to only list for certain item nodes?
I would like to get follow resultset:
item value
===== =====
ALL_HTTP HTTP_CONNECTION:xxxx
ALL_RAW Connection: xxxxx
I would also like to be able to filter the query by ErrorID
Content of AllXml column may look like this.
<error
application="/"
message="hello world"
source="TestWebElmah"
detail="xxxxx">
<serverVariables>
<item
name="ALL_HTTP">
<value
string="HTTP_CONNECTION:xxxx" />
</item>
<item
name="ALL_RAW">
<value
string="Connection: xxxxx" />
</item>
</serverVariables>
</error>
Remote Addr nodes
select T.N.value('(value/#string)[1]', 'varchar(30)') as REMOTE_ADDR
from
(select cast(AllXml as xml) as AllXml from ELMAH_Error) e
cross apply AllXml.nodes('//item[#name="REMOTE_ADDR"]') as T(N)
HTTP User Agents which contain mozilla
select T.N.value('(value/#string)[1]', 'varchar(30)') as HTTP_USER_AGENT
from
(select cast(AllXml as xml) as AllXml from ELMAH_Error) e
cross apply AllXml.nodes('//item[#name="HTTP_USER_AGENT"]') as T(N)
where T.N.value('(value/#string)[1]', 'varchar(30)') like '%mozilla%'
Elmah table stores the AllXml column as nvarchar so it needs to be casted to xml
all tags + values, by error id
select T.N.value('#name', 'varchar(30)') as Name,
T.N.value('(value/#string)[1]', 'varchar(30)') as Value
from
(select cast(AllXml as xml) as AllXml from ELMAH_Error where ErrorId = 'DC82172B-F2C0-48CE-8621-A60B702ECF93') e
cross apply AllXml.nodes('/error/serverVariables/item') as T(N)
Before voting down this answer, because uses most of the part of Mikael Eriksson's answer, I let you know I'll happily accept the downvotes only for this reason, since is mainly true
This query will give you all item nodes
select T.N.value('#name', 'varchar(30)') as Name,
T.N.value('(value/#string)[1]', 'varchar(30)') as Value
from Elmah_Error
cross apply AllXml.nodes('/error/serverVariables/item') as T(N)
If you want to filter on any of the values you can put that in a sub-query apply a regular where clause.
select Name,
Value
from
(
select T.N.value('#name', 'varchar(30)') as Name,
T.N.value('(value/#string)[1]', 'varchar(30)') as Value
from Elmah_Error
cross apply AllXml.nodes('/error/serverVariables/item') as T(N)
) T
where Name = 'ALL_HTTP'

How should i design that database in asp.net?

i am e newbie programmer and i want to improve a "student program" for schools. In the program i want to add lesson information. For example:
Student X
Lesson name 1st exam 2nd exam 3rdexam
mathematics 80 70 80
history 70 70 70
...
I have a database that called KFS with three tables.
Identity
RecordID | firstname | lastname | address | city
Lesson
LessonID | name | description
Lessondetail
DataID | RecordID | LessonID | lessonname | firstpoint | secondpoint | thirdpoint
I can already show list of students in a GridView, but I also want to show the selected student's points.
Is my database enough for this application? If yes, how can i design that relationship and show in gridview? Or should i modify my database?
My first thought when looking at your database design (and it could do with editing to make more clear) is: Will a LessonDetail always have 3 exams? Or could it possibly have more at some time in the future?
I would be tempted to break it up into something like this:
LessonDetail(DetailID, DataID, RecordID, LessonID, LessonName)
LessonPoint(DetailID, Point)
That way a Lesson can have as many exam points as you need.
I'll second Dan Diplo's advice about normalizing LessonDetail if it's not certain that you'll always have 3 exams. Unfortunately, that requires a pivot to get your data in the format you want - but that's another question. Also, you have LessonName in LessonDetail - but it should be pulled from Lesson instead.
The ASP.NET side is fairly easy - it's just a standard Master/Details view:
<asp:GridView DataSourceId="dsStudents" runat="server" DataKeyNames="RecordId" />
<asp:DetailsView DataSourceId="dsLessons" runat="server" />
<asp:SqlDataSource ID="dsStudents" runat="server" SelectCommandText=
"SELECT RecordID, firstname, lastname, address, city
FROM Identity
ORDER BY RecordID"
/>
<asp:SqlDataSource ID="dsLessons" runat="server" SelectCommandText=
"SELECT D.LessonID, L.Name, FirstPoint, SecondPoint, ThirdPoint
FROM LessonDetail as D
JOIN Lesson as L ON
D.LessonID = L.LessonID
WHERE D.RecordID = #r
ORDER BY D.LessonID"
>
<SelectParameters>
<asp:ControlParameter Name="r" ControlID="gvStudents"
PropertyName="SelectedDataKey" />
</SelectParameters>
</asp:SqlDataSource>

Resources