Skip to content

Commit

Permalink
Closes #1889 - MessageArgs Parameter for CommandMap Functions (#1890)
Browse files Browse the repository at this point in the history
* Updating CommandMap functions to take MessageArgs parameter instead of payload and size.

* Removing old commented out code.

* Removing comment that was missed.

* Updating parsing loop to be parallel.
  • Loading branch information
Ethan-DeBandi99 authored Nov 10, 2022
1 parent f311d1e commit 1e31ee7
Show file tree
Hide file tree
Showing 36 changed files with 202 additions and 298 deletions.
6 changes: 2 additions & 4 deletions src/ArgSortMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ module ArgSortMsg
/* Find the permutation that sorts multiple arrays, treating each array as a
new level of the sorting key.
*/
proc coargsortMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc coargsortMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string;
var msgArgs = parseMessageArgs(payload, argSize);
var algoName = msgArgs.getValueOf("algoName");
var algorithm: SortingAlgorithm = defaultSortAlgorithm;
if algoName != "" {
Expand Down Expand Up @@ -325,10 +324,9 @@ module ArgSortMsg
}

/* argsort takes pdarray and returns an index vector iv which sorts the array */
proc argsortMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc argsortMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var name = msgArgs.getValueOf("name");
var algoName = msgArgs.getValueOf("algoName");
var algorithm: SortingAlgorithm = defaultSortAlgorithm;
Expand Down
12 changes: 4 additions & 8 deletions src/ArraySetopsMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ module ArraySetopsMsg
:type st: borrowed SymTab
:returns: (MsgTuple) response message
*/
proc intersect1dMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc intersect1dMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var isUnique = msgArgs.get("assume_unique").getBoolValue();

var vname = st.nextName();
Expand Down Expand Up @@ -91,10 +90,9 @@ module ArraySetopsMsg
:type st: borrowed SymTab
:returns: (MsgTuple) response message
*/
proc setxor1dMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc setxor1dMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var isUnique = msgArgs.get("assume_unique").getBoolValue();

var vname = st.nextName();
Expand Down Expand Up @@ -146,10 +144,9 @@ module ArraySetopsMsg
:type st: borrowed SymTab
:returns: (MsgTuple) response message
*/
proc setdiff1dMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc setdiff1dMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var isUnique = msgArgs.get("assume_unique").getBoolValue();

var vname = st.nextName();
Expand Down Expand Up @@ -201,10 +198,9 @@ module ArraySetopsMsg
:type st: borrowed SymTab
:returns: (MsgTuple) response message
*/
proc union1dMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc union1dMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);

var vname = st.nextName();

