textChunkDS#
- swordfish.function.textChunkDS()#
To load an extremely large text file into DolphinDB database, we can first use function textChunkDS to divide the text file into multiple data sources with the size of each data source specified by chunkSize, then use function mr to load data.
When loading data files in DolphinDB, a random sample of the data is analyzed to determine the data type for each column. However, this sampling method does not always accurately determine the column types. It is recommend to use the extractTextSchema function to check the schema of the input file before loading the data. You can specify the intended data type for each column in the “type” field of the schema. For date or time columns particularly, if DolphinDB does not recognize the correct data types, you need to set the temporal type in the “type” field, and provide the date/time format string (e.g. “MM/dd/yyyy”) in the “format” field. Refer to Parsing and Format of Temporal Variables for temproal formats in DolphinDB.
- Parameters:
filename (Constant) – A string indicating the input text file name with its absolute path. Currently only .csv files are supported.
chunkSize (Constant) – A positive integer indicating the size of a file chunk (in MB). The upper limit is max(maxMemSize / workerNum, 2048MB), representing the greater of the maximum available memory per worker or 2048MB.
delimiter (Constant, optional) – A STRING scalar indicating the table column separator, by default DFLT. It can consist of one or more characters, with the default being a comma (‘,’).
schema (Constant, optional) –
A table, by default DFLT. It can have the following columns, among which “name” and “type” columns are required.
Column
Data Type
Description
name
STRING scalar
column name
type
STRING scalar
data type
format
STRING scalar
the format of temporal columns
col
INT scalar or vector
the columns to be loaded
skipRows (Constant, optional) – An integer between 0 and 1024 indicating the rows in the beginning of the text file to be ignored, by default DFLT.
arrayDelimiter (Constant, optional) – A single character indicating the delimiter for columns holding the array vectors in the file, by default DFLT. Since the array vectors cannot be recognized automatically, you must use the schema parameter to update the data type of the type column with the corresponding array vector data type before import.
containHeader (Constant, optional) – A Boolean value indicating whether the file contains a header row, by default DFLT. See loadText for the detailed determining rules.
arrayMarker (Constant, optional) –
A string containing 2 characters or a CHAR pair, by default DFLT. These two characters represent the identifiers for the left and right boundaries of an array vector.
It cannot contain spaces, tabs (\t), or newline characters (\t or \n).
It cannot contain digits or letters.
If one is a double quote (“), the other must also be a double quote.
If the identifier is ‘, “, or \, a backslash ( \ ) escape character should be used as appropriate. For example, arrayMarker=”\”\””.
If delimiter specifies a single character, arrayMarker cannot contain the same character.
If delimiter specifies multiple characters, the left boundary of arrayMarker cannot be the same as the first character of delimiter.