Skip to content

Commit 6e95673

Browse files
aasimkhan30Aasim KhanCopilot
authored
Fix datepart argument parsing in date functions with AGENTS files (#201)
* Add support for DATEADD, DATEDIFF, and related functions; normalize parameters in function calls * Add comprehensive tests for DATEPART and related functions; include various arities and edge cases Co-authored-by: Copilot <copilot@github.com> --------- Co-authored-by: Aasim Khan <aasimkhan@gmail.com> Co-authored-by: Copilot <copilot@github.com>
1 parent 67f9eab commit 6e95673

17 files changed

Lines changed: 251 additions & 1 deletion

SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,20 @@ internal static class CodeGenerationSupporter
293293
internal const string DataRetention = "DATA_RETENTION";
294294
internal const string DataSource = "DATA_SOURCE";
295295
internal const string Date = "DATE";
296+
internal const string DateAdd = "DATEADD";
297+
internal const string DateBucket = "DATE_BUCKET";
296298
internal const string DateCorrelationOptimization = "DATE_CORRELATION_OPTIMIZATION";
299+
internal const string DateDiff = "DATEDIFF";
300+
internal const string DateDiffBig = "DATEDIFF_BIG";
297301
internal const string DateFirst = "DATEFIRST";
298302
internal const string DateFormat = "DATEFORMAT";
299303
internal const string DateFormat2 = "DATE_FORMAT";
304+
internal const string DateName = "DATENAME";
305+
internal const string DatePart = "DATEPART";
300306
internal const string DateTime = "DATETIME";
301307
internal const string DateTime2 = "DATETIME2";
302308
internal const string DateTimeOffset = "DATETIMEOFFSET";
309+
internal const string DateTrunc = "DATETRUNC";
303310
internal const string Deterministic = "DETERMINISTIC";
304311
internal const string DboOnly = "DBO_ONLY";
305312
internal const string DbChaining = "DB_CHAINING";

SqlScriptDom/Parser/TSql/TSql100.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20874,6 +20874,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
2087420874
:
2087520875
(
2087620876
expressionList[vParent, vParent.Parameters]
20877+
{
20878+
NormalizeDatePartFunctionFirstParameter(vParent);
20879+
}
2087720880
|
2087820881
vColumn=starColumnReferenceExpression
2087920882
{

SqlScriptDom/Parser/TSql/TSql110.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23849,6 +23849,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
2384923849
:
2385023850
(
2385123851
expressionList[vParent, vParent.Parameters]
23852+
{
23853+
NormalizeDatePartFunctionFirstParameter(vParent);
23854+
}
2385223855
|
2385323856
vColumn=starColumnReferenceExpression
2385423857
{

SqlScriptDom/Parser/TSql/TSql120.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24598,6 +24598,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
2459824598
:
2459924599
(
2460024600
expressionList[vParent, vParent.Parameters]
24601+
{
24602+
NormalizeDatePartFunctionFirstParameter(vParent);
24603+
}
2460124604
|
2460224605
vColumn=starColumnReferenceExpression
2460324606
{

SqlScriptDom/Parser/TSql/TSql130.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29420,6 +29420,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
2942029420
:
2942129421
(
2942229422
expressionList[vParent, vParent.Parameters]
29423+
{
29424+
NormalizeDatePartFunctionFirstParameter(vParent);
29425+
}
2942329426
|
2942429427
vColumn=starColumnReferenceExpression
2942529428
{

SqlScriptDom/Parser/TSql/TSql140.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30253,6 +30253,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
3025330253
:
3025430254
(
3025530255
expressionList[vParent, vParent.Parameters]
30256+
{
30257+
NormalizeDatePartFunctionFirstParameter(vParent);
30258+
}
3025630259
|
3025730260
vColumn=starColumnReferenceExpression
3025830261
{

SqlScriptDom/Parser/TSql/TSql150.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31406,6 +31406,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
3140631406
:
3140731407
(
3140831408
expressionList[vParent, vParent.Parameters]
31409+
{
31410+
NormalizeDatePartFunctionFirstParameter(vParent);
31411+
}
3140931412
|
3141031413
vColumn=starColumnReferenceExpression
3141131414
{

SqlScriptDom/Parser/TSql/TSql160.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32218,6 +32218,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
3221832218
:
3221932219
(
3222032220
expressionList[vParent, vParent.Parameters]
32221+
{
32222+
NormalizeDatePartFunctionFirstParameter(vParent);
32223+
}
3222132224
|
3222232225
vColumn=starColumnReferenceExpression
3222332226
{

SqlScriptDom/Parser/TSql/TSql170.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33346,6 +33346,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
3334633346
:
3334733347
(
3334833348
expressionList[vParent, vParent.Parameters]
33349+
{
33350+
NormalizeDatePartFunctionFirstParameter(vParent);
33351+
}
3334933352
|
3335033353
vColumn=starColumnReferenceExpression
3335133354
{

SqlScriptDom/Parser/TSql/TSql180.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33346,6 +33346,9 @@ regularBuiltInFunctionCall [FunctionCall vParent]
3334633346
:
3334733347
(
3334833348
expressionList[vParent, vParent.Parameters]
33349+
{
33350+
NormalizeDatePartFunctionFirstParameter(vParent);
33351+
}
3334933352
|
3335033353
vColumn=starColumnReferenceExpression
3335133354
{

0 commit comments

Comments
 (0)