Monday, March 25, 2013

Managing Fact & Dimension

Recently I got a question from our team member on how are we managing, delta data merging to master data and how do we do synch with source data periodically.  It is very big topic, but How do I put them all in 15 minute discussion…The following example I showed to him and he got the insight into it.

The following script, which talks about common scenario for most of the projects.  Hope any one who is get starting with Warehouse projects.

-------------------------------------
-- Assume scenario where you get source data as
-- single flat table, you need to extract the masters
-- create surrogate keys and handle INSERT / UPDATE for repeated runs.

-- Source Table: tblSource
-- Target Table: dimPlan, factTransaction

-- Temp tables: wrkSource, wrkPlan

-------------------------------------

----------------
-- SOURCE TABLE
----------------
IF OBJECT_ID('tblSource') IS NOT NULL DROP TABLE tblSource
CREATE TABLE tblSource
(
Id INT,
Name VARCHAR(100),
PlanCode CHAR(2),
PlanDesc VARCHAR(200),
)


----------------
-- TEMP TABLE
----------------
IF OBJECT_ID('wrkSource') IS NOT NULL DROP TABLE wrkSource
-- 1. Transaction
CREATE TABLE wrkSource
(
Id INT,
Name VARCHAR(100),
PlanKey INT
)

IF OBJECT_ID('wrkPlan') IS NOT NULL DROP TABLE wrkPlan
-- 2. Master
CREATE TABLE wrkPlan
(
PlanCode CHAR(2),
PlanDesc VARCHAR(200)
)


----------------
-- TARGET TABLE
----------------
IF OBJECT_ID('dimPlan') IS NOT NULL DROP TABLE dimPlan
-- 1. Master
CREATE TABLE dimPlan
(
Id INT IDENTITY(1,1),
PlanCode CHAR(2),
PlanDesc VARCHAR(200)
)

IF OBJECT_ID('factTransaction') IS NOT NULL DROP TABLE factTransaction
-- 2. Transaction
CREATE TABLE factTransaction
(
Id INT,
Name VARCHAR(100),
PlanKey INT
)


----------------
-- MERGE SP
----------------
DROP PROC MG
GO
CREATE PROC MG
AS
BEGIN
-- Extract Master
TRUNCATE TABLE wrkPlan
INSERT INTO wrkPlan(PlanCode, PlanDesc)
SELECT PlanCode, PlanDesc
FROM (
SELECT ROW_NUMBER() OVER (PARTITION BY PlanCode ORDER BY PlanDesc) RNO, PlanCode, PlanDesc
FROM tblSource) S
WHERE RNO =1

-- Merge master
;MERGE dimPlan AS T
USING wrkPlan AS S
ON T.PlanCode = S.PlanCode
WHEN MATCHED THEN UPDATE SET T.PlanDesc = S.PlanDesc
WHEN NOT MATCHED THEN INSERT (PlanCode, PlanDesc) VALUES(S.PlanCode, S.PlanDesc);


-- Merge master --- IF TYPE 2 ON INCLUDE DESC
--;MERGE dimPlan AS T
--USING wrkPlan AS S
--ON T.PlanCode = S.PlanCode
--WHEN MATCHED THEN UPDATE SET T.PlanDesc = S.PlanDesc
--WHEN NOT MATCHED THEN INSERT (PlanCode, PlanDesc) VALUES(S.PlanCode, S.PlanDesc);

-- Extract transaction
TRUNCATE TABLE wrkSource
INSERT INTO wrkSource (id,Name, PlanKey)
SELECT s.id, S.Name, P.Id
FROM tblSource S
JOIN dimPlan P ON S.PlanCode = P.PlanCode


-- Merge transaction
MERGE factTransaction AS T
USING wrkSource AS S
ON T.ID = S.ID
WHEN MATCHED THEN UPDATE SET id = s.id, Name = S.Name, PlanKey = S.PlanKey
WHEN NOT MATCHED THEN INSERT (id,NAME, plankey) VALUES (s.ID,S.NAME, s.plankey);
END
go



----------------
-- UNIT TEST
----------------

SELECT 'Unit test 1. New data' UNIT_TEST
INSERT INTO tblSource VALUES
(1,'RAM','aa','aaaaaaa'),
(2,'RAMA','aa','aaaaaaa'),
(3,'RAMAN','bb','bbbbbbb'),
(4,'RAMU','bb','bbbbbbb')

go

SELECT * FROM tblSource
EXEC MG
SELECT * FROM factTransaction
SELECT * FROM dimPlan

SELECT 'Unit test 2. Data change' UNIT_TEST
INSERT INTO tblSource VALUES (5,'RAddM','aa','aaaaaaa')
UPDATE tblSource SET NAME = 'UPDATED...', PlanCode = 'BB', PlanDesc = 'aaUPDATED TO BBBBB' WHERE ID =2

SELECT * FROM tblSource
EXEC MG
SELECT * FROM factTransaction
SELECT * FROM dimPlan

Monday, February 4, 2013

Windows Restart

I was trying to install SharePoint 2013, the setup was complaining about a pending system restart.  Even after multiple restart / Shutdown.  The error message is same, it is confirmed that I need some tweak in Windows to make it working.

