Skip to content
This repository was archived by the owner on Jun 29, 2019. It is now read-only.

Commit 323be27

Browse files
author
xibingaomsft
committed
parameterize .py file and limit random number to 3 digit
1 parent 51dff48 commit 323be27

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

Misc/SQLDW/LoadDataToSQLDW.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
DECLARE @StorageAccountKey varchar(255)
23
SET @StorageAccountKey = 'x'
34

@@ -37,6 +38,15 @@ SET @nyctaxi_sample = 'x'
3738

3839
DECLARE @load_data_template varchar(8000)
3940
SET @load_data_template = '
41+
42+
BEGIN TRY
43+
--Try to create the master key
44+
CREATE MASTER KEY
45+
END TRY
46+
BEGIN CATCH
47+
--If the master key exists, do nothing
48+
END CATCH;
49+
4050
-- Create a database scoped credential
4151
CREATE DATABASE SCOPED CREDENTIAL {KeyAlias}
4252
WITH IDENTITY = ''asbkey'' ,

Misc/SQLDW/SQLDW_Data_Import.ps1

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ function ReadHostInput(){
33
$StorageAccountKey0 = Read-Host -Prompt 'Input the storage account key' -AsSecureString
44
$StorageAccountKey1 = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($StorageAccountKey0)
55
$Script:StorageAccountKey = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($StorageAccountKey1)
6-
$ContainerName0 = Read-Host -Prompt 'Input your storage account container name to upload the NYC Taxi dataset to. Only letters (lower case), numbers, and the dash (-) character are allowed'
6+
$ContainerName0 = Read-Host -Prompt 'Input your storage account container name to upload the NYC Taxi dataset to. Only letters, numbers, and the dash (-) character'
77
$Script:Server = Read-Host -Prompt 'Input the SQL DW server name'
88
$Script:Database = Read-Host -Prompt 'Input the SQL DW database name'
99
$Script:Username = Read-Host -Prompt 'Input the SQL DW user name'
10-
$pass0 = Read-Host -Prompt 'Input the password of user name which has the previlige to create the database' -AsSecureString
10+
$pass0 = Read-Host -Prompt 'Input the password of user name which has the previlege to create the database' -AsSecureString
1111
$pass1 = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass0)
1212
$Script:Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($pass1)
1313

14-
$Script:RandomNumber = Get-Random
14+
$Script:RandomNumber = Get-Random -minimum 100 -maximum 999
1515

