Skip to content

Commit

Permalink
Added initial support for BQ HLL functions
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Smart <jlsmart@meta.com>
  • Loading branch information
anagrd-ai committed Dec 22, 2024
1 parent c31fd85 commit 50bd059
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/malloy/src/dialect/standardsql/dialect_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import {
DefinitionBlueprint,
DefinitionBlueprintMap,
OverloadedDefinitionBlueprint,
TypeDescBlueprint,
} from '../functions/util';

// Cute shortcut So you can write things like: {array: T} and {dimension: T}
const T: TypeDescBlueprint = {generic: 'T'};

const date_from_unix_date: DefinitionBlueprint = {
takes: {'unix_date': 'number'},
returns: 'date',
Expand Down Expand Up @@ -69,6 +73,38 @@ export const STANDARDSQL_DIALECT_FUNCTIONS: DefinitionBlueprintMap = {
date_from_unix_date,
string_agg,
string_agg_distinct,
hll_accumulate: {
default: {
takes: {'value': {dimension: T}},
returns: {measure: {sql_native: 'bytes'}},
generic: {
'T': ['string', 'number'],
},
isSymmetric: true,
impl: {function: 'HLL_COUNT.INIT'},
},
},
hll_combine: {
takes: {'value': {sql_native: 'bytes'}},
returns: {measure: {sql_native: 'bytes'}},
impl: {function: 'HLL_COUNT.MERGE_PARTIAL'},
isSymmetric: true,
},
hll_estimate: {
takes: {'value': {sql_native: 'bytes'}},
returns: {dimension: 'number'},
impl: {function: 'HLL_COUNT.EXTRACT'},
},
hll_export: {
takes: {'value': {sql_native: 'bytes'}},
returns: {dimension: {sql_native: 'bytes'}},
impl: {sql: 'CAST(${value} AS BYTES)'},
},
hll_import: {
takes: {'value': {sql_native: 'bytes'}},
returns: {dimension: {sql_native: 'bytes'}},
impl: {sql: 'CAST(${value} AS BYTES)'},
},
...def('repeat', {'str': 'string', 'n': 'number'}, 'string'),
...def('reverse', {'str': 'string'}, 'string'),
};
1 change: 1 addition & 0 deletions packages/malloy/src/dialect/standardsql/standardsql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class StandardSQLDialect extends Dialect {
cantPartitionWindowFunctionsOnExpressions = true;
hasModOperator = false;
nestedArrays = false; // Can't have an array of arrays for some reason
supportsHyperLogLog = true;

quoteTablePath(tablePath: string): string {
return `\`${tablePath}\``;
Expand Down

0 comments on commit 50bd059

Please sign in to comment.