1

1.table1:

([ID:`1`2`3]Name:`A`B`C;Client:`P`Q`S;ClientType:`QW`DS`WW;NameType:`jj`ll`oo;Basket:`QD`IO`LK;Sepal:5.1 4.5 23.5;Length:2 34 6;Species:`setosa`setosa`setosa)

2.write a simple function to select table1 data

api:{[Params]
   if [Params~();Params:()!()];
   defaultCols:`ID`Name`Client!(`ID`Name`Client);
if[`extraCols in key Params;
 defaultCols:defaultCols,Params[`extraCols]!Params `extraCols];
: ?[ select  from table1;();0b;defaultCols];
}

3.test api[(enlist[`extraCols]!enlist(`Species`Length))]

 ID Name  Client    Species  Length
 1    A     B        setosa    2
 2    B     Q        setosa    34
 3    C     S        setosa    6

When I used one Params to test:api[(enlist[`extraCols]!enlist(`Species))] But result type error.In my limited experience with this . Could you please help me understand this . thanks.

And i want to get below result and how to change my api

ID Name  Client    Species
1    A     B       setosa
2    B     Q       setosa
3    C     S       setosa
3
  • Please format code, description properly. Also the image is missing Commented May 25, 2018 at 5:28
  • reformat code ... Commented May 25, 2018 at 6:19
  • If i need to change function api? Commented May 25, 2018 at 6:50

1 Answer 1

1

I imagine the type error is coming from the statement in your if condition:

if[`extraCols in key Params;
 defaultCols:defaultCols,Params[`extraCols]!Params `extraCols]

You create a dictionary Params[`extraCols]!Params `extraCols

If there is only one element in Params`extraCols then you would need to enlist this when creating the dictionary to avoid such a type error, i.e:

enlist[Params`extraCols]!enlist Params`extraCols

It is also worthwhile putting a breakpoint inside your function to check the type of your arguments and give yourself an opportunity to debug. You should then be able to see that Params`extraCols is the atom `Species (should have type -11h) rather than a list.

Sign up to request clarification or add additional context in comments.

2 Comments

Use api[(enlist[Species]!enlistSpecies)] still return defaultCols and no `Species col showing
You should update your api function as I have mentioned above, and call it with the same argument as before (api[(enlist[`extraCols]!enlist(`Species))]).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.