Here is the solution which worked for me

  1. Open Register Editor using Run "regedit" .
  2. Find the key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager"
  3. Rename the "PendingFileRenameOperations" value to "PendingFileRenameOperations2"

The magic worked, the setup program is no more complaining about pending windows restart.

Happy coding.

Sunday, February 3, 2013

XBox Live connection

I am excited to connect XBox to internet and want to stream video directly in TV.  But configuring XBox to connect XBox Live had some hiccup. 

To connect XBox live, XBox required update and for update it needs to connect XBox live, the cyclic dependency made it stuck.

Update Failed

Can't download the update.  To test your connection, open System Settings and select Network Settings, Test Xbox LIVE Connection.

If the problem persists, go to
www.xbox.com/support.

Status Code:335A-0000-0000-0300-8007-2751

The error message description pointed me to change the MTU settings minimum to 1364.  This URL helped to get the MTU setting.

ping www.expedient.net -f -l 1492

My router MTU setting was higher than the minimum required.  So there is no clue, Connected XBox support chat, waited for 30 minutes.  No response, I was keep searching solution on the web for the problem, In the XBox update site it is mentioned that we can do update using USB, DVD.  Wow… that looked like good plan.  Yes, it was I downloaded the XBox updated to USB drive and loaded to XBox device.  boooom it updated and connected to XBox Live.

Thrilled to see XBox live videos, to my surprise all the video had some price tag!! 

Wednesday, January 9, 2013

SharePoint Error Story

There was one JavaScript error which is killing every ones time.

Some time when we access a SSRS Drill thru in some scenario we go the following error.

Dialog

When we debug in IE it given long list of complaints.

SCRIPT5022: Sys.WebForms.PageRequestManagerServerErrorException: An unexpected error has occurred.
ScriptResource.axd, line 5 character 16485

HTML1202: http://server/sites/site/ is running in Compatibility View because 'Display intranet sites in Compatibility View' is checked.
SEC7115: :visited and :link styles can only differ by color. Some styles were not applied to :visited.
HTML1202: http://Set/sites/projec/Pages/RepName.aspx is running in Compatibility View because 'Display intranet sites in Compatibility View' is checked.
HTML1512: Unmatched end tag.
RepName.aspx, line 1095 character 105

SEC7115: :visited and :link styles can only differ by color. Some styles were not applied to :visited.
ReportName.aspx

SCRIPT5022: Sys.WebForms.PageRequestManagerServerErrorException: An unexpected error has occurred.
ScriptResource.axd, line 5 character 16485

SCRIPT5022: Sys.WebForms.PageRequestManagerServerErrorException: An unexpected error has occurred.
ScriptResource.axd, line 5 character 16485

SCRIPT5022: Sys.WebForms.PageRequestManagerServerErrorException: An unexpected error has occurred.
ScriptResource.axd, line 5 character 16485

As it is a JavaScript error, every one started looking into client configurations and then Web.Config.

We found many solutions they all worked in first go, as the error was intermittent after every setting change we believed the issue is fixed.  But the truth is the Error smiled to us once in a while!!

  • Turn off HTTP 1.1 in browser
  • Turn off Async Rendering in Report Viewer Web part
  • Recreate the page
  • aspnet:MaxHttpCollectionKeys
  • scriptResourceHandler enableCompression="false" enableCaching="true"

then what!!

Start from the beginning.  We started analyzing the all the logs, SharePoint, SSRS, IIS.  Try reproducing the error and get point in time error log.  The point in time error study helped.

We got the following error message in SharePoint log

Message

Unexpected error occurred in method 'GetObject' , usage 'SPViewStateCache' - Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out.. Additional Information : The client was trying to communicate with the server : net.tcp:/DEVSRV2.com:22233     at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)     at Microsoft.ApplicationServer.Caching.DataCache.InternalGet(String key, DataCacheItemVersion& version, String region, IMonitoringListener listener)     at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass49.<Get>b__48()     at Microsoft.SharePoint.DistributedCaching.SPDistributedCache.GetObject(String key)'.

Unable to write SPDistributedCache call usage entry.

ViewStateLog: Failed to read from the velocity cache: http://ServerName/sites/ProjName/Pages/ReportName.aspx

So the culprit is Distributed Cache

  • Distributed Cache is the new service in SharePoint 2013
  • For View State, DistributedViewStateCache is used.
  • As the View State is not available while loading the page, we are getting the Java Script Error.

Lessons

  • Understand the problem first before jumping to solutions, try to get some pattern.  All Bing answers are not for you!!
  • Get as many logs as possible. especially the point in time log.  Get the log backup.
  • Widen the scope and thing broader for the intermittent issues.

Happy coding & debugging!!

Monday, November 19, 2012

SSAS

Great collection of useful SSAS articles.  It helped me.  It will help all.

http://ssas-wiki.com

Thursday, October 4, 2012

Insert Object in Office 2013

Office 2013 become much more smart and packed with lot of features, at the same time switching between the version always has some learning curve.  Recently we spend few minute in searching the insert object option in 2013.

image

In Office 2010

Insert object

Engineering Excellence

Engineering Excellence Having solid engineering process and tools in place help to improve the agility of the system. Here is the high-level...