Posted: Thu Aug 05, 2010 3:52 am Post subject: Reg:Splitting the files
Newbie
Joined: 02 Aug 2010 Posts: 3
I have a file of 4mb which has 10000 records i need to split the file into multiple files based on the 500 records.every 500 records it generates a new file with new file name.
I took fileinput node for input i select properties
DELIMETER:Custom delimeter;
CUSTOM DELIMETER:0A;
DELIMETER TYPE:Postfix;
and i took computenode and fileoutput node.
Compute node:
DECLARE SIZE SHARED INTEGER 5;
DECLARE SEQNO SHARED INTEGER 0;
CREATE COMPUTE MODULE LargeFileHandling_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
DECLARE CNT INTEGER 1;
DECLARE FNAME CHARACTER;
SET Environment.Variable.OutDirName='C:\\Output';
SET Environment.Variable.FileName=InputLocalEnvironment.File.Name;
SET Environment.Variable.DirName=InputLocalEnvironment.File.Directory;
SET Environment.Variable.FilPos=POSITION('.' IN Environment.Variable.FileName REPEAT 3);
SET Environment.Variable.FirstFile=SUBSTRING(Environment.Variable.FileName FROM 1 FOR Environment.Variable.FilPos);
SET Environment.Variable.SecondFile=SUBSTRING(Environment.Variable.FileName FROM Environment.Variable.FilPos+2);
SET Environment.Variable.Seqno=SUBSTRING(Environment.Variable.FileName FROM Environment.Variable.FilPos+1 for 1);
IF SEQNO=0 THEN
SET SEQNO=Environment.Variable.Seqno;
END IF;
SET Environment.Variable.CastSeqNo=CAST(SEQNO AS CHARACTER);
SET FNAME=Environment.Variable.FirstFile||Environment.Variable.CastSeqNo||Environment.Variable.SecondFile;
IF InputLocalEnvironment.File.IsEmpty=FALSE THEN
IF InputLocalEnvironment.File.Record<=SIZE THEN
SET OutputLocalEnvironment.Destination.File.Directory = Environment.Variable.OutDirName;
SET OutputLocalEnvironment.Destination.File.Name = FNAME;
SET OutputRoot = InputRoot;
ELSE
SET OutputLocalEnvironment.Destination.File.Directory = Environment.Variable.OutDirName;
SET OutputLocalEnvironment.Destination.File.Name = FNAME;
PROPAGATE TO TERMINAL 'out1' DELETE NONE;
SET SIZE=SIZE+5;
SET SEQNO=SEQNO+1;
END IF;
END IF;
RETURN TRUE;
END;
but it splits multiple files problem is it generates after the records complted also it generating files with white spaces.
Posted: Thu Aug 05, 2010 5:43 am Post subject: Re: Reg:Splitting the files
Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
ravikumarlankalapalli wrote:
but it splits multiple files problem is it generates after the records complted also it generating files with white spaces.
yes...expected..as you are splitting a file so blank lines or white spaces are expected.
and you haven't put that logic in your current existing code though.
you can check for the empty line and shrink it...using ESQL or Java _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum