Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions src/ts_generator/sql_parser/expressions/functions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
// LIST OF FUNCTIONS FOUND https://www.w3schools.com/mysql/mysql_ref_functions.asp
pub static NUMERIC_FUNCTIONS: &[&str] = &[
"ABS", "ACOS", "ASIN", "ATAN", "ATAN2", "AVG", "CEIL", "CEILING", "COS", "COT", "COUNT", "DEGREES", "DIV", "EXP",
"FLOOR", "GREATEST", "LEAST", "LN", "LOG", "LOG10", "LOG2", "MAX", "MIN", "MOD", "PI", "POW", "POWER", "RADIANS",
"RAND", "ROUND", "SIGN", "SIN", "SQRT", "SUM", "TAN", "TRUNCATE", "TRUNC",
"ABS",
"ACOS",
"ASIN",
"ATAN",
"ATAN2",
"AVG",
"CEIL",
"CEILING",
"COS",
"COT",
"COUNT",
"DEGREES",
"DIV",
"EXP",
"FLOOR",
"GREATEST",
"LEAST",
"LN",
"LOG",
"LOG10",
"LOG2",
"MAX",
"MIN",
"MOD",
"PI",
"POW",
"POWER",
"RADIANS",
"RAND",
"ROUND",
"SIGN",
"SIN",
"SQRT",
"SUM",
"TAN",
"TRUNCATE",
"TRUNC",
// Window / ranking functions that always return a numeric value
"RANK",
"DENSE_RANK",
"ROW_NUMBER",
"NTILE",
"PERCENT_RANK",
"CUME_DIST",
];

