loadTextEx
Syntax
loadTextEx(dbHandle, tableName, partitionColumns, filename, [delimiter],
[schema], [skipRows=0], [transform])
Arguments
dbHandle the distributed database where the imported data will be saved. The database can be either in the distributed file system or an in-memory database.
tableName a string indicating the name of the table with the imported data.
partitionColumns a string scalar/vector indicating partitioning column(s). For sequential partition, partitionColumns is "" as it doesn't need a partitioning column. For composite partition, partitionColumns is a string vector.
filename the input text file name with its absolute path.
delimiter a STRING scalar indicating the table column separator. It can consist of one or more characters, with the default being a comma (',').
schema a table. For details, see the schema parameter of loadText.
skipRows is an integer between 0 and 1024 indicating the rows in the beginning of the text file to be ignored. The default value is 0.
transform is a unary function. The parameter of the function must be a table.
Details
Load a text file into DolphinDB database.
If dbHandle is specified and is not empty string "": load a text file to a distributed database. The result is a table object with metadata of the table.
If dbHandle is empty string "" or unspecified: load a text file as a
partitioned in-memory table. For this usage, when we define dbHandle with
function database
, the parameter directory must also be the empty
string "" or unspecified.
If parameter transform is specified, we need to first execute createPartitionedTable and then load the data. The system will apply the function specified in parameter transform and then save the results into the database.
Function loadTextEx
and function loadText share many common features, such as whether
the first row is treated as the header, how the data types of columns are
determined, how the system adjusts illegal column names, etc. For more details,
please refer to function loadText.
Examples
n=10000
ID=rand(100, n)
dates=2017.08.07..2017.08.11
date=rand(dates, n)
vol=rand(1..10 join int(), n)
t=table(ID, date, vol)
saveText(t, "C:/DolphinDB/Data/t.txt");
db = database(directory="dfs://rangedb", partitionType=RANGE, partitionScheme=0 51 101)
pt=loadTextEx(dbHandle=db,tableName=`pt, partitionColumns=`ID, filename="/home/DolphinDB/Data/t.txt");
db = database("dfs://rangedb")
pt = loadTable(db, `pt);
Example: Load t.txt into a DFS database with a composite domain.
dbDate = database(directory="", partitionType=VALUE, partitionScheme=2017.08.07..2017.08.11)
dbID=database(directory="", partitionType=RANGE, partitionScheme=0 51 101)
db = database(directory="dfs://compoDB", partitionType=COMPO, partitionScheme=[dbDate, dbID])
pt = loadTextEx(dbHandle=db,tableName=`pt, partitionColumns=`date`ID, filename="/home/DolphinDB/Data/t.txt");
Example: Load t.txt into a partitioned in-memory table with value domain on date.
db = database(directory="", partitionType=VALUE, partitionScheme=2017.08.07..2017.08.11)
pt = db.loadTextEx(tableName="", partitionColumns=`date, filename="/home/DolphinDB/Data/t.txt");
pt.sortBy!(`ID`x);
dbDate = database(directory="", partitionType=VALUE, partitionScheme=2017.08.07..2017.08.11)
dbID=database(directory="", partitionType=RANGE, partitionScheme=0 51 101)
db = database(directory="dfs://compoDB", partitionType=COMPO, partitionScheme=[dbDate, dbID]);
pt=db.createPartitionedTable(table=t, tableName=`pt, partitionColumns=`date`ID)
pt=loadTextEx(dbHandle=db, tableName=`pt, partitionColumns=`date`ID, filename="/home/DolphinDB/Data/t.txt", transform=nullFill!{,0});