Azure流分析 - 加入csv文件会返回0行

时间:2015-06-29 16:26:35

标签: azure azure-stream-analytics

我有以下查询:

SELECT
[VanList].deviceId
,[VanList].[VanName]
events.[timestamp]
,events.externaltemp
,events.internaltemp
,events.humidity
,events.latitude    
,events.longitude

INTO
    [iot-powerBI]
FROM
    [iot-EventHub] as events timestamp by [timestamp]
    join [VanList] on events.DeviceId = [VanList].deviceId

其中iot-eventHub是我的事件中心,VanList是已上传到azure存储的引用列表(csv文件)。

我尝试上传示例数据来测试查询,但它总是返回0行。

enter image description here

以下是我的事件中心输入

捕获的JSON示例
    [
   {
      "DeviceId":1,
      "Timestamp":"2015-06-29T12:15:18.0000000",
      "ExternalTemp":9,
      "InternalTemp":8,
      "Humidity":43,
      "Latitude":51.3854942,
      "Longitude":-1.12774682,
      "EventProcessedUtcTime":"2015-06-29T12:25:46.0932317Z",
      "PartitionId":1,
      "EventEnqueuedUtcTime":"2015-06-29T12:15:18.5990000Z"
   } ]

以下是我的CSV参考数据示例。

deviceId,VanName
1,VAN 1
2,VAN 2
3,Standby Van

两个列表都包含设备ID为1,因此我希望我的查询能够将两者结合在一起。

我在我的查询语法中尝试过使用“内连接”和“连接”,但都没有导致成功连接。 我的Stream Analytics查询有什么问题?

2 个答案:

答案 0 :(得分:2)

尝试在联接中添加CAST功能。我不确定为什么这样做并且为VanList引用数据输入添加CREATE TABLE子句并不能完成同样的事情。但我认为这很有效。

SELECT
[VanList].deviceId
,[VanList].[VanName]
,events.[timestamp]
,events.externaltemp
,events.internaltemp
,events.humidity
,events.latitude    
,events.longitude

INTO
    [iot-powerBI]
FROM
    [iot-EventHub] as events timestamp by [Timestamp]
    join [VanList] on events.DeviceId = cast([VanList].deviceId as bigint)

答案 1 :(得分:0)

我唯一能看到的是您在原始查询中缺少逗号,否则看起来是正确的。我会尝试重新创建Stream Analytics工作。这是另一个对我有用的例子。

SELECT 
   countryref.CountryName as Geography,
    input.GeographyId as GeographyId

    into [country-out]

FROM input timestamp by [TransactionDateTime]
Join countryref 
on countryref.GeographyID = input.GeographyId here

输入数据示例

{"pageid":801,"firstname":"Gertrude","geographyid":2,"itemid":2,"itemprice":79.0,"transactiondatetime":"2015-06-30T14:25:51.0000000","creditcardnumber":"2ggnC"}
    {"pageid":801,"firstname":"Venice","geographyid":1,"itemid":10,"itemprice":169.0,"transactiondatetime":"2015-06-30T14:25:51.0000000","creditcardnumber":"xLyOp"}
    {"pageid":801,"firstname":"Christinia","geographyid":2,"itemid":2,"itemprice":79.0,"transactiondatetime":"2015-06-30T14:25:51.0000000","creditcardnumber":"VuycQ"}
    {"pageid":801,"firstname":"Dorethea","geographyid":4,"itemid":2,"itemprice":79.0,"transactiondatetime":"2015-06-30T14:25:51.0000000","creditcardnumber":"tgvQP"}
    {"pageid":801,"firstname":"Dwain","geographyid":4,"itemid":4,"itemprice":129.0,"transactiondatetime":"2015-06-30T14:25:51.0000000","creditcardnumber":"O5TwV"}

国家/地区参考数据

[
  {
    "GeographyID":1,
    "CountryName":"USA"
  },
  {
    "GeographyID":2,
    "CountryName":"China"
  },
  {
    "GeographyID":3,
    "CountryName":"Brazil"
  },
  {
    "GeographyID":4,
    "CountryName":"Andrews country"
  },
  {
    "GeographyID":5,
    "CountryName":"Chile"
  }
]