Expand Down
3 changes: 1 addition & 2 deletions src/BroadcastMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module BroadcastMsg {
* full size of the array, optionally applying a permutation
* to return the result in the order of the original array.
*/
proc broadcastMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);
proc broadcastMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
const size = msgArgs.get("size").getIntValue();
// Segments must be an int64 array
const gs = getGenericTypedArrayEntry(msgArgs.getValueOf("segName"), st);
Expand Down
3 changes: 1 addition & 2 deletions src/CastMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ module CastMsg {
private config const logLevel = ServerConfig.logLevel;
const castLogger = new Logger(logLevel);

proc castMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc castMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var msgArgs = parseMessageArgs(payload, argSize);
var name = msgArgs.getValueOf("name");
var objtype = msgArgs.getValueOf("objType");
var targetDtype = msgArgs.getValueOf("targetDtype");
Expand Down
8 changes: 4 additions & 4 deletions src/CommandMap.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module CommandMap {
* construct the FCF type, but there is no way to generate a
* FCF that throws using `func()` today.
*/
proc akMsgSign(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc akMsgSign(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var rep = new MsgTuple("dummy-msg", MsgType.NORMAL);
return rep;
}
Expand All @@ -18,7 +18,7 @@ module CommandMap {
* Just like akMsgSign, but Messages which have a binary return
* require a different signature
*/
proc akBinMsgSign(cmd: string, payload: string, argSize: int, st: borrowed SymTab): bytes throws {
proc akBinMsgSign(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): bytes throws {
var nb = b"\x00";
return nb;
}
Expand Down Expand Up @@ -79,11 +79,11 @@ module CommandMap {
return cm1(0..idx_close-1) + ", " + cm2(1..cm2.size-1);
}

proc executeCommand(cmd: string, args, argSize, st) throws {
proc executeCommand(cmd: string, msgArgs, st) throws {
var repTuple: MsgTuple;
if commandMap.contains(cmd) {
usedModules.add(moduleMap[cmd]);
repTuple = commandMap.getBorrowed(cmd)(cmd, args, argSize, st);
repTuple = commandMap.getBorrowed(cmd)(cmd, msgArgs, st);
} else {
repTuple = new MsgTuple("Unrecognized command: %s".format(cmd), MsgType.ERROR);
}
Expand Down
3 changes: 1 addition & 2 deletions src/ConcatenateMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ module ConcatenateMsg
/* Concatenate a list of arrays together
to form one array
*/
proc concatenateMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab) : MsgTuple throws {
proc concatenateMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab) : MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string;
var msgArgs = parseMessageArgs(payload, argSize);
var objtype = msgArgs.getValueOf("objType");
var mode = msgArgs.getValueOf("mode");
var n = msgArgs.get("nstr").getIntValue(); // number of arrays to sort
Expand Down
3 changes: 1 addition & 2 deletions src/DataFrameIndexingMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@
return "SegArray+%s+created %s+created %s".format(col, st.attrib(s_name), st.attrib(v_name));
}

proc dataframeBatchIndexingMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc dataframeBatchIndexingMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var jsonsize = msgArgs.get("size").getIntValue();

var eleList = msgArgs.get("columns").getList(jsonsize);
Expand Down
15 changes: 5 additions & 10 deletions src/EfuncMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ module EfuncMsg
:throws: `UndefinedSymbolError(name)`
*/

proc efuncMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc efuncMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message; attributes of returned array(s) will be appended to this string
var msgArgs = parseMessageArgs(payload, argSize);
var name = msgArgs.getValueOf("array");
var efunc = msgArgs.getValueOf("func");
var rname = st.nextName();
Expand Down Expand Up @@ -310,11 +309,10 @@ module EfuncMsg
:returns: (MsgTuple)
:throws: `UndefinedSymbolError(name)`
*/
proc efunc3vvMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc efunc3vvMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
// split request into fields
var msgArgs = parseMessageArgs(payload, argSize);
var rname = st.nextName();

var efunc = msgArgs.getValueOf("func");
Expand Down Expand Up @@ -419,10 +417,9 @@ module EfuncMsg
:returns: (MsgTuple)
:throws: `UndefinedSymbolError(name)`
*/
proc efunc3vsMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc efunc3vsMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var efunc = msgArgs.getValueOf("func");
var dtype = str2dtype(msgArgs.getValueOf("dtype"));
var rname = st.nextName();
Expand Down Expand Up @@ -534,10 +531,9 @@ module EfuncMsg
:returns: (MsgTuple)
:throws: `UndefinedSymbolError(name)`
*/
proc efunc3svMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc efunc3svMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var efunc = msgArgs.getValueOf("func");
var dtype = str2dtype(msgArgs.getValueOf("dtype"));
var rname = st.nextName();
Expand Down Expand Up @@ -649,10 +645,9 @@ module EfuncMsg
:returns: (MsgTuple)
:throws: `UndefinedSymbolError(name)`
*/
proc efunc3ssMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc efunc3ssMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
param pn = Reflection.getRoutineName();
var repMsg: string; // response message
var msgArgs = parseMessageArgs(payload, argSize);
var dtype = str2dtype(msgArgs.getValueOf("dtype"));
var efunc = msgArgs.getValueOf("func");
var rname = st.nextName();
Expand Down
3 changes: 1 addition & 2 deletions src/EncodingMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ module EncodingMsg {
private config const logLevel = ServerConfig.logLevel;
const emLogger = new Logger(logLevel);

proc encodeDecodeMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc encodeDecodeMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var repMsg: string;
var msgArgs = parseMessageArgs(payload, argSize);
var encoding = msgArgs.getValueOf("encoding");

var stringsObj = getSegString(msgArgs.getValueOf("obj"), st);
Expand Down
18 changes: 7 additions & 11 deletions src/FileIO.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ module FileIO {
return getFileTypeByMagic(getFirstEightBytesFromFile(filename));
}

proc getFileTypeMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);
proc getFileTypeMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var filename = msgArgs.getValueOf("filename");

// If the filename represents a glob pattern, retrieve the locale 0 filename
Expand Down Expand Up @@ -298,9 +297,7 @@ module FileIO {
}
}

proc lsAnyMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);

proc lsAnyMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
// Retrieve filename from payload
var filename: string = msgArgs.getValueOf("filename");
if filename.isEmpty() {
Expand Down Expand Up @@ -331,19 +328,18 @@ module FileIO {

select getFileType(filename) {
when FileType.HDF5 {
return executeCommand("lshdf", payload, argSize, st);
return executeCommand("lshdf", msgArgs, st);
}
when FileType.PARQUET {
return executeCommand("lspq", payload, argSize, st);
return executeCommand("lspq", msgArgs, st);
} otherwise {
var errorMsg = "Unsupported file type; Parquet and HDF5 are only supported formats";
return new MsgTuple(errorMsg, MsgType.ERROR);
}
}
}

proc readAnyMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);
proc readAnyMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var nfiles = msgArgs.get("filename_size").getIntValue();
var filelist: [0..#nfiles] string;

Expand Down Expand Up @@ -386,10 +382,10 @@ module FileIO {

select getFileType(filenames[0]) {
when FileType.HDF5 {
return executeCommand("readAllHdf", payload, argSize, st);
return executeCommand("readAllHdf", msgArgs, st);
}
when FileType.PARQUET {
return executeCommand("readAllParquet", payload, argSize, st);
return executeCommand("readAllParquet", msgArgs, st);
} otherwise {
var errorMsg = "Unsupported file type; Parquet and HDF5 are only supported formats";
return new MsgTuple(errorMsg, MsgType.ERROR);
Expand Down
6 changes: 2 additions & 4 deletions src/FlattenMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module FlattenMsg {
private config const logLevel = ServerConfig.logLevel;
const fmLogger = new Logger(logLevel);

proc segFlattenMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);
proc segFlattenMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
const objtype = msgArgs.getValueOf("objtype");
const returnSegs: bool = msgArgs.get("return_segs").getBoolValue();
const regex: bool = msgArgs.get("regex").getBoolValue();
Expand Down Expand Up @@ -45,10 +44,9 @@ module FlattenMsg {
return new MsgTuple(repMsg, MsgType.NORMAL);
}

proc segmentedSplitMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc segmentedSplitMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var pn = Reflection.getRoutineName();
var repMsg: string;
var msgArgs = parseMessageArgs(payload, argSize);

const objtype = msgArgs.getValueOf("objtype");
const name = msgArgs.getValueOf("parent_name");
Expand Down
6 changes: 2 additions & 4 deletions src/GenSymIO.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ module GenSymIO {
* Creates a pdarray server-side and returns the SymTab name used to
* retrieve the pdarray from the SymTab.
*/
proc arrayMsg(cmd: string, args: string, argSize: int, ref data: bytes, st: borrowed SymTab): MsgTuple throws {
proc arrayMsg(cmd: string, msgArgs: borrowed MessageArgs, ref data: bytes, st: borrowed SymTab): MsgTuple throws {
// Set up our return items
var msgType = MsgType.NORMAL;
var msg:string = "";
var rname:string = "";
var msgArgs = parseMessageArgs(args, argSize);
var dtype = DType.UNDEF;
var size:int;
var asSegStr = false;
Expand Down Expand Up @@ -128,10 +127,9 @@ module GenSymIO {
* Outputs the pdarray as a Numpy ndarray in the form of a
* Chapel Bytes object
*/
proc tondarrayMsg(cmd: string, payload: string, argSize: int, st:
proc tondarrayMsg(cmd: string, msgArgs: borrowed MessageArgs, st:
borrowed SymTab): bytes throws {
var arrayBytes: bytes;
var msgArgs = parseMessageArgs(payload, argSize);
var abstractEntry = st.lookup(msgArgs.getValueOf("array"));
if !abstractEntry.isAssignableTo(SymbolEntryType.TypedArraySymEntry) {
var errorMsg = "Error: Unhandled SymbolEntryType %s".format(abstractEntry.entryType);
Expand Down
4 changes: 1 addition & 3 deletions src/GroupByMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ module GroupByMsg {
private config const logLevel = ServerConfig.logLevel;
const gmLogger = new Logger(logLevel);

proc createGroupByMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);

proc createGroupByMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
const assumeSorted = msgArgs.get("assumeSortedStr").getBoolValue();
var n = msgArgs.get("nkeys").getIntValue();
var keynames = msgArgs.get("keynames").getList(n);
Expand Down
12 changes: 3 additions & 9 deletions src/HDF5Msg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,7 @@ module HDF5Msg {
Parse and exectue tohdf message.
Determines the type of the object to be written and calls the corresponding write functionality.
*/
proc tohdfMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);

proc tohdfMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var objType: ObjType = msgArgs.getValueOf("objType").toUpper(): ObjType; // pdarray, Strings, ArrayView

select objType {
Expand Down Expand Up @@ -1010,10 +1008,8 @@ module HDF5Msg {
return items;
}

proc lshdfMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
// reqMsg: "lshdf [<json_filename>]"
proc lshdfMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var repMsg: string;
var msgArgs = parseMessageArgs(payload, argSize);

// Retrieve filename from payload
var filename: string = msgArgs.getValueOf("filename");
Expand Down Expand Up @@ -1670,9 +1666,7 @@ module HDF5Msg {
/*
Read HDF5 files into an Arkouda Object
*/
proc readAllHdfMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
var msgArgs = parseMessageArgs(payload, argSize);

proc readAllHdfMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var strictTypes: bool = msgArgs.get("strict_types").getBoolValue();

var allowErrors: bool = msgArgs.get("allow_errors").getBoolValue(); // default is false
Expand Down
3 changes: 1 addition & 2 deletions src/HDF5Msg_LEGACY.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1774,9 +1774,8 @@ module HDF5Msg_LEGACY {
/**
* Reads all datasets from 1..n HDF5 files into an Arkouda symbol table.
*/
proc readAllHdfMsg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc readAllHdfMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var repMsg: string;
var msgArgs = parseMessageArgs(payload, argSize);
var strictTypes: bool = msgArgs.get("strict_types").getBoolValue();

var allowErrors: bool = msgArgs.get("allow_errors").getBoolValue(); // default is false
Expand Down
3 changes: 1 addition & 2 deletions src/HDF5MultiDim.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ module HDF5MultiDim {
The resulting data is always in flattened form (as expected by ArrayView)
Adds a pdarray containing the flattened data and a pdarray containing the shape of the object to the symbol table
*/
proc read_hdf_multi_msg(cmd: string, payload: string, argSize: int, st: borrowed SymTab): MsgTuple throws {
proc read_hdf_multi_msg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
// Currently always load flat as row major
var msgArgs = parseMessageArgs(payload, argSize);
var filename = msgArgs.getValueOf("filename");
var dset_name = msgArgs.getValueOf("dset");

Expand Down
Loading

0 comments on commit 1e31ee7

Please sign in to comment.