Put assert UDFs in `mozfun` project (#4367)
* Put assert UDFs in `mozfun` project. * Tweak syntax in `assert.array_equals()` to avoid SQLGlot parsing error. https://github.com/tobymao/sqlglot/issues/2348 * Fix SQL syntax error in `assert.struct_equals()` tests. * Fix UDF dependency file path logic when deploying to stage. * Change regular expressions in `parse_routine` module to allow quotes around routines' dataset and name.
This commit is contained in:
Родитель
95e90efb4d
Коммит
4bbbc32a5b
|
@ -146,6 +146,8 @@ def create(ctx, name, sql_dir, project_id, udf, stored_procedure):
|
|||
routine_path = Path(sql_dir) / project_id / dataset / name
|
||||
routine_path.mkdir(parents=True)
|
||||
|
||||
assert_udf_qualifier = "" if project_id == "mozfun" else "mozfun."
|
||||
|
||||
# create SQL file with UDF definition
|
||||
if udf:
|
||||
routine_file = routine_path / UDF_FILE
|
||||
|
@ -161,7 +163,7 @@ def create(ctx, name, sql_dir, project_id, udf, stored_procedure):
|
|||
);
|
||||
|
||||
-- Tests
|
||||
SELECT assert.true({dataset}.{name}())
|
||||
SELECT {assert_udf_qualifier}assert.true({dataset}.{name}())
|
||||
"""
|
||||
)
|
||||
+ "\n"
|
||||
|
@ -178,7 +180,7 @@ def create(ctx, name, sql_dir, project_id, udf, stored_procedure):
|
|||
END;
|
||||
|
||||
-- Tests
|
||||
SELECT assert.true({dataset}.{name}())
|
||||
SELECT {assert_udf_qualifier}assert.true({dataset}.{name}())
|
||||
"""
|
||||
)
|
||||
+ "\n"
|
||||
|
|
|
@ -206,12 +206,9 @@ def _udf_dependencies(artifact_files):
|
|||
udfs_to_publish = accumulate_dependencies([], raw_routines, raw_routine.name)
|
||||
|
||||
for dependency in udfs_to_publish:
|
||||
dataset, name = dependency.split(".")
|
||||
file_path = (
|
||||
raw_routine.filepath.parent.parent.parent / dataset / name / UDF_FILE
|
||||
)
|
||||
if file_path not in artifact_files:
|
||||
artifact_files.add(file_path)
|
||||
if dependency in raw_routines:
|
||||
file_path = Path(raw_routines[dependency].filepath)
|
||||
udf_dependencies.add(file_path)
|
||||
|
||||
return udf_dependencies
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ def parsed_routines():
|
|||
if _parsed_routines is None:
|
||||
_parsed_routines = {
|
||||
routine.filepath: routine
|
||||
for project in (project_dirs() + ["tests/assert"])
|
||||
for project in project_dirs()
|
||||
for routine in parse_routines(project)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ PERSISTENT_UDF_PREFIX_RE_STR = (
|
|||
)
|
||||
PERSISTENT_UDF_PREFIX = re.compile(PERSISTENT_UDF_PREFIX_RE_STR, re.IGNORECASE)
|
||||
PERSISTENT_UDF_RE = re.compile(
|
||||
rf"{PERSISTENT_UDF_PREFIX_RE_STR}\s+`?(?:[a-zA-Z0-9_-]*`?\.)?({UDF_CHAR}*)\.({UDF_CHAR}+)`?",
|
||||
rf"{PERSISTENT_UDF_PREFIX_RE_STR}\s+(?:`?[a-zA-Z0-9_-]+`?\.)?`?({UDF_CHAR}+)`?\.`?({UDF_CHAR}+)`?",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
UDF_NAME_RE = re.compile(r"^([a-zA-Z0-9_]+\.)?[a-zA-Z][a-zA-Z0-9_]{0,255}$")
|
||||
|
@ -53,13 +53,9 @@ def get_routines_from_dir(project_dir):
|
|||
|
||||
def get_routines(project):
|
||||
"""Return all routines that could be referenced by the project."""
|
||||
return (
|
||||
get_routines_from_dir(project)
|
||||
+ get_routines_from_dir(
|
||||
Path(ConfigLoader.get("default", "sql_dir", fallback="sql")) / "mozfun"
|
||||
)
|
||||
+ get_routines_from_dir(ConfigLoader.get("routine", "assert_udf_dir"))
|
||||
) # assert UDFs used for testing
|
||||
return get_routines_from_dir(project) + get_routines_from_dir(
|
||||
Path(ConfigLoader.get("default", "sql_dir", fallback="sql")) / "mozfun"
|
||||
)
|
||||
|
||||
|
||||
@attr.s(auto_attribs=True)
|
||||
|
@ -232,10 +228,7 @@ def read_routine_dir(*project_dirs):
|
|||
global raw_routines
|
||||
|
||||
if not project_dirs:
|
||||
project_dirs = (
|
||||
ConfigLoader.get("default", "sql_dir"),
|
||||
ConfigLoader.get("routine", "assert_udf_dir"),
|
||||
)
|
||||
project_dirs = (ConfigLoader.get("default", "sql_dir"),)
|
||||
|
||||
if project_dirs not in raw_routines:
|
||||
raw_routines[project_dirs] = {
|
||||
|
@ -257,7 +250,6 @@ def parse_routines(project_dir):
|
|||
raw_routines = read_routine_dir(
|
||||
project_dir,
|
||||
Path(ConfigLoader.get("default", "sql_dir", fallback="sql")) / "mozfun",
|
||||
ConfigLoader.get("routine", "assert_udf_dir"),
|
||||
)
|
||||
|
||||
# prepend udf definitions to tests
|
||||
|
@ -338,7 +330,7 @@ def sub_local_routines(test, project, raw_routines=None, stored_procedure_test=F
|
|||
if stored_procedure_test:
|
||||
replace_name = f"{GENERIC_DATASET}.{replace_name}"
|
||||
sql = re.sub(
|
||||
rf"`?(?:`?{routine.project}`?\.)?{dataset}.{name}`?",
|
||||
rf"(?<![\w\.])(`?{routine.project}`?\.)?`?{dataset}`?\.`?{name}`?(?=\()",
|
||||
replace_name,
|
||||
sql,
|
||||
)
|
||||
|
|
|
@ -350,7 +350,6 @@ routine:
|
|||
gcs_path: ""
|
||||
skip:
|
||||
- sql/moz-fx-data-shared-prod/udf/main_summary_scalars/udf.sql
|
||||
assert_udf_dir: tests/assert
|
||||
example_dir: examples
|
||||
project: mozfun
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ that defines a UDF that does not define a temporary function is collected as a
|
|||
test and executed independently of other tests in the file.
|
||||
|
||||
Each test must use the UDF and throw an error to fail. Assert functions defined
|
||||
in `tests/assert/` may be used to evaluate outputs. Tests must not use any
|
||||
in `sql/mozfun/assert/` may be used to evaluate outputs. Tests must not use any
|
||||
query parameters and should not reference any tables. Each test that is
|
||||
expected to fail must be preceded by a comment like `#xfail`, similar to a [SQL
|
||||
dialect prefix] in the BigQuery Cloud Console.
|
||||
|
@ -56,8 +56,8 @@ CREATE TEMP FUNCTION udf_example(option INT64) AS (
|
|||
);
|
||||
-- Tests
|
||||
SELECT
|
||||
assert_true(udf_example(1)),
|
||||
assert_false(udf_example(0));
|
||||
mozfun.assert.true(udf_example(1)),
|
||||
mozfun.assert.false(udf_example(0));
|
||||
#xfail
|
||||
SELECT
|
||||
udf_example(-1);
|
||||
|
|
|
@ -5,22 +5,22 @@ RETURNS BOOLEAN AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.true(udf.active_n_weeks_ago(1 << 0, 0)),
|
||||
assert.true(udf.active_n_weeks_ago(1 << 6, 0)),
|
||||
assert.true(udf.active_n_weeks_ago(1 << 7, 1)),
|
||||
assert.true(udf.active_n_weeks_ago(1 << 13, 1)),
|
||||
assert.true(udf.active_n_weeks_ago(1 << 14, 2)),
|
||||
assert.true(udf.active_n_weeks_ago(1 << 20, 2)),
|
||||
assert.true(udf.active_n_weeks_ago(1 << 21, 3)),
|
||||
assert.true(udf.active_n_weeks_ago(1 << 27, 3)),
|
||||
assert.true(udf.active_n_weeks_ago(1 + (1 << 9), 1)),
|
||||
assert.false(udf.active_n_weeks_ago(0, 0)),
|
||||
assert.false(udf.active_n_weeks_ago(1 << 6, 1)),
|
||||
assert.false(udf.active_n_weeks_ago(1 << 7, 0)),
|
||||
assert.false(udf.active_n_weeks_ago(1 << 13, 2)),
|
||||
assert.false(udf.active_n_weeks_ago(1 << 14, 1)),
|
||||
assert.false(udf.active_n_weeks_ago(1 << 20, 3)),
|
||||
assert.false(udf.active_n_weeks_ago(1 << 21, 2)),
|
||||
assert.false(udf.active_n_weeks_ago(1 << 27, 4)),
|
||||
assert.null(udf.active_n_weeks_ago(NULL, 0)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 0, 0)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 6, 0)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 7, 1)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 13, 1)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 14, 2)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 20, 2)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 21, 3)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 << 27, 3)),
|
||||
mozfun.assert.true(udf.active_n_weeks_ago(1 + (1 << 9), 1)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(0, 0)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(1 << 6, 1)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(1 << 7, 0)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(1 << 13, 2)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(1 << 14, 1)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(1 << 20, 3)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(1 << 21, 2)),
|
||||
mozfun.assert.false(udf.active_n_weeks_ago(1 << 27, 4)),
|
||||
mozfun.assert.null(udf.active_n_weeks_ago(NULL, 0)),
|
||||
TRUE
|
||||
|
|
|
@ -23,7 +23,7 @@ CREATE OR REPLACE FUNCTION udf.active_values_from_days_seen_map(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
['a', 'b'],
|
||||
udf.active_values_from_days_seen_map(
|
||||
[STRUCT('a' AS key, 1 AS value), STRUCT('b' AS key, 3 AS value)],
|
||||
|
@ -31,7 +31,7 @@ SELECT
|
|||
1
|
||||
)
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
['a'],
|
||||
udf.active_values_from_days_seen_map(
|
||||
[STRUCT('a' AS key, 2048 AS value), STRUCT('b' AS key, 3 AS value)],
|
||||
|
@ -39,7 +39,7 @@ SELECT
|
|||
7
|
||||
)
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
['b'],
|
||||
udf.active_values_from_days_seen_map(
|
||||
[STRUCT('a' AS key, 2048 AS value), STRUCT('b' AS key, 3 AS value)],
|
||||
|
@ -47,7 +47,7 @@ SELECT
|
|||
7
|
||||
)
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
['a', 'b'],
|
||||
udf.active_values_from_days_seen_map(
|
||||
[STRUCT('a' AS key, 1 AS value), STRUCT('b' AS key, 3 AS value)],
|
||||
|
|
|
@ -85,17 +85,17 @@ oct_second AS (
|
|||
examples
|
||||
)
|
||||
SELECT
|
||||
assert.array_equals([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 5], res.total_searches),
|
||||
assert.array_equals([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10], res.tagged_searches),
|
||||
assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15], res.search_with_ads),
|
||||
assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20], res.ad_click)
|
||||
mozfun.assert.array_equals([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 5], res.total_searches),
|
||||
mozfun.assert.array_equals([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10], res.tagged_searches),
|
||||
mozfun.assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15], res.search_with_ads),
|
||||
mozfun.assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20], res.ad_click)
|
||||
FROM
|
||||
oct_first
|
||||
UNION ALL
|
||||
SELECT
|
||||
assert.array_equals([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 5], res.total_searches),
|
||||
assert.array_equals([12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 11], res.tagged_searches),
|
||||
assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15], res.search_with_ads),
|
||||
assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20], res.ad_click)
|
||||
mozfun.assert.array_equals([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 5], res.total_searches),
|
||||
mozfun.assert.array_equals([12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 11], res.tagged_searches),
|
||||
mozfun.assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15], res.search_with_ads),
|
||||
mozfun.assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20], res.ad_click)
|
||||
FROM
|
||||
oct_second
|
||||
|
|
|
@ -382,7 +382,7 @@ expected AS (
|
|||
)
|
||||
)
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
exp,
|
||||
CASE
|
||||
WHEN res_type = "total_searches"
|
||||
|
|
|
@ -63,17 +63,17 @@ correct_sum AS (
|
|||
) AS actual
|
||||
)
|
||||
SELECT
|
||||
assert.array_equals([0, 2, 3, 4], actual.total_searches),
|
||||
assert.array_equals([1, 0, 3, 4], actual.tagged_searches),
|
||||
assert.array_equals([1, 2, 0, 4], actual.search_with_ads),
|
||||
assert.array_equals([1, 2, 3, 0], actual.ad_click),
|
||||
mozfun.assert.array_equals([0, 2, 3, 4], actual.total_searches),
|
||||
mozfun.assert.array_equals([1, 0, 3, 4], actual.tagged_searches),
|
||||
mozfun.assert.array_equals([1, 2, 0, 4], actual.search_with_ads),
|
||||
mozfun.assert.array_equals([1, 2, 3, 0], actual.ad_click),
|
||||
FROM
|
||||
correct_order
|
||||
UNION ALL
|
||||
SELECT
|
||||
assert.array_equals([3, 6, 1], actual.total_searches),
|
||||
assert.array_equals([5, 7, 1], actual.tagged_searches),
|
||||
assert.array_equals([7, 8, 1], actual.search_with_ads),
|
||||
assert.array_equals([9, 9, 1], actual.ad_click),
|
||||
mozfun.assert.array_equals([3, 6, 1], actual.total_searches),
|
||||
mozfun.assert.array_equals([5, 7, 1], actual.tagged_searches),
|
||||
mozfun.assert.array_equals([7, 8, 1], actual.search_with_ads),
|
||||
mozfun.assert.array_equals([9, 9, 1], actual.ad_click),
|
||||
FROM
|
||||
correct_sum
|
||||
|
|
|
@ -20,7 +20,7 @@ CREATE OR REPLACE FUNCTION udf.aggregate_active_addons(active_addons ANY TYPE) A
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
[STRUCT('d' AS addon_id), STRUCT('b' AS addon_id), STRUCT('a' AS addon_id)],
|
||||
udf.aggregate_active_addons(
|
||||
[
|
||||
|
|
|
@ -42,7 +42,7 @@ CREATE OR REPLACE FUNCTION udf.aggregate_map_first(maps ANY TYPE) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
[STRUCT('A' AS key, '2' AS value), STRUCT('B' AS key, '1' AS value)],
|
||||
udf.aggregate_map_first(
|
||||
[
|
||||
|
|
|
@ -67,7 +67,7 @@ CREATE OR REPLACE FUNCTION udf.aggregate_search_counts(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
STRUCT(
|
||||
5 AS search_count_abouthome,
|
||||
1 AS search_count_contextmenu,
|
||||
|
@ -95,7 +95,7 @@ SELECT
|
|||
]
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
STRUCT(
|
||||
0 AS search_count_all,
|
||||
0 AS search_count_abouthome,
|
||||
|
|
|
@ -45,11 +45,11 @@ WITH output AS (
|
|||
) AS res
|
||||
)
|
||||
SELECT
|
||||
assert.equals("google", res[OFFSET(0)].key),
|
||||
assert.array_equals(udf.array_11_zeroes_then(10), res[OFFSET(0)].value.total_searches),
|
||||
assert.array_equals(udf.array_11_zeroes_then(5), res[OFFSET(0)].value.tagged_searches),
|
||||
assert.array_equals(udf.array_11_zeroes_then(0), res[OFFSET(0)].value.search_with_ads),
|
||||
assert.array_equals(udf.array_11_zeroes_then(0), res[OFFSET(0)].value.ad_click),
|
||||
assert.equals(ARRAY_LENGTH(res), 1)
|
||||
mozfun.assert.equals("google", res[OFFSET(0)].key),
|
||||
mozfun.assert.array_equals(udf.array_11_zeroes_then(10), res[OFFSET(0)].value.total_searches),
|
||||
mozfun.assert.array_equals(udf.array_11_zeroes_then(5), res[OFFSET(0)].value.tagged_searches),
|
||||
mozfun.assert.array_equals(udf.array_11_zeroes_then(0), res[OFFSET(0)].value.search_with_ads),
|
||||
mozfun.assert.array_equals(udf.array_11_zeroes_then(0), res[OFFSET(0)].value.ad_click),
|
||||
mozfun.assert.equals(ARRAY_LENGTH(res), 1)
|
||||
FROM
|
||||
output;
|
||||
|
|
|
@ -7,4 +7,4 @@ CREATE OR REPLACE FUNCTION udf.array_11_zeroes_then(val INT64) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114], udf.array_11_zeroes_then(114))
|
||||
mozfun.assert.array_equals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114], udf.array_11_zeroes_then(114))
|
||||
|
|
|
@ -12,5 +12,5 @@ CREATE OR REPLACE FUNCTION udf.array_drop_first_and_append(arr ANY TYPE, append
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals([2, 3, 4], udf.array_drop_first_and_append([1, 2, 3], 4)),
|
||||
assert.array_equals([4], udf.array_drop_first_and_append([], 4));
|
||||
mozfun.assert.array_equals([2, 3, 4], udf.array_drop_first_and_append([1, 2, 3], 4)),
|
||||
mozfun.assert.array_equals([4], udf.array_drop_first_and_append([], 4));
|
||||
|
|
|
@ -18,6 +18,6 @@ CREATE OR REPLACE FUNCTION udf.array_slice(arr ANY TYPE, start_index INT64, end_
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.array_equals([1, 2, 3], udf.array_slice([1, 2, 3], 0, 2)),
|
||||
assert.array_equals([1, 2], udf.array_slice([1, 2, 3], 0, 1)),
|
||||
assert.array_equals(['2'], udf.array_slice(['1', '2', '3'], 1, 1)),
|
||||
mozfun.assert.array_equals([1, 2, 3], udf.array_slice([1, 2, 3], 0, 2)),
|
||||
mozfun.assert.array_equals([1, 2], udf.array_slice([1, 2, 3], 0, 1)),
|
||||
mozfun.assert.array_equals(['2'], udf.array_slice(['1', '2', '3'], 1, 1)),
|
||||
|
|
|
@ -7,5 +7,5 @@ CREATE OR REPLACE FUNCTION udf.bitcount_lowest_7(x INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(7, udf.bitcount_lowest_7(255)),
|
||||
assert.equals(1, udf.bitcount_lowest_7(2))
|
||||
mozfun.assert.equals(7, udf.bitcount_lowest_7(255)),
|
||||
mozfun.assert.equals(1, udf.bitcount_lowest_7(2))
|
||||
|
|
|
@ -20,7 +20,7 @@ CREATE OR REPLACE FUNCTION udf.bitmask_range(start_ordinal INT64, _length INT64)
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(1, udf.bitmask_range(1, 1)),
|
||||
assert.equals(30, udf.bitmask_range(2, 4)),
|
||||
mozfun.assert.equals(1, udf.bitmask_range(1, 1)),
|
||||
mozfun.assert.equals(30, udf.bitmask_range(2, 4)),
|
||||
-- Taking just the second and third bits (from the right) of binary 11011 should give us 00010 (decimal 2)
|
||||
assert.equals(2, ((1 << 4) + (1 << 3) + (1 << 1) + (1 << 0)) & udf.bitmask_range(2, 2))
|
||||
mozfun.assert.equals(2, ((1 << 4) + (1 << 3) + (1 << 1) + (1 << 0)) & udf.bitmask_range(2, 2))
|
||||
|
|
|
@ -5,7 +5,7 @@ CREATE OR REPLACE FUNCTION udf.bits28_days_since_seen(bits INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.null(udf.bits28_days_since_seen(0)),
|
||||
assert.equals(0, udf.bits28_days_since_seen(1)),
|
||||
assert.equals(3, udf.bits28_days_since_seen(8)),
|
||||
assert.equals(0, udf.bits28_days_since_seen(8 + 1))
|
||||
mozfun.assert.null(udf.bits28_days_since_seen(0)),
|
||||
mozfun.assert.equals(0, udf.bits28_days_since_seen(1)),
|
||||
mozfun.assert.equals(3, udf.bits28_days_since_seen(8)),
|
||||
mozfun.assert.equals(0, udf.bits28_days_since_seen(8 + 1))
|
||||
|
|
|
@ -5,8 +5,8 @@ CREATE OR REPLACE FUNCTION udf.bits28_from_string(s STRING) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(1, udf.bits28_from_string('1')),
|
||||
assert.equals(1, udf.bits28_from_string('01')),
|
||||
assert.equals(1, udf.bits28_from_string('0000000000000000000000000001')),
|
||||
assert.equals(2, udf.bits28_from_string('10')),
|
||||
assert.equals(5, udf.bits28_from_string('101'));
|
||||
mozfun.assert.equals(1, udf.bits28_from_string('1')),
|
||||
mozfun.assert.equals(1, udf.bits28_from_string('01')),
|
||||
mozfun.assert.equals(1, udf.bits28_from_string('0000000000000000000000000001')),
|
||||
mozfun.assert.equals(2, udf.bits28_from_string('10')),
|
||||
mozfun.assert.equals(5, udf.bits28_from_string('101'));
|
||||
|
|
|
@ -6,7 +6,7 @@ RETURNS INT64 AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(1 << 3, udf.bits28_range(1 << 10, -13, 7)),
|
||||
assert.equals(0, udf.bits28_range(1 << 10, -6, 7)),
|
||||
assert.equals(1, udf.bits28_range(1, 0, 1)),
|
||||
assert.equals(0, udf.bits28_range(0, 0, 1));
|
||||
mozfun.assert.equals(1 << 3, udf.bits28_range(1 << 10, -13, 7)),
|
||||
mozfun.assert.equals(0, udf.bits28_range(1 << 10, -6, 7)),
|
||||
mozfun.assert.equals(1, udf.bits28_range(1, 0, 1)),
|
||||
mozfun.assert.equals(0, udf.bits28_range(0, 0, 1));
|
||||
|
|
|
@ -9,19 +9,19 @@ WITH test_data AS (
|
|||
udf.bits28_retention((1 << 13) | (1 << 10) | 1, DATE('2020-01-28')) AS retention
|
||||
)
|
||||
SELECT
|
||||
assert.equals(DATE('2020-01-28'), retention.day_0.metric_date),
|
||||
assert.equals(DATE('2020-01-22'), retention.day_6.metric_date),
|
||||
assert.equals(DATE('2020-01-15'), retention.day_13.metric_date),
|
||||
assert.equals(DATE('2020-01-08'), retention.day_20.metric_date),
|
||||
assert.equals(DATE('2020-01-01'), retention.day_27.metric_date),
|
||||
assert.true(retention.day_0.active_on_metric_date),
|
||||
assert.false(retention.day_6.active_on_metric_date),
|
||||
assert.true(retention.day_13.active_on_metric_date),
|
||||
assert.false(retention.day_20.active_on_metric_date),
|
||||
assert.false(retention.day_27.active_on_metric_date),
|
||||
assert.true(retention.day_13.active_in_week_0),
|
||||
assert.true(retention.day_13.active_in_week_0_after_metric_date),
|
||||
assert.true(retention.day_13.active_in_week_1),
|
||||
assert.false(retention.day_20.active_in_week_0),
|
||||
mozfun.assert.equals(DATE('2020-01-28'), retention.day_0.metric_date),
|
||||
mozfun.assert.equals(DATE('2020-01-22'), retention.day_6.metric_date),
|
||||
mozfun.assert.equals(DATE('2020-01-15'), retention.day_13.metric_date),
|
||||
mozfun.assert.equals(DATE('2020-01-08'), retention.day_20.metric_date),
|
||||
mozfun.assert.equals(DATE('2020-01-01'), retention.day_27.metric_date),
|
||||
mozfun.assert.true(retention.day_0.active_on_metric_date),
|
||||
mozfun.assert.false(retention.day_6.active_on_metric_date),
|
||||
mozfun.assert.true(retention.day_13.active_on_metric_date),
|
||||
mozfun.assert.false(retention.day_20.active_on_metric_date),
|
||||
mozfun.assert.false(retention.day_27.active_on_metric_date),
|
||||
mozfun.assert.true(retention.day_13.active_in_week_0),
|
||||
mozfun.assert.true(retention.day_13.active_in_week_0_after_metric_date),
|
||||
mozfun.assert.true(retention.day_13.active_in_week_1),
|
||||
mozfun.assert.false(retention.day_20.active_in_week_0),
|
||||
FROM
|
||||
test_data
|
||||
|
|
|
@ -6,9 +6,9 @@ RETURNS ARRAY<DATE> AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_empty(udf.bits28_to_dates(0, '2020-01-28')),
|
||||
assert.array_equals([DATE('2020-01-28')], udf.bits28_to_dates(1, '2020-01-28')),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_empty(udf.bits28_to_dates(0, '2020-01-28')),
|
||||
mozfun.assert.array_equals([DATE('2020-01-28')], udf.bits28_to_dates(1, '2020-01-28')),
|
||||
mozfun.assert.array_equals(
|
||||
[DATE('2020-01-01'), DATE('2020-01-28')],
|
||||
udf.bits28_to_dates(1 | (1 << 27), '2020-01-28')
|
||||
),
|
||||
|
|
|
@ -5,4 +5,4 @@ CREATE OR REPLACE FUNCTION udf.bits28_to_string(bits INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals('0100000000000000000000000010', udf.bits28_to_string((1 << 1) | (1 << 26)))
|
||||
mozfun.assert.equals('0100000000000000000000000010', udf.bits28_to_string((1 << 1) | (1 << 26)))
|
||||
|
|
|
@ -40,11 +40,11 @@ CREATE OR REPLACE FUNCTION udf.bits_from_offsets(offsets ARRAY<INT64>) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(b'\x01', udf.bits_from_offsets([0])),
|
||||
assert.equals(b'\x02', udf.bits_from_offsets([1])),
|
||||
assert.equals(b'\x03', udf.bits_from_offsets([0, 1])),
|
||||
assert.equals(b'\xff', udf.bits_from_offsets([0, 1, 2, 3, 4, 5, 6, 7])),
|
||||
assert.equals(b'\x01\xff', udf.bits_from_offsets([0, 1, 2, 3, 4, 5, 6, 7, 8])),
|
||||
assert.equals(b'\x01\xff', udf.bits_from_offsets([8, 0, 1, 2, 3, 4, 5, 6, 7])),
|
||||
assert.equals(b'\x01', udf.bits_from_offsets([0, 2048])),
|
||||
assert.equals(CONCAT(b'\x80', REPEAT(b'\x00', 255)), udf.bits_from_offsets([2047]));
|
||||
mozfun.assert.equals(b'\x01', udf.bits_from_offsets([0])),
|
||||
mozfun.assert.equals(b'\x02', udf.bits_from_offsets([1])),
|
||||
mozfun.assert.equals(b'\x03', udf.bits_from_offsets([0, 1])),
|
||||
mozfun.assert.equals(b'\xff', udf.bits_from_offsets([0, 1, 2, 3, 4, 5, 6, 7])),
|
||||
mozfun.assert.equals(b'\x01\xff', udf.bits_from_offsets([0, 1, 2, 3, 4, 5, 6, 7, 8])),
|
||||
mozfun.assert.equals(b'\x01\xff', udf.bits_from_offsets([8, 0, 1, 2, 3, 4, 5, 6, 7])),
|
||||
mozfun.assert.equals(b'\x01', udf.bits_from_offsets([0, 2048])),
|
||||
mozfun.assert.equals(CONCAT(b'\x80', REPEAT(b'\x00', 255)), udf.bits_from_offsets([2047]));
|
||||
|
|
|
@ -10,17 +10,17 @@ CREATE OR REPLACE FUNCTION udf.bits_to_active_n_weeks_ago(b BYTES, n INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(b'\x00\x00\x00\x01', 0)),
|
||||
assert.equals(FALSE, udf.bits_to_active_n_weeks_ago(b'\x00\x00\x00\x01', 1)),
|
||||
assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(b'\xF0\x00\x00\x01', 4)),
|
||||
assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(b'\xF0\x00\x00\x70', 0)),
|
||||
assert.equals(CAST(NULL AS BOOL), udf.bits_to_active_n_weeks_ago(NULL, 1)),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(b'\x00\x00\x00\x01', 0)),
|
||||
mozfun.assert.equals(FALSE, udf.bits_to_active_n_weeks_ago(b'\x00\x00\x00\x01', 1)),
|
||||
mozfun.assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(b'\xF0\x00\x00\x01', 4)),
|
||||
mozfun.assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(b'\xF0\x00\x00\x70', 0)),
|
||||
mozfun.assert.equals(CAST(NULL AS BOOL), udf.bits_to_active_n_weeks_ago(NULL, 1)),
|
||||
mozfun.assert.equals(
|
||||
FALSE,
|
||||
udf.bits_to_active_n_weeks_ago(b'\x0F\x00\x00\x00\x00\x00\x00\x00\x00\x03', 5)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
TRUE,
|
||||
udf.bits_to_active_n_weeks_ago(b'\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x03', 0)
|
||||
),
|
||||
assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(udf.one_as_365_bits() << 22, 3));
|
||||
mozfun.assert.equals(TRUE, udf.bits_to_active_n_weeks_ago(udf.one_as_365_bits() << 22, 3));
|
||||
|
|
|
@ -9,6 +9,6 @@ CREATE OR REPLACE FUNCTION udf.bits_to_days_seen(b BYTES) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(0, udf.bits_to_days_seen(b'\x00')),
|
||||
assert.equals(2, udf.bits_to_days_seen(b'\x03')),
|
||||
assert.equals(16, udf.bits_to_days_seen(b'\xff\xff'))
|
||||
mozfun.assert.equals(0, udf.bits_to_days_seen(b'\x00')),
|
||||
mozfun.assert.equals(2, udf.bits_to_days_seen(b'\x03')),
|
||||
mozfun.assert.equals(16, udf.bits_to_days_seen(b'\xff\xff'))
|
||||
|
|
|
@ -24,15 +24,27 @@ CREATE OR REPLACE FUNCTION udf.bits_to_days_since_first_seen(b BYTES) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(0, udf.bits_to_days_since_first_seen(b'\x00\x01')),
|
||||
assert.equals(0, udf.bits_to_days_since_first_seen(b'\x00\x00\x00\x01')),
|
||||
assert.equals(8, udf.bits_to_days_since_first_seen(b'\x01\x00')),
|
||||
assert.equals(NULL, udf.bits_to_days_since_first_seen(b'\x00\x00')),
|
||||
assert.equals(1, udf.bits_to_days_since_first_seen(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03')),
|
||||
assert.equals(79, udf.bits_to_days_since_first_seen(b'\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00')),
|
||||
assert.equals(79, udf.bits_to_days_since_first_seen(b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')),
|
||||
assert.equals(71, udf.bits_to_days_since_first_seen(b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(0, udf.bits_to_days_since_first_seen(b'\x00\x01')),
|
||||
mozfun.assert.equals(0, udf.bits_to_days_since_first_seen(b'\x00\x00\x00\x01')),
|
||||
mozfun.assert.equals(8, udf.bits_to_days_since_first_seen(b'\x01\x00')),
|
||||
mozfun.assert.equals(NULL, udf.bits_to_days_since_first_seen(b'\x00\x00')),
|
||||
mozfun.assert.equals(
|
||||
1,
|
||||
udf.bits_to_days_since_first_seen(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03')
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
79,
|
||||
udf.bits_to_days_since_first_seen(b'\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
79,
|
||||
udf.bits_to_days_since_first_seen(b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
71,
|
||||
udf.bits_to_days_since_first_seen(b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
3,
|
||||
udf.bits_to_days_since_first_seen(
|
||||
FROM_HEX(
|
||||
|
@ -40,7 +52,7 @@ SELECT
|
|||
)
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
11,
|
||||
udf.bits_to_days_since_first_seen(
|
||||
FROM_HEX(
|
||||
|
@ -48,7 +60,7 @@ SELECT
|
|||
)
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
19,
|
||||
udf.bits_to_days_since_first_seen(
|
||||
FROM_HEX(
|
||||
|
@ -56,7 +68,7 @@ SELECT
|
|||
)
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
254,
|
||||
udf.bits_to_days_since_first_seen(
|
||||
FROM_HEX(
|
||||
|
|
|
@ -23,13 +23,16 @@ CREATE OR REPLACE FUNCTION udf.bits_to_days_since_seen(b BYTES) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(0, udf.bits_to_days_since_seen(b'\x00\x01')),
|
||||
assert.equals(0, udf.bits_to_days_since_seen(b'\x00\x00\x00\x01')),
|
||||
assert.equals(8, udf.bits_to_days_since_seen(b'\x01\x00')),
|
||||
assert.equals(NULL, udf.bits_to_days_since_seen(b'\x00\x00')),
|
||||
assert.equals(0, udf.bits_to_days_since_seen(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03')),
|
||||
assert.equals(76, udf.bits_to_days_since_seen(b'\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00')),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(0, udf.bits_to_days_since_seen(b'\x00\x01')),
|
||||
mozfun.assert.equals(0, udf.bits_to_days_since_seen(b'\x00\x00\x00\x01')),
|
||||
mozfun.assert.equals(8, udf.bits_to_days_since_seen(b'\x01\x00')),
|
||||
mozfun.assert.equals(NULL, udf.bits_to_days_since_seen(b'\x00\x00')),
|
||||
mozfun.assert.equals(0, udf.bits_to_days_since_seen(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03')),
|
||||
mozfun.assert.equals(
|
||||
76,
|
||||
udf.bits_to_days_since_seen(b'\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
1,
|
||||
udf.bits_to_days_since_seen(
|
||||
FROM_HEX(
|
||||
|
@ -37,7 +40,7 @@ SELECT
|
|||
)
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
9,
|
||||
udf.bits_to_days_since_seen(
|
||||
FROM_HEX(
|
||||
|
@ -45,7 +48,7 @@ SELECT
|
|||
)
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
17,
|
||||
udf.bits_to_days_since_seen(
|
||||
FROM_HEX(
|
||||
|
@ -53,7 +56,7 @@ SELECT
|
|||
)
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
233,
|
||||
udf.bits_to_days_since_seen(
|
||||
FROM_HEX(
|
||||
|
|
|
@ -5,6 +5,6 @@ CREATE OR REPLACE FUNCTION udf.bool_to_365_bits(val BOOLEAN) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(b'\x01', LTRIM(udf.bool_to_365_bits(TRUE), b'\x00')),
|
||||
assert.equals(b'', LTRIM(udf.bool_to_365_bits(FALSE), b'\x00')),
|
||||
assert.equals(b'', LTRIM(udf.bool_to_365_bits(NULL), b'\x00'));
|
||||
mozfun.assert.equals(b'\x01', LTRIM(udf.bool_to_365_bits(TRUE), b'\x00')),
|
||||
mozfun.assert.equals(b'', LTRIM(udf.bool_to_365_bits(FALSE), b'\x00')),
|
||||
mozfun.assert.equals(b'', LTRIM(udf.bool_to_365_bits(NULL), b'\x00'));
|
||||
|
|
|
@ -18,9 +18,9 @@ CREATE OR REPLACE FUNCTION udf.boolean_histogram_to_boolean(histogram STRING) AS
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(TRUE, udf.boolean_histogram_to_boolean('{"values":{"0":1,"1":1}}')),
|
||||
assert.null(udf.boolean_histogram_to_boolean('{}')),
|
||||
assert.equals(FALSE, udf.boolean_histogram_to_boolean('{"values":{"0":1}}')),
|
||||
assert.equals(TRUE, udf.boolean_histogram_to_boolean('0,1')),
|
||||
assert.equals(TRUE, udf.boolean_histogram_to_boolean('1,1')),
|
||||
assert.equals(FALSE, udf.boolean_histogram_to_boolean('1,0'))
|
||||
mozfun.assert.equals(TRUE, udf.boolean_histogram_to_boolean('{"values":{"0":1,"1":1}}')),
|
||||
mozfun.assert.null(udf.boolean_histogram_to_boolean('{}')),
|
||||
mozfun.assert.equals(FALSE, udf.boolean_histogram_to_boolean('{"values":{"0":1}}')),
|
||||
mozfun.assert.equals(TRUE, udf.boolean_histogram_to_boolean('0,1')),
|
||||
mozfun.assert.equals(TRUE, udf.boolean_histogram_to_boolean('1,1')),
|
||||
mozfun.assert.equals(FALSE, udf.boolean_histogram_to_boolean('1,0'))
|
||||
|
|
|
@ -14,8 +14,8 @@ or else 0.
|
|||
*/
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(2, udf.coalesce_adjacent_days_28_bits(1, 64)),
|
||||
assert.equals(128, udf.coalesce_adjacent_days_28_bits(64, 1)),
|
||||
assert.equals(64, udf.coalesce_adjacent_days_28_bits(0, 64)),
|
||||
assert.equals(64, udf.coalesce_adjacent_days_28_bits(NULL, 64)),
|
||||
assert.equals(0, udf.coalesce_adjacent_days_28_bits(NULL, NULL));
|
||||
mozfun.assert.equals(2, udf.coalesce_adjacent_days_28_bits(1, 64)),
|
||||
mozfun.assert.equals(128, udf.coalesce_adjacent_days_28_bits(64, 1)),
|
||||
mozfun.assert.equals(64, udf.coalesce_adjacent_days_28_bits(0, 64)),
|
||||
mozfun.assert.equals(64, udf.coalesce_adjacent_days_28_bits(NULL, 64)),
|
||||
mozfun.assert.equals(0, udf.coalesce_adjacent_days_28_bits(NULL, NULL));
|
||||
|
|
|
@ -18,20 +18,20 @@ CREATE OR REPLACE FUNCTION udf.coalesce_adjacent_days_365_bits(prev BYTES, curr
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 1,
|
||||
udf.coalesce_adjacent_days_365_bits(udf.one_as_365_bits(), udf.one_as_365_bits() << 10)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 10,
|
||||
udf.coalesce_adjacent_days_365_bits(udf.one_as_365_bits() << 9, udf.one_as_365_bits())
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 9,
|
||||
udf.coalesce_adjacent_days_365_bits(udf.zero_as_365_bits(), udf.one_as_365_bits() << 9)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 9,
|
||||
udf.coalesce_adjacent_days_365_bits(NULL, udf.one_as_365_bits() << 9)
|
||||
),
|
||||
assert.equals(udf.zero_as_365_bits(), udf.coalesce_adjacent_days_365_bits(NULL, NULL));
|
||||
mozfun.assert.equals(udf.zero_as_365_bits(), udf.coalesce_adjacent_days_365_bits(NULL, NULL));
|
||||
|
|
|
@ -12,7 +12,7 @@ CREATE OR REPLACE FUNCTION udf.combine_adjacent_days_28_bits(prev INT64, curr IN
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(3, udf.combine_adjacent_days_28_bits(1, 1)),
|
||||
assert.equals(4, udf.combine_adjacent_days_28_bits(2, 4)),
|
||||
assert.equals(6, udf.combine_adjacent_days_28_bits(3, 4)),
|
||||
assert.equals(4, udf.combine_adjacent_days_28_bits(2, NULL));
|
||||
mozfun.assert.equals(3, udf.combine_adjacent_days_28_bits(1, 1)),
|
||||
mozfun.assert.equals(4, udf.combine_adjacent_days_28_bits(2, 4)),
|
||||
mozfun.assert.equals(6, udf.combine_adjacent_days_28_bits(3, 4)),
|
||||
mozfun.assert.equals(4, udf.combine_adjacent_days_28_bits(2, NULL));
|
||||
|
|
|
@ -4,31 +4,31 @@ CREATE OR REPLACE FUNCTION udf.combine_adjacent_days_365_bits(prev BYTES, curr B
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits(),
|
||||
udf.combine_adjacent_days_365_bits(udf.zero_as_365_bits(), udf.one_as_365_bits())
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 364 | udf.one_as_365_bits(),
|
||||
udf.combine_adjacent_days_365_bits(udf.one_as_365_bits() << 363, udf.one_as_365_bits())
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits(),
|
||||
udf.combine_adjacent_days_365_bits(udf.one_as_365_bits() << 364, udf.one_as_365_bits())
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 1,
|
||||
udf.combine_adjacent_days_365_bits(udf.one_as_365_bits(), udf.zero_as_365_bits())
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 1,
|
||||
udf.combine_adjacent_days_365_bits(udf.one_as_365_bits(), NULL)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits(),
|
||||
udf.combine_adjacent_days_365_bits(NULL, udf.one_as_365_bits())
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 1 | udf.one_as_365_bits(),
|
||||
udf.combine_adjacent_days_365_bits(udf.one_as_365_bits(), udf.one_as_365_bits())
|
||||
);
|
||||
|
|
|
@ -52,7 +52,7 @@ CREATE OR REPLACE FUNCTION udf.combine_days_seen_maps(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
[
|
||||
STRUCT("key1" AS key, 3 AS value),
|
||||
STRUCT("key2" AS key, 6 AS value),
|
||||
|
|
|
@ -54,7 +54,7 @@ CREATE OR REPLACE FUNCTION udf.combine_experiment_days(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
udf.combine_experiment_days(
|
||||
[
|
||||
STRUCT("exp1" AS experiment, "1a" AS branch, 1 AS bits),
|
||||
|
|
|
@ -31,4 +31,4 @@ CREATE OR REPLACE FUNCTION udf.country_code_to_flag(
|
|||
-- Tests
|
||||
SELECT
|
||||
-- The emoji below may not be visible in your code editor.
|
||||
assert.equals('🇫🇮', udf.country_code_to_flag('FI'));
|
||||
mozfun.assert.equals('🇫🇮', udf.country_code_to_flag('FI'));
|
||||
|
|
|
@ -16,4 +16,7 @@ CREATE OR REPLACE FUNCTION udf.days_seen_bytes_to_rfm(days_seen_bytes BYTES) AS
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(STRUCT(2 AS frequency, 4 AS T, 2 AS recency), udf.days_seen_bytes_to_rfm(b'\x14'))
|
||||
mozfun.assert.equals(
|
||||
STRUCT(2 AS frequency, 4 AS T, 2 AS recency),
|
||||
udf.days_seen_bytes_to_rfm(b'\x14')
|
||||
)
|
||||
|
|
|
@ -18,9 +18,9 @@ CREATE OR REPLACE FUNCTION udf.days_since_created_profile_as_28_bits(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(2, udf.days_since_created_profile_as_28_bits(1)),
|
||||
assert.equals(4, udf.days_since_created_profile_as_28_bits(2)),
|
||||
assert.equals(64, udf.days_since_created_profile_as_28_bits(6)),
|
||||
assert.equals(0, udf.days_since_created_profile_as_28_bits(7)),
|
||||
assert.equals(0, udf.days_since_created_profile_as_28_bits(-1)),
|
||||
assert.equals(0, udf.days_since_created_profile_as_28_bits(NULL));
|
||||
mozfun.assert.equals(2, udf.days_since_created_profile_as_28_bits(1)),
|
||||
mozfun.assert.equals(4, udf.days_since_created_profile_as_28_bits(2)),
|
||||
mozfun.assert.equals(64, udf.days_since_created_profile_as_28_bits(6)),
|
||||
mozfun.assert.equals(0, udf.days_since_created_profile_as_28_bits(7)),
|
||||
mozfun.assert.equals(0, udf.days_since_created_profile_as_28_bits(-1)),
|
||||
mozfun.assert.equals(0, udf.days_since_created_profile_as_28_bits(NULL));
|
||||
|
|
|
@ -26,13 +26,13 @@ CREATE OR REPLACE FUNCTION udf.deanonymize_event(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(1, udf.deanonymize_event(event).event_timestamp),
|
||||
assert.equals("normandy", udf.deanonymize_event(event).event_category),
|
||||
assert.equals("enroll", udf.deanonymize_event(event).event_method),
|
||||
assert.equals("pref-flip", udf.deanonymize_event(event).event_object),
|
||||
assert.equals("test-experiment", udf.deanonymize_event(event).event_string_value),
|
||||
assert.equals("branch", udf.deanonymize_event(event).event_map_values[OFFSET(0)].key),
|
||||
assert.equals("control", udf.deanonymize_event(event).event_map_values[OFFSET(0)].value)
|
||||
mozfun.assert.equals(1, udf.deanonymize_event(event).event_timestamp),
|
||||
mozfun.assert.equals("normandy", udf.deanonymize_event(event).event_category),
|
||||
mozfun.assert.equals("enroll", udf.deanonymize_event(event).event_method),
|
||||
mozfun.assert.equals("pref-flip", udf.deanonymize_event(event).event_object),
|
||||
mozfun.assert.equals("test-experiment", udf.deanonymize_event(event).event_string_value),
|
||||
mozfun.assert.equals("branch", udf.deanonymize_event(event).event_map_values[OFFSET(0)].key),
|
||||
mozfun.assert.equals("control", udf.deanonymize_event(event).event_map_values[OFFSET(0)].value)
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -47,7 +47,7 @@ FROM
|
|||
);
|
||||
|
||||
SELECT
|
||||
assert.null(udf.deanonymize_event(event).event_timestamp)
|
||||
mozfun.assert.null(udf.deanonymize_event(event).event_timestamp)
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
|
|
|
@ -22,5 +22,5 @@ CREATE OR REPLACE FUNCTION udf.decode_int64(raw BYTES) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(1, udf.decode_int64(b'\x00\x00\x00\x00\x00\x00\x00\x01')),
|
||||
assert.equals(16, udf.decode_int64(b'\x00\x00\x00\x00\x00\x00\x00\x10'));
|
||||
mozfun.assert.equals(1, udf.decode_int64(b'\x00\x00\x00\x00\x00\x00\x00\x01')),
|
||||
mozfun.assert.equals(16, udf.decode_int64(b'\x00\x00\x00\x00\x00\x00\x00\x10'));
|
||||
|
|
|
@ -9,10 +9,10 @@ CREATE OR REPLACE FUNCTION udf.dedupe_array(list ANY TYPE) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.array_equals(['foo'], udf.dedupe_array(['foo'])),
|
||||
assert.array_equals(['foo'], udf.dedupe_array(['foo', 'foo'])),
|
||||
assert.array_equals(['foo', 'bar'], udf.dedupe_array(['foo', 'bar', 'bar', 'foo'])),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(['foo'], udf.dedupe_array(['foo'])),
|
||||
mozfun.assert.array_equals(['foo'], udf.dedupe_array(['foo', 'foo'])),
|
||||
mozfun.assert.array_equals(['foo', 'bar'], udf.dedupe_array(['foo', 'bar', 'bar', 'foo'])),
|
||||
mozfun.assert.array_equals(
|
||||
['foo', 'bar', 'baz'],
|
||||
udf.dedupe_array(['foo', 'bar', 'bar', 'baz', 'foo', 'baz', 'bar'])
|
||||
);
|
||||
|
|
|
@ -28,18 +28,18 @@ CREATE OR REPLACE FUNCTION udf.event_code_points_to_string(code_points ANY TYPE)
|
|||
);
|
||||
|
||||
SELECT
|
||||
assert.equals("!", udf.event_code_points_to_string([33])),
|
||||
assert.equals("#", udf.event_code_points_to_string([34])),
|
||||
assert.equals("-", udf.event_code_points_to_string([43])),
|
||||
assert.equals(CODE_POINTS_TO_STRING([1, 2]), udf.event_code_points_to_string([1, 2])),
|
||||
assert.equals(
|
||||
mozfun.assert.equals("!", udf.event_code_points_to_string([33])),
|
||||
mozfun.assert.equals("#", udf.event_code_points_to_string([34])),
|
||||
mozfun.assert.equals("-", udf.event_code_points_to_string([43])),
|
||||
mozfun.assert.equals(CODE_POINTS_TO_STRING([1, 2]), udf.event_code_points_to_string([1, 2])),
|
||||
mozfun.assert.equals(
|
||||
CODE_POINTS_TO_STRING(NULL),
|
||||
udf.event_code_points_to_string(CAST(NULL AS ARRAY<INT64>))
|
||||
),
|
||||
assert.equals(CODE_POINTS_TO_STRING([NULL]), udf.event_code_points_to_string([NULL])),
|
||||
assert.equals(CODE_POINTS_TO_STRING([]), udf.event_code_points_to_string([]));
|
||||
mozfun.assert.equals(CODE_POINTS_TO_STRING([NULL]), udf.event_code_points_to_string([NULL])),
|
||||
mozfun.assert.equals(CODE_POINTS_TO_STRING([]), udf.event_code_points_to_string([]));
|
||||
|
||||
SELECT
|
||||
assert.not_null(udf.event_code_points_to_string([n]))
|
||||
mozfun.assert.not_null(udf.event_code_points_to_string([n]))
|
||||
FROM
|
||||
UNNEST(GENERATE_ARRAY(1, 1000000)) AS n
|
||||
|
|
|
@ -12,17 +12,17 @@ CREATE OR REPLACE FUNCTION udf.experiment_search_metric_to_array(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.experiment_search_metric_to_array([STRUCT("engine1", 3)])[OFFSET(0)],
|
||||
"[3,0,0]"
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.experiment_search_metric_to_array([STRUCT("engine1", 100), STRUCT("engine2", 4)])[
|
||||
OFFSET(0)
|
||||
],
|
||||
"[100,0,0]"
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.experiment_search_metric_to_array([STRUCT("engine1", 100), STRUCT("engine2", 4)])[
|
||||
OFFSET(1)
|
||||
],
|
||||
|
|
|
@ -22,7 +22,7 @@ extracted AS (
|
|||
)
|
||||
--
|
||||
SELECT
|
||||
assert.equals(1, has_value),
|
||||
assert.null(null_value)
|
||||
mozfun.assert.equals(1, has_value),
|
||||
mozfun.assert.null(null_value)
|
||||
FROM
|
||||
extracted
|
||||
|
|
|
@ -9,8 +9,8 @@ CREATE OR REPLACE FUNCTION udf.extract_document_type(table_name STRING) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals("type", udf.extract_document_type("type_v1")),
|
||||
assert.equals(
|
||||
mozfun.assert.equals("type", udf.extract_document_type("type_v1")),
|
||||
mozfun.assert.equals(
|
||||
"namespace__namespace_type",
|
||||
udf.extract_document_type("namespace__namespace_type_v20191031")
|
||||
);
|
||||
|
|
|
@ -9,5 +9,8 @@ CREATE OR REPLACE FUNCTION udf.extract_document_version(table_name STRING) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals("1", udf.extract_document_version("type_v1")),
|
||||
assert.equals("20191031", udf.extract_document_version("namespace__namespace_type_v20191031"));
|
||||
mozfun.assert.equals("1", udf.extract_document_version("type_v1")),
|
||||
mozfun.assert.equals(
|
||||
"20191031",
|
||||
udf.extract_document_version("namespace__namespace_type_v20191031")
|
||||
);
|
||||
|
|
|
@ -42,10 +42,10 @@ extracted AS (
|
|||
)
|
||||
--
|
||||
SELECT
|
||||
assert.equals(7, hsum)
|
||||
mozfun.assert.equals(7, hsum)
|
||||
FROM
|
||||
extracted;
|
||||
|
||||
--
|
||||
SELECT
|
||||
assert.null(udf.extract_histogram_sum('foo'));
|
||||
mozfun.assert.null(udf.extract_histogram_sum('foo'));
|
||||
|
|
|
@ -20,24 +20,24 @@ RETURNS STRING AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.null(
|
||||
mozfun.assert.null(
|
||||
udf.extract_schema_validation_path(
|
||||
"com.mozilla.telemetry.decoder.Deduplicate$DuplicateIdException: A message with this documentId has already been successfully processed."
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
"#/events/1/timestamp",
|
||||
udf.extract_schema_validation_path(
|
||||
"org.everit.json.schema.ValidationException: #/events/1/timestamp: -2 is not greater or equal to 0"
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
"#/client_info",
|
||||
udf.extract_schema_validation_path(
|
||||
"org.everit.json.schema.ValidationException: #: required key [client_info] not found"
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
"#/application/buildID",
|
||||
udf.extract_schema_validation_path(
|
||||
"org.everit.json.schema.ValidationException: #/application: extraneous key [buildID] is not permitted"
|
||||
|
|
|
@ -4,22 +4,22 @@ CREATE OR REPLACE FUNCTION udf.fenix_build_to_datetime(app_build STRING) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(DATETIME '2020-06-05 14:34:00', udf.fenix_build_to_datetime("21571434")),
|
||||
assert.equals(DATETIME '2018-01-01 00:00:00', udf.fenix_build_to_datetime("00010000")),
|
||||
assert.equals(DATETIME '2027-12-31 23:59:00', udf.fenix_build_to_datetime("93652359")),
|
||||
assert.equals(DATETIME '2020-08-13 04:00:00', udf.fenix_build_to_datetime("2015757667")),
|
||||
assert.equals(DATETIME '2014-12-28 00:00:00', udf.fenix_build_to_datetime("0000000000")),
|
||||
assert.equals(DATETIME '2014-12-28 00:00:00', udf.fenix_build_to_datetime("0000000001")),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(DATETIME '2020-06-05 14:34:00', udf.fenix_build_to_datetime("21571434")),
|
||||
mozfun.assert.equals(DATETIME '2018-01-01 00:00:00', udf.fenix_build_to_datetime("00010000")),
|
||||
mozfun.assert.equals(DATETIME '2027-12-31 23:59:00', udf.fenix_build_to_datetime("93652359")),
|
||||
mozfun.assert.equals(DATETIME '2020-08-13 04:00:00', udf.fenix_build_to_datetime("2015757667")),
|
||||
mozfun.assert.equals(DATETIME '2014-12-28 00:00:00', udf.fenix_build_to_datetime("0000000000")),
|
||||
mozfun.assert.equals(DATETIME '2014-12-28 00:00:00', udf.fenix_build_to_datetime("0000000001")),
|
||||
mozfun.assert.equals(
|
||||
DATETIME '2014-12-28 00:00:00',
|
||||
udf.fenix_build_to_datetime(CAST(1 << 31 AS STRING))
|
||||
),
|
||||
assert.equals(DATETIME '2014-12-28 01:00:00', udf.fenix_build_to_datetime("0000000009")),
|
||||
assert.null(udf.fenix_build_to_datetime("7777777")),
|
||||
assert.null(udf.fenix_build_to_datetime("999999999")),
|
||||
assert.null(udf.fenix_build_to_datetime("3")),
|
||||
assert.null(udf.fenix_build_to_datetime("hi")),
|
||||
mozfun.assert.equals(DATETIME '2014-12-28 01:00:00', udf.fenix_build_to_datetime("0000000009")),
|
||||
mozfun.assert.null(udf.fenix_build_to_datetime("7777777")),
|
||||
mozfun.assert.null(udf.fenix_build_to_datetime("999999999")),
|
||||
mozfun.assert.null(udf.fenix_build_to_datetime("3")),
|
||||
mozfun.assert.null(udf.fenix_build_to_datetime("hi")),
|
||||
-- 8 digits, minutes place is 60
|
||||
assert.null(udf.fenix_build_to_datetime("11831860")),
|
||||
mozfun.assert.null(udf.fenix_build_to_datetime("11831860")),
|
||||
-- 8 digits, hours place is 24
|
||||
assert.null(udf.fenix_build_to_datetime("11832459"))
|
||||
mozfun.assert.null(udf.fenix_build_to_datetime("11832459"))
|
||||
|
|
|
@ -15,6 +15,6 @@ RETURNS BOOLEAN AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.true(udf.ga_is_mozilla_browser('Mozilla')),
|
||||
assert.true(udf.ga_is_mozilla_browser('Firefox')),
|
||||
assert.false(udf.ga_is_mozilla_browser('Chrome'));
|
||||
mozfun.assert.true(udf.ga_is_mozilla_browser('Mozilla')),
|
||||
mozfun.assert.true(udf.ga_is_mozilla_browser('Firefox')),
|
||||
mozfun.assert.false(udf.ga_is_mozilla_browser('Chrome'));
|
||||
|
|
|
@ -29,11 +29,11 @@ CREATE OR REPLACE FUNCTION udf.geo_struct(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
STRUCT('a' AS country, 'b' AS city, 'c' AS geo_subdivision1, 'd' AS geo_subdivision2),
|
||||
udf.geo_struct('a', 'b', 'c', 'd')
|
||||
),
|
||||
assert.null(udf.geo_struct('??', 'b', 'c', 'd')),
|
||||
assert.null(udf.geo_struct('a', '??', 'c', 'd').city),
|
||||
assert.null(udf.geo_struct('a', 'b', '??', 'd').geo_subdivision1),
|
||||
assert.null(udf.geo_struct('a', 'b', 'c', '??').geo_subdivision2)
|
||||
mozfun.assert.null(udf.geo_struct('??', 'b', 'c', 'd')),
|
||||
mozfun.assert.null(udf.geo_struct('a', '??', 'c', 'd').city),
|
||||
mozfun.assert.null(udf.geo_struct('a', 'b', '??', 'd').geo_subdivision1),
|
||||
mozfun.assert.null(udf.geo_struct('a', 'b', 'c', '??').geo_subdivision2)
|
||||
|
|
|
@ -5,4 +5,4 @@ CREATE OR REPLACE FUNCTION udf.get_key(map ANY TYPE, k ANY TYPE) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(12, udf.get_key([STRUCT('foo' AS key, 42 AS value), ('bar', 12)], 'bar'));
|
||||
mozfun.assert.equals(12, udf.get_key([STRUCT('foo' AS key, 42 AS value), ('bar', 12)], 'bar'));
|
||||
|
|
|
@ -5,8 +5,11 @@ CREATE OR REPLACE FUNCTION udf.get_key_with_null(map ANY TYPE, k ANY TYPE) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(12, udf.get_key_with_null([STRUCT('foo' AS key, 42 AS value), ('bar', 12)], 'bar')),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
12,
|
||||
udf.get_key_with_null([STRUCT('foo' AS key, 42 AS value), ('bar', 12)], 'bar')
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
12,
|
||||
udf.get_key_with_null(
|
||||
[STRUCT('foo' AS key, 42 AS value), (CAST(NULL AS STRING), 12)],
|
||||
|
|
|
@ -43,18 +43,18 @@ CREATE OR REPLACE FUNCTION udf.gzip_length_footer(compressed BYTES) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
4,
|
||||
udf.gzip_length_footer(
|
||||
-- printf test | gzip -c | python3 -c 'import sys; print(sys.stdin.buffer.read())'
|
||||
b'\x1f\x8b\x08\x00\xc4\x15\x8e^\x00\x03+I-.\x01\x00\x0c~\x7f\xd8\x04\x00\x00\x00'
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
0,
|
||||
udf.gzip_length_footer(
|
||||
-- gzip -c < /dev/null | python3 -c 'import sys; print(sys.stdin.buffer.read())'
|
||||
b'\x1f\x8b\x08\x00\xe7\x15\x8e^\x00\x03\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||
)
|
||||
),
|
||||
assert.equals(16, udf.gzip_length_footer(b"\x10\x00\x00\x00"));
|
||||
mozfun.assert.equals(16, udf.gzip_length_footer(b"\x10\x00\x00\x00"));
|
||||
|
|
|
@ -11,7 +11,7 @@ CREATE OR REPLACE FUNCTION udf.histogram_max_key_with_nonzero_value(histogram ST
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(1, udf.histogram_max_key_with_nonzero_value('{"values":{"0":3,"1":2}}')),
|
||||
assert.null(udf.histogram_max_key_with_nonzero_value('{}')),
|
||||
assert.null(udf.histogram_max_key_with_nonzero_value('{"values":{"0":0}}')),
|
||||
assert.equals(5, udf.histogram_max_key_with_nonzero_value('{"values":{"5":1}}'))
|
||||
mozfun.assert.equals(1, udf.histogram_max_key_with_nonzero_value('{"values":{"0":3,"1":2}}')),
|
||||
mozfun.assert.null(udf.histogram_max_key_with_nonzero_value('{}')),
|
||||
mozfun.assert.null(udf.histogram_max_key_with_nonzero_value('{"values":{"0":0}}')),
|
||||
mozfun.assert.equals(5, udf.histogram_max_key_with_nonzero_value('{"values":{"5":1}}'))
|
||||
|
|
|
@ -4,9 +4,9 @@ CREATE OR REPLACE FUNCTION udf.int_to_365_bits(value INT64) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(b'\x0F', LTRIM(udf.int_to_365_bits(15), b'\x00')),
|
||||
assert.equals(udf.one_as_365_bits() << 63, udf.int_to_365_bits(1 << 63)),
|
||||
assert.equals(udf.one_as_365_bits() << 22, udf.int_to_365_bits(1 << 22)),
|
||||
assert.equals(b'\x01\x00', LTRIM(udf.int_to_365_bits(1 << 8), b'\x00')),
|
||||
assert.equals(udf.one_as_365_bits() << 5, udf.int_to_365_bits(32)),
|
||||
assert.equals(CAST(NULL AS BYTES), udf.int_to_365_bits(NULL));
|
||||
mozfun.assert.equals(b'\x0F', LTRIM(udf.int_to_365_bits(15), b'\x00')),
|
||||
mozfun.assert.equals(udf.one_as_365_bits() << 63, udf.int_to_365_bits(1 << 63)),
|
||||
mozfun.assert.equals(udf.one_as_365_bits() << 22, udf.int_to_365_bits(1 << 22)),
|
||||
mozfun.assert.equals(b'\x01\x00', LTRIM(udf.int_to_365_bits(1 << 8), b'\x00')),
|
||||
mozfun.assert.equals(udf.one_as_365_bits() << 5, udf.int_to_365_bits(32)),
|
||||
mozfun.assert.equals(CAST(NULL AS BYTES), udf.int_to_365_bits(NULL));
|
||||
|
|
|
@ -14,8 +14,8 @@ CREATE OR REPLACE FUNCTION udf.int_to_hex_string(value INT64) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals('F', LTRIM(udf.int_to_hex_string(15), '0')),
|
||||
assert.equals('08000000000000000', udf.int_to_hex_string(1 << 63)),
|
||||
assert.equals('10', LTRIM(udf.int_to_hex_string(1 << 4), '0')),
|
||||
assert.equals('00000000000000020', udf.int_to_hex_string(32)),
|
||||
assert.equals(CAST(NULL AS STRING), udf.int_to_hex_string(NULL));
|
||||
mozfun.assert.equals('F', LTRIM(udf.int_to_hex_string(15), '0')),
|
||||
mozfun.assert.equals('08000000000000000', udf.int_to_hex_string(1 << 63)),
|
||||
mozfun.assert.equals('10', LTRIM(udf.int_to_hex_string(1 << 4), '0')),
|
||||
mozfun.assert.equals('00000000000000020', udf.int_to_hex_string(32)),
|
||||
mozfun.assert.equals(CAST(NULL AS STRING), udf.int_to_hex_string(NULL));
|
||||
|
|
|
@ -27,8 +27,8 @@ WITH histograms AS (
|
|||
]
|
||||
)
|
||||
SELECT
|
||||
assert.null(udf.keyed_histogram_get_sum(ARRAY<STRUCT<key STRING, value STRING>>[], 'dne')),
|
||||
assert.null(udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'dne')),
|
||||
assert.equals(1, udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'key1')),
|
||||
assert.equals(2, udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'key2')),
|
||||
assert.null(udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'key3'))
|
||||
mozfun.assert.null(udf.keyed_histogram_get_sum(ARRAY<STRUCT<key STRING, value STRING>>[], 'dne')),
|
||||
mozfun.assert.null(udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'dne')),
|
||||
mozfun.assert.equals(1, udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'key1')),
|
||||
mozfun.assert.equals(2, udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'key2')),
|
||||
mozfun.assert.null(udf.keyed_histogram_get_sum((SELECT * FROM histograms), 'key3'))
|
||||
|
|
|
@ -23,18 +23,18 @@ CREATE OR REPLACE FUNCTION udf.kv_array_append_to_json_string(input STRING, arr
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
'{"hello":"world","foo":"bar","baz":"boo"}',
|
||||
udf.kv_array_append_to_json_string(
|
||||
'{"hello":"world"}',
|
||||
[STRUCT("foo" AS key, "bar" AS value), STRUCT("baz" AS key, "boo" AS value)]
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
'{"foo":"bar"}',
|
||||
udf.kv_array_append_to_json_string(CAST(NULL AS STRING), [STRUCT("foo" AS key, "bar" AS value)])
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
'{"foo":"bar"}',
|
||||
udf.kv_array_append_to_json_string('{}', [STRUCT("foo" AS key, "bar" AS value)])
|
||||
);
|
||||
|
|
|
@ -25,13 +25,13 @@ CREATE OR REPLACE FUNCTION udf.kv_array_to_json_string(kv_arr ANY TYPE) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
'{"hello":"1","world":"2"}',
|
||||
udf.kv_array_to_json_string(
|
||||
[STRUCT('hello' AS key, 1 AS value), STRUCT('world' AS key, 2 AS value)]
|
||||
)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
'{"one-entry":"1"}',
|
||||
udf.kv_array_to_json_string([STRUCT('one-entry' AS key, 1 AS value)])
|
||||
);
|
||||
|
|
|
@ -23,5 +23,5 @@ CREATE OR REPLACE FUNCTION udf.map_bing_revenue_country_to_country_code(country
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals('US', udf.map_bing_revenue_country_to_country_code('CTY_United States')),
|
||||
assert.equals('Other', udf.map_bing_revenue_country_to_country_code('CTY_Bolivia'))
|
||||
mozfun.assert.equals('US', udf.map_bing_revenue_country_to_country_code('CTY_United States')),
|
||||
mozfun.assert.equals('Other', udf.map_bing_revenue_country_to_country_code('CTY_Bolivia'))
|
||||
|
|
|
@ -5,7 +5,7 @@ CREATE OR REPLACE FUNCTION udf.map_mode_last(entries ANY TYPE) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
[STRUCT('foo' AS key, 'bar' AS value), STRUCT('baz' AS key, 'fred' AS value)],
|
||||
udf.map_mode_last(
|
||||
[
|
||||
|
@ -15,7 +15,7 @@ SELECT
|
|||
]
|
||||
)
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
[STRUCT('foo' AS key, 'bar' AS value), STRUCT('baz' AS key, 'fred' AS value)],
|
||||
udf.map_mode_last(
|
||||
[
|
||||
|
|
|
@ -23,8 +23,8 @@ CREATE OR REPLACE FUNCTION udf.map_revenue_country(engine STRING, country STRING
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals('US', udf.map_revenue_country('Google', 'US')),
|
||||
assert.equals('US', udf.map_revenue_country('Bing', 'US')),
|
||||
assert.equals('Other', udf.map_revenue_country('Bing', 'AU')),
|
||||
assert.equals('ROW', udf.map_revenue_country('Google', 'AU')),
|
||||
assert.equals(CAST(NULL AS STRING), udf.map_revenue_country('Amazon', 'US'))
|
||||
mozfun.assert.equals('US', udf.map_revenue_country('Google', 'US')),
|
||||
mozfun.assert.equals('US', udf.map_revenue_country('Bing', 'US')),
|
||||
mozfun.assert.equals('Other', udf.map_revenue_country('Bing', 'AU')),
|
||||
mozfun.assert.equals('ROW', udf.map_revenue_country('Google', 'AU')),
|
||||
mozfun.assert.equals(CAST(NULL AS STRING), udf.map_revenue_country('Amazon', 'US'))
|
||||
|
|
|
@ -206,6 +206,6 @@ merged_expected_actual AS (
|
|||
)
|
||||
)
|
||||
SELECT
|
||||
assert.array_equals(expected, actual)
|
||||
mozfun.assert.array_equals(expected, actual)
|
||||
FROM
|
||||
merged_expected_actual
|
||||
|
|
|
@ -35,19 +35,19 @@ CREATE OR REPLACE FUNCTION udf.mod_uint128(dividend BYTES, divisor INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
0,
|
||||
udf.mod_uint128(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 2)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
1,
|
||||
udf.mod_uint128(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01', 2)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
464,
|
||||
udf.mod_uint128(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2c\x58\x1c\x36', 2342)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
4065,
|
||||
udf.mod_uint128(b'\x00\x00\x00\x00\x00\x00\x2c\x2c\x2c\x2c\x2c\x2c\x2c\x58\x1c\x36', 10009)
|
||||
)
|
||||
|
|
|
@ -23,14 +23,14 @@ CREATE OR REPLACE FUNCTION udf.normalize_fenix_metrics(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
'foo',
|
||||
udf.normalize_fenix_metrics(
|
||||
'19.0.0',
|
||||
STRUCT(STRUCT('foo' AS foo) AS timing_distribution)
|
||||
).timing_distribution.foo
|
||||
),
|
||||
assert.null(
|
||||
mozfun.assert.null(
|
||||
udf.normalize_fenix_metrics(
|
||||
'0.3.0',
|
||||
STRUCT(STRUCT('foo' AS foo) AS timing_distribution)
|
||||
|
|
|
@ -28,16 +28,16 @@ CREATE OR REPLACE FUNCTION udf.normalize_main_payload(payload ANY TYPE) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
3,
|
||||
udf.normalize_main_payload(STRUCT(STRUCT(3 AS session_length) AS info)).info.session_length
|
||||
),
|
||||
assert.null(
|
||||
mozfun.assert.null(
|
||||
udf.normalize_main_payload(
|
||||
STRUCT(STRUCT(-98984108 AS session_length) AS info)
|
||||
).info.session_length
|
||||
),
|
||||
assert.null(
|
||||
mozfun.assert.null(
|
||||
udf.normalize_main_payload(
|
||||
STRUCT(STRUCT(51536000 AS session_length) AS info)
|
||||
).info.session_length
|
||||
|
|
|
@ -97,10 +97,10 @@ WITH actual AS (
|
|||
) AS engine_searches
|
||||
)
|
||||
SELECT
|
||||
assert.array_equals(GENERATE_ARRAY(24, 46, 2), searches.value.total_searches),
|
||||
assert.array_equals(GENERATE_ARRAY(26, 48, 2), searches.value.tagged_searches),
|
||||
assert.array_equals(GENERATE_ARRAY(28, 50, 2), searches.value.search_with_ads),
|
||||
assert.array_equals(GENERATE_ARRAY(30, 52, 2), searches.value.ad_click),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(24, 46, 2), searches.value.total_searches),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(26, 48, 2), searches.value.tagged_searches),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(28, 50, 2), searches.value.search_with_ads),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(30, 52, 2), searches.value.ad_click),
|
||||
FROM
|
||||
actual
|
||||
CROSS JOIN
|
||||
|
@ -109,10 +109,10 @@ WHERE
|
|||
searches.key IS NULL
|
||||
UNION ALL
|
||||
SELECT
|
||||
assert.array_equals(GENERATE_ARRAY(6, 28, 2), searches.value.total_searches),
|
||||
assert.array_equals(GENERATE_ARRAY(8, 30, 2), searches.value.tagged_searches),
|
||||
assert.array_equals(GENERATE_ARRAY(10, 32, 2), searches.value.search_with_ads),
|
||||
assert.array_equals(GENERATE_ARRAY(12, 34, 2), searches.value.ad_click),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(6, 28, 2), searches.value.total_searches),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(8, 30, 2), searches.value.tagged_searches),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(10, 32, 2), searches.value.search_with_ads),
|
||||
mozfun.assert.array_equals(GENERATE_ARRAY(12, 34, 2), searches.value.ad_click),
|
||||
FROM
|
||||
actual
|
||||
CROSS JOIN
|
||||
|
|
|
@ -20,8 +20,8 @@ CREATE OR REPLACE FUNCTION udf.normalize_search_engine(engine STRING) AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals('Engine1', udf.normalize_search_engine('engine1')),
|
||||
assert.equals('Engine2', udf.normalize_search_engine('Engine2-abc')),
|
||||
assert.equals('Other', udf.normalize_search_engine('not-Engine1')),
|
||||
assert.equals('Other', udf.normalize_search_engine('engine')),
|
||||
assert.null(udf.normalize_search_engine(NULL))
|
||||
mozfun.assert.equals('Engine1', udf.normalize_search_engine('engine1')),
|
||||
mozfun.assert.equals('Engine2', udf.normalize_search_engine('Engine2-abc')),
|
||||
mozfun.assert.equals('Other', udf.normalize_search_engine('not-Engine1')),
|
||||
mozfun.assert.equals('Other', udf.normalize_search_engine('engine')),
|
||||
mozfun.assert.null(udf.normalize_search_engine(NULL))
|
||||
|
|
|
@ -11,4 +11,4 @@ CREATE OR REPLACE FUNCTION udf.null_if_empty_list(list ANY TYPE) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.null(udf.null_if_empty_list([]));
|
||||
mozfun.assert.null(udf.null_if_empty_list([]));
|
||||
|
|
|
@ -64,18 +64,18 @@ WITH examples AS (
|
|||
) AS empty_indices,
|
||||
)
|
||||
SELECT
|
||||
assert.equals('""', udf.pack_event_properties(null_property, indices)),
|
||||
assert.equals('""', udf.pack_event_properties(no_property, indices)),
|
||||
assert.equals('"b', udf.pack_event_properties(single_property, indices)),
|
||||
assert.equals('"a', udf.pack_event_properties(duplicate_property, indices)),
|
||||
assert.equals('a"', udf.pack_event_properties(secondary_property, indices)),
|
||||
mozfun.assert.equals('""', udf.pack_event_properties(null_property, indices)),
|
||||
mozfun.assert.equals('""', udf.pack_event_properties(no_property, indices)),
|
||||
mozfun.assert.equals('"b', udf.pack_event_properties(single_property, indices)),
|
||||
mozfun.assert.equals('"a', udf.pack_event_properties(duplicate_property, indices)),
|
||||
mozfun.assert.equals('a"', udf.pack_event_properties(secondary_property, indices)),
|
||||
-- We specifically ignore unknown properties, this gives us flexibility during encoding
|
||||
assert.equals('""', udf.pack_event_properties(unknown_property, indices)),
|
||||
assert.equals('', udf.pack_event_properties(null_property, empty_indices)),
|
||||
assert.equals('', udf.pack_event_properties(no_property, empty_indices)),
|
||||
assert.equals('', udf.pack_event_properties(single_property, empty_indices)),
|
||||
assert.equals('', udf.pack_event_properties(duplicate_property, empty_indices)),
|
||||
assert.equals('', udf.pack_event_properties(secondary_property, empty_indices)),
|
||||
assert.equals('', udf.pack_event_properties(unknown_property, empty_indices)),
|
||||
mozfun.assert.equals('""', udf.pack_event_properties(unknown_property, indices)),
|
||||
mozfun.assert.equals('', udf.pack_event_properties(null_property, empty_indices)),
|
||||
mozfun.assert.equals('', udf.pack_event_properties(no_property, empty_indices)),
|
||||
mozfun.assert.equals('', udf.pack_event_properties(single_property, empty_indices)),
|
||||
mozfun.assert.equals('', udf.pack_event_properties(duplicate_property, empty_indices)),
|
||||
mozfun.assert.equals('', udf.pack_event_properties(secondary_property, empty_indices)),
|
||||
mozfun.assert.equals('', udf.pack_event_properties(unknown_property, empty_indices)),
|
||||
FROM
|
||||
examples
|
||||
|
|
|
@ -8,4 +8,4 @@ CREATE OR REPLACE FUNCTION udf.parquet_array_sum(list ANY TYPE) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(10, udf.parquet_array_sum([STRUCT(5 AS element), STRUCT(5 AS element)]))
|
||||
mozfun.assert.equals(10, udf.parquet_array_sum([STRUCT(5 AS element), STRUCT(5 AS element)]))
|
||||
|
|
|
@ -47,17 +47,17 @@ RETURNS STRUCT<
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals("telemetry", udf.parse_desktop_telemetry_uri(uri1).namespace),
|
||||
assert.equals(
|
||||
mozfun.assert.equals("telemetry", udf.parse_desktop_telemetry_uri(uri1).namespace),
|
||||
mozfun.assert.equals(
|
||||
"ce39b608-f595-4c69-b6a6-f7a436604648",
|
||||
udf.parse_desktop_telemetry_uri(uri1).document_id
|
||||
),
|
||||
assert.equals("main", udf.parse_desktop_telemetry_uri(uri1).document_type),
|
||||
assert.equals("Firefox", udf.parse_desktop_telemetry_uri(uri1).app_name),
|
||||
assert.equals("61.0a1", udf.parse_desktop_telemetry_uri(uri1).app_version),
|
||||
assert.equals("nightly", udf.parse_desktop_telemetry_uri(uri1).app_update_channel),
|
||||
assert.equals("20180328030202", udf.parse_desktop_telemetry_uri(uri1).app_build_id),
|
||||
assert.null(udf.parse_desktop_telemetry_uri(uri2))
|
||||
mozfun.assert.equals("main", udf.parse_desktop_telemetry_uri(uri1).document_type),
|
||||
mozfun.assert.equals("Firefox", udf.parse_desktop_telemetry_uri(uri1).app_name),
|
||||
mozfun.assert.equals("61.0a1", udf.parse_desktop_telemetry_uri(uri1).app_version),
|
||||
mozfun.assert.equals("nightly", udf.parse_desktop_telemetry_uri(uri1).app_update_channel),
|
||||
mozfun.assert.equals("20180328030202", udf.parse_desktop_telemetry_uri(uri1).app_build_id),
|
||||
mozfun.assert.null(udf.parse_desktop_telemetry_uri(uri2))
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
|
|
|
@ -15,8 +15,8 @@ RETURNS DATE AS (
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(DATE '2019-11-04', udf.parse_iso8601_date('2019-11-04')),
|
||||
assert.equals(DATE '2019-11-04', udf.parse_iso8601_date('2019-11-04T21:15:00+00:00')),
|
||||
assert.equals(DATE '2019-11-04', udf.parse_iso8601_date('20191104T211500Z')),
|
||||
assert.equals(DATE '0100-01-01', udf.parse_iso8601_date('100-1-1')),
|
||||
assert.null(udf.parse_iso8601_date('2000/01/01'))
|
||||
mozfun.assert.equals(DATE '2019-11-04', udf.parse_iso8601_date('2019-11-04')),
|
||||
mozfun.assert.equals(DATE '2019-11-04', udf.parse_iso8601_date('2019-11-04T21:15:00+00:00')),
|
||||
mozfun.assert.equals(DATE '2019-11-04', udf.parse_iso8601_date('20191104T211500Z')),
|
||||
mozfun.assert.equals(DATE '0100-01-01', udf.parse_iso8601_date('100-1-1')),
|
||||
mozfun.assert.null(udf.parse_iso8601_date('2000/01/01'))
|
||||
|
|
|
@ -9,6 +9,6 @@ CREATE OR REPLACE FUNCTION udf.pos_of_leading_set_bit(i INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(udf.pos_of_leading_set_bit(0), NULL),
|
||||
assert.equals(udf.pos_of_leading_set_bit(1), 0),
|
||||
assert.equals(udf.pos_of_leading_set_bit(2), 1);
|
||||
mozfun.assert.equals(udf.pos_of_leading_set_bit(0), NULL),
|
||||
mozfun.assert.equals(udf.pos_of_leading_set_bit(1), 0),
|
||||
mozfun.assert.equals(udf.pos_of_leading_set_bit(2), 1);
|
||||
|
|
|
@ -16,7 +16,7 @@ CREATE OR REPLACE FUNCTION udf.pos_of_trailing_set_bit(bits INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.null(udf.pos_of_trailing_set_bit(0)),
|
||||
assert.equals(0, udf.pos_of_trailing_set_bit(1)),
|
||||
assert.equals(3, udf.pos_of_trailing_set_bit(8)),
|
||||
assert.equals(0, udf.pos_of_trailing_set_bit(8 + 1))
|
||||
mozfun.assert.null(udf.pos_of_trailing_set_bit(0)),
|
||||
mozfun.assert.equals(0, udf.pos_of_trailing_set_bit(1)),
|
||||
mozfun.assert.equals(3, udf.pos_of_trailing_set_bit(8)),
|
||||
mozfun.assert.equals(0, udf.pos_of_trailing_set_bit(8 + 1))
|
||||
|
|
|
@ -66,12 +66,12 @@ WITH b AS (
|
|||
udf.product_info_with_baseline('Firefox', 'Windows')
|
||||
)
|
||||
SELECT
|
||||
assert.equals('firefox_desktop', b.app_name),
|
||||
assert.equals('Firefox', b.product),
|
||||
assert.equals('Firefox for Desktop', b.canonical_app_name),
|
||||
assert.equals('Firefox for Desktop', b.canonical_name),
|
||||
assert.true(b.contributes_to_2020_kpi),
|
||||
assert.true(b.contributes_to_2021_kpi),
|
||||
mozfun.assert.equals('firefox_desktop', b.app_name),
|
||||
mozfun.assert.equals('Firefox', b.product),
|
||||
mozfun.assert.equals('Firefox for Desktop', b.canonical_app_name),
|
||||
mozfun.assert.equals('Firefox for Desktop', b.canonical_name),
|
||||
mozfun.assert.true(b.contributes_to_2020_kpi),
|
||||
mozfun.assert.true(b.contributes_to_2021_kpi),
|
||||
FROM
|
||||
b;
|
||||
|
||||
|
@ -80,10 +80,10 @@ WITH b AS (
|
|||
udf.product_info_with_baseline('Focus iOS Baseline', 'iOS')
|
||||
)
|
||||
SELECT
|
||||
assert.equals('focus_ios', b.app_name),
|
||||
assert.equals('Focus iOS Baseline', b.product),
|
||||
assert.equals('Focus iOS', b.canonical_app_name),
|
||||
assert.true(b.contributes_to_2020_kpi),
|
||||
assert.true(b.contributes_to_2021_kpi),
|
||||
mozfun.assert.equals('focus_ios', b.app_name),
|
||||
mozfun.assert.equals('Focus iOS Baseline', b.product),
|
||||
mozfun.assert.equals('Focus iOS', b.canonical_app_name),
|
||||
mozfun.assert.true(b.contributes_to_2020_kpi),
|
||||
mozfun.assert.true(b.contributes_to_2021_kpi),
|
||||
FROM
|
||||
b;
|
||||
|
|
|
@ -13,11 +13,19 @@ RETURNS STRING AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.null(udf.pseudonymize_ad_id("q7RZx9leE4AHjn9DRQR8kLtjO0FNwmj/61ECGxFinno=", b"\x14")),
|
||||
assert.null(udf.pseudonymize_ad_id("ksEEnM6/esBxl2myqrVLo31ePBoQZZnkCm81vefaF90=", b"\x14")),
|
||||
assert.not_null(udf.pseudonymize_ad_id("7RZx9leE4AHjn9DRQR8kLtjO0FNwmj/61ECGxFinno=", b"\x14")),
|
||||
assert.not_null(udf.pseudonymize_ad_id("sEEnM6/esBxl2myqrVLo31ePBoQZZnkCm81vefaF90=", b"\x14")),
|
||||
assert.equals(
|
||||
mozfun.assert.null(
|
||||
udf.pseudonymize_ad_id("q7RZx9leE4AHjn9DRQR8kLtjO0FNwmj/61ECGxFinno=", b"\x14")
|
||||
),
|
||||
mozfun.assert.null(
|
||||
udf.pseudonymize_ad_id("ksEEnM6/esBxl2myqrVLo31ePBoQZZnkCm81vefaF90=", b"\x14")
|
||||
),
|
||||
mozfun.assert.not_null(
|
||||
udf.pseudonymize_ad_id("7RZx9leE4AHjn9DRQR8kLtjO0FNwmj/61ECGxFinno=", b"\x14")
|
||||
),
|
||||
mozfun.assert.not_null(
|
||||
udf.pseudonymize_ad_id("sEEnM6/esBxl2myqrVLo31ePBoQZZnkCm81vefaF90=", b"\x14")
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
udf.pseudonymize_ad_id("abc", b"\x14"),
|
||||
TO_HEX(udf.hmac_sha256(b"\x14", CAST("abc" AS BYTES)))
|
||||
)
|
||||
|
|
|
@ -15,7 +15,7 @@ CREATE OR REPLACE FUNCTION udf.quantile_search_metric_contribution(
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(1.0, udf.quantile_search_metric_contribution(73, 1, 60)),
|
||||
assert.null(udf.quantile_search_metric_contribution(29, 9, 60)),
|
||||
assert.equals(8.0, udf.quantile_search_metric_contribution(118, 8, 21)),
|
||||
assert.null(udf.quantile_search_metric_contribution(10, 5, 21));
|
||||
mozfun.assert.equals(1.0, udf.quantile_search_metric_contribution(73, 1, 60)),
|
||||
mozfun.assert.null(udf.quantile_search_metric_contribution(29, 9, 60)),
|
||||
mozfun.assert.equals(8.0, udf.quantile_search_metric_contribution(118, 8, 21)),
|
||||
mozfun.assert.null(udf.quantile_search_metric_contribution(10, 5, 21));
|
||||
|
|
|
@ -12,19 +12,19 @@ CREATE OR REPLACE FUNCTION udf.round_timestamp_to_minute(
|
|||
|
||||
-- Test
|
||||
SELECT
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
TIMESTAMP '2019-01-01 13:30:00',
|
||||
udf.round_timestamp_to_minute(TIMESTAMP '2019-01-01 13:31:11', 5)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
TIMESTAMP '2019-05-03 00:30:00',
|
||||
udf.round_timestamp_to_minute(TIMESTAMP '2019-05-03 00:34:59', 5)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
TIMESTAMP '2019-05-03 00:34:00',
|
||||
udf.round_timestamp_to_minute(TIMESTAMP '2019-05-03 00:34:59', 2)
|
||||
),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
TIMESTAMP '2019-05-03 00:34:00',
|
||||
udf.round_timestamp_to_minute(TIMESTAMP '2019-05-03 00:34:59.999999', 2)
|
||||
)
|
||||
|
|
|
@ -96,5 +96,5 @@ CREATE OR REPLACE FUNCTION udf.safe_crc32_uuid(value BYTES) AS (
|
|||
|
||||
--Tests
|
||||
SELECT
|
||||
assert.equals(308953907, udf.safe_crc32_uuid(b"51baf8b4-75d1-3648-b96d-809569b89a12")),
|
||||
assert.null(udf.safe_crc32_uuid(b"length != 36"))
|
||||
mozfun.assert.equals(308953907, udf.safe_crc32_uuid(b"51baf8b4-75d1-3648-b96d-809569b89a12")),
|
||||
mozfun.assert.null(udf.safe_crc32_uuid(b"length != 36"))
|
||||
|
|
|
@ -7,7 +7,7 @@ CREATE OR REPLACE FUNCTION udf.safe_sample_id(client_id STRING) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(sample_id, udf.safe_sample_id(client_id))
|
||||
mozfun.assert.equals(sample_id, udf.safe_sample_id(client_id))
|
||||
FROM
|
||||
UNNEST(
|
||||
[
|
||||
|
|
|
@ -16,11 +16,11 @@ CREATE OR REPLACE FUNCTION udf.search_counts_map_sum(
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
ARRAY<STRUCT<engine STRING, source STRING, count INT64>>[],
|
||||
udf.search_counts_map_sum(ARRAY<STRUCT<engine STRING, source STRING, count INT64>>[])
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
ARRAY<STRUCT<engine STRING, source STRING, count INT64>>[
|
||||
('engine1', 'urlbar', 3),
|
||||
('engine1', 'contextmenu', 7),
|
||||
|
|
|
@ -9,7 +9,7 @@ CREATE OR REPLACE FUNCTION udf.shift_28_bits_one_day(x INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(2, udf.shift_28_bits_one_day(1)),
|
||||
assert.equals(1 << 8, udf.shift_28_bits_one_day(1 << 7)),
|
||||
assert.equals(1 << 27, udf.shift_28_bits_one_day(1 << 26)),
|
||||
assert.equals(0, udf.shift_28_bits_one_day(1 << 27));
|
||||
mozfun.assert.equals(2, udf.shift_28_bits_one_day(1)),
|
||||
mozfun.assert.equals(1 << 8, udf.shift_28_bits_one_day(1 << 7)),
|
||||
mozfun.assert.equals(1 << 27, udf.shift_28_bits_one_day(1 << 26)),
|
||||
mozfun.assert.equals(0, udf.shift_28_bits_one_day(1 << 27));
|
||||
|
|
|
@ -9,11 +9,20 @@ CREATE OR REPLACE FUNCTION udf.shift_365_bits_one_day(x BYTES) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(udf.one_as_365_bits() << 1, udf.shift_365_bits_one_day(udf.one_as_365_bits())),
|
||||
assert.equals(udf.one_as_365_bits() << 8, udf.shift_365_bits_one_day(udf.one_as_365_bits() << 7)),
|
||||
assert.equals(
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 1,
|
||||
udf.shift_365_bits_one_day(udf.one_as_365_bits())
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 8,
|
||||
udf.shift_365_bits_one_day(udf.one_as_365_bits() << 7)
|
||||
),
|
||||
mozfun.assert.equals(
|
||||
udf.one_as_365_bits() << 364,
|
||||
udf.shift_365_bits_one_day(udf.one_as_365_bits() << 363)
|
||||
),
|
||||
assert.equals(udf.zero_as_365_bits(), udf.shift_365_bits_one_day(udf.one_as_365_bits() << 364)),
|
||||
assert.equals(udf.zero_as_365_bits(), udf.shift_365_bits_one_day(NULL));
|
||||
mozfun.assert.equals(
|
||||
udf.zero_as_365_bits(),
|
||||
udf.shift_365_bits_one_day(udf.one_as_365_bits() << 364)
|
||||
),
|
||||
mozfun.assert.equals(udf.zero_as_365_bits(), udf.shift_365_bits_one_day(NULL));
|
||||
|
|
|
@ -7,5 +7,5 @@ CREATE OR REPLACE FUNCTION udf.shift_one_day(x INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(4, udf.shift_one_day(2)),
|
||||
assert.equals(0, udf.shift_one_day(NULL))
|
||||
mozfun.assert.equals(4, udf.shift_one_day(2)),
|
||||
mozfun.assert.equals(0, udf.shift_one_day(NULL))
|
||||
|
|
|
@ -35,13 +35,13 @@ CREATE OR REPLACE FUNCTION udf.vector_add(a ARRAY<INT64>, b ARRAY<INT64>) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals(ARRAY[2, 3, 4], udf.vector_add(ARRAY[1, 2, 3], ARRAY[1, 1, 1])),
|
||||
assert.array_equals(ARRAY[2, 3, 4, 1], udf.vector_add(ARRAY[1, 2, 3], ARRAY[1, 1, 1, 1])),
|
||||
assert.array_equals(ARRAY[2, 3, 4, 4], udf.vector_add(ARRAY[1, 2, 3, 4], ARRAY[1, 1, 1])),
|
||||
assert.array_equals(ARRAY[2, 3, 1], udf.vector_add(ARRAY[1, 2, NULL], ARRAY[1, 1, 1])),
|
||||
assert.array_equals(ARRAY[1, 1, 1], udf.vector_add(NULL, ARRAY[1, 1, 1])),
|
||||
assert.array_equals(ARRAY[1, 1, NULL], udf.vector_add(NULL, ARRAY[1, 1, NULL])),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(ARRAY[2, 3, 4], udf.vector_add(ARRAY[1, 2, 3], ARRAY[1, 1, 1])),
|
||||
mozfun.assert.array_equals(ARRAY[2, 3, 4, 1], udf.vector_add(ARRAY[1, 2, 3], ARRAY[1, 1, 1, 1])),
|
||||
mozfun.assert.array_equals(ARRAY[2, 3, 4, 4], udf.vector_add(ARRAY[1, 2, 3, 4], ARRAY[1, 1, 1])),
|
||||
mozfun.assert.array_equals(ARRAY[2, 3, 1], udf.vector_add(ARRAY[1, 2, NULL], ARRAY[1, 1, 1])),
|
||||
mozfun.assert.array_equals(ARRAY[1, 1, 1], udf.vector_add(NULL, ARRAY[1, 1, 1])),
|
||||
mozfun.assert.array_equals(ARRAY[1, 1, NULL], udf.vector_add(NULL, ARRAY[1, 1, NULL])),
|
||||
mozfun.assert.array_equals(
|
||||
ARRAY[2, 3, NULL, 4],
|
||||
udf.vector_add(ARRAY[1, 2, NULL, 3], ARRAY[1, 1, NULL, 1])
|
||||
);
|
||||
|
|
|
@ -7,7 +7,7 @@ CREATE OR REPLACE FUNCTION udf.zeroed_array(len INT64) AS (
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.array_equals([0, 0], udf.zeroed_array(2)),
|
||||
assert.array_equals([0], udf.zeroed_array(1)),
|
||||
assert.array_equals([], udf.zeroed_array(0)),
|
||||
assert.array_equals([], udf.zeroed_array(-1));
|
||||
mozfun.assert.array_equals([0, 0], udf.zeroed_array(2)),
|
||||
mozfun.assert.array_equals([0], udf.zeroed_array(1)),
|
||||
mozfun.assert.array_equals([], udf.zeroed_array(0)),
|
||||
mozfun.assert.array_equals([], udf.zeroed_array(-1));
|
||||
|
|
|
@ -46,7 +46,7 @@ AS
|
|||
throw "percentile must be a value between 0 and 100";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getQuantileSamples(percentile, histogram, n_samples) {
|
||||
/*
|
||||
Returns a sorted array of quantile samples from a `histogram` at a target `percentile`.
|
||||
|
@ -76,7 +76,7 @@ AS
|
|||
*/
|
||||
const scale = 1000;
|
||||
total = Math.ceil(total * scale);
|
||||
|
||||
|
||||
/* sample the quantile of interest */
|
||||
var samples = [];
|
||||
for ( var i = 0; i < n_samples; i++ ) {
|
||||
|
@ -110,7 +110,7 @@ AS
|
|||
}
|
||||
|
||||
function getPercentileBin(percentile, quantile_samples) {
|
||||
/*
|
||||
/*
|
||||
Returns the target `percentile` from a sorted array of samples.
|
||||
*/
|
||||
validatePercentile(percentile);
|
||||
|
@ -125,7 +125,7 @@ AS
|
|||
}
|
||||
|
||||
function binToValue(bin_value, histogram, location) {
|
||||
/*
|
||||
/*
|
||||
Returns the estimated value of a `location` inside a histogram bin,
|
||||
where `location` is between 0 (left edge) and 1 (right edge).
|
||||
*/
|
||||
|
@ -152,7 +152,7 @@ AS
|
|||
}
|
||||
|
||||
function getPercentilesWithCI(percentiles, histogram, metric) {
|
||||
|
||||
|
||||
if ( !percentiles.length ) {
|
||||
throw "percentiles must be a non-empty array of integers";
|
||||
}
|
||||
|
@ -166,14 +166,14 @@ AS
|
|||
var lower = null; /* left edge of lower estimate bin */
|
||||
var point = null; /* center of point estimate bin */
|
||||
var upper = null; /* right edge of upper estimate bin */
|
||||
|
||||
|
||||
if ( histogram.values && histogram && histogramIsNonZero(histogram.values) ) {
|
||||
var quantile_samples = getQuantileSamples(percentile, histogram.values, 10000);
|
||||
lower = binToValue(getPercentileBin( 5, quantile_samples), histogram.values, 0.0);
|
||||
point = binToValue(getPercentileBin(50, quantile_samples), histogram.values, 0.5);
|
||||
upper = binToValue(getPercentileBin(95, quantile_samples), histogram.values, 1.0);
|
||||
}
|
||||
|
||||
|
||||
results.push({
|
||||
"metric": metric,
|
||||
"statistic": "percentile",
|
||||
|
@ -275,48 +275,48 @@ seven_bin_results AS (
|
|||
)
|
||||
-- valid outputs
|
||||
SELECT
|
||||
assert.equals('test', (SELECT DISTINCT metric FROM all_zero_results)),
|
||||
assert.equals('percentile', (SELECT DISTINCT statistic FROM all_zero_results)),
|
||||
assert.array_equals(
|
||||
mozfun.assert.equals('test', (SELECT DISTINCT metric FROM all_zero_results)),
|
||||
mozfun.assert.equals('percentile', (SELECT DISTINCT statistic FROM all_zero_results)),
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT ['5', '25', '50', '75', '95']),
|
||||
(SELECT ARRAY(SELECT parameter FROM all_zero_results))
|
||||
),
|
||||
assert.array_empty((SELECT ARRAY(SELECT lower FROM all_zero_results WHERE lower IS NOT NULL))),
|
||||
assert.array_empty((SELECT ARRAY(SELECT point FROM all_zero_results WHERE point IS NOT NULL))),
|
||||
assert.array_empty((SELECT ARRAY(SELECT upper FROM all_zero_results WHERE upper IS NOT NULL))),
|
||||
assert.equals('test', (SELECT DISTINCT metric FROM one_bin_results)),
|
||||
assert.equals('percentile', (SELECT DISTINCT statistic FROM one_bin_results)),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_empty((SELECT ARRAY(SELECT lower FROM all_zero_results WHERE lower IS NOT NULL))),
|
||||
mozfun.assert.array_empty((SELECT ARRAY(SELECT point FROM all_zero_results WHERE point IS NOT NULL))),
|
||||
mozfun.assert.array_empty((SELECT ARRAY(SELECT upper FROM all_zero_results WHERE upper IS NOT NULL))),
|
||||
mozfun.assert.equals('test', (SELECT DISTINCT metric FROM one_bin_results)),
|
||||
mozfun.assert.equals('percentile', (SELECT DISTINCT statistic FROM one_bin_results)),
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT ['5', '25', '50', '75', '95']),
|
||||
(SELECT ARRAY(SELECT parameter FROM one_bin_results))
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT [1.0, 1.0, 1.0, 1.0, 1.0]),
|
||||
(SELECT ARRAY(SELECT lower FROM one_bin_results))
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT [1.5, 1.5, 1.5, 1.5, 1.5]),
|
||||
(SELECT ARRAY(SELECT point FROM one_bin_results))
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT [2.0, 2.0, 2.0, 2.0, 2.0]),
|
||||
(SELECT ARRAY(SELECT upper FROM one_bin_results))
|
||||
),
|
||||
assert.equals('test', (SELECT DISTINCT metric FROM seven_bin_results)),
|
||||
assert.equals('percentile', (SELECT DISTINCT statistic FROM seven_bin_results)),
|
||||
assert.array_equals(
|
||||
mozfun.assert.equals('test', (SELECT DISTINCT metric FROM seven_bin_results)),
|
||||
mozfun.assert.equals('percentile', (SELECT DISTINCT statistic FROM seven_bin_results)),
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT ['5', '25', '50', '75', '95']),
|
||||
(SELECT ARRAY(SELECT parameter FROM seven_bin_results))
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT [-2.5, -1.5, -0.5, 0.5, 1.5]),
|
||||
(SELECT ARRAY(SELECT lower FROM seven_bin_results))
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT [-2.0, -1.0, 0.0, 1.0, 2.0]),
|
||||
(SELECT ARRAY(SELECT point FROM seven_bin_results))
|
||||
),
|
||||
assert.array_equals(
|
||||
mozfun.assert.array_equals(
|
||||
(SELECT [-1.5, -0.5, 0.5, 1.5, 2.5]),
|
||||
(SELECT ARRAY(SELECT upper FROM seven_bin_results))
|
||||
);
|
||||
|
|
|
@ -48,4 +48,4 @@ AS
|
|||
|
||||
-- Tests
|
||||
SELECT
|
||||
assert.equals(308953907, udf_js.crc32("51baf8b4-75d1-3648-b96d-809569b89a12"));
|
||||
mozfun.assert.equals(308953907, udf_js.crc32("51baf8b4-75d1-3648-b96d-809569b89a12"));
|
||||
|
|
|
@ -46,7 +46,7 @@ return decodeURIComponent(decodeURIComponent(attribution))
|
|||
-- Tests
|
||||
-- complete string
|
||||
SELECT
|
||||
assert.struct_equals(
|
||||
mozfun.assert.struct_equals(
|
||||
STRUCT(
|
||||
'whatsnew',
|
||||
'(not set)',
|
||||
|
@ -65,7 +65,7 @@ SELECT
|
|||
|
||||
-- missing fields, need to include schema whenever using NULL
|
||||
SELECT
|
||||
assert.struct_equals(
|
||||
mozfun.assert.struct_equals(
|
||||
STRUCT<
|
||||
campaign STRING,
|
||||
content STRING,
|
||||
|
@ -94,7 +94,7 @@ SELECT
|
|||
|
||||
-- extra fields, need to include schema whenever using NULL
|
||||
SELECT
|
||||
assert.struct_equals(
|
||||
mozfun.assert.struct_equals(
|
||||
STRUCT(
|
||||
'whatsnew',
|
||||
'(not set)',
|
||||
|
@ -113,7 +113,7 @@ SELECT
|
|||
|
||||
-- NULL, need to include schema whenever using NULL
|
||||
SELECT
|
||||
assert.struct_equals(
|
||||
mozfun.assert.struct_equals(
|
||||
STRUCT<
|
||||
campaign STRING,
|
||||
content STRING,
|
||||
|
@ -130,7 +130,7 @@ SELECT
|
|||
|
||||
-- empty string, need to include schema whenever using NULL
|
||||
SELECT
|
||||
assert.struct_equals(
|
||||
mozfun.assert.struct_equals(
|
||||
STRUCT<
|
||||
campaign STRING,
|
||||
content STRING,
|
||||
|
@ -147,7 +147,7 @@ SELECT
|
|||
|
||||
-- not encoded
|
||||
SELECT
|
||||
assert.struct_equals(
|
||||
mozfun.assert.struct_equals(
|
||||
STRUCT(
|
||||
'whatsnew',
|
||||
'(not set)',
|
||||
|
|
|
@ -8,6 +8,6 @@ RETURNS STRING AS (
|
|||
|
||||
--
|
||||
SELECT
|
||||
assert.equals("test", udf_js.extract_string_from_bytes(FROM_BASE64("e3Rlc3R9"))),
|
||||
assert.equals("", udf_js.extract_string_from_bytes(FROM_BASE64("e30="))),
|
||||
assert.null(udf_js.extract_string_from_bytes(FROM_BASE64(NULL)))
|
||||
mozfun.assert.equals("test", udf_js.extract_string_from_bytes(FROM_BASE64("e3Rlc3R9"))),
|
||||
mozfun.assert.equals("", udf_js.extract_string_from_bytes(FROM_BASE64("e30="))),
|
||||
mozfun.assert.null(udf_js.extract_string_from_bytes(FROM_BASE64(NULL)))
|
||||
|
|
|
@ -70,6 +70,6 @@ unzipped AS (
|
|||
)
|
||||
--
|
||||
SELECT
|
||||
assert.equals(expected, result)
|
||||
mozfun.assert.equals(expected, result)
|
||||
FROM
|
||||
unzipped
|
||||
|
|
|
@ -219,32 +219,32 @@ WITH jackknife AS (
|
|||
) AS percentile_90
|
||||
)
|
||||
SELECT
|
||||
assert.equals(1, percentile_10.high),
|
||||
assert.equals(1, percentile_10.low),
|
||||
assert.equals(1, percentile_10.percentile),
|
||||
assert.equals(1, percentile_20.high),
|
||||
assert.equals(1, percentile_20.low),
|
||||
assert.equals(1, percentile_20.percentile),
|
||||
assert.equals(3.08, percentile_30.high),
|
||||
assert.equals(-1.08, percentile_30.low),
|
||||
assert.equals(1, percentile_30.percentile),
|
||||
assert.equals(2, percentile_40.high),
|
||||
assert.equals(2, percentile_40.low),
|
||||
assert.equals(2, percentile_40.percentile),
|
||||
assert.equals(2, percentile_50.high),
|
||||
assert.equals(2, percentile_50.low),
|
||||
assert.equals(2, percentile_50.percentile),
|
||||
assert.equals(11.21, percentile_60.high),
|
||||
assert.equals(-3.21, percentile_60.low),
|
||||
assert.equals(4, percentile_60.percentile),
|
||||
assert.equals(7.94, percentile_70.high),
|
||||
assert.equals(2.06, percentile_70.low),
|
||||
assert.equals(5, percentile_70.percentile),
|
||||
assert.equals(8.08, percentile_80.high),
|
||||
assert.equals(3.92, percentile_80.low),
|
||||
assert.equals(6, percentile_80.percentile),
|
||||
assert.equals(6, percentile_90.high),
|
||||
assert.equals(6, percentile_90.low),
|
||||
assert.equals(6, percentile_90.percentile)
|
||||
mozfun.assert.equals(1, percentile_10.high),
|
||||
mozfun.assert.equals(1, percentile_10.low),
|
||||
mozfun.assert.equals(1, percentile_10.percentile),
|
||||
mozfun.assert.equals(1, percentile_20.high),
|
||||
mozfun.assert.equals(1, percentile_20.low),
|
||||
mozfun.assert.equals(1, percentile_20.percentile),
|
||||
mozfun.assert.equals(3.08, percentile_30.high),
|
||||
mozfun.assert.equals(-1.08, percentile_30.low),
|
||||
mozfun.assert.equals(1, percentile_30.percentile),
|
||||
mozfun.assert.equals(2, percentile_40.high),
|
||||
mozfun.assert.equals(2, percentile_40.low),
|
||||
mozfun.assert.equals(2, percentile_40.percentile),
|
||||
mozfun.assert.equals(2, percentile_50.high),
|
||||
mozfun.assert.equals(2, percentile_50.low),
|
||||
mozfun.assert.equals(2, percentile_50.percentile),
|
||||
mozfun.assert.equals(11.21, percentile_60.high),
|
||||
mozfun.assert.equals(-3.21, percentile_60.low),
|
||||
mozfun.assert.equals(4, percentile_60.percentile),
|
||||
mozfun.assert.equals(7.94, percentile_70.high),
|
||||
mozfun.assert.equals(2.06, percentile_70.low),
|
||||
mozfun.assert.equals(5, percentile_70.percentile),
|
||||
mozfun.assert.equals(8.08, percentile_80.high),
|
||||
mozfun.assert.equals(3.92, percentile_80.low),
|
||||
mozfun.assert.equals(6, percentile_80.percentile),
|
||||
mozfun.assert.equals(6, percentile_90.high),
|
||||
mozfun.assert.equals(6, percentile_90.low),
|
||||
mozfun.assert.equals(6, percentile_90.percentile)
|
||||
FROM
|
||||
jackknife
|
||||
|
|
|
@ -115,4 +115,4 @@ return sum_buckets_with_ci(n_buckets, counts_per_bucket);
|
|||
-- Tests
|
||||
SELECT
|
||||
-- Make sure a single-element array doesn't throw an error.
|
||||
assert.equals(5, udf_js.jackknife_sum_ci(20, [5]).total)
|
||||
mozfun.assert.equals(5, udf_js.jackknife_sum_ci(20, [5]).total)
|
||||
|
|
|
@ -60,13 +60,13 @@ extracted AS (
|
|||
)
|
||||
--
|
||||
SELECT
|
||||
assert.equals('parent', e[OFFSET(0)].event_process),
|
||||
assert.equals(15872099, e[OFFSET(0)].event_timestamp),
|
||||
assert.equals('uptake.remotecontent.result', e[OFFSET(0)].event_category),
|
||||
assert.equals('uptake', e[OFFSET(0)].event_method),
|
||||
assert.equals('remotesettings', e[OFFSET(0)].event_object),
|
||||
assert.equals('success', e[OFFSET(0)].event_string_value),
|
||||
assert.array_equals(
|
||||
mozfun.assert.equals('parent', e[OFFSET(0)].event_process),
|
||||
mozfun.assert.equals(15872099, e[OFFSET(0)].event_timestamp),
|
||||
mozfun.assert.equals('uptake.remotecontent.result', e[OFFSET(0)].event_category),
|
||||
mozfun.assert.equals('uptake', e[OFFSET(0)].event_method),
|
||||
mozfun.assert.equals('remotesettings', e[OFFSET(0)].event_object),
|
||||
mozfun.assert.equals('success', e[OFFSET(0)].event_string_value),
|
||||
mozfun.assert.array_equals(
|
||||
[
|
||||
STRUCT('age' AS key, '6879' AS value),
|
||||
STRUCT('source' AS key, 'settings-changes-monitoring' AS value),
|
||||
|
@ -74,19 +74,22 @@ SELECT
|
|||
],
|
||||
e[OFFSET(0)].event_map_values
|
||||
),
|
||||
assert.equals('parent', e[OFFSET(1)].event_process),
|
||||
assert.equals(15872100, e[OFFSET(1)].event_timestamp),
|
||||
assert.equals('ui', e[OFFSET(1)].event_category),
|
||||
assert.equals('click', e[OFFSET(1)].event_method),
|
||||
assert.equals('back', e[OFFSET(1)].event_object),
|
||||
assert.null(e[OFFSET(1)].event_string_value),
|
||||
assert.array_empty(e[OFFSET(1)].event_map_values),
|
||||
assert.equals('content', e[OFFSET(2)].event_process),
|
||||
assert.equals(15872110, e[OFFSET(2)].event_timestamp),
|
||||
assert.equals('ui', e[OFFSET(2)].event_category),
|
||||
assert.equals('click', e[OFFSET(2)].event_method),
|
||||
assert.equals('forward', e[OFFSET(2)].event_object),
|
||||
assert.null(e[OFFSET(2)].event_string_value),
|
||||
assert.array_equals([STRUCT('enabled' AS key, 'true' AS value)], e[OFFSET(2)].event_map_values)
|
||||
mozfun.assert.equals('parent', e[OFFSET(1)].event_process),
|
||||
mozfun.assert.equals(15872100, e[OFFSET(1)].event_timestamp),
|
||||
mozfun.assert.equals('ui', e[OFFSET(1)].event_category),
|
||||
mozfun.assert.equals('click', e[OFFSET(1)].event_method),
|
||||
mozfun.assert.equals('back', e[OFFSET(1)].event_object),
|
||||
mozfun.assert.null(e[OFFSET(1)].event_string_value),
|
||||
mozfun.assert.array_empty(e[OFFSET(1)].event_map_values),
|
||||
mozfun.assert.equals('content', e[OFFSET(2)].event_process),
|
||||
mozfun.assert.equals(15872110, e[OFFSET(2)].event_timestamp),
|
||||
mozfun.assert.equals('ui', e[OFFSET(2)].event_category),
|
||||
mozfun.assert.equals('click', e[OFFSET(2)].event_method),
|
||||
mozfun.assert.equals('forward', e[OFFSET(2)].event_object),
|
||||
mozfun.assert.null(e[OFFSET(2)].event_string_value),
|
||||
mozfun.assert.array_equals(
|
||||
[STRUCT('enabled' AS key, 'true' AS value)],
|
||||
e[OFFSET(2)].event_map_values
|
||||
)
|
||||
FROM
|
||||
extracted
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче