简体   繁体   English

Transform.parquet 文件 varchar 列到 Azure Synapse 中的日期时间

[英]Transform .parquet file varchar column to datetime in Azure Synapse

I am sending JSON telemetry data from our IoT Hub to Azure Data Lake Gen2 in the form of.parquet files.我以 .parquet 文件的形式将 JSON 遥测数据从我们的 IoT 中心发送到 Azure Data Lake Gen2。 From the data lake I've then created a view in my Azure Synapse Serverless SQL pool that I can connect to and query data for reports.然后,我在我的 Azure Synapse Serverless SQL 池中创建了一个视图,我可以连接到该池并查询数据以获取报告。

CREATE VIEW DeviceTelemetryView
AS SELECT * FROM
    OPENROWSET(
        BULK 'https://test123.dfs.core.windows.net/devicetelemetry/*/*/*/*/*/',
        FORMAT = 'PARQUET'
    ) AS [result]

This is what my view data looks like:这是我的视图数据的样子: 在此处输入图像描述

Most of these reports are based on date time ranges.这些报告中的大多数都基于日期时间范围。 Therefore I want to be able to write SQL queries that use my date time stamp.因此,我希望能够编写使用我的日期时间戳的 SQL 查询。

The Current Issue当前问题

When I look at the current data type for the dateTimeStamp column, it defaults to varchar(8000) even though I believe my JSON is in the correct datetime format: "2021-11-29T21:45:00" .当我查看 dateTimeStamp 列的当前数据类型时,它默认为 varchar(8000) 即使我相信我的 JSON 的日期时间格式正确: "2021-11-29T21:45:00" How can I transform this specific field to a datetime field in my view to run queries on it?如何在我的视图中将此特定字段转换为日期时间字段以对其运行查询?

When I look at the current data type for the dateTimeStamp column, it defaults to varchar(8000)当我查看 dateTimeStamp 列的当前数据类型时,它默认为 varchar(8000)

I think you would have to look at the data type for that column in the parquet file, it's likely to be a string in your case.我认为您必须查看镶木地板文件中该列的数据类型,在您的情况下它可能是一个字符串。 Sql interpret as a varchar(8000). Sql 解释为 varchar(8000)。

even though I believe my JSON is in the correct datetime format: "2021-11-29T21:45:00".即使我相信我的 JSON 的日期时间格式正确:“2021-11-29T21:45:00”。

Even if the timestamp format is correct, I think you'd have to tip system so it knows to cast that string to a datetime即使时间戳格式是正确的,我认为您必须提示系统,以便它知道将该字符串转换为日期时间

How can I transform this specific field to a datetime field in my view to run queries on it?如何在我的视图中将此特定字段转换为日期时间字段以对其运行查询?

I'm not an expert in sql but I think you can convert a string to a timestamp using cast and convert我不是 sql 方面的专家,但我认为您可以使用cast 和 convert 将字符串转换为时间戳

CREATE VIEW DeviceTelemetryView
AS SELECT corporationid, deviceid, version, Convert(dateTimestamp, 126), data FROM
    OPENROWSET(
        BULK 'https://test123.dfs.core.windows.net/devicetelemetry/*/*/*/*/*/',
        FORMAT = 'PARQUET'
    ) AS [result]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM