Removing duplicate records from .Xdf file

279 views Asked by At

I would like to remove the duplicate records from my large .xdf file trans.xdf. Here is the file details:

File name: /poc/revor/data/trans.xdf
Number of observations: 1000000000
Number of variables: 5
Number of blocks: 40
Compression type: zlib
Variable information:
Var 1: CARD_ID, Type: character
Var 2: SE_NO, Type: character
Var 3: r12m_cv, Type: numeric, Low/High: (-2348.7600, 40587.3900)
Var 4: r12m_roc, Type: numeric, Low/High: (0.0000, 231.0000)
Var 5: PROD_GRP_CD, Type: character

Also below is the sample data of the file:

CARD_ID SE_NO   r12m_cv r12m_roc    PROD_GRP_CD
900000999000000000          1045815024  110 1   1
900000999000000000          1052487253  247.52  2   1
900000999000000000          9999999999  38.72   1   1
900000999000000000          1090389768  1679.96 16  1
900000999000000000          1091226035  0   1   1
900000999000000000          1091241208  538.68  4   1
900000999000000000          9999999999  83  1   1
900000999000000000          1091468041  148.4   3   1
900000999000000000          1092640358  3.13    1   1
900000999000000000          1093468692  546.29  1   1

I have tried using rxDataStep function to use its transform parameter to call to unique() function over the .xdf file. Below is the code for the same:

uniq_dat <- function( dataList )
{
    datalist <- unique(datalist)
    return(datalist)
}

rxDataStepXdf(inFile = "/poc/revor/data/trans.xdf",outFile = "/poc/revor/data/trans.xdf",transformFunc = uniq_dat,overwrite = TRUE) 

But was getting below error:

Error in unique(datalist) : object 'datalist' not found

Error in transformation function: Error in unique(datalist) : object 'datalist' not found

Error in rxCall("RxDataStep", params) :

So anybody could point out the mistake that I am doing here or if there is a better way to remove the duplicate records from the .Xdf file. I am avoiding loading the data into inmemory dataframe as the data is pretty huge.

I am running the above code in Revolution R Environment over HDFS.

If the same can be obtained by any other approach then the example for the same would be appreciated.

Thanks for the help in advance :)

Cheers,

Amit

1

There are 1 answers

0
Selcuk Can On

you can remove the duplicate values providing removeDupKeys=TRUE parameter for rxSort() function. For example for your case:

XdfFilePath <- file.path("<your file's fully qualified path>/trans.xdf")
rxSort(inData = XdfFilePath,sortByVars=c("CARD_ID","SE_NO","r12m_cv","r12m_roc","PROD_GRP_CD"), removeDupKeys=TRUE) 

if you want to remove duplicate records based on a specific key column, for example, based on SE_NO column set the key value as sortByVars="SE_NO"