現在很多個人和商業裝置含有從實體世界中收集資訊的傳感器。例如,大多數電話擁有 GPS,健身裝置可跟蹤你走的步數,恒溫控制器可監控建築的溫度。
在此教程中,你将了解如何将 HDInsight 用于處理暖氣、通風和空氣調節 (HVAC) 系統産生的曆史資料,以識别不能有效維持設定溫度的系統。你将了解如何:
優化和豐富來自多個國家/地區的建築的溫度資料
分析資料以确定哪些建築在保持适宜溫度方面存在問題(實際記錄的溫度對比恒溫控制器設定的溫度)
推斷建築中使用的 HVAC 系統的可靠性
在 Microsoft Excel 中可視化資料
已使用群集配置你完成腳本和查詢所需的所有内容。要将已分析的資料導出到 Microsoft Excel,你必須滿足以下要求:
必須安裝了 Microsoft Excel 2013。
以下 URL 的檔案包含 HVAC 系統設定的溫度以及實際記錄的溫度。這些檔案也包含建築中繼資料,如位置和 HVAC 系統資訊。我們已将此資料加載到此群集的 Windows Azure 存儲 Blob。
可使用此頁頂部的檔案浏覽器頁籤通路存儲在 Windows Azure 存儲 Blob 中的資料。此示例的資料可在 [default storage account]/[defaultcontainer]/HdiSamples/SensorSampleData 路徑下找到。
來自世界 20棟大型建築的傳感器資料
wasb://[email protected]/HdiSamples/SensorSampleData/hvac/
20 棟建築的中繼資料
wasb://[email protected]/HdiSamples/SensorSampleData/building/
以下配置單元語句将建立外部表,允許配置單元查詢存儲在 Azure Blob 存儲的資料。外部表以初始檔案格式保留資料,同時允許配置單元針對檔案内的資料執行查詢。在這種情況下,資料作為逗号分隔值 (CSV) 存儲在檔案中。
以下配置單元語句通過描述檔案内字段、檔案間定界符(逗号)和 Azure Blob 存儲中檔案的位置建立了兩個名為 hvac 和 building 的新表。由此,你可以建立針對自身資料的配置單元查詢。
Create hvac table:
DROP TABLE IFEXISTS hvac;
--create the hvactable on comma-separated sensor data
CREATE EXTERNALTABLE hvac(date STRING, time STRING, targettemp BIGINT,
actualtempBIGINT, system BIGINT, systemage BIGINT, buildingid BIGINT)
ROW FORMATDELIMITED FIELDS TERMINATED BY ','
STORED ASTEXTFILE LOCATION'wasb://[email protected]/HdiSamples/SensorSampleData/hvac/';
Create building table:
DROP TABLE IF EXISTS building;
--create the building table on comma-separated building data
CREATE EXTERNAL TABLE building(buildingid BIGINT,buildingmgr STRING,
buildingageBIGINT, hvacproduct STRING, country STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE LOCATION'wasb://[email protected]/HdiSamples/SensorSampleData/building/';
以下配置單元查詢建立了來自 HVAC 資料的一些溫度,進而查找溫度變化(參見以下查詢)。尤其是查找恒溫控制器設定的目标溫度與記錄溫度之間的差别。如果差别大于 5,則 temp_diff 列将設為“熱”或“冷”,且 extremetemp 設為 1;否則,temp_diff 将設為“正常”且 extremetemp 設為 0。
查詢會将結果寫入兩個新表:hvac_temperatures 和 hvac_building(參見以下“建立表”語句)。hvac_building 表将包含管理者、樓齡和建築的 HVAC 系統等建築資訊,也将用于通過與 hvac_temperatures 表聯接來查找建築的溫度資料。
Create hvac_temperatures table:
DROP TABLE IFEXISTS hvac_temperatures;
--create thehvac_temperatures table by selecting from the hvac table
CREATE TABLEhvac_temperatures AS
SELECT *,targettemp - actualtemp AS temp_diff,
IF((targettemp - actualtemp)> 5, 'COLD',
IF((targettemp - actualtemp)< -5, 'HOT', 'NORMAL')) AS temprange,
IF((targettemp - actualtemp)> 5, '1', IF((targettemp - actualtemp) < -5, '1', 0)) AS extremetemp
FROM hvac;
Create hvac_building table:
DROP TABLE IFEXISTS hvac_building;
--create thehvac_building table by joining the building table and the hvac_temperaturestable
CREATE TABLEhvac_building AS
SELECT h.*,b.country, b.hvacproduct, b.buildingage, b.buildingmgr
FROM building bJOIN hvac_temperatures h ON b.buildingid = h.buildingid;
選擇送出以建立“配置單元”表,并執行分析存儲在 Windows AzureBlob 存儲的傳感器資料的查詢。送出作業後,可通過選擇下方檢視詳細資訊來檢視詳細資訊。
頁底的作業狀态變為已完成後,繼續執行将資料加載到 Excel。
DROP TABLE IF EXISTS hvac;
--create the hvac table on comma-separated sensor data
CREATE EXTERNAL TABLE hvac(date STRING, time STRING,targettemp BIGINT,
actualtempBIGINT, system BIGINT, systemage BIGINT, buildingid BIGINT)
STORED AS TEXTFILE LOCATION'wasb://[email protected]/HdiSamples/SensorSampleData/hvac/';
--create the building table on comma-separatedbuilding data
buildingageBIGINT, hvacproduct STRING, country STRING)
DROP TABLE IF EXISTS hvac_temperatures;
--create the hvac_temperatures table by selecting fromthe hvac table
CREATE TABLE hvac_temperatures AS
SELECT *, targettemp - actualtemp AS temp_diff,
IF((targettemp- actualtemp) > 5, 'COLD',
IF((targettemp- actualtemp) < -5, 'HOT', 'NORMAL')) AS temprange,
IF((targettemp- actualtemp) > 5, '1', IF((targettemp - actualtemp) < -5, '1', 0)) ASextremetemp
DROP TABLE IF EXISTS hvac_building;
--create the hvac_building table by joining thebuilding table and the hvac_temperatures table
CREATE TABLE hvac_building AS
SELECT h.*, b.country, b.hvacproduct, b.buildingage,b.buildingmgr
FROM building b JOIN hvac_temperatures h ONb.buildingid = h.buildingid;
作業會話
查詢名稱
日期
ID
操作
狀态
表中無可用資料
1. 打開 Excel 并建立空白的工作表。
2. 從資料頁籤中,選擇來自其他源,然後選擇來自 Microsoft 查詢。

