简体   繁体   English

时间 function 在 Azure 数据工厂 - 表达式生成器

[英]Time function in Azure Data Factory - Expression Builder

I only need to take the time part from the 'Timestamp type source attribute' and load it into a dedicated SQL pool table (Time datatype column).我只需要从“时间戳类型源属性”中提取时间部分并将其加载到专用的 SQL 池表(时间数据类型列)中。 But I don't find a time function within the expression builder in ADF, is there a way I can do it?但是我在 ADF 的表达式生成器中找不到时间 function,有什么办法可以做到吗?

-What did I do? -我做了什么? -I took the time part from the source attribute using substring and then tried to load the same into the destination table, when I do the destination table inserted null values as the column at the destination table is set to time datatype. -我使用 ZE83AED3DDF4667DEC0DAAAACB2BB3BE0BZ 从源属性中获取时间部分,然后尝试将其加载到目标表中,当我在目标表中插入 null 值时,因为目标表中的列设置为时间数据类型。

快递生成器

映射

数据预览

I tried to reproduce this and got the same issue.我试图重现这一点并遇到了同样的问题。 The following is a demonstration of the same.以下是相同的演示。 I have a table called mydemo as shown below.我有一个名为mydemo的表,如下所示。

CREATE  TABLE [dbo].[mydemo]
(
id int  NOT  NULL,
my_date date,
my_time time
)
WITH
(
DISTRIBUTION = HASH (id),
CLUSTERED COLUMNSTORE INDEX
)
GO

The following is my source data in my dataflow.以下是我的数据流中的源数据。

在此处输入图像描述

  • time is not a recognized datatype in azure dataflow ( date and timestamp are accepted). time不是 azure 数据流中可识别的数据类型(接受date and timestamp )。 Therefore, dataflow fails to convert string ( @substring(<timestamp_col>,12,5) ) into time type.因此,数据流无法将string ( @substring(<timestamp_col>,12,5) ) 转换为time类型。
  • For better understanding, you can load your sink table as source in dataflow.为了更好地理解,您可以将接收器表加载为数据流中的源。 The time column will be read as 1900-01-01 12:34:56 when time value in the table row is 12:34:56 .当表格行中的时间值为 12:34:56 时,时间列将被读取为1900-01-01 12:34:56 12:34:56
#my table row
insert  into mydemo values(200,'2022-08-18','12:34:56')

在此处输入图像描述

  • So, instead of using substring(<timestamp_col>,12,5) to return 00:01 , use concat('1900-01-01 ',substring(<timestamp_col>,12,8)) which returns 1900-01-01 00:01:00 .因此,不要使用substring(<timestamp_col>,12,5)返回00:01 ,而是使用concat('1900-01-01 ',substring(<timestamp_col>,12,8))返回1900-01-01 00:01:00

在此处输入图像描述

  • Configure the sink, mapping and look at the resulting data in data preview .配置接收器、映射并在data preview中查看生成的数据。 Now, azure dataflow will be able to successfully insert the values and give desired results.现在,azure 数据流将能够成功插入值并给出所需的结果。

在此处输入图像描述

  • The following is the output after successful insertion of record into dedicated pool table.以下是成功将记录插入专用池表后的 output。

在此处输入图像描述

NOTE: You can construct valid yyyy-MM-dd hh:mm:ss as a value using concat('1900-01-01 ',substring(<timestamp_col>,12,8)) in place of 1900-01-01 hh:mm:ss in derived column transformation .注意:您可以使用 concat('1900-01-01 ',substring(<timestamp_col>,12,8)) 代替1900-01-01 hh:mm:ss构造有效yyyy-MM-dd hh:mm:ss作为值1900-01-01 hh:mm:ssderived column transformation中。

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

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