Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed translated content for 'zh'
Sv translation
languageen
Info

The transformation scripting engine's base concept is based on the Groovy scripting language.

Section
Column

Transformation scripting is an advanced feature for processing data during import. Thanks to transformation scripts you can:

  • cleanup values
  • change values
  • create new columns with values computed from other column(s)
  • mark values with flags and notes
  • build intelligence for handling values according to column names

You are allowed to enter transformation scripts in the column detail dialog while setting or editting import settings.

Transformation scripts syntax resembles the Groovy and Java syntax. It is designed to be readable and effective but not strict. Users familiar with scripting and programming should know, that some of the common features (like loops) are absent because of security and performance reasons. Script can be applied to and import column. The basic function is transforming the input value of a column row to another value.

Transformation scripts basics

  • You can use variables in scripts for storing values and working with them
  • You can use conditions and branching
  • You can use wide pallete of functions

Our first script using variable and function:

Code Block
val = value()
return trim(val)

This script trims whitespaces from the beginning and end of the column value of each data import cell. You can see, that the last line contains command return. The function of the script can be described as "pick a value from the current cell, apply function trim and return the result".

How to access the column values?

Accessing the value we want to process is a key issue. Scripts provide a function value() which returns the current value. There are more advanced possibilities to access values:

Object value()returns the value (String, Number, LocalDate, LocalTime - according to column type) of current column.

Object value(int columnIndex)

returns the value (String, Number, LocalDate, LocalTime - according to column type) of column at columnIndex

Object value(String indicatorCode)

returns the value (String, Number, LocalDate, LocalTime - according to column type) of column specified by indicatorCode. Applicable in existing data sets only.

Object value(String attributeCode)

returns the value (String, Number, LocalDate, LocalTime - according to column type) of column specified by attributeCode. Applicable in existing data sets only.

LocalDate dateValue()
returns the value as LocalDate of current column.
LocalDate dateValue(int columnIndex)
returns the value as LocalDate of column at columnIndex
LocalDate dateValue(String attributeCode)
returns the LocalDate value of column specified by attributeCode. Applicable in existing data sets only.
LocalTime timeValue()
returns the value as LocalTime of current column.
LocalTime timeValue(int columnIndex)
returns the value as LocalDate of current column at columnIndex.
LocalTime timeValue(String attributeCode)
returns the LocalTime value of column specified by attributeCode. Applicable in existing data sets only.
Integer integerValue()
returns the value as Integer of current column.
Integer integerValue(int columnIndex)
returns the value as Integer of current column at columnIndex.
Integer integerValue(String code)
returns the Integer value of column specified by attributeCode. Applicable in existing data sets only.
Double doubleValue()
returns the value as Double of current column.
Double doubleValue(int columnIndex)
returns the value as Double of current column at columnIndex.
Double doubleValue(String code)
returns the Double value of column specified by attributeCode. Applicable in existing data sets only.

String name()

returns the name of the current column

String name(int columntIndex)

returns the name of the column a colimnIndex

String format()

returns format of the current column

String defaultValue()

returns default value of the current column, which is the value in "Replace empty cells with value"

String getFileName()returns file name of imported file
String getPath()returns path to the imported file. Useful for zip archives, ftp folders or http connections.

Variables

You can store values into variables and use them into expressions or as a script result. The typing of variables is dynamic thus in most of the cases there is no need to think of a variable type. 

Example of declaring universal variables which are dynamically typed. You can assign values to variables for later use:

Code Block
a = value()
b = 12
c = 100.56
bool = false
e = "Hello"
x = b + c
return e + " world"

You can retype a variable or function return by adding as nameOfType:

Code Block
double b = value() as double

Type name

 

boolean

stores boolean value True / False, used usually as a result of functions in branching expressions

String

stores a string of characters

int

stores an integer number

double

stores an decimal number

Date

represents an Date object in gregorian format

LocalDate

represents the Date part of the date for using in date and time functions

LocalTime

represents the Time part of the date for using in date and time functions

DateTime

represents the DateTime object for using in date and time functions

The values function returns a String value. String cannot be handled as a number unless it is properly converted. The conversion usually consists of normalization (ex.: round all numbers to 2 decimal places) or cleanup (ex.: replace all "," with ".").

More scripting language basics

Transformation scripts topics

Advanced script tools

Sv translation
languageja


Info

変換スクリプトエンジンの基本概念は、Groovyスクリプト言語に基づいています。


Section


Column

変換スクリプトは、インポート中にデータを処理するための高度な機能です。変換スクリプトで以下のことが可能です:

  • 値をクリーンアップ
  • 値を変更する
  • 他の列から計算された値で新しい列を作成する
  • フラグとメモで値をマークする
  • 列名に従って値を処理するためのインテリジェンスを構築する

インポート設定の設定または編集中に、列の詳細ダイアログに変換スクリプトを入力できます。


