Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit for verbose.q #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alvin-c-shih
Copy link
Contributor

THE FOLLOWING DISCLAIMER APPLIES TO ALL SOFTWARE CODE AND OTHER MATERIALS CONTRIBUTED IN CONNECTION WITH THIS SOFTWARE:
THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.
ONLY THE SOFTWARE CODE AND OTHER MATERIALS CONTRIBUTED IN CONNECTION WITH THIS SOFTWARE, IF ANY, THAT ARE ATTACHED TO (OR OTHERWISE ACCOMPANY) THIS SUBMISSION (AND ORDINARY COURSE CONTRIBUTIONS OF FUTURES PATCHES THERETO) ARE TO BE CONSIDERED A CONTRIBUTION. NO OTHER SOFTWARE CODE OR MATERIALS ARE A CONTRIBUTION.

// @param x String
.finos.verbose.escapeID:{conv:-11h=type x;$[conv;`$;::]ssr[.h.hug[.Q.an except "_"]$[conv;string x;x];"%";"_"]};

.finos.verbose.numToOrdinalString: ((1 + til 11)!("First"; "Second"; "Third"; "Fourth"; "Fifth"; "Sixth"; "Seventh"; "Eighth"; "Ninth"; "Tenth";"Eleventh"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the goal of having this here? Why does it specifically go from 1 to 11?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

if[100h<>type fun; '"fun must be a lambda"];
if[100h<>type errorHandler; '"errorHandler must be a lambda"];
if[not type[params] within 0 20h; '"params must be a list"];
try[fun;params;errorHandler]};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no global try function yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will put in .finos.errorTrapDot and use that instead.

.finos.verbose.setKeyColNr:{[keycount;table]
if[not type[keycount] in -6 -7h; '"keycount must be an integer"];
if[0>keycount; '"keycount must be nonnegative"];
if[not type[table] in 98 99h; '"2nd argument must be a table"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.Q.qt could be used to check if the object is a table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

];
keycount!table};

//workaround for inability to use table syntax with security.q
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to add security.q as well? If not then this is a stranded comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change it to be the more general term, "parse tree filters".

if[not 10h=type str; '".finos.verbose.sym only works on string argument"];
`$str};

//wrapper to allow xasc in secure gateway (raw xasc may modify table in-place)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"secure gateway" is a stranded reference. Repeated multiple times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also changed to refer to "parse tree filters".

if[not .Q.qt[tbl]; '".finos.verbose.xkey expects a table"];
keyCols xkey tbl};

//wrapper to allow case-insenstive xasc in secure gateway (raw xasc may modify table in-place)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong function name in the comment. Also this function is not really iasc, which is unary, works on a list (can be a table), and returns a list of indices. Therefore the name is confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to xasciuntil someone comes up with a better name.

s:((),sortCols)!{$[x in "sC";(lower;y);y]}'[(0!meta[?[tbl;();0b;{![x;x]}(),sortCols]])[;`t];sortCols];
.finos.verbose.xkey[xk] (0!tbl) iasc ?[tbl;();0b;s]};

//wrapper to allow case-insenstive xdesc in secure gateway (raw xdesc may modify table in-place)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, but with desc instead of asc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to xdesci.

.finos.verbose.xkey[xk] (0!tbl) idesc ?[tbl;();0b;s]};

//wrapper to allow null-ignoring xasc in secure gateway (raw xasc may modify table in-place)
.finos.verbose.nasc:{[sortCols;tbl]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new functionality, not an equivalent of a built-in q operator/function. It might be better to put into a separate file (query.q?) and add a thin wrapper here if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

$[(sd<cd);fun1[sd;min[ed,cd-1]];()],$[(ed>cd-1);fun2[max[sd,cd];ed];()]
};

//by default these are identity, specify the timezone parameter to have these overwritten in setup.q
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the referenced setup.q, these are useless as well as anything that depends on them.

first value flip `nr xasc ![([] constr: constrList; nr: (1 + count constrList) + til count constrList);
enlist (min';(in;(.finos.verbose.collectFields';`constr);enlist pre));
0b;
.istat.FIELDAS[`i;`nr]]};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaked proprietary function name, also other occurrences below.

//@param o symbol list specifying your domain specific ordering
//@param t the table which columns should be rearranged
//
.finos.verbose.fixColumnOrderGEN: {[o;t]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another "screaming" suffix.

keys[t], o inter cols value[t]; // leave keys untouched sort value cols against ordering
98h ~ type t; // if not keyed table
o inter cols t; // sort all cols against ordering
'"invalid branch"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a better error message.

// This function can be used for example to calculate the midprice of and index (weighted set of instruments).
//
.finos.verbose.aggregateFieldValuesAsOf: {[t; k; p; v; colname; binop]
piv: fills .ms.pivot.pvtfw[t; k; p; v; (); ()];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaked proprietary function name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted.

// unkeys a table. It is just a projection of .finos.verbose.xkey setting the first parameter to empty list
.finos.verbose.unkey: .finos.verbose.xkey[()];

.finos.verbose.priv.validateSelectArgs:{[tbl;constr;grp;stat;cnt;ord]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would prefer the params of all the qsql wrappers conform to the traditional t/c/b/a naming; perhaps tbl contr by aggs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are inherited names, but to me stat makes more sense because the a is not necessarily an aggregation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants