Tuesday, December 25, 2018

How to create a free Databricks account and start work with it?





To learn Databricks you can create a free Databricks account by following the steps below. This account can be used to practice Clusters, Workspace (Notebooks), Data, SparkUI and etc. This free account is created in AWS (Amazon Web Services).

Paid version has some additional features like Jobs (Scheduling) and etc. 




Step 1: Go to below URL:




Step 2: Go to “Community Edition” and click on “Get Started”






Step 3: Fill-in below form (Sign up for Databricks Community Edition) and click on “Sign up”.

                                          
       




Step 4: You will get email from Databricks to confirm your email address




Step 5: Click on the link and choose your password




Step 6:  Go to login Screen and give your credentials (email address and password)



Step 7: You will get Databricks welcome screen



Step 8: You can create your own new Notebook or Cluster or Table 





Additional Info:
1. Welcome to Big Data world.
2.  Databricks can be developed and deployed in Azure cloud or Amazon Web Service Cloud.
3.  To lean more about Databricks pricing please refer below link.


Thursday, October 4, 2018

Azure – Data warehouse – Elastic feature in Azure SQL Server


Azure – Data warehouse – Elastic feature in Azure SQL Server

Given Scenario:
I have more than 1 Azure SQL databases and I need to write ETL program to populate records from more than one database, also need to do some manipulation or massage the data before loading. Due to country specific regulatory requirement and licensing cost, I was recommended not to use Azure Data Factory or Azure Data Bricks.

Solution:
Azure SQL Server Database has a feature called “Elastic Query”, by using this feature you can connect to more than one Azure SQL databases and write queries on them. Therefore, you can connect and fetch records from more than one database.

There are 5 steps that you need to follow to use Elastic feature                         
Step 1: Create Master Key
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<Password>';

Step 2: Create database scoped credential
CREATE DATABASE SCOPED CREDENTIAL <ElasticDBQuery_Name>
 WITH IDENTITY = '<UserName>',
 SECRET = '<Password>'; 
                                                                            
Step 3: Create External Data Source
CREATE EXTERNAL DATA SOURCE <DS_Name4Elastic> WITH
    (TYPE = RDBMS,
    LOCATION = '<Azure SQL Server>',
    DATABASE_NAME = '<Azure Database>',
    CREDENTIAL = < ElasticDBQuery_Name >,
) ;

Step 4: Create Schema (This is optional – I created it for clarity purpose)
Create Schema <Elastic Schema>
ð  This is to separate elastic tables with other database objects. This step is not needed.

Step 5: Create External Tables
CREATE EXTERNAL TABLE [<Elastic Schema>].[DimCustomer](
[CustomerNumber] [int] IDENTITY(1,1) NOT NULL Primary Key,
[CustomerName] [nVarchar](100) NULL,
[LocationKey] [int] NULL,
……
)
 WITH
( DATA_SOURCE = <DS_Name4Elastic>,
                SCHEMA_NAME = '<SourceDBSchema>',
                OBJECT_NAME = '<SourceDBTableName>'
                )

GO


Challenges:

  •        Except nVarchar(Max), other LOB data types are not support (eg XML Datatype).
  •        To call Stored Procedure from one Azure database to another database. You need to use “EXEC SP_EXECUTE_REMOTE”.
  •        When you use “EXEC SP_EXECUTE_REMOTE”, you cannot return set of records as output parameter.
  •      Create table in Source, Dump the data in Source, then pull it in Target (using elastic feature)
                  
Limitation of Elastic Queries:


  •         Running your first elastic query will take few minutes because it load the elastic query functionality.
  •          Scripting of external data sources or external tables from SSMS or SSDT is not yet supported.
  •          Import/Export for SQL DB does not yet support external data sources and external tables. If you need to use Import/Export, drop these objects before exporting and then re-create them after importing.
  •         Elastic query currently only supports read-only access to external tables. You can, however, use full T-SQL functionality on the database where the external table is defined. This can be useful to, e.g., persist temporary results using, e.g., SELECT INTO, or to define stored procedures on the elastic query database which refer to external tables.
  •          Except for nvarchar(max), LOB types are not supported in external table definitions.
  •          Column statistics over external tables are currently not supported. Tables statistics are supported, but need to be created manually.


Reference materials:





Other Info:
a. The source table structure and external table structure should be same.
b.  If the password or credentials are changed in source database, then use below command to change the credentials.

Error Message
Msg 46824, Level 16, State 1, Line 192
Login failed on <Azure SQL Server>.  Please verify that the shards are accessible and that the credential information affiliated with external data source <DS_Name4Elastic> is correct.


