Page 1 of 1

Posted: Mon Nov 21, 2011 2:41 pm
by ray.wurlod
Parse the comma-delimited field into separate columns using Transformer stage then use Pivot stage.

Posted: Mon Nov 21, 2011 6:36 pm
by chulett
Split off, linked and moved to the proper forum. :wink:

Another possibility - the technique mentioned in this FAQ post.

Posted: Mon Nov 21, 2011 7:16 pm
by qt_ky
Craig, is it possible to get the "special access" to read that FAQ link?

Posted: Mon Nov 21, 2011 9:00 pm
by chulett
:?

AFAIK, there shouldn't be any "special access" required to read that forum, it's one of the public ones. Is that what it is telling you? Anyone else having an issue?

Eric, can you access it directly from the FAQ forum? It's almost at the bottom of the listed posts there.

Posted: Tue Nov 22, 2011 7:41 am
by qt_ky
chulett wrote::?

Eric, can you access it directly from the FAQ forum? It's almost at the bottom of the listed posts there.
I get this message when clicking any topic within the FAQ forum. Maybe it's just my ID having a problem.

"Sorry, but only users granted special access can read topics in this forum."

Thanks.

Posted: Tue Nov 22, 2011 8:08 am
by chulett
At a high level, the FAQ posting details writing a routine to loop thru the delimited string and building one long string where the 'key' fields are repeated per each pivoted column and then a record terminator (LF or CR/LF) concatenated into the string between each 'record'. What you get is one long record that when read back after writing it out get automagically turned into many records.

With 8.5 you could use the looping capabilites in the transformer for this rather than having to write a routine.

Posted: Tue Nov 22, 2011 8:53 am
by datisaq
You can write a shell script for the dynamic pivot.
I have one you can use this as reference and change accordingly

Code: Select all

#!/usr/bin/ksh

###########################################################################
#
#
# Script Name:  DynamicPivot.sh
#
#
# Input:        DynamicPivot.sh {Input File Absolute Path}
#
#
# Output:       Output File Absolute Path
#		0 - for success
#               Error Description - for failure
#
#
# Description:
#
#               This script gets executed on the command line, with
#               one arguments (see Input). 
#               This will perform the dynamic pivoting mechanism.
#               
#               This will pivot the data of file having two fields 
#		one file which is key field(Not Nullable) and the other field(pivot field)
#		 
#
###########################################################################
###########################################################################
#
# Setting the standard variables
#
###########################################################################

PROG=`basename ${0}`
EXIT_STATUS=0
NOW=`date`

###########################################################################
#
# Check command line arguments
#
###########################################################################

if [ ${#} -ne 2 ]
then
   echo "${NOW} ${PROG}: Invalid parameter list."
   echo "${NOW} ${PROG}: The script needs 2 parameters:"
   echo "${NOW} ${PROG}: Source File Absolute path and Target File Absolute path"
   exit 99;
fi

INPUT_FILE_PATH=${1}
OUTPUT_FILE_PATH=${2}

cat /dev/null > ${OUTPUT_FILE_PATH}

while read i
do
field1=`echo ${i} | awk -F '|' '{print $1;}'`
cnt_fld2=`echo ${i} | awk -F '|' '{print $2;}' | awk -F ',' '{print NF;}'`

j=1
if [ cnt_fld2 -eq 0 ];then
echo ${field1}"|" >> ${OUTPUT_FILE_PATH}
else
while [ j -le ${cnt_fld2} ]
do
echo ${field1}"|"`echo ${i} | awk -F '|' '{print $2;}' | awk -F ',' -v name="$j" '{print $name;}'` >> ${OUTPUT_FILE_PATH}
j=`expr ${j} + 1`
done
fi
done < ${INPUT_FILE_PATH}
exit 0;

Posted: Tue Nov 22, 2011 2:12 pm
by ray.wurlod
You could also convert the commas to value marks (@VM) and write to a hashed file, then read from the hashed file normalized on the multi-valued column.

Posted: Thu Dec 01, 2011 5:16 am
by joycerecacho
Hi Guys,

At the end of the story, I created a routine which counts the number of delimiters in a list and sums one.
Example:
Joyce, John, Mary

Delimiters = 2 (+1) = "3"

Then, I wrote a FOR loop starting from 1 and going until Delimiters quantity.

Inside de Loop, it generates a string and between the values I put 'Char(10)' to break down in lines.
So, in the examples above, the result was: JoyceChar(10)JohnChar(10)Mary(Char10)
If I read this file, would be:

Joyce
John
Mary

It worked very well, was simple and fast.

Thank you guys.

Best Regards,

Posted: Sun Feb 26, 2012 3:25 am
by karthi_gana
Ray,
...the hashed file normalized on the multi-valued column.
i dont understand this context. can you pls explain it?