Skip to content

Commit

Permalink
delete overdef
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Dec 20, 2024
1 parent 9f4e1ff commit b1d195f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 51 deletions.
22 changes: 1 addition & 21 deletions packages/malloy/src/dialect/functions/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ function* findGenerics(
}
}

type NamedDef = {[name: string]: DefinitionBlueprint}; // to make overdef work, exclude overloaded
/**
* Shortcut for non overloaded functions definitions. Default implementation
* will be the function name turned to upper case. Default type for
Expand All @@ -783,7 +782,7 @@ export function def(
takes: Record<string, TypeDescBlueprint>,
returns: TypeDescBlueprint,
options: Partial<Omit<DefinitionBlueprint, 'takes' | 'returns'>> = {}
): NamedDef {
) {
let anyGenerics = false;
const generic: {[name: string]: TypeDescElementBlueprintOrNamedGeneric[]} =
{};
Expand All @@ -809,22 +808,3 @@ export function def(
};
return {[name]: newDef};
}

/**
* Even more experimental than def(), is overdef() which uses
* def() to define an overloaded function.
* @param name Name of function
* @param overloads one def() for each overload
* @returns dot dot dot-able bluepreint definition
*/
export function overdef(
name: string,
...overloads: NamedDef[]
): DefinitionBlueprintMap {
const overload: OverloadedDefinitionBlueprint = {};
for (const one of overloads) {
const name = Object.keys(one)[0];
overload[name] = one[name];
}
return {[name]: overload};
}
54 changes: 24 additions & 30 deletions packages/malloy/src/dialect/trino/dialect_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
OverloadedDefinitionBlueprint,
TypeDescBlueprint,
def,
overdef,
} from '../functions/util';

/*
Expand Down Expand Up @@ -268,9 +267,8 @@ export const TRINO_DIALECT_FUNCTIONS: DefinitionBlueprintMap = {
isSymmetric: true,
}
),
...overdef(
'hll_accumulate',
def(
hll_accumulate: {
...def(
'default',
{'value': {dimension: T}},
{measure: {sql_native: 'hyperloglog'}},
Expand All @@ -282,7 +280,7 @@ export const TRINO_DIALECT_FUNCTIONS: DefinitionBlueprintMap = {
impl: {function: 'APPROX_SET'},
}
),
def(
...def(
'with_percent',
{'value': {dimension: T}, 'accuracy': 'number'},
{measure: {sql_native: 'hyperloglog'}},
Expand All @@ -293,8 +291,8 @@ export const TRINO_DIALECT_FUNCTIONS: DefinitionBlueprintMap = {
isSymmetric: true,
impl: {function: 'APPROX_SET'},
}
)
),
),
},
...def(
'hll_combine',
{'value': {sql_native: 'hyperloglog'}},
Expand Down Expand Up @@ -389,41 +387,37 @@ export const TRINO_DIALECT_FUNCTIONS: DefinitionBlueprintMap = {

export const PRESTO_DIALECT_FUNCTIONS: DefinitionBlueprintMap = {
...TRINO_DIALECT_FUNCTIONS,
...overdef(
'array_intersect',
def('array_intersect', {'x': {array: T}, 'y': {array: T}}, {array: T}),
def(
array_intersect: {
...def('array_intersect', {'x': {array: T}, 'y': {array: T}}, {array: T}),
...def(
'nested_array',
{'x': {array: {array: T}}},
{array: T},
{impl: {function: 'ARRAY_INTERSECT'}}
)
),
...overdef(
'array_least_frequent',
def('array_least_frequent', {'x': {array: T}}, {array: T}),
def(
),
},
array_least_frequent: {
...def('array_least_frequent', {'x': {array: T}}, {array: T}),
...def(
'bottom_n',
{'array_v': {array: T}, 'n': 'number'},
{array: T},
{impl: {function: 'ARRAY_LEAST_FREQUENT'}}
)
),
...overdef(
'array_position',
def('array_position', {'x': {array: T}, 'el': T}, 'number'),
def(
),
},
array_poiition: {
...def('array_position', {'x': {array: T}, 'el': T}, 'number'),
...def(
'nth_instance',
{'x': {array: T}, 'el': T, 'instance': 'number'},
'number',
{impl: {function: 'ARRAY_POSITION'}}
)
),
...overdef(
'reverse',
{string_reverse},
def('reverse', {'x': {array: T}}, {array: T})
),
),
},
reverse: {
string_reverse,
...def('reverse', {'x': {array: T}}, {array: T}),
},
...def('array_average', {'x': {array: T}}, 'number'),
...def('array_has_duplicates', {'x': {array: T}}, 'boolean'),
...def('array_cum_sum', {numeric_array: {array: T}}, {array: 'number'}),
Expand Down

0 comments on commit b1d195f

Please sign in to comment.