Join us at Snowflake Summit June 26-29 in Las Vegas!

Spread Functionality Added to the Rel Standard Library

Huda Nassar

09 October 2021

less than a minute read

We are excited to announce that we now support a spread functionality implemented natively in Rel. We support two main strategies: even and ratio.

Even

For the even strategy, we spread an equal number of units to all elements in a relation, and when we can no longer have equal amounts, we spread the remaining singletons in order starting with the first element in a lexicographic order.

def R = {"Flamingo"; "Cat"; "Dog"}

def output = spread[:even, R, 10]

Relation:

"Cat"4
"Dog"3
"Flamingo"3

Ratio

For the ratio strategy, we spread a number proportional to the weight corresponding to each element in a relation (provided by the user). Remaining singletons are spread in order after the elements are sorted according to their weights.

def R = {("Flamingo", 1); ("Cat", 2); ("Dog", 3)}

def output = spread[:ratio, R, decimal[64, 2, 10.0]]

Relation:

"Cat"3.33
"Dog"5.0
"Flamingo"1.67

Notice, for decimal numbers the digit precision (here: 2) is preserved during the spread.

Related Posts

Get Early Access

Join our community, keep up to date with the latest developments in our monthly newsletter, and get early access to RelationalAI.