1616
$Script:KeyAlias = 'KeyAlias' + '_' + $RandomNumber
1717
$Script:ContainerName = $ContainerName0 + '-' + $RandomNumber
@@ -22,9 +22,10 @@ function ReadHostInput(){
2222
$Script:external_nyctaxi_fare = 'external_nyctaxi_fare' + '_' + $RandomNumber
2323

2424
#Specify your table names
25-
$TripTableName0 = Read-Host -Prompt 'Input the NYC Taxi Trip table name, for example nyctaxi_trip_yourname (no dash(-) in table name)'
26-
$FareTableName0 = Read-Host -Prompt 'Input the NYC Taxi Fare table name, for example nyctaxi_fare_yourname (no dash(-) in table name)'
27-
$SampleTableName0 = Read-Host -Prompt 'Input the NYC Taxi 1% Sample table name, for example nyctaxi_sample_yourname (no dash(-) in table name)'
25+
26+
if(($TripTableName0 = Read-Host "Input the NYC Taxi Trip table name") -eq ''){$TripTableName0 = "nyctaxitrip"}else{}
27+
if(($FareTableName0 = Read-Host "Input the NYC Taxi Fare table name") -eq ''){$FareTableName0 = "nyctaxifare"}else{}
28+
if(($SampleTableName0 = Read-Host "Input the NYC Taxi Sample table name") -eq ''){$SampleTableName0 = "nyctaxisample"}else{}
2829
$Script:TripTableName = $TripTableName0 + '_' + $RandomNumber
2930
$Script:FareTableName = $FareTableName0 + '_' + $RandomNumber
3031
$Script:SampleTableName = $SampleTableName0 + '_' + $RandomNumber
@@ -303,7 +304,7 @@ If (Test-Path $conf_file){
303304
}
304305

305306
$DestURL = "http://$StorageAccountName.blob.core.windows.net/$ContainerName"
306-
Write-Host "DestURL: " $DestURL
307+
#Write-Host "DestURL: " $DestURL
307308
# The NYC Taxi dataset on public blob
308309
$Source = "http://getgoing.blob.core.windows.net/public/nyctaxidataset"
309310

@@ -372,12 +373,10 @@ try
372373

373374
$SQLCommand = New-Object System.Data.SqlClient.SqlCommand($qa2, $SQLConnection)
374375
$SQLCommand.CommandTimeout = 0
375-
$SQLCommand.ExecuteScalar()
376376
$qa2_result = $SQLCommand.ExecuteScalar()
377377

378378
$SQLCommand = New-Object System.Data.SqlClient.SqlCommand($qa3, $SQLConnection)
379379
$SQLCommand.CommandTimeout = 0
380-
$SQLCommand.ExecuteScalar()
381380
$qa3_result = $SQLCommand.ExecuteScalar()
382381

383382

@@ -404,6 +403,15 @@ try
404403
(gc ./SQLDW_Explorations.ipynb).replace('<password>', $Password) | sc ./SQLDW_Explorations.ipynb
405404
(gc ./SQLDW_Explorations.ipynb).replace('<database server>', 'SQL Server Native Client 11.0') | sc ./SQLDW_Explorations.ipynb
406405

406+
(gc ./SQLDW_Explorations_Scripts.py).replace('<nyctaxi_trip>', $TripTableName) | sc ./SQLDW_Explorations_Scripts.py
407+
(gc ./SQLDW_Explorations_Scripts.py).replace('<nyctaxi_fare>', $FareTableName) | sc ./SQLDW_Explorations_Scripts.py
408+
(gc ./SQLDW_Explorations_Scripts.py).replace('<nyctaxi_sample>', $SampleTableName) | sc ./SQLDW_Explorations_Scripts.py
409+
410+
(gc ./SQLDW_Explorations_Scripts.py).replace('<server name>', $Server) | sc ./SQLDW_Explorations_Scripts.py
411+
(gc ./SQLDW_Explorations_Scripts.py).replace('<database name>', $Database) | sc ./SQLDW_Explorations_Scripts.py
412+
(gc ./SQLDW_Explorations_Scripts.py).replace('<user name>', $Username) | sc ./SQLDW_Explorations_Scripts.py
413+
(gc ./SQLDW_Explorations_Scripts.py).replace('<password>', $Password) | sc ./SQLDW_Explorations_Scripts.py
414+
(gc ./SQLDW_Explorations_Scripts.py).replace('<database server>', 'SQL Server Native Client 11.0') | sc ./SQLDW_Explorations_Scripts.py
407415
}
408416
else
409417
{
@@ -420,8 +428,17 @@ try
420428
(gc ./SQLDW_Explorations.ipynb) -replace '<database name>', $Database
421429
(gc ./SQLDW_Explorations.ipynb) -replace '<user name>', $Username
422430
(gc ./SQLDW_Explorations.ipynb) -replace '<password>', $Password
423-
(gc ./SQLDW_Explorations.ipynb) -replace '<database driver>', 'SQL Server Native Client 11.0'
431+
(gc ./SQLDW_Explorations.ipynb) -replace '<database server>', 'SQL Server Native Client 11.0'
424432

433+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<nyctaxi_trip>', $TripTableName
434+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<nyctaxi_fare>', $FareTableName
435+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<nyctaxi_sample>', $SampleTableName
436+
437+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<server name>', $Server
438+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<database name>', $Database
439+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<user name>', $Username
440+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<password>', $Password
441+
(gc ./SQLDW_Explorations_Scripts.py) -replace '<database server>', 'SQL Server Native Client 11.0'
425442
}
426443

427444
$end_time = Get-Date

0 commit comments

Comments
 (0)