MAPDELIMITEDEXTRACTOR
Extracts data with a delimiter character and other optional arguments, returning a single VMap value.
Syntax
MAPDELIMITEDEXTRACTOR (record-value [ USING PARAMETERS param=value[,...] ])
Arguments
record-value- String containing a JSON or delimited format record on which to apply the expression.
Parameters
delimiter- Single delimiter character.
Default:
| header_names- Delimiter-separated list of column header names.
Default:
ucoln, wherenis the column offset number, starting with0for the first column. trim- Boolean, trim white space from header names and field values.
Default:
true treat_empty_val_as_null- Boolean, set empty fields to
NULLrather than an empty string ('').Default:
true
Examples
These examples use a short set of delimited data:
Name|CITY|New city|State|zip
Tom|BOSTON|boston|MA|01
Eric|Burlington|BURLINGTON|MA|02
Jamie|cambridge|CAMBRIDGE|MA|08
To begin, save this data as delim.dat.
-
Create a flex table,
dflex:=> CREATE FLEX TABLE dflex(); CREATE TABLE -
Use COPY to load the
delim.datfile. Use the flex tablesfdelimitedparserwith theheader='false'option:=> COPY dflex FROM '/home/release/kmm/flextables/delim.dat' parser fdelimitedparser(header='false'); Rows Loaded ------------- 4 (1 row) -
Create a columnar table,
dtab, with an identityidcolumn, adelimcolumn, and avmapcolumn to hold a VMap:=> CREATE TABLE dtab (id IDENTITY(1,1), delim varchar(128), vmap long varbinary(512)); CREATE TABLE -
Use COPY to load the
delim.datfile into thedtabtable. MAPDELIMITEDEXTRACTOR uses theheader_namesparameter to specify a header row for the sample data, along withdelimiter '!':=> COPY dtab(delim, vmap AS MAPDELIMITEDEXTRACTOR (delim USING PARAMETERS header_names='Name|CITY|New City|State|Zip')) FROM '/home/dbadmin/data/delim.dat' DELIMITER '!'; Rows Loaded ------------- 4 (1 row) -
Use MAPTOSTRING for the flex table
dflexto view the__raw__column contents. Notice the default header names in use (ucol0–ucol4), since you specifiedheader='false'when you loaded the flex table:=> SELECT MAPTOSTRING(__raw__) FROM dflex limit 10; maptostring ------------------------------------------------------------------------------------- { "ucol0" : "Jamie", "ucol1" : "cambridge", "ucol2" : "CAMBRIDGE", "ucol3" : "MA", "ucol4" : "08" } { "ucol0" : "Name", "ucol1" : "CITY", "ucol2" : "New city", "ucol3" : "State", "ucol4" : "zip" } { "ucol0" : "Tom", "ucol1" : "BOSTON", "ucol2" : "boston", "ucol3" : "MA", "ucol4" : "01" } { "ucol0" : "Eric", "ucol1" : "Burlington", "ucol2" : "BURLINGTON", "ucol3" : "MA", "ucol4" : "02" } (4 rows) -
Use MAPTOSTRING again, this time with the
dtabtable'svmapcolumn. Compare the results of this output to those for the flex table. Note that MAPTOSTRING returns theheader_nameparameter values you specified when you loaded the data:=> SELECT MAPTOSTRING(vmap) FROM dtab; maptostring ------------------------------------------------------------------------------------------------------------------------ { "CITY" : "CITY", "Name" : "Name", "New City" : "New city", "State" : "State", "Zip" : "zip" } { "CITY" : "BOSTON", "Name" : "Tom", "New City" : "boston", "State" : "MA", "Zip" : "02121" } { "CITY" : "Burlington", "Name" : "Eric", "New City" : "BURLINGTON", "State" : "MA", "Zip" : "02482" } { "CITY" : "cambridge", "Name" : "Jamie", "New City" : "CAMBRIDGE", "State" : "MA", "Zip" : "02811" } (4 rows) -
Query the
delimcolumn to view the contents differently:=> SELECT delim FROM dtab; delim ------------------------------------- Name|CITY|New city|State|zip Tom|BOSTON|boston|MA|02121 Eric|Burlington|BURLINGTON|MA|02482 Jamie|cambridge|CAMBRIDGE|MA|02811 (4 rows)