Skip to content

Commit

Permalink
Added core UDF's for mostRecentDayOfWeek and previousDayOfWeek
Browse files Browse the repository at this point in the history
  • Loading branch information
Jdelens96 committed Feb 28, 2024
1 parent 953847b commit 12705c4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,61 @@ function <<sql.Extension>> meta::external::query::sql::coreExtension():SQLExtens

let part = $args->at(0)->reactivate()->toOne()->cast(@String);

let enum = [
pair('year', DurationUnit.YEARS),
pair('month', DurationUnit.MONTHS),
pair('week', DurationUnit.WEEKS),
pair('day', DurationUnit.DAYS),
pair('hour', DurationUnit.HOURS),
pair('minute', DurationUnit.MINUTES),
pair('second', DurationUnit.SECONDS),
pair('millisecond', DurationUnit.MILLISECONDS)
]->getValue($part->toLower());
let enum = mapDuration($part) ;

nullOrSfe(dateDiff_Date_1__Date_1__DurationUnit_1__Integer_1_, [$args->at(1), $args->at(2), processExtractEnumValue($enum)]) ;
}),
processor('most_recent_day_of_week', Date, {args, fc, ctx |
assertEquals(2, $args->size(), 'incorrect number of args for core_most_recent_day_of_week');

let part = $args->at(0)->reactivate()->toOne()->cast(@String);

let enum = mapDayOfWeek($part);

nullOrSfe(mostRecentDayOfWeek_Date_1__DayOfWeek_1__Date_1_, [$args->at(1), processExtractEnumValue($enum)]) ;
}),
processor('previous_day_of_week', Date, {args, fc, ctx |
assertEquals(2, $args->size(), 'incorrect number of args for core_previous_day_of_week');

let part = $args->at(0)->reactivate()->toOne()->cast(@String);

let enum = mapDayOfWeek($part);

nullOrSfe(previousDayOfWeek_Date_1__DayOfWeek_1__Date_1_, [$args->at(1), processExtractEnumValue($enum)]) ;
}),
aggregate('unique_value_only', Any, {args, fc, ctx |
sfe(uniqueValueOnly_T_MANY__T_$0_1$_, $args->at(0).genericType, $args->at(0).genericType, $args->at(0))
})
]
)
)
}

function meta::external::query::sql::mapDuration(durationUnit:String[1]):DurationUnit[1]
{
[
pair('year', DurationUnit.YEARS),
pair('month', DurationUnit.MONTHS),
pair('week', DurationUnit.WEEKS),
pair('day', DurationUnit.DAYS),
pair('hour', DurationUnit.HOURS),
pair('minute', DurationUnit.MINUTES),
pair('second', DurationUnit.SECONDS),
pair('millisecond', DurationUnit.MILLISECONDS)
]->getValue($durationUnit->toLower());

}

function meta::external::query::sql::mapDayOfWeek(stringDate:String[1]):DayOfWeek[1]
{
[
pair('monday', DayOfWeek.Monday),
pair('tuesday', DayOfWeek.Tuesday),
pair('wednesday', DayOfWeek.Wednesday),
pair('thursday', DayOfWeek.Thursday),
pair('friday', DayOfWeek.Friday),
pair('saturday', DayOfWeek.Saturday),
pair('sunday', DayOfWeek.Sunday)
]->getValue($stringDate->toLower());

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ function <<test.Test>> meta::external::query::sql::transformation::queryToPure::
)
}

function <<test.Test>> meta::external::query::sql::transformation::queryToPure::tests::testMostRecentDayOfWeek():Boolean[1]
{
test(
'SELECT core_most_recent_day_of_week(\'monday\', StrictDate) as MostRecentDayOfWeek FROM service."/service/service1"',

{| FlatInput.all()->project(
[ x | $x.booleanIn, x | $x.integerIn, x | $x.floatIn, x | $x.decimalIn, x | $x.strictDateIn, x | $x.dateTimeIn, x | $x.stringIn ],
[ 'Boolean', 'Integer', 'Float', 'Decimal', 'StrictDate', 'DateTime', 'String' ])->project([
col(row:TDSRow[1] | mostRecentDayOfWeek($row.getStrictDate('StrictDate'), DayOfWeek.Monday), 'MostRecentDayOfWeek')
])
}
)
}

function <<test.Test>> meta::external::query::sql::transformation::queryToPure::tests::testPreviousDayOfWeek():Boolean[1]
{
test(
'SELECT core_previous_day_of_week(\'monday\', StrictDate) as PreviousDayOfWeek FROM service."/service/service1"',

{| FlatInput.all()->project(
[ x | $x.booleanIn, x | $x.integerIn, x | $x.floatIn, x | $x.decimalIn, x | $x.strictDateIn, x | $x.dateTimeIn, x | $x.stringIn ],
[ 'Boolean', 'Integer', 'Float', 'Decimal', 'StrictDate', 'DateTime', 'String' ])->project([
col(row:TDSRow[1] | previousDayOfWeek($row.getStrictDate('StrictDate'), DayOfWeek.Monday), 'PreviousDayOfWeek')
])
}
)
}

function <<test.Test>> meta::external::query::sql::transformation::queryToPure::tests::testUniqueValueOnly():Boolean[1]
{
test(
Expand Down

0 comments on commit 12705c4

Please sign in to comment.