Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
admin:basics:rawdata:implementation:delimited [2011/03/08 21:55]
els
— (current)
Line 1: Line 1:
-~~NOTOC~~ 
  
-{{page>:​top_add&​nofooter&​noeditbtn}} 
- 
-====== Administration:​ Omnidex Fundamentals ====== 
- 
-===== Raw Data Files ===== 
- 
-[[admin:​basics:​rawdata:​home|Overview]] | 
-[[admin:​basics:​rawdata:​types|File Types]] | 
-[[admin:​basics:​rawdata:​environments|Environments]] | 
-[[admin:​basics:​rawdata:​queries|Queries]] | 
-[[admin:​basics:​rawdata:​updates|Updates]] | 
-[[admin:​basics:​rawdata:​creation|Creating Raw Data Files]] | 
-**[[admin:​basics:​rawdata:​implementation|Implementation Details]]** 
- 
- 
----- 
-==== Implementation Details: Delimited Files ==== 
- 
-[[admin:​basics:​rawdata:​implementation:​fixed|Fixed-length]] | 
-**[[admin:​basics:​rawdata:​implementation:​delimited|Delimited]]** | 
-[[admin:​basics:​rawdata:​implementation:​ost|Omnidex Standalone Tables]] | 
-[[admin:​basics:​rawdata:​implementation:​hdfs|Hadoop Distributed File System]] ​ 
- 
----- 
- 
-=== Environment === 
- 
-The Omnidex Environment File has specific syntax when accessing raw data files.  ​ 
- 
-== Declaring Databases for Raw Data Files == 
- 
-Databases in Omnidex are of a particular type, such as Oracle, SQL Server, MySQL or ODBC.  A database that accesses raw data file has its own type: FILE.  All tables within this database must be raw data files, though they can be a mixture of the types of raw data files supported by Omnidex. ​ This includes fixed-length files, delimited files, Omnidex Standalone Tables and Hadoop Distributed File System (HDFS) files. 
- 
-<​code>​ 
-create database ​      "​SIMPLE"​ 
- ​type ​                FILE 
- ​index_directory ​     "​idx"​ 
- ​in ​                  "​simple.xml";​ 
-</​code>​ 
- 
- 
-== Declaring Tables for Delimited Files == 
- 
-Tables must point to the delimited file, and the file must match the record layout specified in the CREATE TABLE statement.  ​ 
- 
-In the [[dev:​sql:​statements:​create_table:​home|CREATE TABLE]] statement, the [[admin:​basics:​rawdata:​delimited:​options|OPTIONS clause]] is used to identify this as a delimited file and indicate which delimiters to use.  The DELIMITED option indicates that this is a delimited file.  The remaining options govern the specific delimiters and behavior to use when parsing the file.  
- 
-In the CREATE TABLE statement, the PHYSICAL clause is used to point to the physical location of the raw data file.  This PHYSICAL clause can contain a relative path name (relative to the location of the Omnidex Environment File) such as "​dat/​states.dat",​ or an absolute path name such as "​d:/​class/​lab1/​dat/​states.dat"​. ​ This PHYSICAL clause can also contain wildcard as described below, and can also reference [[appendix:​reference:​envvar|environment variables]] using a special syntax. 
- 
-<code sql> 
-create table          "​STATES"​ 
- ​options ​             "​DELIMITED"​ 
- ​physical ​            "​dat/​states.csv"​ 
- ... 
-</​code>​ 
- 
-In the example above, a single file was used as the source of data for a table. ​ It is also possible for multiple files to be used as the source of data for a table. ​ As long as the files all share the same record layout, they will all be processed when reading the table. Filesets can be declared as a comma-separated list of files, or they can be declared using wildcards in the filename. ​ In this example, three files are declared individually in the PHYSICAL clause: 
- 
-<code sql> 
-create table          "​STATES"​ 
- ​options ​             "​DELIMITED"​ 
- ​physical ​            "​c:/​class/​lab1/​dat/​states1.csv, ​ 
-                       ​c:/​class/​lab1/​dat/​states2.csv, ​ 
-                       ​d:/​class/​lab1/​dat/​states3.csv"​ 
- ... 
-</​code>​ 
- 
-In this second example, wildcards are used to declare these files: 
- 
-<code sql> 
-create table          "​STATES"​ 
- ​options ​             "​DELIMITED"​ 
- ​physical ​            "​c:/​class/​lab1/​dat/​states*.csv, ​ 
-                       ​d:/​class/​lab1/​dat/​states*.csv"​ 
- ... 
-</​code>​ 
- 
-Files can reside in multiple directories and in multiple drives or volumes to allow a table to span multiple storage devices. ​ Files may also reside on a Storage Area Network (SAN); in fact, this is one of the most common implementations of Omnidex. ​ Files may also reside on simple mapped drives; however, users should expect performance degradation to occur in this scenario. ​ 
- 
-Wildcards provide a great flexibility since they allow more data to be added to a table by simply moving another file into place. ​ Care should be taken with this approach, though, since the table must be reindexed as soon as new data is in place. 
- 
-== Options == 
- 
-The OPTIONS clause of the CREATE TABLE statement is used to specify the column and record delimiters and other behavior or delimited files. ​ The following options are supported: 
- 
-== COLUMN and RECORD == 
- 
-  COLUMN='​c'​ or COLUMN='​cc'​ 
-  RECORD='​c'​ or RECORD='​cc'​ 
- 
-The COLUMN option indicates the delimiter used to separate columns in a row.  The RECORD option indicates the delimiter used to separate rows in a file.  Unprintable characters can be used as well, and are specified using the tokens described below: 
- 
-^ Character ^ Description ​         ^ 
-| \a        | alert                | 
-| \b        | bell                 | 
-| \f        | formfeed ​            | 
-| \n        | linefeed ​            | 
-| \r        | carriage-return ​     | 
-| \t        | horizontal tab       | 
-| \v        | vertical tab         | 
-| %%\\%% ​   | backslash ​           | 
-| \' ​       | single-quote ​        | 
-| \nnn      | octal value          | 
-  ​ 
-The default column separator is a tab (eg. COLUMN='​\t'​). ​ The default record separator is a combination of carriage return and linefeed for Microsoft Windows servers (eg. RECORD='​\r\n'​),​ and a linefeed for UNIX servers (eg. RECORD='​\n'​). 
- 
-== QUOTES === 
- 
-  QUOTES 
- 
-Some delimited files will quote the content of some or all of the columns. ​ This insures that delimiter characters found in the data are not treated as actual delimiters. ​ For example, the column "​William Smith, Attorney at Law" is often quoted in a comma-delimited file so that the embedded comma is not treated as a delimiter. ​ In these cases, use the QUOTES option to interpret quotation marks as having this purpose, rather than being part of the data.  Quotes will be considered part of the data by default. ​ 
- 
-In this example, the textual data is quoted to insure that delimiter characters in the data are not treated as column or record delimiters: 
- 
-^Column\\ ​ Datatype ​ ^ID\\  INTEGER ​ ^COMPANY\\ ​ STRING(31) ​ ^ 
-^Row 1      |1,"​Mabel'​s Famous Diner" ​           || 
-^Row 2      |2,"​William Smith, Attorney at Law" ​ || 
- 
-== ESCAPE === 
- 
-  ESCAPE='​c'​ 
- 
-As an alternative to quoting, delimited files may use an escape character to indicate that the subsequent character should not be considered a delimiter, but rather is part of the data.  Rather than quoting the data, an escape character precedes every occurrence of the delimiter in the data itself. ​ (Ironically,​ if the escape character itself exists in the data, then it too must be escaped using its own character.) ​ Escaping may be turned off using the OFF setting. ​ In this example, the default escape character of \ is used prevent commas, apostrophes and quotes from being considered delimiters: 
- 
-^Column\\ ​ Datatype ​ ^ID\\  INTEGER ​ ^COMPANY\\ ​ STRING(31) ​ ^ 
-^Row 1      |1,​Mabel\'​s \"​Famous\"​ Diner        || 
-^Row 2      |2,William Smith\, Attorney at Law  || 
- 
-== HEADER == 
- 
-  HEADER 
- 
-The HEADER option indicates that the first row of the file contains column names rather than data and should be ignored when reading the table. 
- 
-== Record Layouts == 
- 
-The record layout described in the CREATE TABLE statement must exactly match the order of columns in the data file.  Care must also be taken with binary columns to insure that the character content in the data file can be legitimately converted to the binary datatype declared in the table. ​ If these record layouts do not match, Omnidex will have problems reading the data from the delimited file.  ​ 
- 
-In the CREATE TABLE statement, the record layout is specified using the COLUMN clause. ​ The datatypes and lengths for these columns can be nearly any datatype supported by Omnidex. ​ The only exceptions are the VARCHAR and CLOB datatypes, as these require that the underlying data also include stored data lengths. ​ With raw data files, use STRING and CHARACTER datatypes instead. 
- 
-<code sql> 
-create table          "​STATES"​ 
- ​options ​             "​DELIMITED COLUMN=','​ RECORD='​\r\n'"​ 
- ​physical ​            "​dat/​states.dat"​ 
- ( 
-  "​STATE" ​            ​CHARACTER(2), ​               ​ 
-  "​DESCRIPTION" ​      ​STRING(31), ​                 
-  "​STATE_CODE" ​       CHARACTER(2), ​               ​ 
-  "​REGION" ​           CHARACTER(2), ​               ​ 
-  "​COUNTRY" ​          ​CHARACTER(2), ​               ​ 
-  "​TAX_RATE" ​         FLOAT                        
- ) 
- ​in ​                  "​simple.xml";​ 
-</​code>​ 
- 
-Most raw data files are accompanied by some kind of record layout that can be used to construct the CREATE TABLE statement. ​ For those that do not, the [[programs:​odxsql:​commands:​dump_delimited|DUMP DELIMITED]] command in OdxSQL can be helpful. ​ This command will dump each line of the file in hex, honoring the line delimiters specified.  ​ 
- 
-<​code>​ 
-> dump delimited states.csv 
- 
-Delimited file dump for states.csv 
- 
-Record delimiter: \r\n 
- 
-states.csv is 1.6K 
- 
-Next, First or Quit: 
-Filename: states.csv ​ Record: 2  Offset: 0 
-00000-00015: ​  ​414b2c41 6c61736b 612c3032 2c50432c ​    ​AK,​Alaska,​02,​PC,​ 
-00016-00028: ​  ​55532c30 2e303030 3030300d 0a           ​US,​0.000000.. 
-Next, First or Quit: 
-Filename: states.csv ​ Record: 4  Offset: 29 
-00000-00015: ​  ​414c2c41 6c616261 6d612c30 312c4553 ​    ​AL,​Alabama,​01,​ES 
-00016-00029: ​  ​2c55532c 342e3030 30303030 0d0a         ,​US,​4.000000.. 
-Next, First or Quit: 
-Filename: states.csv ​ Record: 6  Offset: 59 
-00000-00015: ​  ​41522c41 726b616e 7361732c 30352c57 ​    ​AR,​Arkansas,​05,​W 
-00016-00030: ​  ​532c5553 2c342e36 32353030 300d0a ​      ​S,​US,​4.625000.. 
-</​code>​ 
- 
-\\ 
- 
-Note that if an Offset Index exists for this file, the options recorded in the Offset Index will be used rather than prompting for options, and the information from the Offset Index is displayed. 
- 
- 
-Omnidex cannot verify that the record layouts exactly match, so it is always wise to retrieve a few rows and visually inspect that the column definition and the data file line up properly. 
- 
-=== Exporting Fixed-length Data Files === 
- 
-The Omnidex EXPORT statement can be used to create fixed-length data files from another Omnidex environment. ​ By default, the EXPORT statement will create a fixed-length data file.  To create a delimited file, use the same options as used in the CREATE TABLE statement described above. 
- 
-== Example 1: Export of a table == 
- 
-This example exports all of the columns and rows from a table. 
- 
-<​code>​ 
-export ​       (select ​       * 
-                 ​from ​       INDIVIDUALS) 
-  to          individuals.csv 
-  with        DELIMITED, COLUMN=','​ RECORD='​\r\n'​ DELETE; 
-</​code>​ 
- 
-=====  ===== 
- 
-**[[admin:​basics:​rawdata:​creation|Prev]]** 
- 
-====== Additional Resources ====== 
- 
-See also:  
- 
-{{page>:​admin:​basics:​see_also&​nofooter&​noeditbtn}} 
- 
-{{page>:​bottom_add&​nofooter&​noeditbtn}} 
 
Back to top
admin/basics/rawdata/implementation/delimited.1299621304.txt.gz ยท Last modified: 2012/10/26 14:57 (external edit)