I have written an AggregateFactory Vertica UDF which returns a single value
getReturnTypes(si,columnTypes args,columnTypes returnTypes){
returnTypes.addVarbinary(512);
//I want to add second returnType
returnTypes.addFloat("");
}
getProtoType(si,columnTypes args,columnTypes returnTypes){
returnTypes.addVarbinary(512);
//I want to add second returnType
returnTypes.addFloat("");
}
this is not working, how can I return two values from an AggregateFactory UDF?
You cannot. User Defined Aggregate Functions (as explained in the fine manual) return ONE value per group. You might want to write a User Defined Transform Function (maybe a multi-phase Transform Function).
Related
This is a macro that I want to use it in Laravel collection. I know what the transpose is and how it works. But I didn't get exactly how this piece of code is implementing transpose in Laravel collection.
Can you explain how the items that we will pass, would be transposed?
What new static($items) does here?
Collection::macro('transpose', function () {
$items = array_map(function (...$items) {
return $items;
}, ...$this->values());
return new static($items);
});
The code you provided should be placed in a Service Provider according to the Laravel Docs: https://laravel.com/docs/8.x/collections#extending-collections. However, you could technically place them anywhere.
What exactly don't you understand about the piece of code? The macro function of the Illuminate\Support\Collection accepts a closure. In this case, it means $items is referring to the Collection that transpose is called on.
Then that Collection is mapped (using array_map) and the $items are passed as a spread operator function parameter. Perhaps you're familiar with the spread operator, but it spreads the values of an array (or other iterable) to separate variables.
In that same function, these separate variables are returned, and the values() are provided as a spread operator to run through the callback function. For more information about array_map, you can read the PHP Docs: https://www.php.net/manual/en/function.array-map.php.
If anything is unclear, please let me know what part needs clarification.
in order to calculate the inverse function of f(x) I defined following function:
inv(fx):=exp▶list(solve(fx=y,x),x)
which output is:
inv(x^(2)) {piecewise(−√(y),y≥0),piecewise(√(y),y≥0)}
So that part works already, but how can I use this result as a callable function i(y)?
Thanks for your help
Outside of your program, you can turn the result into function i(y) with:
i(y):=piecewise(-√(y),y≥0,√(y),y≥0)
I do not have a CAS, so your results may differ, but, because the function can only return one value, it would only return (and display in the graph) the first value, in this case, -√(y). If you want to display on the graph or get the values of both, you would be better off creating two separate functions (-√(y), and √(y)). Hope this helps you "use the result as a callable function."
I am working on a web api project (back end) and I am searching for some more optimized way to get multiple parameter from front end. There are numerous ways like
i) name each parameter in action parameter stack
ii) extract from request body like Request.Content.ReadAsStringAsync().Result;
iii) define complex types (model) and use that type to receive values. like MyAction(UserLog log)
I have to create hundreds of functions which may take variable number of parameters. I don't want to use first option above, it is hectic for large data.
The second is confusing as no one can predict what to post.
The third one forces me to create hundreds of input models. So is there any better way to do so?
You could try using a form data collection
Its basically a Key Value Pair which allows for an element of genericness.
Edit - another link
Another option would be to apply dynamic object parameters on your Post Verbs.
E.g.
public string Post(dynamic value)
{
string s = "";
foreach (dynamic item in value)
{
s = s + item.content + " ";
}
return s;
}
Per the docs, "The call operator always returns the current selection, regardless of the return value of the specified function." I'd like to know if there is a variant of call or reasonable workaround for getting call-behavior that returns values other than the selection.
Motivation:
I've got a chart and a datebrush, each encapsulated in a function
function trends_datebrush() {
// Setup
function chart(_selection) {
_selection.each(function(_data) {
// Do things
...});
}
return chart;
};
(The chart follows a similar format but isn't called datebrush).
These are instantiated with:
d3.select("someDiv")
.datum("data")
.call(trends_datebrush());
// And then we call the chart
I'd like to return a subselection from brush to be used as the data variable in the chart call. As is I need to make them both aware of some higher order global state, which gets messy especially since I want other control functions to drill down on the data. If I could override call, then I could do something like
d3.select("someDiv")
.datum("data")
.call(trends_datebrush())
.call(trends_chart());
And then if I were to implement some new filter I could throw it into the chain with another call statement.
tl;DR: Looking for ways to get chain chart calls s.t. they can pass transformed data to each other. I want monadic D3 charts! Except I don't really know monads so I might be misusing the word.
I have a method drive that goes like this:
public double drive(double milesTraveled, double gasUsed)
{
gasInTank -= gasUsed;
return totalMiles += milesTraveled;
}
I know I can't return multiple values from a method, but that's kind of what I need to do because I need both of these values in my main method, and as it is now it's obviously only returning the one. I can't think of anything that would work. Sorry if this is a super beginner question. What can I do to get both values to return from the method?
You can return multiple value from a function. To do this You can use structure.
In the structure you can keep required field and can return structure variable after operation.
You can also make a class for the required field if You are using OOPS supporting language but Structure is best way.
In most languages you can only return a single value from a method. That single value could be a complex type, such as a struct, array or object.
Some languages also allow you to define output parameters or pass in pointers or references to outside storage locations. These kinds of parameters also allow you to return additional values from your method.
not sure, but can you take array of your values?
array[0]=gasInTank;
array[0] -= gasUsed;
array[1]=milesTraveled;
array[1] -= milesTraveled;
return array;