variables position

Is there a way to check if the variable is in the right position? I do not want to reorder the position of the columns. If table a is correct. Then, table b with 'site' column in the first column and 'subjid' column in the second will be incorrect. How do I flag the incorrect position of the variables or send the incorrect dataset through pass/fail port? Is there a component that I can check variables' positions? Related question, if there are only supposed to have two variables(subjid and site). Then, how can I flag the dataset (such as send the whole dataset to either fail or pass port)when there are more than two variables or less than two? Thank you for reading this long questions!

table a
subjid site
1234 a
5678 b

table b
site subjid
a 1234
b 5678

Answers 8
PC
PC 2018-07-03

I'm not sure that there's a component that can do that, but you can do it using PilotScript.

There are a couple of ways to read the property list in PilotScript. First you can iterete over the properties using:

NumProperties()

To tell you how may columns/properties/variables you have in a given record and:

IthPropertyName()

To get the name. The alternative is to simply ask for all the property names at once using:

RPropertyNames('.*');

That argument there is a regular expression which, in this case, asks for anything. Fortunately, that gives you the columns in the order they are found.

You then need to store that "correct order" and store it. I assume you'd like to take that correct order from the first record then test all further records? If so, I would share an example with you but I don't appear to be able to upload anything anymore. The old forum was way better than this!

PC
PC 2018-07-03

Rather than try and write the complete explanation in this rather limited editor, I've written a blog about how you should achieve this. It should be found at http://finiaconsulting.com/blog/2018/07/property-ordering-pilotscript/ 
I hope that helps.

CC
CC 2018-07-03

Hi Phil, thank you for taking the time to write this very detail solution for this issue. I was able to read the blog from my phone but was not able to download the protocol because my work pc is preventing me from it. I will check it out with my personal pc later. Another question came up when I was reading the blog. The raw excel file that I'm reading into pp has properties that contains space(ex. 'site id', 'collection time'). Would you know how to eliminate the space between words for properties that are in the dataset before running your protocol?

LB
LB 2018-07-03

There may be a simpler method... The following code can be placed into a custom manipulator. It will fail all records that do not have the same number and order of properties as the first record.                                             -----------------

if #columnOrder is not defined then
    #columnOrder:=rpropertynames('.*');
    contract('|',#columnOrder);
    #pass:=true;
else
    #curColumnOrder:=rpropertynames('.*');
    contract('|',#curColumnOrder);
    if #curColumnOrder eq #ColumnOrder then
        #pass:=true;
    else
        #pass:=false;
    end if;
end if;

P.S. if you add a parameter to your Custom Filter component called 'Ignore Spaces' and make it a boolean, then this version will strip the spaces from the names before doing the matching.

if #columnOrder is not defined then
    #columnOrder:=rpropertynames('.*');
    contract('|',#columnOrder);
    if Parameter('Ignore Spaces') is defined and Parameter('Ignore Spaces') then
        strreplace(#curColumnOrder,' ','');
    end if;
    #pass:=true;
else
    #curColumnOrder:=rpropertynames('.*');
    contract('|',#curColumnOrder);
    if Parameter('Ignore Spaces') is defined and Parameter('Ignore Spaces') then
        strreplace(#curColumnOrder,' ','');
    end if;
    if #curColumnOrder eq #ColumnOrder then
        #pass:=true;
    else
        #pass:=false;
    end if;
end if;

PC
PC 2018-07-04

That's quite neat - rather than comparing property names as an array, collapse them to a delimited string and compare those. The addition to handle spaces isn't quite right though. The lines which read:

 strreplace(#curColumnOrder,' ','');

Will throw an error. I think it should actually read as:

#curColumnOrder := strreplace(#curColumnOrder,' ','');

Plus, the first one should use #columnOrder rather than #curColumnOrder I think. As for the example protocol, if you can't read it from my website, I'm not sure what to do - I don't appear to be able to attach anything to this new, "improved" forum. Ah, I can upload a zip but can't upload XML. Weird. It's attached here.

comment imagecomment image
PC
PC 2018-07-04

Oh, and I've not added anything to support removing spaces to that attached example.

CC
CC 2018-07-04

Hi Phil, Leo, Thank you for taking the time for helping me! I've tried both protocols and both worked! I did make changes in Leo's protocol according to Phil's suggestion. I'm still fairly new to Pipeline Pilot so what you two had came up with is really great . I can incorporate this into the protocol that I'm currently working on which is QCing datasets.

CC
CC 2018-07-06

Hi Phil, Leo, I tested out the protocols you two have worked on and they worked by themselves. But, when I implemented them into my protocol. It stopped working. Dataset just went to the fail port. But, it should go to pass port.  I have used the same files for all three protocols. I tested out the two protocols you two have provided individually.
update: I copied part of protocol into your protocol then it worked. I'm not sure why it wasn't working if it's the other way around. Also, is there way to find out what property is missing or extra when the dataset fail the check?                                                                                                                                     

comment imagecomment imagecomment imagecomment imagecomment imagecomment imagecomment imagecomment image