Syntax for setting/updating register fields in Map CRDT on server - erlang

What is the syntax for setting lwwreg register values in CRDT Map on server side in Riak? I tried a code like below which doesn't seem to be valid:
%% Obj is a map object to which we want to add/set a register "uname" with value
%% "ahmed"
riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,
{update,[{assign,<<"uname">>,<<"ahmed">>}]},undefined})
I get an error about the operation being invalid - I looked around in source code for riak_dt_map.erl but still can't figure out correct syntax:
> riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,{update,
[{assign,<<"uname">>,<<"ahmed">>}]},undefined}).
** exception error: no function clause matching
riak_dt_map:apply_ops([{assign,<<"uname">>,<<"ahmed">>}],
{<<"testing">>,1},
{[{<<"testing">>,1}],
.....
Will appreciate pointers on correct syntax.

Figured it out. The correct syntax is below - the key must be accompanied by the type of the field which is riak_dt_lwwreg in this case, and assign operation must be specified for register value - so, the syntax becomes:
riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,{update,
[{update,{<<"uname">>,riak_dt_lwwreg},{assign,<<"ahmed">>}}]},undefined})

Related

`Error: request to generate code for .compileTime proc`

I have a small helper proc that is supposed to tell me at compile-time whether a type is an object-type or not.
func isObject*[T](val: typedesc[T]): bool {.compileTime.} = T is (object or ref object)
However, when I call this proc with a simple echo to see whether it works, I receive an error:
type A = object
echo isObject(A)
Error: request to generate code for .compileTime proc: isObject
Why is that? It should be perfectly valid to just call this, isObject should just compile to true and in the end what's written there is echo true, why does this cause this cryptic error?
The problem here is that runtime code (The echo call) is trying to work with a compiletime proc.
That is not valid, as the compiler would not replace the function-call with its result, but try to actually call the function at runtime instead. The compiler knows this is invalid behaviour and thus prohibits it by throwing an error, albeit one that isn't that useful.
The only way this can be allowed is if you store the result of the compile-time proc in a compile-time variable, aka a const. These are allowed to be used at runtime.
So the calling code would look more like this instead:
type A = object
const x = isObject(A)
echo x
EDIT:
As Elegantbeef pointed out on nim's discord:
Another alternative is to just do what I thought would happen initially and have that isObject(A) call evaluate fully at compile-time, so that at runtime it goes away and all that's left is it's result, true.
To do so, just use static:
type A = object
echo static(isObject(A))

changeset begin/end methods in DPC_EXT but GCS_METHODS-CHANGESET_BEGIN unknown

