Skip to content

Commit 50bd059

Browse files
committed
Added initial support for BQ HLL functions
Signed-off-by: Jason Smart <jlsmart@meta.com>
1 parent c31fd85 commit 50bd059

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

packages/malloy/src/dialect/standardsql/dialect_functions.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import {
1010
DefinitionBlueprint,
1111
DefinitionBlueprintMap,
1212
OverloadedDefinitionBlueprint,
13+
TypeDescBlueprint,
1314
} from '../functions/util';
1415

16+
// Cute shortcut So you can write things like: {array: T} and {dimension: T}
17+
const T: TypeDescBlueprint = {generic: 'T'};
18+
1519
const date_from_unix_date: DefinitionBlueprint = {
1620
takes: {'unix_date': 'number'},
1721
returns: 'date',
@@ -69,6 +73,38 @@ export const STANDARDSQL_DIALECT_FUNCTIONS: DefinitionBlueprintMap = {
6973
date_from_unix_date,
7074
string_agg,
7175
string_agg_distinct,
76+
hll_accumulate: {
77+
default: {
78+
takes: {'value': {dimension: T}},
79+
returns: {measure: {sql_native: 'bytes'}},
80+
generic: {
81+
'T': ['string', 'number'],
82+
},
83+
isSymmetric: true,
84+
impl: {function: 'HLL_COUNT.INIT'},
85+
},
86+
},
87+
hll_combine: {
88+
takes: {'value': {sql_native: 'bytes'}},
89+
returns: {measure: {sql_native: 'bytes'}},
90+
impl: {function: 'HLL_COUNT.MERGE_PARTIAL'},
91+
isSymmetric: true,
92+
},
93+
hll_estimate: {
94+
takes: {'value': {sql_native: 'bytes'}},
95+
returns: {dimension: 'number'},
96+
impl: {function: 'HLL_COUNT.EXTRACT'},
97+
},
98+
hll_export: {
99+
takes: {'value': {sql_native: 'bytes'}},
100+
returns: {dimension: {sql_native: 'bytes'}},
101+
impl: {sql: 'CAST(${value} AS BYTES)'},
102+
},
103+
hll_import: {
104+
takes: {'value': {sql_native: 'bytes'}},
105+
returns: {dimension: {sql_native: 'bytes'}},
106+
impl: {sql: 'CAST(${value} AS BYTES)'},
107+
},
72108
...def('repeat', {'str': 'string', 'n': 'number'}, 'string'),
73109
...def('reverse', {'str': 'string'}, 'string'),
74110
};

packages/malloy/src/dialect/standardsql/standardsql.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class StandardSQLDialect extends Dialect {
126126
cantPartitionWindowFunctionsOnExpressions = true;
127127
hasModOperator = false;
128128
nestedArrays = false; // Can't have an array of arrays for some reason
129+
supportsHyperLogLog = true;
129130

130131
quoteTablePath(tablePath: string): string {
131132
return `\`${tablePath}\``;

0 commit comments

Comments
 (0)