変換スクリプトの構文は、GroovyとJavaの構文に似ています。読みやすく効果的であるように設計されていますが、厳密ではありません。スクリプトとプログラミングに精通しているユーザーは、セキュリティやパフォーマンス上の理由から、ループなどの一般的な機能の一部が欠落していることを知っている必要があります。スクリプトを適用して列をインポートできます。基本的な機能は、列・行の入力値を別の値に変換することです。

変換スクリプトの基本

    • スクリプトで変数を使用して、値を保存し、操作することができます。
    • 条件分岐を使用できます。
    • 幅広い機能のパレットを使用できます。


変数と関数を使用した最初のスクリプト:

Code Block
val = value()
return trim(val)

このスクリプトは、各データインポートセルの列値の最初と最後から空白を削除します。ご覧のとおり、最後の行にはreturnコマンドが含まれています。スクリプトの関数は、「現在のセルから値を選択し、トリム関数を適用して結果を返す」と説明できます。

列の値にアクセスするには?

処理したい値にアクセスすることが重要な課題です。スクリプトは、現在の値を返すvalue()関数を提供します。値にアクセスするためのより高度な可能性があります。

Object value()現在カラムの値(String, Number, LocalDate, LocalTime – カラムタイプ通り)を返却します。

Object value(int columnIndex)

カラムのインデックス位置にあるカラムの値(String, Number, LocalDate, LocalTime – カラムタイプ通り)を返却します。

Object value(String indicatorCode)

インジケータコードで指定された列の値(String, Number, LocalDate, LocalTime – カラムタイプ通り)を返却します。既存のデータを内のみ適用可能で設定します。

Object value(String attributeCode)

属性コードで指定された列の値(String, Number, LocalDate, LocalTime – カラムタイプ通り)を返却します。既存のデータを内のみ適用可能で設定します。

LocalDate dateValue()
現在のカラムのLocalDatとして値を返却します。
LocalDate dateValue(int columnIndex)
columnIndexでカラムのLocalDateとして値を返却します。
LocalDate dateValue(String attributeCode)
属性コードで指定されたカラムのLocalDate値を返却します。既存のデータを内のみ適用可能で設定します。
LocalTime timeValue()
現在のカラムの現地時間として値を返却します。
LocalTime timeValue(int columnIndex)
現在の列の列インデックスでのLocalDateとして値を返却します 。(LocalTime?)
LocalTime timeValue(String attributeCode)

属性コードで指定されたカラムのLocalTimeを返却します。既存のデータを内のみ適用可能で設定します。

Integer integerValue()
現在の列の整数として値を返却します。
Integer integerValue(int columnIndex)
columnIndexで現在の列の整数として値を返却します。
Integer integerValue(String code)
attributeCodeで指定された列の整数値を返却します。既存のデータを内のみ適用可能で設定します。
Double doubleValue()
現在の列のダブルとして値を返却します。
Double doubleValue(int columnIndex)
columnIndexで現在の列のダブルとして値を返却します。
Double doubleValue(String code)
attributeCodeで指定されたカラムのDouble値を返却します。既存のデータを内のみ適用可能で設定します。

String name()

現在のカラムの名前を返却します。

String name(int columntIndex)

colimnIndexの名前を返却します。

String format()

現在のカラムの形式を返却します。

String defaultValue()

「値と空のセルを交換」の値が現在のカラムのデフォルト値を返却します。

String getFileName()インポートされたファイルのファイル名を返却します。
String getPath()インポートされたファイルへのパスを返却します。 zipアーカイブ、FTPフォルダまたはHTTP接続するのに便利です。

変数

スクリプトの結果として変数に値を格納し、式にまたはそれらを使用できる。変数のタイピングはほとんどの場合で動的ですの変数の型を考えるする必要がなりません。

動的に型指定される汎用変数の宣言の例 後で使用するために変数に値を割り当てることができます:

Code Block
a = value()
b = 12
c = 100.56
bool = false
e = "Hello"
x = b + c
return e + " world"

as nameOfTypeを追加することで変数や関数のリターンを再入力できます。

Code Block
double b = value() as double


タイプ名


boolean

店はboolean値は、True / Falseの、式の分岐内の関数の結果として通常使用されます

String

文字の文字列を格納

int

整数値を格納

double

10進数で格納

Date

gregory形式でDateオブジェクトを表す

LocalDate

日付と時間の関数で使用するための日付の日付部分を表す

LocalTime

日付と時間の関数で使用するための日付の時間部分を表す

DateTime

日付と時間の関数で使用するためのDateTimeオブジェクトを表す

値関数はString型の値を返却します。それが正しく変換されない限り、文字列は数として扱うことはできません。変換は、通常(例:"。"ですべて","を置き換える)、正規化(例:ラウンド小数点以下2桁までのすべての数字)またはクリーンアップで構成されています。

詳細スクリプト言語の基礎

変換スクリプトのトピック

高度なスクリプトツール