Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Sv translation
languageen

To be able to work with data in a ML Project, they first need to be loaded. Data can be loaded from a CSV file, XLS file, database, data set or a temporary table. There two ways how to read data in BellaDati ML Studio - row by row or as an stream. 

Reading Row by row

When reading data row by row, the content of the cycle (closure) is executed for each row of of the file. For each row (cycle), these variables are set:

  • row
  • values[n] - returns value in n-th column for current row.
  • columns[n] - returns name (header) of n-th column.
  • index - returns number of the row.

Reading from CSV File

Function readCSVFile() is used for loading data from a CSV file. The function is defined like this:

Code Block
languagegroovy
readCSVFile(String file, String separator, String escape, int limit, Closure<Object> closure)

Parameters

Parameters file and separator are mandatory, parameters escape, limit and closure are optional.

  • file - defines the name of file which should be read. This file needs to be uploaded to the project.
  • separator - defines the separator between values. Can be comma, semicolon etc.
  • escape - defines character which is used of escaping of text.
  • limit - defines the limit of rows which will be loaded.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.

Sample usage

Code Block
languagegroovy
linenumberstrue
def rows = 0
readCSVFile('file.csv', ',', '', 10) {
  rows++
  println index
  println values[1]
}
println rows

This code will print the row index and value of second column for first 10 rows of the file to the console. After finishing the loop it will display the total number of iterations, in this case 10.

Reading from XLS File

Function readXLSFile() is used for loading data from XLS file. The function is defined like this:

Code Block
languagegroovy
readXLSFile(String file, int limit, Closure<Object> closure)

Parameters

Parameters file is mandatory, parameters limit and closure are optional.

  • file - defines the name of file which should be read. This file needs to be uploaded to the project.
  • limit - defines the limit of rows which will be loaded.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.

Sample usage

Code Block
languagegroovy
linenumberstrue
def rows = 0
readXLSFile('samplexls.xls', 5){
  rows++
  println index
  println values[1]
}

println rows

This code will print the row index and value of second column for first 5 rows of the file to the console. After finishing the loop it will display the total number of iterations, in this case 5.

Reading from SQL Database

Function readSQL is used for loading data from an SQL database. This function uses SQL connections which were previously defined in BellaDati. See Data Sources for more information.

The function is defined like this:

Code Block
languagegroovy
readSQL(Long id, String sql, int limit, Closure<Object> closure)

Parameters

Parameters id and sql are mandatory, parameters limit and closure are optional.

  • id - defines the id of the data source. It can be set by the Code builder.
  • sql - defines the sql query.
  • limit - defines the limit of rows which will be loaded.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.

Sample usage

Code Block
languagegroovy
linenumberstrue
readSQL(1, 'select * from customers', 10) {
  println values[0]
  rows++
  println columns[0]
	}
println rows

This code will use database connection with ID 1 and it will load all columns for 10 rows from table customers.

Reading from Data Set

Function readDataset() is used for loading data from a data set. The function is defined like this:

Code Block
languagegroovy
readDataset(Integer id, int limit, Closure<Object> closure)

Parameters

Parameter id is mandatory, parameters limit and closure are optional.

  • id - defines the id of the data set. It can be set by the Code builder or it can be found in the URL of the data set.
  • limit - defines the limit of rows which will be loaded.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.

Sample usage

Code Block
languagegroovy
linenumberstrue
readDataset(10,5) {
  println values[0]
  println columns[0]
}

This code will use data set with ID 10 and it will load name and value of first column for 5 rows.

Reading from Table

Function table() can be used for loading data from a temporary table which was previously stored in the project. The table is available for current session only. The function is defined like this:

Code Block
languagegroovy
table(String id, Closure<Object> closure)

Parameters

Parameters id is mandatory, parameter closure is optional.

  • id - defines the id (name) of the table. It is set when creating the table.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.

Sample usage

Code Block
languagegroovy
linenumberstrue
table('table') {
  println values[0]
  }

This code will print value of first column for each row of the table to the console.

Reading as a Stream
Anchor
stream
stream

When reading data as a stream, the rows are not iterated, but instead sent all at once as na input stream. In most cases, it is better to use reading row by row. We suggest using streams only when necessary, for example with some Python scripts.

Streaming from CSV file

Function streamCSVFile() is used for streaming data from a CSV file. The function is defined like this:

Code Block
languagegroovy
streamCSVFile(String file, String separator, String escape, int limit)

Parameters

Parameters file and separator are mandatory, parameters escape and limit are optional.

  • file - defines the name of file which should be read. This file needs to be uploaded to the project.
  • separator - defines the separator between values. Can be comma, semicolon etc.
  • escape - defines character which is used of escaping of text.
  • limit - defines the limit of rows which will be loaded.

Sample usage

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamCSVFile('train_v2.csv',','))

This code will print the all values from the file, separated by a comma.

Streaming from XLS file

Function streamXLSFile() is used for streaming data from a XLS file. The function is defined like this:

Code Block
languagegroovy
streamXLSFile(String file, int limit)

Parameters

Parameters file is mandatory, parameter limit is optional.

  • file - defines the name of file which should be read. This file needs to be uploaded to the project.
  • limit - defines the limit of rows which will be loaded.

Sample usage

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamXLSFile('samplexls.xls',5))

This code will print first five rows from the file, with values separated by a comma.

Streaming from SQL database

Function streamXLSFile() is used for streaming data from a XLS file. The function is defined like this:

Code Block
languagegroovy
streamSQL(Long id, String sql, int limit)

Parameters

Parameters id id mandatory.

  • id - defines the id of the data set. It can be set by the Code builder or it can be found in the URL of the data set.

Sample usage

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamSQL(1, 'select * from table',5))

This code will print first five rows from the table, with values separated by a comma.

Streaming from Data set

Function streamDataset() is used for streaming data from a data set. The function is defined like this:

Code Block
languagegroovy
streamDataset(Integer id)

Parameters

Parameters id is mandatory.

  • id - defines the id of the data source. It can be set by the Code builder.

Sample usage

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamDataset(1))

This code will print all rows from the data set.

Streaming from Table

Function streamTable() can be used for streaming data from a temporary table which was previously stored in the project. The table is available for current session only. The function is defined like this:

Code Block
languagegroovy
streamTable(Integer id)

Parameters

Parameters id is mandatory.

  • id - defines the id (name) of the table. It is set when creating the table.

Sample usage

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamTable('table'))

This code will print all rows from the table.

Sv translation
languageja

MLプロジェクトでデータを処理できるように、最初に読込が必要があります。データは、CSVファイル、XLSファイル、データベース、データセット、または一時テーブルから読み込めます。BellaDati ML Studioでは行ごとに、またはストリームとしてデータを読み込む手段が2つあります。 

1行ずつ読み込む

行ごとにデータを読み込む場合、ファイルの行ごとにサイクルの中身(クロージャ)が実行されます。

各行(サイクル)ごとに、下記の変数が設定されます。

To be able to work with data in a ML Project, they first need to be loaded. Data can be loaded from a CSV file, XLS file, database, data set or a temporary table. There two ways how to read data in BellaDati ML Studio - row by row or as an stream. 

Reading Row by row

When reading data row by row, the content of the cycle (closure) is executed for each row of of the file. For each row (cycle), these variables are set:

  • row
  • values[n] - returns value in n-th column for current row. 現行の行に向けのnコラム目の戻り値
  • columns[n] - returns name (header) of n-th column.
  • index - returns number of the row.

Reading from CSV File

  •  nコラム目の戻り名称(ヘッダ)
  • index行の戻り番号

CSVファイルからの読込

readCSVFile()の関数の目的はCSVファイルからデータを読込する為です。 

この関数は以下のように定義されます。Function readCSVFile() is used for loading data from a CSV file. The function is defined like this:

Code Block
languagegroovy
readCSVFile(String file, String separator, String escape, int limit, Closure<Object> closure)
Parameters

パラメータ

Parameters パラメータ「file and separator are mandatory, parameters escape, limit and closure are optional.

  • file - defines the name of file which should be read. This file needs to be uploaded to the project.
  • separator - defines the separator between values. Can be comma, semicolon etc.
  • escape - defines character which is used of escaping of text.
  • limit - defines the limit of rows which will be loaded.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.
Sample usage

」及び「separator」は必須であるが、パラメーラ「escape」、「limit」、「closure」は任意です。

  • file読込対象ファイル名を定義します。このファイルはプロジェクトへアップロードする必要があります。
  • separatorコンマ、セミコロンなどの各値の間に区切り文字を定義します。
  • escape - テキストのエスケープ文字を定義します。
  • limit - 読込対象行の制限を定義する。
  • closure - クロージャはファイルの各行のごとに実行されるコードブロックです。クロージャはパラメータまたは中括弧で関数の本体として書込みがあります。基本的は必須ですが、任意のパラメータとして設定することができます。詳細は、Groovyクロージャを参照してください。

使用例

Code Block
languagegroovy
linenumberstrue
def rows = 0
readCSVFile('file.csv', ',', '', 10) {
  rows++
  println index
  println values[1]
}
println rows

This code will print the row index and value of second column for first 10 rows of the file to the console. After finishing the loop it will display the total number of iterations, in this case 10.

Reading from XLS File

println rows
このコードはファイルの先頭10行の2番目の列の行インデックスと値をコンソールに印刷します。

ループを終了した後、総計反復回数を表示ます。この場合には10になります。

XLSファイルからの読込

readXLSFile()の関数の目的はXLSファイルからデータを読込する為です。 

この関数は以下のように定義されます。Function readXLSFile() is used for loading data from XLS file. The function is defined like this:

Code Block
languagegroovy
readXLSFile(String file, int limit, Closure<Object> closure)
Parameters

パラメータ

Parameters file is mandatory, parameters limit and closure are optional.パラメータ「file 」は必須ですが、パラメータ「limit」及び「closure 」は任意です。

  • file - defines the name of file which should be read. This file needs to be uploaded to the project. 読込対象ファイル名を定義します。このファイルはプロジェクトへアップロードする必要があります。
  • limit - defines the limit of rows which will be loaded.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.
Sample usage
  •  読込対象行の制限を定義する。
  • closure - クロージャはファイルの各行のごとに実行されるコードブロックです。クロージャはパラメータまたは中括弧で関数の本体として書込みがあります。基本的は必須ですが、任意のパラメータとして設定することができます。詳細は、Groovyクロージャを参照してください。

使用例

Code Block
languagegroovy
linenumberstrue
def rows = 0
readXLSFile('samplexls.xls', 5){
  rows++
  println index
  println values[1]
}

println rows

This code will print the row index and value of second column for first 5 rows of the file to the console. After finishing the loop it will display the total number of iterations, in this case 5.

Reading from SQL Database

Function readSQL is used for loading data from an SQL database. This function uses SQL connections which were previously defined in BellaDati. See Data Sources for more information.

rows
このコードはファイルの先頭5行の2番目の列の行インデックスと値をコンソールに印刷します。

ループを終了した後、総計反復回数を表示ます。この場合には5になります。

SQLデータベースからの読込

readSQLの関数の目的はSQLデータベースからデータを読込する為です。

この関数はBellaDati に事前に定義されているSQL接続を使用します。

詳細はデータソースをご参照ください。

この関数は以下のように定義されます。The function is defined like this:

Code Block
languagegroovy
readSQL(Long id, String sql, int limit, Closure<Object> closure)
Parameters

パラメータ

Parameters パラメータ「id and sql are mandatory, parameters limit and closure are optional.

  • id - defines the id of the data source. It can be set by the Code builder.
  • sql - defines the sql query.
  • limit - defines the limit of rows which will be loaded.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.
Sample usage

」及び「sql」は必須ですが、パラメータ「limit」及び「closure」は任意です。

  • idデータソースのIDを定義します。
  • sqlSQLクエリを定義します。
  • limit - 読込対象行の制限を定義する。
  • closure - クロージャはファイルの各行のごとに実行されるコードブロックです。クロージャはパラメータまたは中括弧で関数の本体として書込みがあります。基本的は必須ですが、任意のパラメータとして設定することができます。詳細は、Groovyクロージャを参照してください。

使用例

Code Block
languagegroovy
linenumberstrue
readSQL(1, 'select * from customers', 10) {
  println values[0]
  rows++
  println columns[0]
	}
println rows

This code will use database connection with ID 1 and it will load all columns for 10 rows from table customers.

Reading from Data Set

このコードはID 1のデータベース接続を使用することで得意先テーブルから10行分で全てのコラムを読み込みます。

データセットからの読込

readDataset()の関数の目的はデータセットからデータを読込する為です。 

この関数は以下のように定義されます。Function readDataset() is used for loading data from a data set. The function is defined like this:

Code Block
languagegroovy
readDataset(Integer id, int limit, Closure<Object> closure)
Parameters

パラメータ

Parameter id is mandatory, parameters limit and closure are optional.パラメータ「id」は必須ですが、パラメータ「limit」及び「closure」は任意です。

  • id - defines the id of the data set. It can be set by the Code builder or it can be found in the URL of the data set. データセットのIDを定義します。コードビルダーに設定されることも、データセットのURLに設定することもできます
  • limit - defines the limit of rows which will be loaded. 読込対象行の制限を定義する。
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.
Sample usage
  •  クロージャはファイルの各行のごとに実行されるコードブロックです。クロージャはパラメータまたは中括弧で関数の本体として書込みがあります。基本的は必須ですが、任意のパラメータとして設定することができます。詳細は、Groovyクロージャを参照してください。

使用例

Code Block
languagegroovy
linenumberstrue
readDataset(10,5) {
  println values[0]
  println columns[0]
}

This code will use data set with ID 10 and it will load name and value of first column for 5 rows.

Reading from Table

このコードはID 10のデータセットを使用することで5行分で一番目のコラムの名称・値を読み込みます。

テーブルからの読込

table()の関数の目的は事前にプロジェクトに保存された一時テーブルからデータを読込する為です。このテーブルは現行のセッションにのみ使用できます。この関数は以下のように定義されます。Function table() can be used for loading data from a temporary table which was previously stored in the project. The table is available for current session only. The function is defined like this:

Code Block
languagegroovy
table(String id, Closure<Object> closure)
Parameters

パラメータ

Parameters id is mandatory, parameter closure is optional.パラメータ「id」は必須ですが、パラメータ「closure」は任意です。

  • id - defines the id (name) of the table. It is set when creating the table.
  • closure - closure is a block of code that is executed for each line of the file. The closure has to be written either as a parameter or as a body of the function in curly braces. Therefore it is optional as parameter but mandatory in general. See Groovy closures for more information.
Sample usage
  •  テーブルのID(名称)を定義します。テーブルを作成する時にIDを設定します。
  • closure - クロージャはファイルの各行のごとに実行されるコードブロックです。クロージャはパラメータまたは中括弧で関数の本体として書込みがあります。基本的は必須ですが、任意のパラメータとして設定することができます。詳細は、Groovyクロージャを参照してください。

使用例

Code Block
languagegroovy
linenumberstrue
table('table') {
  println values[0]
  }

This code will print value of first column for each row of the table to the console.

Reading as a Stream

このコードはファイルの各行毎の1番目の列の値をコンソールに印刷します。

ストリームとして読み込む
Anchor
stream
stream

When reading data as a stream, the rows are not iterated, but instead sent all at once as na input stream. In most cases, it is better to use reading row by row. We suggest using streams only when necessary, for example with some Python scripts.

Streaming from CSV file

ストリームとしてデータを読み込む場合、行は反復されませんが、その代わりに入力ストリームとして一度に送信します。通常は1行ずつ読むのが良いです。Pythonスクリプトなど必要に応じてストリームだけを利用すると提案します。

CSVファイルからのストリーム

streamCSVFile()の関数の目的はCSVファイルからデータをストリームする為です。この関数は以下のように定義されます。Function streamCSVFile() is used for streaming data from a CSV file. The function is defined like this:

Code Block
languagegroovy
streamCSVFile(String file, String separator, String escape, int limit)
Parameters

パラメータ

