Math, hash, date/time, type casting, interval, null-handling, utility, anonymization, and Kalman filter functions in Vadalog.
Vadalog provides a comprehensive library of specialized functions for mathematical operations, hashing, date/time manipulation, type casting, and interval checks.
Mathematical Functions
Function
Signature
Description
math:mod()
(dividend, divisor) → number
Modulo operation
math:sqrt()
(x) → double
Square root
math:abs()
(x) → number
Absolute value
math:round()
(x, scale?) → number
Round to nearest integer or decimal places
math:bround()
(x, scale?) → number
Banker’s rounding (round to nearest even)
math:min()
(v1, v2, …) → same type
Minimum value
math:max()
(v1, v2, …) → same type
Maximum value
math:log()
(x) → double
Natural logarithm
math:log10()
(x) → double
Base-10 logarithm
math:pow()
(base, exponent) → double
Power (exponentiation)
math:exp()
(x) → double
Exponential (e^x)
math:ceil()
(x) → number
Round up to nearest integer
math:floor()
(x) → number
Round down to nearest integer
math:sin()
(x) → double
Sine
math:cos()
(x) → double
Cosine
math:tan()
(x) → double
Tangent
math:uniform()
(upperBound) → number
Random integer [0, upperBound)
math:rand()
() → double
Random double [0, 1)
math:PI()
() → double
Pi constant
math:E()
() → double
Euler’s number
math:mod()
Modulo operation:
math:mod(dividend: number, divisor: number) → number
When the second argument is a simple type (e.g., "string", "integer"), the JSON array elements are cast to that type. When it contains : characters, it is parsed as a struct schema — each JSON object in the array is parsed into a struct with the declared fields.Simple type example:
data("[1, 2, 3, 4]").result(L) <- data(J), L = as_list(J, "integer").% L is an array of integers: [1, 2, 3, 4]
Struct schema example (e.g., Qdrant ask() results):
result(Name, Score) <- source(Query), J = ask("find ${Query}", "collection=my_collection,limit=3"), L = as_list(J, "name:string, category:string, __score__:double"), First = collections:get(L, 1), Name = struct:get("name", First), Score = struct:get("__score__", First).
Schema rules:
Fields are matched by name, not by position — the order of fields in the schema does not need to match the JSON.
You only need to declare the fields you want to extract. Omitted fields are ignored.
Same schema format as as_list, but for a single JSON object (not an array). Returns a struct directly.Example:
data("{""name"":""Alice"",""age"":30,""city"":""London""}").result(Name, Age) <- data(J), S = as_struct(J, "name:string, age:integer"), Name = struct:get("name", S), Age = struct:get("age", S).@output("result").% Result: ("Alice", 30)% Note: "city" was in the JSON but not in the schema — it is simply ignored.
as_list vs as_structUse as_list when the JSON is an array of objects (e.g., [{...}, {...}]). Use as_struct when the JSON is a single object (e.g., {...}). Both use the same "field:type, ..." schema format and both match fields by name.
as_set()
Parse a JSON array string into a typed Spark array with duplicates removed:
% Format phone number with default regionformatted_phone(Ph, Fmt) <- phone_data(Ph), Fmt = utils:phone_number(Ph).% Format with specific regionformatted_phone_uk(Ph, Fmt) <- phone_data(Ph), Fmt = utils:phone_number(Ph, "GB").
Masks the given string value by replacing characters with configurable mask characters. The function replaces characters with ‘X’ or ‘x’, and numbers with ‘n’ by default. This is useful for creating copies of tables with sensitive information removed.Arguments:
input - string value to mask (STRING, VARCHAR, CHAR)
upperChar - character to replace upper-case characters with. Specify NULL to retain original character. Default: ‘X’
lowerChar - character to replace lower-case characters with. Specify NULL to retain original character. Default: ‘x’
digitChar - character to replace digit characters with. Specify NULL to retain original character. Default: ‘n’
otherChar - character to replace other characters with. Specify NULL to retain original character
Examples:
% Basic masking with default charactersmasked_email(Name, MaskedEmail) <- user(Name, Email), MaskedEmail = mask(Email).% Input: "John.Doe123@example.com" % Output: "Xxxx.Xxx nnn@xxxxxxx.xxx"% Custom masking with specific characterscustom_masked_ssn(Person, MaskedSSN) <- person(Person, SSN), MaskedSSN = mask(SSN, '*', '*', '#', '-').% Input: "123-45-6789"% Output: "###-##-####"% Preserve certain character typespartial_mask(Data, PartiallyMasked) <- sensitive_data(Data), PartiallyMasked = mask(Data, 'X', NULL, '#', NULL).% Masks only uppercase letters and digits, preserves lowercase and symbols