마크베이스 서버에 텍스트 파일 데이터를 import/export하기 위해서 machloader를 사용한다. 기본적으로 CSV 파일을 이용하여 동작하지만, 다른 포맷도 지원한다.
machloader의 특징은 다음과 같다.
...
machloader is used to import/export text file data to the Machbase server. It works with CSV files by default, but it also supports other formats.
The features of machloader are as follows.
- machloader can specify a datetime type in the schema file. The datetime type specified must be of the type supported by the Machbase server. One datetime type can be applied to all fields, and each field can have a different format.
- To delete and input the input target table data, use the "-m replace" option.
- machloader does not verify the schema and data file consistency. The user must check that the schema, tables, and data files meet the consistency.
- machloader supports APPEND mode by default.
- machloader does not use the "_ARRIVAL_TIME" column by default. You must use the "-a" option to import/export the corresponding column data.
The options for machloader can be seen with the following command:
Code Block |
---|
[mach@localhost]$ machloader -h |
옵션Option | 설명Description | |||||
---|---|---|---|---|---|---|
-s, --server=SERVER | 마크베이스 서버의 IP 주소를 입력한다. Enters Machbase server IP address (default: 127.0.0.1) | |||||
-u, --user=USER | 접속할 사용자명을 입력한다. Enters connecting user name (default: SYS) | |||||
-p, --password=PASSWORD | 접속할 사용자의 패스워드 Connecting user password (default: MANAGER) | |||||
-P, --port=PORT | 마크베이스 서버의 포트 번호 Machbase server port number (default: 5656) | |||||
-i, --import | 데이터 Data import 명령 옵션command option | |||||
-o, --export | 데이터 Data export 명령 옵션command option | |||||
-c, --schema | 데이터베이스의 테이블 정보를 이용하여 스키마 파일을 만드는 명령 옵션Command option to create schema file using the database table information | |||||
-t, --table=TABLE_NAME | 스키마 파일을 생성할 테이블 명을 설정 Sets table name that is creating a schema file | |||||
-f, --form=SCHEMA_FORM_FILE | 스키마 파일명을 지정 Specifies schema filename | |||||
-d, --data=DATA_FILE | 데이터 파일명을 지정Specifies a data file name | |||||
-l, --log=LOG_FILE | machloader 실행 로그 파일을 지정 Specifies a machloader execution log file | |||||
-b, --bad=BAD_FILE | -i 옵션 실행시 입력 오류가 발생한 데이터를 기록하며, 에러 설명을 기록하는 파일명을 지정한다Records the data in which the input error occurred and specifies the file name that records the error description when executing -i option. | |||||
-m, --mode=MODE | Indicates import method when executing -i 옵션 실행시 import 방법을 지시한다. append 또는 replace 옵션이 사용가능 하다. append는 기존 데이터 이후에 데이터를 입력하고 replace는 기존 데이터를 삭제하고 데이터를 입력한다option. The append or replace option is available. Append enters the data after the existing data and replace deletes the existing data and enters the data. | |||||
-D, –delimiter=DELIMITER | 각 필드 구분자를 설정한다. 기본값은 Sets each field delimiter. The default value is ',' 이다. | |||||
-n, --newline=NEWLINE | 각 레코드 구분자를 설정한다. 기본값은 Sets each record separator. The default is '\n' 이다. | |||||
-e, --enclosure=ENCLOSURE | 각 필드의 enclosing 구분자를 설정한다 Sets the enclosing delimiter for each field. | |||||
-r, --format=FORMAT | 파일 입력/출력 시 포맷을 지정한다. Specifies the format for file input/output. (default: csv) | |||||
-a, --atime | 내장 컬럼 Determines whether to use the built-in column "_ARRIVAL_TIME" 을 사용할 것인지를 결정한다. 기본값은 사용하지 않는 것이다. The default value is to not use the column. | |||||
-z, --timezone | Set timezone ex) +0900 -1230 | |||||
-I, --silent | 저작권 관련 출력 및 Does not display copyright-related output and import/export 상태 정보를 표시하지 않는다status information. | |||||
-h, --help | 옵션 리스트를 표시한다 Displays a list of options. | |||||
-F, --dateformat=DATEFORMAT | 컬럼 dateformat을 설정한다. Sets the column dateformat. ("_arrival_time YYYY-MM-DD HH24:MI:SS") dateformat 대신
| |||||
-E, --encoding=CHARACTER_SET | 입/출력하는 파일의 인코딩을 설정한다. 지원되는 인코딩은 UTF8(기본값 Sets the encoding of input/output files. Supported encodings are UTF8 (default), ASCII, MS949, KSC5601, EUCJP, SHIFTJIS, BIG5, GB231280, UTF16이다and UTF16. | |||||
-C, --create | import시에 table이 없으면 생성한다 Creates a table if one does not exist upon import. | |||||
-H, --header | Sets whether header information is present upon import/ export시에 헤더 정보의 유무를 설정한다. 기본값은 미설정이다export. The default value is unset. | |||||
-S, --slash | Specifies the backslash 구분자를 지정한다delimiter. |
기본 사용법
...
Basic Usage
The table must be created first before running the usage below.
CSV
...
File Import
...
Imports CSV file to Machbase server.
Option:
Code Block |
---|
-i: import 지정specification 옵션options -d: 데이터data 파일명file 지정naming 옵션options -t: table 테이블명name 지정specification 옵션option |
Example:
Code Block |
---|
machloader -i -d data.csv -t table_name |
CSV
...
File Export
...
Writes data to a CSV file.
Option:
Code Block |
---|
-o: export 지정specification 옵션options -d: 데이터data 파일명file 지정naming 옵션options -t: 테이블명table name 지정specification 옵션option |
Example:
Code Block |
---|
machloader -o -d data.csv -t table_name |
Use CSV
...
File Header
The header-related setting of the CSV file.
Option:
Code Block |
---|
-i -H: Upon import 할 때 csv 파일의 첫번째 라인을 헤더로 인식한다. 따라서 첫번째 라인은 입력에서 제외된다, the first line of the csv file is recognized as a header. Therefore, the first line is excluded from input. -o -H: Upon export 할 때 테이블의 컬럼명으로 csv 헤더를 생성한다., generates the csv header as the column name of the table.e |
Example:
Code Block |
---|
machloader -i -d data.csv -t table_name -H machloader -o -d data.csv -t table_name -H |
테이블 자동 생성
...
Automatic Table Creation
Regards automatic table creation.
Option:
Code Block |
---|
-C: Automatically import할generates 때the 테이블을table 자동when 생성한다. 컬럼명은importing. The column names are automatically generated as c0, c1, .... 자동으로The 생성된다.generated 생성되는column 컬럼은is varchar (32767) 타입이다type. -H: Generates import할column names 때with csv header 헤더명으로name 컬럼명을when 생성한다importing. |
Example:
Code Block |
---|
machloader -i -d data.csv -t table_name -C machloader -i -d data.csv -t table_name -C -H |
Files Not CSV
...
Format
Sets delimiter for files that are not in CSV format.
Option:
Code Block |
---|
-D: 각Delimiter 필드의option 구분자for 지정each 옵션field -n: 각Specifies 레코드each 구분자record 지정delimiter 옵션option -e: 각Specifies 필드의the enclosing character for 지정each 옵션field. |
Example:
Code Block |
---|
machloader -i -d data.txt -t table_name -D '^' -n '\n' -e '"' machloader -o -d data.txt -t table_name -D '^' -n '\n' -e '"' |
입력 모드 지정
...
Specify Input Mode
When importing (with -i option), there are two modes, REPLACE and APPEND. APPEND is the default. Use REPLACE mode with caution because it deletes existing data.
Option:
Code Block |
---|
-m: Specifies import 모드 지정mode |
Example:
Code Block |
---|
machloader -i -d data.csv -t table_name -m replace |
접속 정보 지정
...
Specify Connection Information
Specifies server IP, 사용자, 패스워드를 별도로 지정한다user, and password separately.
Option:
Code Block |
---|
-s: 서버Specifies server IP 주소 지정address (default: 127.0.0.1) -P: 서버Specifies 포트server 번호port 지정number (default: 5656) -u: Specifies 접속할the connecting 사용자명user 지정name (default: SYS) -p: 접속할 사용자의 패스워드 지정Specifies the password of the connecting user (default: MANAGER) |
Example:
Code Block |
---|
machloader -i -s 192.168.0.10 -P 5656 -u mach -p machbase -d data.csv -t table_name |
로그 파일 생성
...
Create Log File
Creates the execution log file for machloader.
Option:
Code Block |
---|
Code Block |
-b: Sets the name of the log file to generate the data that is not input when importing.
-l: Sets the name of the log file to generate the data and error message that were not input when importing. |
Example:
Code Block |
---|
machloader -i -d data.csv -t table_name -b table_name.bad -l table_name.log |
스키마 파일 생성
...
Create Schema File
The machloader schema file can be created. Import/export is possible even if the data type format is changed using a schema file or the number of columns in the table and data file is different.
Option:
Code Block |
---|
-c: 스키마schema 파일file 생성creation 옵션options -t: 테이블명table name 지정specification 옵션option -f: created 생성될schema 스키마file 파일명name 지정specification 옵션option |
Example:
Code Block |
---|
machloader -c -t table_name -f table_name.fmt machloader -c -t table_name -f table_name.fmt -a |
스키마 파일에서 datetime 형식 설정
...
Set datetime Format in Schema File
The date format can be set to preference with the DATEFORMAT option.
Syntax:
Code Block |
---|
# Set for 모든all datetime 컬럼에 대해서 설정한다columns. DATEFORMAT <dateformat> # 개별Set datetimefor 컬럼에individual 대해서datetime 설정한다column. DATEFORMAT <column_name> <format> |
Example:
Code Block |
---|
-- 스키마 파일(datetest.fmt)에 Set dateformat for each field in datetest.csv 파일의file 각in 필드에the 맞게schema dateformat을 설정한다file (datetest.fmt). datetest.fmt table datetest { INS_DT datetime; UPT_DT datetime; } DATEFORMAT ins_dt "YYYY/MM/DD HH12:MI:SS" DATEFORMAT upt_dt "YYYY DD MM HH12:MI:SS" datetest.csv 2017/02/20 11:05:23,2017 20 02 11:05:23 2017/02/20 11:06:34,2017 20 02 11:06:34 -- Import datetest.csv 파일을file importand 하고check 입력된input 데이터를 확인한다data. machloader -i -f datetest.fmt -d datetest.csv ----------------------------------------------------------------- Machbase Data Import/Export Utility. Release Version 5.1.9.community Copyright 2014, MACHBASE Corporation or its subsidiaries. All Rights Reserved. ----------------------------------------------------------------- Import time : 0 hour 0 min 0.39 sec Load success count : 2 Load fail count : 0 mach> SELECT * FROM datetest; INS_DT UPT_DT ------------------------------------------------------------------- 2017-02-20 11:06:34 000:000:000 2017-02-20 11:06:34 000:000:000 2017-02-20 11:05:23 000:000:000 2017-02-20 11:05:23 000:000:000 [2] row(s) selected. Elapsed time: 0.000 |
IGNORE
CSV 파일의 특정 필드를 입력하려 하지 않을 때, IGNORE 옵션을 fmt 파일에 설정할 수 있다.
ignoretest.csv 파일은 세 개의 필드를 갖지만, 마지막 필드가 필요 없을 경우, fmt 파일에 필요 없는 컬럼에 IGNORE를 명시한다When you do not want to enter a specific field in the CSV file, you can set the IGNORE option in the fmt file.
The ignoretest.csv file has three fields, but if the last field is not needed, specify IGNORE in the column that is not needed in the fmt file.
Example:
Code Block |
---|
-- Set ignoretest.fmtignore 파일에option 마지막for 필드에last 대해서field ignorein 옵션을ignoretest.fmt 설정한다file. ignoretest.fmt table ignoretest { ID integer; MSG varchar(40); SUB_ID integer IGNORE; } ignoretest.csv 1, "msg1", 3 2, "msg2", 4 -- Import ignoretest.csv 파일을 importfile 하고and 입력된check 데이터를input 확인한다data. machloader -i -f ignoretest.fmt -d ignoretest.csv ----------------------------------------------------------------- Machbase Data Import/Export Utility. Release Version 5.1.9.community Copyright 2014, MACHBASE Corporation or its subsidiaries. All Rights Reserved. ----------------------------------------------------------------- NLS : US7ASCII EXECUTE MODE : IMPORT SCHMEA FILE : ignoretest.fmt DATA FILE : ignoretest.csv IMPORT_MODE : APPEND FILED TERM : , ROW TERM : \n ENCLOSURE : " ARRIVAL_TIME : FALSE ENCODING : NONE HEADER : FALSE CREATE TABLE : FALSE Progress bar Imported records Error records 2 0 Import time : 0 hour 0 min 0.39 sec Load success count : 2 Load fail count : 0 mach> SELECT * FROM ignoretest; ID MSG --------------------------------------------------------- 2 msg2 1 msg1 [2] row(s) selected. Elapsed time: 0.000 |
컬럼 개수가 필드 개수보다 많은 경우
테이블의 컬럼 개수가 데이터 파일의 필드 개수보다 많은 경우에는 스키마 파일에 지정된 컬럼만 입력되고 다른 컬럼은 NULL로 입력된다.
컬럼 개수가 필드 개수보다 적은 경우
...
If Number of Columns Is More Than Number of Fields
If the number of columns in the table is greater than the number of fields in the data file, only the columns specified in the schema file are entered, and the other columns are entered as NULL.
If Number of Columns Is Less Than Number of Fields
If the number of columns in the table is less than the number of fields in the data file, fields not in the table must be excluded with the IGNORE option.
Example:
Code Block |
---|
-- 마지막 필드에 대해서 ignore 옵션을 설정해서 제외한다 Import ignoretest.csv file and exclude input data by setting ignore option for last field. loader_test.fmt table loader_test { ID integer; MSG varchar (40); SUB_ID integer IGNORE; } |
...