-
Notifications
You must be signed in to change notification settings - Fork 16
util.q
This library contains a set of general utility functions.
We define the use of the built-in command line argument -e
to also define if the process is started in debug mode or not. By using -e 1
, this function will return true.
Wraps the built-in system
command to run it with protected execute. If the system
command fails (i.e. the process exits with a non-zero status), this function will throw SystemCallFailedException
. The error will also be logged to the console.
An extended version of the built-in trim
function. As well as removing spaces from the beginning and end of a string, it also removes new line and tab characters.
A null
like function with support for checking empty dictionaries, empty tables and lists will all null elements. Below are some examples of how this function differs to null
:
q) null 1 2 3
000b
q) .util.isEmpty 1 2 3
0b
q)null (`;0N;0Np;0Nf)
1111b
q).util.isEmpty (`;0N;0Np;0Nf)
1b
q) null ()!()
q) .util.isEmpty ()!()
1b
q) null flip `col1`col2!"SS"$\:()
col1 col2
---------
q) .util.isEmpty flip `col1`col2!"SS"$\:()
1b
This function will unenumerate any enumerated columns in an unkeyed table.
This function allows you to rename a column, or columns, in a table. The table should be unkeyed prior to passing into this function.
This function returns the number of rows in root namespace tables. Optionally, you can specify a subset of the tables to return the counts for
This function empties any root namespace table specified.
A standard string find and replace function. This function supports multiple "find" and "replace" values as long as there are an equal number of find and replace values.
q) .util.findAndReplace["a b.c"; " "; "/"]
"a/b.c"
/ Note in this case when replacing multiple characters with the same one,
/ the length of the 'find' and 'replace' argument must be the same
q) .util.findAndReplace["a b.c"; " ."; 2#"/"]
"a/b/c"
q) .util.findAndReplace["a b.c"; " ."; "/,"]
"a/b,c"
A simple wrapper function around the built-in .Q.gc
function to provide logging regarding the amount of memory returned to the Operating System. The change in memory usage is returned.
q) a:til 1000000000
q) delete a from `.
q) .util.gc[]
2019.01.10 10:22:19.290 INFO pid-9258 jas 0 Running garbage collection
2019.01.10 10:22:19.892 INFO pid-9258 jas 0 Garbage collection complete [ Returned to OS (from heap): 8192 MB ] [ Time: 0D00:00:00.601529000 ]
used| 1136
heap| 8589934592
peak| 0
wmax| 0
mmap| 0
mphy| 0
syms| 0
symw| 0
Copyright (C) Sport Trades Ltd 2017 - 2020, John Keys and Jaskirat Rajasansir 2020 - 2024