Fix
 ALTER DATABASE SCOPED CREDENTIAL <ElasticDBQuery_Name>
 WITH IDENTITY = '<UserName>',  
 SECRET = <New Password>';


See the link for further details


Saturday, July 8, 2017

Introduction to GIT and SourceTree



Git is an open source Version Control software to handle from small to very large projects with speed and efficiency. For documentation you can see the "https://git-scm.com/doc" link.



I used "SourceTree" as frontend in my local machine. It's a GUI for GIT and also a free software which you can download from "https://www.sourcetreeapp.com" link. The Graph at the Left give pictorial representation the history of the code. The description shows



The key concepts of GIT are as follows:

Remote Master:
This is main repository where the code is stored.  It has the latest merged code.

Local Master:
A copy of all code from remote master is stored in Local. Every developer has to set this in order to do the development.

Clone:
=> Clone option is to get a local copy from remote repository
=> Sample screenshot shown below





Pull changes from a remote repository (Git)

=> Click on the local branch you want to work or local master to get the latest changes from REMOTE Master.
=> Click on Pull button top.











Commit and push a change (Git)

=> Click on Commit button on top
=> Select to files you want commit
=> Click on Stage option.
=> All the selected files will be moved to Stage


=> Give the comments for Commit and enable "Push changes immediately to -". As shown below.



=> The changes will be saved and pushed to Remote.



Create a branch (Git)

=> Click on Branch button on top
=> Give new branch name as shown below






=> It will be created locally
=> Your changes will be tracked & saved in the newly created branch.





See the link for further details (it also contains creation and push a branch to the remote repository). https://confluence.atlassian.com/get-started-with-sourcetree/commit-and-push-a-change-git-847359114.html





Merge changes from one branch to another (Git)

You can merge the changes from other branches. Please see the link for further details




To setup a repository please see the following link. This explains various scenarios of setting up a repository.







Thursday, June 29, 2017

SQL server - How to see the tables, columns and views




How to see the tables, columns and views from SQL server Database?

This Blog is for SQL beginners. The approach is to use “INFORMATION_SCHEMA” view to fetch list of tables/columns/views. Please see the below details for further details.



1.       To view list of all the tables using below command.

SELECT                 *             FROM                   INFORMATION_SCHEMA.TABLES

 



          SP_HELP "INFORMATION_SCHEMA.COLUMNS"
             




2.      To see list of fields of a table, use “INFORMATION_SCHEMA.COLUMNS” view. You can also use "SP_HELP '<tablename>' ", but the problem I faced with SP_HELP is the data type of few columns are not correct.



SELECT                 *             FROM                   INFORMATION_SCHEMA.COLUMNS
             



SP_HELP "INFORMATION_SCHEMA.COLUMNS"


              



3.      To see list of views, use “INFORMATION_SCHEMA.VIEW” view. You can see view script by using “VIEW_DEFINITION”.



   SELECT                        *             FROM                   INFORMATION_SCHEMA.VIEWS


             



SP_HELP "INFORMATION_SCHEMA.VIEW"

              




  

Please refer below link to understand more about “INFORMATION_SCHEMA” view.



Friday, May 12, 2017

Simple SQL Trips and Tricks (Formatting)

I found simple SQL Tips and Tricks which helped me to make the changes quickly and analyze issues.


  • Always give the database name in the script. It should be at the top of any SQL script file.
USE [DBName]
GO
;
  • Use the [SchemaName]  and [TableName] in your SQL commands with square brackets ("[]") for fields, schema and table. For example
SELECT [Field1] , [Field2], [Field3] FROM  [dbo].[Table1]; 
 UPDATE [dbo].[Table1]     SET [Field1]  = 'NewValue'   WHERE [Field2] = 'Condition';

  • Give Tab space between each word and also align vertically as shown below:
 UPDATE [dbo].[Table1]    SET [Field1]  = 'NewValue'   WHERE [Field2] = 'Condition';
 UPDATE [dbo].[Tab2]       SET [Field2]  = 'New'            WHERE [F1]       = 'Condition2'; 
 UPDATE [dbo].[Tab3]       SET [Field5]  = 'Update Val' WHERE [Fld1]    = 'Condition2';  
Above simple alignment steps help us in changing values horizontally (using Shift + Alt and then up or down arrow).
I used Microsoft SQL Server Management Studio (SQL Server Management Solutions, SQL Server Management Studio Projects).