MSSQL 2016 Script
::
sp_configure clr_enabled, 1 RECONFIGURE;IF NOT EXISTS ( SELECT * FROM sys.schemas WHERE name = N'ATSCALEUDAF' ) EXEC('CREATE SCHEMA ATSCALEUDAF');
DROP AGGREGATE IF EXISTS ATSCALEUDAF.hll_aggregate_estimate
DROP AGGREGATE IF EXISTS ATSCALEUDAF.hll_aggregate
DROP AGGREGATE IF EXISTS ATSCALEUDAF.hll_aggregate_merge
DROP AGGREGATE IF EXISTS ATSCALEUDAF.hll_estimate
DROP AGGREGATE IF EXISTS ATSCALEUDAF.quantile_sketch
DROP AGGREGATE IF EXISTS ATSCALEUDAF.quantile_sketch_estimate
DROP AGGREGATE IF EXISTS ATSCALEUDAF.quantile_sketch_merge
DROP AGGREGATE IF EXISTS ATSCALEUDAF.quantile_estimate
DROP FUNCTION IF EXISTS ATSCALEUDAF.atscale_honeybee_version
DROP FUNCTION IF EXISTS ATSCALEUDAF.quantileFromSketch
DROP ASSEMBLY IF EXISTS AtScaleHLLFunctions
CREATE ASSEMBLY AtScaleHLLFunctions from {Honeybee_dll_location}/{Honeybee_dll_name} with PERMISSION_SET = SAFE
CREATE AGGREGATE ATSCALEUDAF.hll_aggregate_estimate (@value nvarchar(max)) RETURNS bigint EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.HyperLogLogAggregateEstimateUDA]
CREATE AGGREGATE ATSCALEUDAF.hll_aggregate (@value sql_variant) RETURNS nvarchar(max) EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.HyperLogLogAggregateUDA]
CREATE AGGREGATE ATSCALEUDAF.hll_aggregate_merge (@value nvarchar(max)) RETURNS nvarchar(max) EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.HyperLogLogAggregateMergeUDA]
CREATE AGGREGATE ATSCALEUDAF.hll_estimate (@value sql_variant) RETURNS bigint EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.HyperLogLogEstimateUDA]
CREATE AGGREGATE ATSCALEUDAF.quantile_sketch_estimate (@value nvarchar(max), @q float) RETURNS float EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.QuantileAggregateEstimateUDA]
CREATE AGGREGATE ATSCALEUDAF.quantile_sketch_merge (@value nvarchar(max)) RETURNS nvarchar(max) EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.QuantileAggregateMergeUDA]
CREATE AGGREGATE ATSCALEUDAF.quantile_sketch (@o float, @cf int) RETURNS nvarchar(max) EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.QuantileAggregateUDA]
CREATE AGGREGATE ATSCALEUDAF.quantile_estimate (@o float, @q float, @cf int) RETURNS float EXTERNAL NAME AtScaleHLLFunctions.[Com.Atscale.Honeybee.Mssql.QuantileEstimateUDA]
GRANT EXECUTE ON ATSCALEUDAF.hll_estimate to PUBLIC