pub static STRING_FUNCTIONS: &[&str] = &[
Expand Down Expand Up @@ -113,7 +154,18 @@ pub fn is_date_function(func_name: &str) -> bool {
}

// Type-polymorphic functions that return the type of their first argument
pub static TYPE_POLYMORPHIC_FUNCTIONS: &[&str] = &["IFNULL", "COALESCE", "NULLIF", "NVL"];
pub static TYPE_POLYMORPHIC_FUNCTIONS: &[&str] = &[
"IFNULL",
"COALESCE",
"NULLIF",
"NVL",
// Window value functions — return the same type as their first argument
"LAG",
"LEAD",
"FIRST_VALUE",
"LAST_VALUE",
"NTH_VALUE",
];

pub fn is_type_polymorphic_function(func_name: &str) -> bool {
TYPE_POLYMORPHIC_FUNCTIONS.contains(&func_name.to_uppercase().as_str())
Expand Down
2 changes: 1 addition & 1 deletion tests/demo/cte/cte.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type RankWithCteParams = [];
export interface IRankWithCteResult {
id: number;
name: string;
rk: any;
rk: number;
}

export interface IRankWithCteQuery {
Expand Down
2 changes: 1 addition & 1 deletion tests/demo/cte/cte.snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type RankWithCteParams = [];
export interface IRankWithCteResult {
id: number;
name: string;
rk: any;
rk: number;
}

export interface IRankWithCteQuery {
Expand Down
16 changes: 8 additions & 8 deletions tests/demo/window/lag_lead.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type BasicLagParams = [];
export interface IBasicLagResult {
id: number;
name: string;
previousName: any;
previousName: string;
}

export interface IBasicLagQuery {
Expand All @@ -16,7 +16,7 @@ export type BasicLeadParams = [];
export interface IBasicLeadResult {
id: number;
name: string;
nextName: any;
nextName: string;
}

export interface IBasicLeadQuery {
Expand All @@ -29,7 +29,7 @@ export type LagWithDefaultParams = [];
export interface ILagWithDefaultResult {
id: number;
name: string;
previousName: any;
previousName: string;
}

export interface ILagWithDefaultQuery {
Expand All @@ -42,8 +42,8 @@ export type LagAndLeadParams = [];
export interface ILagAndLeadResult {
id: number;
name: string;
nextName: any;
previousName: any;
nextName: string;
previousName: string;
}

export interface ILagAndLeadQuery {
Expand All @@ -56,7 +56,7 @@ export type LagWithPartitionParams = [];
export interface ILagWithPartitionResult {
id: number;
name: string;
previousInRarity: any;
previousInRarity: string;
rarity: string | null;
}

Expand All @@ -68,9 +68,9 @@ export interface ILagWithPartitionQuery {
export type FirstLastValueParams = [];

export interface IFirstLastValueResult {
firstInRarity: any;
firstInRarity: string;
id: number;
lastInRarity: any;
lastInRarity: string;
name: string;
rarity: string | null;
}
Expand Down
17 changes: 8 additions & 9 deletions tests/demo/window/lag_lead.snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type BasicLagParams = [];
export interface IBasicLagResult {
id: number;
name: string;
previousName: any;
previousName: string;
}

export interface IBasicLagQuery {
Expand All @@ -16,7 +16,7 @@ export type BasicLeadParams = [];
export interface IBasicLeadResult {
id: number;
name: string;
nextName: any;
nextName: string;
}

export interface IBasicLeadQuery {
Expand All @@ -29,7 +29,7 @@ export type LagWithDefaultParams = [];
export interface ILagWithDefaultResult {
id: number;
name: string;
previousName: any;
previousName: string;
}

export interface ILagWithDefaultQuery {
Expand All @@ -42,8 +42,8 @@ export type LagAndLeadParams = [];
export interface ILagAndLeadResult {
id: number;
name: string;
nextName: any;
previousName: any;
nextName: string;
previousName: string;
}

export interface ILagAndLeadQuery {
Expand All @@ -56,7 +56,7 @@ export type LagWithPartitionParams = [];
export interface ILagWithPartitionResult {
id: number;
name: string;
previousInRarity: any;
previousInRarity: string;
rarity: string | null;
}

Expand All @@ -68,9 +68,9 @@ export interface ILagWithPartitionQuery {
export type FirstLastValueParams = [];

export interface IFirstLastValueResult {
firstInRarity: any;
firstInRarity: string;
id: number;
lastInRarity: any;
lastInRarity: string;
name: string;
rarity: string | null;
}
Expand All @@ -79,4 +79,3 @@ export interface IFirstLastValueQuery {
params: FirstLastValueParams;
result: IFirstLastValueResult;
}

14 changes: 7 additions & 7 deletions tests/demo/window/rank_functions.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type BasicRankParams = [];
export interface IBasicRankResult {
id: number;
name: string;
rank: any;
rank: number;
rarity: string | null;
}

Expand All @@ -15,7 +15,7 @@ export interface IBasicRankQuery {
export type DenseRankParams = [];

export interface IDenseRankResult {
denseRank: any;
denseRank: number;
id: number;
name: string;
rarity: string | null;
Expand All @@ -31,7 +31,7 @@ export type RankWithPartitionParams = [];
export interface IRankWithPartitionResult {
id: number;
name: string;
rank: any;
rank: number;
rarity: string | null;
}

Expand All @@ -43,12 +43,12 @@ export interface IRankWithPartitionQuery {
export type MultipleRankingParams = [];

export interface IMultipleRankingResult {
denseRank: any;
denseRank: number;
id: number;
name: string;
rank: any;
rank: number;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IMultipleRankingQuery {
Expand All @@ -61,7 +61,7 @@ export type NtileQuartilesParams = [];
export interface INtileQuartilesResult {
id: number;
name: string;
quartile: any;
quartile: number;
}

export interface INtileQuartilesQuery {
Expand Down
15 changes: 7 additions & 8 deletions tests/demo/window/rank_functions.snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type BasicRankParams = [];
export interface IBasicRankResult {
id: number;
name: string;
rank: any;
rank: number;
rarity: string | null;
}

Expand All @@ -15,7 +15,7 @@ export interface IBasicRankQuery {
export type DenseRankParams = [];

export interface IDenseRankResult {
denseRank: any;
denseRank: number;
id: number;
name: string;
rarity: string | null;
Expand All @@ -31,7 +31,7 @@ export type RankWithPartitionParams = [];
export interface IRankWithPartitionResult {
id: number;
name: string;
rank: any;
rank: number;
rarity: string | null;
}

Expand All @@ -43,12 +43,12 @@ export interface IRankWithPartitionQuery {
export type MultipleRankingParams = [];

export interface IMultipleRankingResult {
denseRank: any;
denseRank: number;
id: number;
name: string;
rank: any;
rank: number;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IMultipleRankingQuery {
Expand All @@ -61,11 +61,10 @@ export type NtileQuartilesParams = [];
export interface INtileQuartilesResult {
id: number;
name: string;
quartile: any;
quartile: number;
}

export interface INtileQuartilesQuery {
params: NtileQuartilesParams;
result: INtileQuartilesResult;
}

8 changes: 4 additions & 4 deletions tests/demo/window/row_number.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface IBasicRowNumberResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IBasicRowNumberQuery {
Expand All @@ -18,7 +18,7 @@ export interface IRowNumberWithPartitionResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IRowNumberWithPartitionQuery {
Expand All @@ -32,7 +32,7 @@ export interface IRowNumberWithWhereResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IRowNumberWithWhereQuery {
Expand All @@ -46,7 +46,7 @@ export interface IRowNumberWithParamsResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IRowNumberWithParamsQuery {
Expand Down
9 changes: 4 additions & 5 deletions tests/demo/window/row_number.snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface IBasicRowNumberResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IBasicRowNumberQuery {
Expand All @@ -18,7 +18,7 @@ export interface IRowNumberWithPartitionResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IRowNumberWithPartitionQuery {
Expand All @@ -32,7 +32,7 @@ export interface IRowNumberWithWhereResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IRowNumberWithWhereQuery {
Expand All @@ -46,11 +46,10 @@ export interface IRowNumberWithParamsResult {
id: number;
name: string;
rarity: string | null;
rowNum: any;
rowNum: number;
}

export interface IRowNumberWithParamsQuery {
params: RowNumberWithParamsParams;
result: IRowNumberWithParamsResult;
}

Loading