Time function in Azure Data Factory - Expression Builder

694 views Asked by At

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). But I don't find a time function within the expression builder in ADF, is there a way I can do it?

-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.

Express Builder

Mapping

Data Preview

1

There are 1 answers

0
Harshitha On

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.

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.

enter image description here

  • time is not a recognized datatype in azure dataflow (date and timestamp are accepted). Therefore, dataflow fails to convert string (substring(<timestamp_col>,12,5)) into time type.
  • 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.
#my table row
insert  into mydemo values(200,'2022-08-18','12:34:56')

enter image description here

  • 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.

enter image description here

  • Configure the sink, mapping and look at the resulting data in data preview. Now, azure dataflow will be able to successfully insert the values and give desired results.

enter image description here

  • The following is the output after successful insertion of record into dedicated pool table.

enter image description here

NOTE: You can construct valid yyyy-MM-dd hh:mm:ss as a value using concat('yyyy-MM-dd ',substring(<timestamp_col>,12,8)) in place of 1900-01-01 hh:mm:ss in derived column transformation.