17. HDInsight
Java, Eclipse, Hive, etc.
フルマネージド の
Hadoop クラスタ
Data Lake Analytics
C#, SQL & PowerShell
フルマネージド の
分散管理処理クラスタ
DryAd ベース
18. 20
ADL Analytics Account
Links to ADL Stores
ADL Store Account
(the default one)
Job Queue
キーの設置:
- Max Concurrent Jobs
- Max ADLUs per Job
- Max Queue Length
Links to Azure Blob Stores
U-SQL Catalog
Metadata
U-SQL Catalog Data
ADLAU = Azure Data Lake Analytics Unit
19. ブロック (Extent)
Azure Data Lake Store file
…Block 1 Block 2 Block 2
Backend Storage
Data node Data node Data node Data node Data nodeData node
Block Block Block Block Block Block
20. Local
ADL Store
Azure Portal
Azure PowerShell
Azure CLI
Data Lake Tools for Visual Studio
Azure Data Factory
AdlCopy ツール
Azure Stream Analytics
Azure HDInsight Storm
Azure Data Factory
Apache Sqoop
Apache DistCp
Azure Data Factory
AdlCopy ツール
23. REFERENCE ASSEMBLY WebLogExtASM;
@rs =
EXTRACT
UserID string,
Start DateTime,
End DateTime,
Region string,
SitesVisited string,
PagesVisited string
FROM "swebhdfs://Logs/WebLogRecords.csv"
USING WebLogExtractor ();
@result = SELECT UserID,
(End.Subtract(Start)).TotalSeconds AS Duration
FROM @rs ORDER BY Duration DESC FETCH 10;
OUTPUT @result TO "swebhdfs://Logs/Results/top10.txt"
USING Outputter.Tsv();
U-SQL 最初の一歩
• 型定義は C# の型定義と同じ
• データをファイルから抽出・読み込み
するときに、スキーマが必要
Data Lake Store のファイル
独自形式を解析するカスタム関数
C# の関数
行セット:
(中間テーブル
の概念に近い)
TSV形式で読み取る関数
29. Management
Data Lake Analytics アカウント
Jobs
U-SQL job
Catalog
カタログ(メタデータ)
Management
Data Lake Store アカウント
File System
Upload, download, list, delete, rename,
append
(WebHDFS)
Analytics Store
Azure Active Directory
42. File Set: datetimes の使用
EXTRACT
user string,
id string,
date DateTime,
FROM
"/input/{date:yyyy}/{date:MM}/{date:dd}"
USING Extractors.Csv();
43. そして、TABLE の作成
CREATE TABLE SampleDBTutorials.dbo.ClickData
(
SessionId int,
Domain string,
Clinks int,
INDEX idx1 //Name of index
CLUSTERED (Domain ASC)
PARTITIONED BY HASH (Domain)
);
INSERT INTO SampleDBTutorials.dbo.ClickData
SELECT *
FROM @clickdata;
ドメインごとにパーティション分割
Domain1 Domain2 Domain3
Facebook.com Twitter.com Microsoft.com
Facebook.com Twitter.com Microsoft.com
Facebook.com Twitter.com Microsoft.com
44. クラスタ化インデックス による効率的な処理
Full agg
Region ごとにクラスタ化されたテーブル
Read Read Read Read
Full agg Full agg Partial agg Partial agg
Extent 1 Extent 2 Extent 3 Extent 4
Sort Sort
Top 100 Top 100 Sort
Top 100
Top 100
Read Read Read Read
非構造化データ
Partial agg Partial agg Partial agg Partial agg
Full agg Full agg Full agg
Sort Sort Sort
Top 100 Top 100 Top 100
Extent 1 Extent 2 Extent 3 Extent 4
Partition Partition Partition Partition
@rs1 =
SELECT Region,
COUNT() AS Total
FROM @rs
GROUP BY Region;
@rs2 =
SELECT TOP 100
Region, Total
FROM @rs1
ORDER BY Total;
高コストな処理
45.
46. Job Front End
Job Scheduler Compiler Service
Job Queue
Job Manager
U-SQL Catalog
YARN
Job 投入
Job 実行
U-SQL Runtime vertex 実行
47. U-SQL C# user code
C++ system code
Algebra
other files
(system files, deployed resources)
managed dll
Unmanaged dll
Input
script
Compilation output (in job folder)
Files
Meta
Data
Service
Deployed to vertices
Compiler & Optimizer
60. Map reduce
Hbase
トランザクション
HDFS アプリケーションHive クエリ
Azure HDInsight
Hadoop WebHDFS クライアント
Hadoop WebHDFS クライアント
WebHDFS
エンドポイント
WebHDFS
REST API
WebHDFS
REST API
ADL Store file ADL Store file ADL Store file ADL Store fileADL Store file
Azure Data Lake Store
61. スケールに制限なし
U-SQL, SQLのメリットにC#のパワーを加えた新しい言語
Data Lake Store に最適化
Azure データサービスへの FEDERATED QUERY
企業利用のためのセキュリティ、
アクセス制御、暗号化など
ジョブ単位での課金とスケール設定
Azure Data Lake
Analytics
全てのどんなサイズのデータ
でも処理できる
Apache YARNベースの
分析サービス
62. 多くの SQL & .NET DEVELOPERS
宣言型言語の SQL と
逐次実行型である C# のパワーを融合
構造化、一部構造化、非構造化データの融合
全てのデータに分散クエリの実施
U-SQL
Big Data のための新しい言語
66. TABLEオブジェクトを返す関数
U-SQL の記述を含む(OUTPUT と
DDL/DMLを除く)
利点:
– コードの冗長性排除
– 再利用
– スクリプトの管理しやすさ
//create the TVF
DROP FUNCTION IF EXISTS SearchLogView; //DDL statement
CREATE FUNCTION WebLogView ( )
RETURNS @result TABLE (
UserId int, Start DateTime, End DateTime, Region string,
SiteVisited string, PagesVisited string
)
AS BEGIN
@result =
EXTRACT
UserId int, Start DateTime, End DateTime, Region
string,
SiteVisited string, PagesVisited string
FROM “swebhdfs://Logs/WebRecords.txt"
USING WebLogExtractor();
RETURN;
END;
//now use the TVF
@searchlog = WebLogView();
OUTPUT @searchlog TO “swebhdfs://Logs/WebRecords_copy.tsv"
USING Outputters.Tsv();
67. –
–
67
[SqlUserDefinedExtractor]
public class DriverExtractor : IExtractor
{
private byte[] _row_delim;
private string _col_delim;
private Encoding _encoding;
// Define a non-default constructor since I want to pass in my own parameters
public DriverExtractor( string row_delim = "¥r¥n", string col_delim = ",“
, Encoding encoding = null )
{
_encoding = encoding == null ? Encoding.UTF8 : encoding;
_row_delim = _encoding.GetBytes(row_delim);
_col_delim = col_delim;
} // DriverExtractor
// Converting text to target schema
private void OutputValueAtCol_I(string c, int i, IUpdatableRow outputrow)
{
var schema = outputrow.Schema;
if (schema[i].Type == typeof(int))
{
var tmp = Convert.ToInt32(c);
outputrow.Set(i, tmp);
}
...
} //SerializeCol
public override IEnumerable<IRow> Extract( IUnstructuredReader input
, IUpdatableRow outputrow)
{
foreach (var row in input.Split(_row_delim))
{
using(var s = new StreamReader(row, _encoding))
{
int i = 0;
foreach (var c in s.ReadToEnd().Split(new[] { _col_delim }, StringSplitOptions.None))
{
OutputValueAtCol_I(c, i++, outputrow);
} // foreach
} // using
yield return outputrow.AsReadOnly();
} // foreach
} // Extract
} // class DriverExtractor
69. 独自の形式のファイルの読み込み
アセンブリをアップ
ロード・登録
2
CREATE ASSEMBLY WebLogExtAsm
FROM @”/WebLogExtAsm.dll"
WITH PERMISSION_SET =
RESTRICTED;
CREATE EXTRACTOR
WebLogExtractor EXTERNAL NAME
WebLogExtractor;
IExtractor Interfaceを
実装する
using
Microsoft.SCOPE.Interfaces;
public
WebLogExtractor:IExtractor
{
public override
IEnumerable<IRow>
Extract(…)
{
…
}
…
}
1
REFERENCE ASSEMBLY
WebLogExtAsm;
//ビルトイン抽出関数のように使
える
SELECT * FROM
@“swebhdfs://Logs/WebRecords.
txt”
USING WebLogExtractor();
アセンブリを参照
3
70. 集合関数もある!
@tmp1 = SELECT Region, (End.Subtract(Start)).TotalSeconds
AS Duration FROM @rs;
@rs1 = SELECT
COUNT() AS NumUsers,
Region,
SUM (Duration) AS TotalDuration,
AVG (Duration) AS AvgDuration,
MAX (Duration) AS MaxDuration,
MIN (Duration) AS MinDuration
FROM @tmp1
GROUP BY Region;
71. TABLE 作成後の操作
CREATE CLUSTERED INDEX ON
ASC PARTITIONED BY HASH
CREATE STATISTICS IF NOT EXISTS ON
WITH FULLSCAN
View Functions Procedure
72. 行セットの連結
LEFT OUTER JOIN
LEFT INNER JOIN
RIGHT INNER JOIN
RIGHT OUTER JOIN
FULL OUTER JOIN
CROSS JOIN
LEFT SEMI JOIN
RIGHT SEMI JOIN
EXCEPT ALL
EXCEPT DISTINCT
INTERSECT ALL
INTERSECT DISTINCT
UNION ALL
UNION DISTINCT
73. SQL Database に直接アクセス
CREATE CREDENTIAL IF NOT EXISTS dahatakeAdmin
WITH USER_NAME ="dahatake", IDENTITY =
"dahatakeSec";
CREATE DATA SOURCE IF NOT EXISTS pubsSource
FROM AZURESQLDB
WITH
(
PROVIDER_STRING = "Initial
Catalog=pubs;Encrypt=True",
CREDENTIAL = dahatakeAdmin
);
@result = SELECT * FROM EXTERNAL pubsSource
EXECUTE @"SELECT * FROM dbo.employee";
OUTPUT @result TO "/output/employee.csv"
USING Outputters.Csv();
Install-Module AzureRM
Install-AzureRM
Login-AzureRmAccount
Get-AzureRmSubscription
Set-AzureRmContext -SubscriptionId
“<subscription ID>"
$passwd = ConvertTo-SecureString “<password>" -
AsPlainText -Force
$mysecret = New-Object
System.Management.Automation.PSCredential("daha
takeSec", $passwd)
New-AzureRmDataLakeAnalyticsCatalogSecret -
DatabaseName "master" -AccountName
"dahatakeadla" -Secret $mysecret
-Host "dahatakesql.database.windows.net" -Port
1433
資格情報オブジェクト: https://msdn.microsoft.com/ja-jp/library/azure/mt621327.aspx
74.
75. パフォーマンス改善
<><><><>
<><><><>
<><><><>
<><><><>
<><><><>
<><><><>
Extent 1
Region = “en-us”
<><><><>
<><><><>
<><><><>
<><><><>
<><><><>
<><><><>
Extent 2
Region = “en-gb”
<><><><>
<><><><>
<><><><>
<><><><>
<><><><>
<><><><>
Extent 3
Region = “en-fr”CREATE TABLE
LogRecordsTable
(UserId int,
Start DateTime,
Region string,
INDEX idx CLUSTERED
(Region ASC)
PARTITIONED BY HASH
(Region));
インサート時に、
“Region” カラムに基づ
き、3つの範囲に渡って
ハッシュ分散される
INSERT INTO LogRecordsTable
SELECT UserId, Start, End, Region FROM @rs
パーティションが
分かれている
@rs = SELECT * FROM LogRecordsTable
WHERE Region == “en-gb”
1
2
3
86. // THIS CODE IS SCOPE -> NEEDS TO BE UPDATED TO U-SQL
public class SampleNonRecursiveReducer: Reducer
{
public override bool IsRecursive { get { return true; } }
public override Schema Produces(string[] columns, string[] args, Schema input)
{
…
}
public override IEnumerable<Row> Reduce(RowSet input, Row output, string[] args)
{
…
}
}
#ENDCS
87. Distributed data reduction
SELECT Gender, SUM(…) AS Result
FROM HugeInput
GROUP BY Gender;
This job will succeeded even if the input is huge.
• But not all Reducers Can be recursive
− Median
− Percentile