ADF数据流提供了一个日期转换函数,在筛选日期列时可以使用该函数。以下是一个代码示例:
在数据流中添加一个DerivedColumn转换
在DerivedColumn转换中,使用toDateTime函数将日期列转换为DateTime格式
添加一个Select转换并在Select转换中对日期列进行筛选
下面是一个示例代码:
DerivedColumn转换代码示例:
[
{
"name": "Convert date column to DateTime format",
"description": "",
"type": "DerivedColumn",
"schema": [
{
"name": "DateColumn",
"type": "String"
}
],
"derivedColumns": [
{
"name": "DateTimeColumn",
"type": "DateTime",
"expression": "toDateTime(DateColumn, 'yyyy-MM-dd')"
}
],
"inputs": [
{
"referenceName": "InputDataset",
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "DerivedColumnDataset",
"type": "DatasetReference"
}
]
}
]
Select转换代码示例:
[
{
"name": "Filter rows based on Date column",
"description": "",
"type": "Select",
"schema": [
{
"name": "DateTimeColumn",
"type": "DateTime"
}
],
"source": {
"type": "TabularSource",
"sourceOptions": {
"dataset": {
"referenceName": "DerivedColumnDataset",
"type": "DatasetReference"
}
}
},
"sink": {
"type": "TabularSink",
"sinkOptions": {
"dataset": {
"referenceName": "OutputDataset",
"type": "DatasetReference"
}
}
},
"translator": {
"type": "TabularTranslator",
"columnMappings": {
"DateTimeColumn": "DateTimeColumn"
}
},
"filter": {
"condition": {
"value": "DateTimeColumn > yyyy-MM-ddTHH:mm:ss