由于列损坏,无法打开或查询 .parquet 文件

Unable to open or query .parquet files due to corrupted column

我正在将 JSON 遥测数据从 Azure 流分析发送到序列化为 .parquet 文件的 Azure Data Lake Gen2。然后,我从数据湖在我的 Azure Synapse Serverless SQL 池中创建了一个视图,我可以连接到该池并查询报告数据。

每隔一段时间我会运行查询并返回以下错误:

Error handling external file: 'Invalid metadata in parquet file. Number of rows in metadata does not match actual number of rows in parquet file.'. File/External table name: 'https://test123.dfs.core.windows.net/devicetelemetry/2021/12/03/20/-1875592941_d9a0239529f04e1eb587b83d50bbb590_1.parquet'.

当我尝试使用“Apache Parquet Viewer”或任何其他镶木地板查看器打开有问题的 .paqruet 文件时,它出错并拒绝打开文件,抱怨名为 'data' 的列未定义。数据列是一个 JSON 字符串,其中包含来自 IoT 设备的各种传感器读数。

将数据发送到我的 ADLS 的我的 StreamAnalytics 查询如下所示:

SELECT 
  Tel.identities.corporationId AS corporationId, Tel.identities.deviceId, 
  Tel.deviceTelemetry.version, Tel.deviceTelemetry.TimeStamp AS dateTimeStamp, 
  Tel.deviceTelemetry.data
INTO 
  deviceTelemetryADLS
FROM 
  data AS Tel 
WHERE Tel.deviceTelemetry.data IS NOT null

问题

这里使用的 WHERE 子句不会确保数据始终存在吗?否则不会发送?否则我的 .parquet 文件会如何损坏?

有问题的“数据”列是嵌套的 JSON 动态对象数组,SA 似乎无法将其正确转换为镶木地板格式。我们最终做的是创建一个流分析函数,该函数接受这个数组并将其转换为字符串

函数

function main(InputJSON) {
  var InputJSONString = JSON.stringify(InputJSON);
  return InputJSONString;
}

查询

Tel.identities.corporationId AS corporationId, Tel.identities.deviceId, Tel.deviceTelemetry.version, Tel.deviceTelemetry.TimeStamp AS dateTimeStamp, udf.ConvertToJSONString(Tel.deviceTelemetry.data) as deviceData
INTO 
    deviceTelemetryADLS
FROM 
    data AS Tel 
WHERE Tel.deviceTelemetry.data IS NOT null 

因此我们将这个嵌套的 JSON 作为单个列存储在我们的 SQL 中,因为我们不需要索引这些“数据”字段。我们在向 .NET 应用程序查询时将其反序列化为一个对象