-
Notifications
You must be signed in to change notification settings - Fork 0
Lua interface for CSV parser
Tarantool supports CSV file input/output. CSV is comma separated values, like this:
package,method,return value
fio,pathjoin,string
csv,load,table
none,",comma in field", and ""quote""
Commas an linebreaks in fields must be in quotes Quotes in fields is repeated two times quote character. You can set delimiter and quote character:
opts.delimiter = ','
opts.quote = '"'Input/output works through readable/writable objects, for example files or sockets. Readable object has method read(N), which returns N or less bytes as string. Writable object has method write(string), which sends string to output.
It's able to iterate over csv file and read line by line.
lua csv.iterate = function(readable[, opts])
Parameters:
readable must be string or object with method read(num) returns string
opts.chunk_size (default 4096). Parser will read by chunk_size symbols
opts.delimiter (default ',').
opts.quote_char (default '"').
opts.skip_head_lines (default 0). Skip header.
--@return iter function, iterator state
Example:
f = require("fio").open("example.txt", { "O_RDONLY"})
for i, tup in csv.iterate(f) do
print(tup[1], tup[2], tup[3])
endOutput:
package method return value
fio pathjoin string
csv load table
none ,comma in field and "quote"
csv.load = function(readable[, opts]) --@brief parse csv and make table --@param opts like in iterate --@return table If csv file has a header, it may be skipped, with option skip_head_lines = 1 (if header is just 1 line)
csv.dump = function(t[, opts, writable]) --@brief dumps tuple or table as csv --@param t is tuple or table --@param writable must be object with method write(string) like file or socket --@param opts.delimiter (default ','). --@param opts.quote_char (default '"'). --@return there is no writable it returns csv as string
Example: f = require("fio").open("dump.csv", { "O_WRONLY", "O_TRUNC" , "O_CREAT"}, 0x1FF) multiline_header = {{'csv example'}, {'3 numbers per string:'}} csv.dump(multiline_header, f) for i=0,14,3 do t = {i, i + 1, i + 2} s = csv.dump(t, f) end dump.csv: csv example 3 numbers per string: 0,1,2 3,4,5 6,7,8 9,10,11 12,13,14
Architecture Specifications
- Server architecture
- Feature specifications
- What's in a good specification
- Functional indexes
- Space _index structure
- R tree index quick start and usage
- LuaJIT
- Vinyl
- SQL
- Testing
- Performance
How To ...?
- ... add new fuzzers
- ... build RPM or Deb package using packpack
- ... calculate memory size
- ... debug core dump of stripped tarantool
- ... debug core from different OS
- ... debug Lua state with GDB
- ... generate new bootstrap snapshot
- ... use Address Sanitizer
- ... collect a coredump
Lua modules
Useful links