簡體   English   中英

Kusto/Azure 數據資源管理器 - 如何使用時間跨度字段對外部表進行分區?

[英]Kusto/Azure Data Explorer - How can I partition an external table using a timespan field?

希望有人能提供幫助.. 我是 Kusto 的新手,必須從工作的 Azure Blob 存儲帳戶獲取外部表讀取數據,但我擁有的一個表是獨一無二的,因為時間戳列的數據被拆分為 2 個單獨的列,即 LogDate 和 LogTime(參見下面的腳本)。

我的數據存儲在 Azure 存儲帳戶容器(例如容器名為“employeedata”)中的以下結構中:{employeename}/{year}/{month}/{day}/{hour}/{minute}。 csv,采用簡單的 CSV 格式。

我知道 CSV 很好,因為如果我將它導入到普通的 Kusto 表中,它會完美運行。

我用於創建外部表的 KQL 腳本如下所示:

.create-or-alter external table EmpLogs (Employee: string, LogDate: datetime, LogTime:timestamp) 
kind=blob 
partition by (EmployeeName:string = Employee, yyyy:datetime = startofday(LogDate), MM:datetime = startofday(LogDate), dd:datetime = startofday(LogDate), HH:datetime = todatetime(LogTime), mm:datetime = todatetime(LogTime))
pathformat = (EmployeeName "/" datetime_pattern("yyyy", yyyy) "/" datetime_pattern("MM", MM) "/" datetime_pattern("dd", dd) "/" substring(HH, 0, 2) "/" substring(mm, 3, 2) ".csv")
dataformat=csv 
( 
    h@'************************' 
) 
with (folder="EmployeeInfo", includeHeaders="All")

我不斷收到以下錯誤,這不是很有幫助(從完全錯誤中編輯,基本上歸結為某處存在語法錯誤):

語法錯誤:無法解析查詢:{“錯誤”:{“代碼”:“BadRequest_SyntaxError”,“消息”:“請求無效,無法執行。”,“@type”:“Kusto.Data.Exceptions。 SyntaxException", "@message": "語法錯誤:無法解析查詢:. 查詢:'.create-or-alter external table.......

我知道todatetime() function 適用於時間跨度,我用另一個表對其進行了測試,它創建了一個類似於以下內容的日期:0001-01-01 20:18:00.0000000。

我曾嘗試在時間戳/LogTime 列上使用 bin() function,但出現與上述相同的錯誤,甚至嘗試將時間值作為字符串導入並對其進行一些字符串操作,但沒有運氣。 得到相同的語法錯誤。

任何幫助/指導將不勝感激。

謝謝!!

目前,無法基於多列定義外部表分區。 如果您的數據集時間戳分為兩列: LogDate:datetimeLogTime:timestamp ,那么您可以做的最好的事情是按時間使用虛擬列進行分區:

.create-or-alter external table EmpLogs(Employee: string, LogDate:datetime, LogTime:timespan) 
kind=blob 
partition by (EmployeeName:string = Employee, PartitionDate:datetime)
pathformat = (EmployeeName "/" datetime_pattern("yyyy/MM/dd/HH/mm", PartitionDate))
dataformat=csv 
( 
    //h@'************************'
) 
with (folder="EmployeeInfo", includeHeaders="All")

現在,您可以按虛擬列過濾並使用LogTime進行微調:

external_table("EmpLogs")
| where Employee in ("John Doe", ...)
| where PartitionDate between(datetime(2020-01-01 10:00:00) .. datetime(2020-01-01 11:00:00))
| where LogTime ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM