0
0

More than 1 year has passed since last update.

特徴量エンジンKaskadaの宣言型クエリ言語Fenl~関数一覧

Posted at

はじめに

先日、以下の記事を発表しました。

新しいテクノロジーに触れる時はいつでも楽しいものです。

まだまだ勉強中ですが、公式ドキュメントの学習過程の記録として、以下の記事をまとめてみました。

本稿情報のソースとして、下記ドキュメントを参照ください。

カテゴリー別関数一覧

演算子 Operators

演算子 概要
a + b 2 つの数値の合計を返します。
a / b 2 つの数値の除算を返します。
#eq a が b と等しい場合は true を返します。
a > b a が b より大きい場合は true を返します。
a >= b a が b 以上の場合は true を返します。
a and b 2 つのブール値の論理積 (AND) を返します。
a or b 2 つのブール値の論理和 (OR) を返します。
a < b a が b より小さい場合は true を返します。
a < b a が b 以下の場合に true を返します。
a * b 2 つの数値の積を返します。
-n n の否定(negation)を返します。
a != b a が b と等しくない場合は true を返します。
!input ブール値の論理否定を返します。
a - b 2 つの数値の差を返します。

集計関数

集計関数は、行全体を計算するためのメカニズムを提供します。集計の結果は、現在の行までの各キーの集計結果を表します。これは、その行の時点で使用可能な値に対して SQL 集計を実行した場合に得られる結果にほぼ対応します。

オプションの引数windowとして ウィンドウ関数を指定することで、特定のウィンドウで動作するように集計を構成できます。ウィンドウが指定されていない場合、集計は現在時刻までのエンティティのすべての行に対して行われます。ウィンドウが指定されている場合、集計の結果は、現在時刻までの現在のウィンドウ内のエンティティの結果になります。現在のウィンドウはまだ終了していない場合もあります。

Fenl のすべての集計は暗黙的にエンティティ キーにスコープされます。これは、SQL でグループ化された集計を実行するのと同様です。

関数 概要
count 入力内の新しい非 null 値をそれぞれカウントします。Counts each new, non-null value in the input.
count_if 入力内の各真の値をカウントします。Counts each true value across in input.
first 入力全体に存在する最初の値を計算します。Computes the first value present across the input.
last 入力全体に存在する最後の値を計算します。Computes the last value present across the input.
max 入力全体の値の最大値を計算します。
mean 入力全体の値の算術平均を計算します。
min 入力全体の値の最小値を計算します。
stddev 入力全体の値のサンプル標準偏差を計算します。Computes the sample standard deviation of values across the input.
sum 入力全体の値の合計を計算します。
variance 入力全体の値の標本分散を計算します。Computes the sample variance of values across the input.

比較関数 Comparison Functions

関数 概要
eq a が b と等しい場合は true を返します。
gt a が b より大きい場合は true を返します。
gte a が b 以上の場合は true を返します。
lt a が b より小さい場合は true を返します。
lte a が b 以下の場合に true を返します。
neq Ra が b と等しくない場合は true を返します。

グルーピング関数 Grouping Functions

関数 概要
lookup 外部キーの値を検索します。Looks up the value for a foreign key.
with_key 入力値のグループ化を変更します。

論理関数 Logical Functions

関数 概要
coalesce 最初の非 null 値、またはすべての値が null の場合は null を返します。Return first non-null value or null if all values are null.
else null 以外の場合は値を返し、それ以外の場合はデフォルトを返します。Return the value if it is non-null, default otherwise.
if 条件が true の場合は値を返し、それ以外の場合は null を返します。
logical_and 2 つのブール値の論理積 (AND) を返します。
logical_or 2 つのブール値の論理和 (OR) を返します。
not ブール値の論理否定を返します。
null_if 条件が false の場合は値を返し、それ以外の場合は null を返します。

数学関数 Math Functions

関数 概要
add 2 つの数値の合計を返します。
ceil 数値を次に大きい整数に切り上げます。Rounds the number up to the next largest integer.
clamp 最小値と最大値の境界の間にクランプされた値を返します。Returns value clamped between the bounds min and max.
div 2 つの数値の除算を返します。Returns the division of two numbers.
exp e^power を返します。Returns e^power.
floor 数値を次に小さい整数に切り捨てます。Rounds the number down to the next smallest integer.
max 入力全体の値の最大値を計算します。Computes the maximum of values across the input.
mean 入力全体の値の算術平均を計算します。Computes the arithmetic mean of values across the input
min 入力全体の値の最小値を計算します。Computes the minimum of values across the input.
mul 2 つの数値の積を返します。Returns the product of two numbers.
neg n の否定(negation)を返します。Returns the negation of n.
powf ベース^パワーを返します。Returns base^power.
round 数値を最も近い整数に丸めます。Rounds the number to the nearest integer.
sqrt a の平方根を返します。Returns the square root of a.
stddev 入力全体の値のサンプル標準偏差を計算します。Computes the sample standard deviation of values across the input.
sub 2 つの数値の差を返します。Returns the difference of two numbers.
sum 入力全体の値の合計を計算します。Computes the sum of values across the input.
variance 入力全体の値の標本分散を計算します。Computes the sample variance of values across the input.
zip_max 2 つの値の最大値を返します。
zip_min 2 つの値の最小値を返します。

レコード関数 Record Functions

関数 概要
extend レコードを別のフィールドで拡張します。Extends a record with fields from another.
remove_fields レコードからフィールドを削除します。Remove fields from a record.
select_fields レコード内のフィールドを指定されたセットに制限します。Limits fields in a record to a given set.

文字列関数 String Functions

関数 概要
json 文字列から JSON オブジェクトを作成します。
len 文字列の長さを返します。
lower 文字列を小文字に変換します。
substring 開始インデックスと終了インデックスの間の入力の部分文字列を取得します。Takes a substring of the input between start and end indices.
upper 文字列を大文字に変換します。Converts the string to upper case.

ティック関数 Tick Functions

関数 概要
daily 各暦日 (UTC) の開始時に真の値を生成する周期関数。A periodic function that produces a true value at the start of each calendar day (UTC).
hourly 各時間の開始時に真の値を生成する周期関数。A periodic function that produces a true value at the start of each hour.
minutely 毎分の開始時に真の値を生成する周期関数。A periodic function that produces a true value at the start of each minutely.
monthly 各暦月の初め (UTC) に真の値を生成する周期関数。A periodic function that produces a true value at the start of each calendar month (UTC).
yearly 各暦年の初め (UTC) に真の値を生成する周期関数。A periodic function that produces a true value at the start of each calendar year (UTC).

タイム関数 Time Functions

関数 概要
add_time 時間に timedelta (期間または間隔) を追加します。Adds a timedelta (duration or interval) to a time.
day_of_month 指定された時刻の日付を 1 から返します。Return the day-of-month for the given time, starting with 1.
day_of_month0 指定された時刻の日付を 0 から返します。Return the day-of-month for the given time, starting with 0.
day_of_year 指定された時刻の年間通算日を 1 から返します。Return the day-of-year for the given time, starting with 1.
day_of_year0 指定された時刻の年間通算日を 0 から返します。Return the day-of-year for the given time, starting with 0.
days 指定された暦日数に対応する間隔を生成します。Produces an interval corresponding to the given number of calendar days.
days_between 最初のタイムスタンプと 2 番目のタイムスタンプの間の日数を返します。Returns the number of days between the first and second timestamp.
lag e の遅れ値を返します。Returns a lagging value of e.
month_of_year 指定された期間の月を 1 から返します。Return the month-of-year for the given time, starting with 1.
month_of_year0 指定された期間の月を 0 から返します。Return the month-of-year for the given time, starting with 0.
months 指定された暦月数に対応する間隔を生成します。Produces an interval corresponding to the given number of calendar months.
months_between 最初のタイムスタンプと 2 番目のタイムスタンプの間の月数を返します。Returns the number of months between the first and second timestamp.
seconds 指定された秒数に対応する継続時間を生成します。Produces a duration corresponding to the given number of seconds.
seconds_between 最初のタイムスタンプと 2 番目のタイムスタンプの間の秒数を返します。Returns the number of seconds between the first and second timestamp.
shift_to 指定された時間に前方にシフトされた現在の値を生成します。Produces the current value shifted forward to the given time.
shift_until 述語が true になる時点まで前方にシフトされた値を生成します。Produces the value shifted forward to the time the predicate is true.
time_of 入力内の行のタイムスタンプを返します。Returns the timestamp of rows in input.
when 条件が true と評価された場合に、現在の値を生成します。Produces the current value when the condition evaluates to true.
year 指定されたタイムスタンプの年を返します。Return the year of the given timestamp.

ウィンドウ関数 Window Functions

関数 概要
since ウィンドウ集計を構成します。
sliding スライディング ウィンドウ集計を構成します。

そのほかの関数 Misc Functions

関数 概要
hash 入力のハッシュを返します。
is_valid 入力が null 以外の場合は true を返します。

終わりに

本稿は、ドキュメントの逐語的な翻訳に終始した感もあり、それぞれの関数の実際の利用に基づく知見などは含まれておりませんが、Kaskadaに大体どのような関数が揃っているかというイメージを持っていただければ幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0