このトピックでは、Log Serviceのドメイン固有言語 (DSL) の基本構文について説明します。
Comments
ステップのコメントを番号記号 (#) で開始します。 例:
# Specify the default topic. This is a comment at the beginning of a step.
e_set("__topic__", "access_log") # Specify the default topic. This is a comment at the end of a step. 行の折り返し
関数のパラメータリストまたは文字列が1行に収まらない場合は、パラメータリストまたは文字列を区切ることができます。
パラメーターリストにコンマ (,) が含まれている場合は、パラメーターリストをコンマ (,) の直後に分割できます。
If you want to split a string, use a backslash (\) to indicate that the string continues in the next line.
例:
e_set("__topic__", "v1",
"type", "v2", # Use a comma (,) as a line feed.
"length", 100)
e_set("__topic__", "this is a very long long long .........." \
"......long text") # Use a backslash (\) as a line feed. 関数呼び出し
基本関数を呼び出す
e_set("abc", "xyz")説明データ変換ステートメントを記述するときは、関数に渡すデータ型とパラメーターの数が関数の構文を満たしている必要があります。
基本変数パラメータを渡す
str_replace(value, old [,new [,count] ])説明The parameters that are enclosed in the square brackets [] are optional. For example, the
newandcountparameters in the preceding function are optional. You cannot pass these parameters the same way you pass the named parameters. これらのパラメータを順番に渡す必要があります。# Invalid examples str_replace("a-b-c", "-", new='%') str_replace("a-b-c", "-", new='%', count=1) # Valid examples str_replace("a-b-c", "-", '%') str_replace("a-b-c", "-", '%', 2)名前付きパラメータを渡す
デフォルト値を持つパラメータは、名前付きパラメータと呼ばれます。 たとえば、関数
e_set("abc", "xyz", mode="fill")のmodeパラメーターは名前付きパラメーターです。特定の条件に基づいて、特定の関数で名前付きパラメーターの値を渡す必要があります。 詳細については、各関数のパラメーターの説明をご参照ください。
mode=... の形式でパラメータを設定すると、名前付きパラメータの値を渡すことができます。.複数の名前付きパラメータをランダムな順序で渡すことができます。 たとえば、
e_csv("data", ["f1", "f2", "f3"], sep='#', quote="|")とe_csv("data", ["f1", "f2", "f3"], quote="|", sep='#')は同義です。
説明名前付きパラメータは、非名前付きパラメータの後に続く。
Invoke a combination of functions
関数の戻り値をパラメーターの値として別の関数に渡すことができます。 この場合、返される値がパラメーターの値と同じデータ型であることを確認する必要があります。 例:
e_set("abc", v("xyz")) e_set("abc", str_lower(v("xyz")))可変パラメーター
You can pass variable parameters to specific functions. The
v("f1", ....)function specifies that multiple parameters can be passed. Example:v("f1", "f2", "f3").If you need to pass both variable parameters and named parameters, you must place the named parameters after the variable parameters. Example:
v("f1", "f2", "f3", "f4", mode="fill").
演算子
比較演算子
DSL for Log Serviceの標準モードでは、次の比較演算子がサポートされています:
>, <,>=, <=,! =,==. Log Serviceが提供する比較機能を使用して操作を実行することもできます。比較演算子の使用
# The following examples show how to use comparison operators. If the comparison condition is evaluated to True, the related log is discarded. e_if(3 > 2, DROP) # If 3 is greater than 2, the log is discarded. e_if(3 < 2, DROP) # If 3 is less than 2, the log is discarded. e_if(3 >= 2, DROP) # If 3 is greater than or equal to 2, the log is discarded. e_if(3 <= 2, DROP) # If 3 is less than or equal to 2, the log is discarded. e_if(3 == 2, DROP) # If 3 is equal to 2, the log is discarded. e_if(3 != 2, DROP) # If 3 is not equal to 2, the log is discarded. e_if(1 < 2 < 3, DROP) # If 2 is greater than 1 and 2 is less than 3, the log is discarded. e_if(0 < ct_int(v('x')) < 100, DROP) # If the value of the x field is greater than 0 and less than 100, the log is discarded.Use the comparison functions that are provided by Log Service
操作
機能
例:
等しい (
==)op_eq
op_eq(v("name") 、"xiao ming")等しくない (
!op_ne
op_ne(v("name") 、"xiao ming")大なり (
>)op_gt
op_gt(ct_int(v("age"))), )以上 (
>=)op_ge
op_ge(ct_int(v("age")), 18)小なり (
<)op_lt
op_lt(ct_int(v("age")), 18)以下 (
<=)op_le
op_le(ct_int(v("age")), 18)
論理演算子
The following logical operators are supported in the DSL for Log Service in standard mode: AND, OR, and NOT. You can also use the logical functions that are provided by Log Service to perform the operations.
論理演算子の使用
# The following examples show how to use logical operators. If the logical condition is evaluated to True, the related log is discarded. e_if(True and False, DROP) # False is returned. e_if(True or False, DROP) # True is returned. e_if(True and not False, DROP) # True is returned. e_if(3 > 2 and 1 < 3, DROP) # True is returned. e_if(ct_int(v('x')) > 100 or ct_int(v('y')) < 100, DROP) # If the value of the x field is greater than 100 or the value of the y field is less than 100, True is returned.Log Serviceが提供する論理関数を使用する
操作
機能
例:
Logical operator AND (
and)op_and
op_and(op_gt(v("age"), 18), op_lt(v("age"), 31))Logical operator OR (
or)op_or
op_or(op_le(v("age"), 18), op_gt(v("age"), 65))論理演算子NOT (
not)op_not
op_not(op_gt(v("age"), 18))
その他の演算子
特定のDSLオペレータを標準モードで直接使用することはできません。 Log Serviceは、操作の実行に使用できる機能を提供します。 The following table describes the operators and functions.
操作
機能
例:
加算 (
+)op_add
op_add(v("age"), 2)減算 (
-)op_sub
op_sub(v("age"), 2)乗算 (
*)op_mul
op_mul(v("size"), 2)累乗 (
**)op_pow
op_pow(v("サイズ"), 2)切り捨て除算 (
//)op_div_floor
op_div_floor(v("bytes"), 1024)剰余演算 (
%)op_mod
op_mod(v("age"), 10)符号反転 (
-)op_neg
op_neg(v("profit"))存在チェック (
in)op_in
op_in(["pass", "ok"], v("result"))非存在チェック (
not in)op_not_in
op_not_in(["pass", "ok"], v("result"))文字列スライス (
[ ...])op_slice
op_slice(v("message"), 0, 20)In this example, the value of the
afield is 3600 * 6. 次の例は、フィールドの値を指定するための無効な関数と有効な関数を示しています。# * e_set("a", 3600 * 6) # Invalid e_set("a", op_mul(3600, 6)) # Valid # / e_set("bytes_kb", v("bytes") / 1024) # Invalid e_set("bytes_kb", op_div_floor(v("bytes"), 1024)) # Valid
真または偽の評価
イベント処理ロジックを指定する条件がtrueかfalseかをチェックする関数もあります。 条件は、固定値または式関数によって返される値にすることができます。
DSL for Log Serviceオーケストレーションのすべてのタイプのデータに対して、真または偽の評価を実行できます。 次の表に、真または偽の評価のルールを示します。
データ型 | 正しい | 間違い |
ブール | 真、真 | 偽、偽 |
なし | N/A | 常にfalse |
Numeric | 0 や 0.0 以外 | 0 または 0.0 |
String | 空でない | Empty string |
バイト | 空でない | 空のバイト |
Tuple | 空でない | 空のタプル |
List | 空でない | 空のリスト |
辞書 | 空でない | Empty dictionary |
テーブル | 1つ以上のテーブルが存在する | テーブルが存在しません |
Datetime | 1つ以上のdatetimeオブジェクトが存在する | datetimeオブジェクトが存在しません |
次の関数を使用して、条件に基づいてログを破棄できます。
e_if(True, DROP) # If the value of the first parameter is True, the log is discarded.
e_if(1, DROP) # If the value of the first parameter is 1, the log is discarded.
e_if(v("abc"), DROP) #If the abc field exists and the value of this field is not empty, the log is discarded.
e_if(str_isdigit(v("abc")), DROP) # If the abc field exists and the value of this field contains only digits, the log is discarded.