// Get Procedure catalog handle
if (procName == null || procName.isEmpty()) {
LOG.error("Missing procedure name");
return (null);
}
Procedure catalog_proc = catalog_db.getProcedures().getIgnoreCase(procName);
if (catalog_proc == null) {
throw new Exception("Invalid procedure name '" + procName + "'");
}
int expectedParams = catalog_proc.getParameters().size();
// Hack for @AdHoc
if (catalog_proc.getName().equalsIgnoreCase("@AdHoc")) {
expectedParams = 1;
}
// Procedure Parameters
if (params.length != expectedParams) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
for (ProcParameter catalog_param : CatalogUtil.getSortedCatalogItems(catalog_proc.getParameters(), "index")) {
VoltType vtype = VoltType.get(catalog_param.getType());
String key = String.format("[%02d]", catalog_param.getIndex());
String val = vtype.name();
if (vtype == VoltType.TIMESTAMP) {
val += " (FORMATS: ";
String add = "";
int spacer = val.length();
for (String f : VoltTypeUtil.DATE_FORMAT_PATTERNS) {
val += add + f;
add = "\n" + StringUtil.repeat(" ", spacer);
}
val += ")";
}
m.put(key, val);
}
throw new Exception(String.format("Incorrect number of parameters for %s. Expected %d, but was only given %d\n" +
"Expected Input Parameters:\n%s",
catalog_proc, catalog_proc.getParameters().size(), params.length,
StringUtil.prefix(StringUtil.formatMaps(m), " ")).trim());
}
// Convert parameters to the proper type
Object parameters[] = new Object[expectedParams];
for (int i = 0; i < expectedParams; i++) {
ProcParameter catalog_param = catalog_proc.getParameters().get(i);
assert(catalog_param != null) : String.format("Null %s parameter at %d", catalog_proc.getName(), i);
VoltType vt = VoltType.get(catalog_param.getType());
try {
// Split into array
if (catalog_param.getIsarray()) {
List<String> arr = (List<String>)CollectionUtil.addAll(new ArrayList<String>(),
params[i].split(","));
Object inner[] = new Object[arr.size()];
for (int ii = 0, cnt = arr.size(); ii < cnt; ii++) {
inner[ii] = VoltTypeUtil.getObjectFromString(vt, arr.get(ii));
} // FOR
parameters[i] = inner;
// Scalar Paramter
} else {
parameters[i] = VoltTypeUtil.getObjectFromString(vt, params[i]);
}
} catch (ParseException ex) {
LOG.error("Invalid parameter #" + i + ": " + params[i], ex);
return (null);
}
if (LOG.isDebugEnabled())
LOG.debug(String.format("%s: %s [%s / %s]", catalog_param.fullName(),
(catalog_param.getIsarray() ? Arrays.toString((Object[])parameters[i]) : parameters[i]),
vt, parameters[i].getClass()));
} // FOR
LOG.info(String.format("Invoking %s [params=%s]",
catalog_proc.getName(), Arrays.toString(parameters)));
ClientResponse cresponse = client.callProcedure(catalog_proc.getName(), parameters);
return (cresponse);
}