3. 提示選擇資料源時,選擇示例 Microsoft 配置單元 DSN。
4. 在 Microsoft 配置單元 ODBC 驅動器連接配接對話框中,輸入以下值,然後單擊“确定”。
主機 - HDInsight 群集的主機名。例如,mycluster.azurehdinsight.net
使用者名 - HDInsight 群集的管理者名稱
密碼 - 管理者密碼
所有其它字段均為預設值。
5. 在查詢向導中,選擇 hvac_building 表,然後選擇 > 按鈕。
6. 單擊下一步繼續檢視向導,直到到達帶有完成按鈕的對話框。單擊完成。
7. 出現導入資料對話框時,單擊确定以接受預設設定。完成查詢後,資料将顯示在 Excel 中。
因為資料已導入 Excel,你将使用Power View 以可視方式導出資料。
1. 在 Excel 工作表中,選擇插入頁籤,然後選擇 Power View 以打開新的 Power View 報表。
2. 在 Power View 字段區域,選擇國家/地區和 extremetemp 旁的複選框。清除所有其他複選框。
3. 在字段 框,單擊 extremetemp 旁的向下箭頭,然後選擇計數(非空白)。
4. 從設計頁籤中,選擇地圖以在世界地圖上按國家/地區顯示溫度資料。
地圖上顯示的每個圓圈表示記錄溫度高于或低于目标溫度 5 度之上的次數。圓圈越大,在此位置記錄的極端溫度的執行個體越多。
為了進一步篩選資料,以便你檢視記錄溫度高于或低于目标溫度的地點,請執行以下步驟。
1. 在 Power View 字段區域,清除 extremetemp 複選框,然後選擇 temprange 複選框。選擇 temprange 旁的向下箭頭,然後選擇作為大小添加。
2. 将 temprange 從 Power View 字段區域拖到篩選器框,然後選擇熱或冷的複選框,檢視高于或低于目标溫度的地點。
雖然通過可視化地圖上的溫度資料,你可以更容易檢視哪個地點在維持目标溫度方面出現問題,但你無法由此深入了解根本原因。請執行以下步驟,使用生成資訊确定 HVAC 是否是問題的源頭。
1. 打開新的 Excel 工作表,依次選擇資料頁籤、來自其他源、來自 Microsoft Query。按照先前相同步驟導入資料,但此次選擇 hvac_building 表,且僅選擇 hvacproduct 和 extremetemp 列。
2. 導入資料後,選擇插入頁籤,然後選擇 Power View。
3. 在 Power View 字段的 字段 章節中,單擊 extremetemp 字段旁的向下箭頭,然後選擇計數(非空白)。
4. 從設計頁籤中,選擇柱形圖,然後選擇堆積柱形圖。
5. 顯示圖後,選擇左上角按hvacproduct 排序旁的向下箭頭,然後選擇 extremetemp 的計數以按 extremetemp 字段對列進行排序。
從此圖中,你可以看到 FN39TG 的極端溫度執行個體高于其他機關。
在本教程中,你已成功執行用于分析生成 HVAC 傳感器資料的 HDInsight 配置單元作業。要了解更多資訊,請通路我們的其餘示例作業。如果你具有本教程或其他示例方面的回報,請使用上面的幫助 + 回報連結。
使用以下連結繼續了解如何将配置單元和 Excel 與 HDInsight 一同使用。
<a target="_blank" href="http://azure.microsoft.com/en-us/documentation/articles/hdinsight-use-hive/">将配置單元和 HDInsight 中 Hadoop 一同使用</a>
<a target="_blank" href="http://azure.microsoft.com/en-us/documentation/articles/hdinsight-analyze-twitter-data/">使用 HDInsight 中 Hadoop 分析 Twitter 資料</a>
<a target="_blank" href="http://azure.microsoft.com/en-us/documentation/articles/hdinsight-connect-excel-hive-odbc-driver/">使用 Microsoft 配置單元 ODBC 驅動程式将 Excel 連接配接到 Hadoop</a>
<a target="_blank" href="http://azure.microsoft.com/en-us/documentation/articles/hdinsight-connect-excel-power-query/">使用 Power Query 将 Excel 連接配接到 Hadoop</a>