Parameters パラメータ「file and separator are mandatory, parameters escape and limit are optional.

  • file - defines the name of file which should be read. This file needs to be uploaded to the project.
  • separator - defines the separator between values. Can be comma, semicolon etc.
  • escape - defines character which is used of escaping of text.
  • limit - defines the limit of rows which will be loaded.
Sample usage

」及び separator 」は必須ですが、パラメータ「escape」及び「limit 」は任意です。

  • file - 読込対象ファイル名を定義します。このファイルはプロジェクトへアップロードする必要があります。
  • separator - コンマ、セミコロンなどの各値の間に区切り文字を定義します。
  • escape - テキストのエスケープ文字を定義します。
  • limit - 読込対象行の制限を定義する。

使用例

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamCSVFile('train_v2.csv',','))

This code will print the all values from the file, separated by a comma.

Streaming from XLS file

)

このコードはコンマで区切りられるファイルの全ての値を印刷します。

XLSファイルからのストリーム

streamXLSFile()の関数の目的はXLSファイルからデータをストリームする為です。この関数は以下のように定義されます。Function streamXLSFile() is used for streaming data from a XLS file. The function is defined like this:

Code Block
languagegroovy
streamXLSFile(String file, int limit)
Parameters

パラメータ

Parameters file is mandatory, parameter limit is optional.

  • file - defines the name of file which should be read. This file needs to be uploaded to the project.
  • limit - defines the limit of rows which will be loaded.
Sample usage

パラメータ「fileは必須ですが、パラメータ「limit 」は任意です。

  • file - 読込対象ファイル名を定義します。このファイルはプロジェクトへアップロードする必要があります。
  • limit - 読込対象行の制限を定義する。

使用例

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamXLSFile('samplexls.xls',5))

This code will print first five rows from the file, with values separated by a comma.

Streaming from SQL database

このコードはコンマで区切りられるファイルの先頭5行を印刷します。

SQLデータベースからのストリーム

streamXLSFile()の関数の目的はXLSファイルからデータをストリームする為です。この関数は以下のように定義されます。Function streamXLSFile() is used for streaming data from a XLS file. The function is defined like this:

Code Block
languagegroovy
streamSQL(Long id, String sql, int limit)
Parameters

パラメータ

Parameters id id mandatory.パラメータ「id 」は必須です。

  • id - defines the id of the data set. It can be set by the Code builder or it can be found in the URL of the data set.
Sample usage
  •  データセットのIDを定義します。コードビルダーに設定されることも、データセットのURLに設定することもできます

使用例

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamSQL(1, 'select * from table',5))

This code will print first five rows from the table, with values separated by a comma.

Streaming from Data set

table',5))

このコードはコンマで区切りられるテーブルの先頭5行を印刷します。

データセットからのストリーム

streamDataset()の関数の目的はデータセットからデータをストリームする為です。この関数は以下のように定義されます。Function streamDataset() is used for streaming data from a data set. The function is defined like this:

Code Block
languagegroovy
streamDataset(Integer id)
Parameters

パラメータ

Parameters パラメータ「id is mandatory.

  • id - defines the id of the data source. It can be set by the Code builder.
Sample usage

」は必須です。

  • id - データソースのIDを定義します。コードビルダーに設定されます。

使用例

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamDataset(1))

This code will print all rows from the data set.

Streaming from Table

このコードがデータセットから全ての列を印刷します。

テーブルからのストリーム

streamTable()関数の目的はプロジェクトに事前に保存された一時テーブルからデータをストリームする為です。このテーブルは現行のセッションだけに利用可能です。この関数は以下のように定義されます。Function streamTable() can be used for streaming data from a temporary table which was previously stored in the project. The table is available for current session only. The function is defined like this:

Code Block
languagegroovy
streamTable(Integer id)
Parameters

パラメータ

Parameters パラメータ「id is mandatory.」は必須です。

  • id - defines the id (name) of the table. It is set when creating the table.
Sample usage
  •  テーブルのID(名称)を定義します。テーブルを作成する時にIDを設定します。

使用例

Code Block
languagegroovy
linenumberstrue
println org.apache.commons.io.IOUtils.toString(streamTable('table'))

This code will print all rows from the table.このコードがテーブルから全ての列を印刷します。