My SAPui5 web app throws this error in Chrome's console:
The following problem occurred: HTTP request failed500,Internal Server Error,{"error":{
"code":"/IWBEP/CM_MGW_RT/053","message":{"lang":"en","value":"Default changeset impleme
ntation allows only one operation"},"innererror":{"application":{"component_id":"CA","s
ervice_namespace":"/SAP/","service_id":"YFLEXUI_LEAVE_REQUEST_SRV","service_version":"0
001"},"transactionid":"something","timestamp":"something","Error_Resolution":{"SAP_Tran
saction":"For backend administrators: run transaction /IWFND/ERROR_LOG on SAP Gateway h
ub system and search for entries with the timestamp above for more details","SAP_Note":
"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/179
7736)"},"errordetails":[{"code":"/IWBEP/CX_MGW_TECH_EXCEPTION","message":"Default chang
eset implementation allows only one operation","propertyref":"","severity":"error","tar
get":""}]}}} -
According to some posts on the internet, the problem is caused by the conflict between these methods:
/iwbep/if_mgw_appl_srv_runtime~changeset_begin
/iwbep/if_mgw_appl_srv_runtime~changeset_end
and
/iwbep/if_mgw_core_srv_runtime~changeset_begin
/iwbep/if_mgw_core_srv_runtime~changeset_end
Most people advice to redefine the methods /iwbep/if_mgw_appl_srv_runtime~changeset_begin and /iwbep/if_mgw_appl_srv_runtime~changeset_end.
This is my /iwbep/if_mgw_appl_srv_runtime~changeset_begin method:
METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_begin.
* Default Implementation:
* - Local Update Task
* - Only one operation in each changeset
* - No deferred processing: Immediate process changset operation
SET UPDATE TASK LOCAL.
IF lines( it_operation_info ) > 1.
RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception
EXPORTING
textid = /iwbep/cx_mgw_tech_exception=>changeset_default_violation
method = gcs_methods-changeset_begin.
ENDIF.
CLEAR cv_defer_mode.
ENDMETHOD.
The problem is, in SE80, after the redefinition of /iwbep/if_mgw_appl_srv_runtime~changeset_begin when I try to check that method and activate it, SAP throws this error:
Field GCS_METHODS-CHANGESET_BEGIN is unknown
Can you tell me how can /iwbep/if_mgw_appl_srv_runtime~changeset_begin's redefinition cause such error?
FYI. gcs_methods is a private constant. It might be causing the problem.
A subclass cannot use a private member of its superclass (unless the superclass said the subclass is its friend).
As the superclass is generated, you have to duplicate the constant in your own program.
We had the same issue recently and redefined the method like this:
METHOD /iwbep/if_mgw_core_srv_runtime~changeset_begin.
IF line_exists( it_operation_info[ entity_type = 'ENTITY_TYPE' ] ).
cv_defer_mode = abap_true.
ENDIF.
ENDMETHOD
I'm no expert on this topic, but this implementation fixed our problem.
What the issue with your private constant is, however, I cannot tell.
The error is the inactive methods on the class interface. A simple code check tells all the erros of this implementation.
BR,

SAP HANA Stored Procedure optional output parameter with text type

Let's imagine that I have created the stored procedure in SAP HANA database and would like to have optional out parameter with text type, like error details. As I have read to achieve this I should use some default value thus I have done like this:
PROCEDURE "myProcedure"
(
IN inSomeParameter BIGINT,
OUT outResult INTEGER, -- output, result of the operation
OUT outErrorDetail NVARCHAR(32) default ''
)
Unfortunately build failed with the following error:
OUT and IN OUT parameters may not have default expressions
So, I decided to try with null, but it failed the same way. Later I changed the type to integer just to try and it failed exactly same way again.
In the same time this works:
PROCEDURE "myProcedure"
(
IN inSomeParameter BIGINT,
OUT outResult INTEGER, -- output, result of the operation
OUT outErrorDetail TABLE(errorDetails NVARCHAR(32)) default empty
)
but it feels like a huge overkill - to make a table to return only one text value.
Do you have any suggestion how to add optional output parameter?
SQL Script in its current state doesn’t allow for optional OUT parameters.
Why don’t you just set the OUT parameter default value in the procedure body right before the code?
This adds boilerplate code, but you could also use it to convey explicit success messages.

Invalid coercion: () as xs:string in xdmp:xslt-eval

I am making use of MarkLogic's ability to call XQuery functions in the XSL transform.
Let's say I have an XQuery library with a function whose signature looks like the following. This is for illustrative purposes only.
declare function my-func:ex-join($first as xs:string, $last as xs:string) as xs:string
{
fn:concat($first, '-', $last)
}
From XQuery, I can call this function with empty sequence as parameters, with no issues, i.e.
ex-join((), '1244')
The function will just return an empty sequence, but I don't get any errors. If I try to all this function from with in my XSL transform,as in:
<xsl:value-of select="my-func:ex-join(//node/value/text(), 'something')"/>
If the /node/value does not exist, and an empty sequence is passed in, I get the coercion error.
Does anyone have suggestions to work around the coercion problem, outside of checking the values in XSL prior to the select? These are auto-generated XSL templates, which would mean a lot of coded checks.
Thanks,
-tj
Attempts to invoke that function in XQuery would fail too. It is probably due to function mapping that you don't notice this though. Put the following at the top of your XQuery code:
declare option xdmp:mapping "false";
Next to this, you only need to change the signature of your function to accept empty-sequences. Replace as xs:string with as xs:string?:
declare function my-func:ex-join($first as xs:string?, $last as xs:string?) as xs:string
fn:concat will accept empty sequences as arguments, so no further changes required to make it work..
HTH!

HackLang by Facebook is not strict

Good day,
I have problem. I want to simulate some errors in hacklang.
<?hh
namespace Exsys\HHVM;
class HHVMFacade{
private $vector = Vector {1,2,3};
public function echoProduct() : Vector<string>{
return $this->vector;
}
public function test(Vector<string> $vector) : void{
var_dump($vector);
}
}
Function echoProduct() returns Vector of strings. But private property $vector is Vector of integers. When I call echoFunction and returning value use as argument for function test(). I get
object(HH\Vector)#35357 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
Why? I am expecting some error because types mismatch.
There's two things at play here:
Generics aren't reified, so the runtime has no information about them. This means the runtime is only checking that you're returning a Vector.
$this->vector itself isn't typed. This means the type checker (hh_client) treats it as a unknown type. Unknown types match against everything, so there's no problem returning an unknown type where a Vector<string> is expected.
This is to allow you to gradually type your code. Whenever a type isn't known, the type checker just assumes that the developer knows what's happening.
The first thing I'd do is change the file from partial mode to strict mode, which simply involves changing from <?hh to <?hh // strict. This causes the type checker to complain about any missing type information (as well as a couple of other things, like no superglobals and you can't call non-Hack code).
This produces the error:
test.hh:6:13,19: Please add a type hint (Naming[2001])
If you then type $vector as Vector<int> (private Vector<int> $vector), hh_client then produces:
test.hh:9:16,28: Invalid return type (Typing[4110])
test.hh:8:44,49: This is a string
test.hh:6:20,22: It is incompatible with an int
test.hh:8:44,49: Considering that this type argument is invariant with respect to Vector
Which is the error you expected. You can also get this error simply by adding the type to $vector, without switching to strict mode, though I prefer to write my Hack in the strongest mode that the code supports.
With more recent versions of HHVM, the type checker is called whenever Hack code is run (there's an INI flag to turn this off), so causing the type mismatch will also cause execution of the code to fail.

Resources