rjava S4 Object toString - rjava

I retrieved a java object with rjava package obj<-.jnew('test/Test'). If I execute print(obj), then I call the toString methode of the java representation. The output in R studio console looks like:
[1] "Java-Object{myToString {\n property {\n code:..."
I want to assign the string output above to a variable. When I assign the print methode to a variable a<-print(obj), then I initialize an other S4 object (no string dput(a)). How to assign the string of print(obj) to a variable?
I already tried as.character, paste0, etc.. All of them throwing the error:
Error in as.character.default(new("jobjRef", jobj = <pointer:
0x0000013d347d1538>, : no method for coercing this S4 class to a
vector

Related

How to access / address nested fields on Logstash

I am currently trying to convert a nested sub field that contains hexadecimal string to an int type field using Logstash filter
ruby{
code => 'event.set("[transactions][gasprice_int]", event.get("[transactions][gasPrice]").to_i(16))'
}
but it's returning the error
[ERROR][logstash.filters.ruby ][main][2342d24206691f4db46a60285e910d102a6310e78cf8af43c9a2f1a1d66f58a8] Ruby exception occurred: wrong number of arguments calling `to_i` (given 1, expected 0)
I also tried looping through json objects in transactions field using
transactions_num = event.get("[transactions]").size
transactions_num.times do |index|
event.set("[transactions][#{index}][gasprice_int]", event.get("[transactions][#{index}][gasPrice].to_i(16)"))
end
but this also returned an error of
[ERROR][logstash.filters.ruby ][main][99b05fdb6022cc15b0f97ba10cabb3e7c1a8fabb8e0c47d6660861badffdb28e] Ruby exception occurred: Invalid FieldReference: `[transactions][0][gasPrice].to_i(16)`
This method of conversion of hex-string to int type using a ruby filter worked when I wasn't dealing with nested fields, so can anyone please help me how to correctly address nested fields in this case?
btw,
this is the code that still works
ruby {
code => 'event.set("difficulty_int", event.get("difficulty").to_i(16))'
}
I think you have answered this one yourself in your final example - the to_i should not be inside the double quotes. So
...event.get("[transactions][#{index}][gasPrice].to_i(16)"))
should be
...event.get("[transactions][#{index}][gasPrice]").to_i(16))

Writing null values into parquet file with mapper

I am trying to do the following:
String x=null;
Group group = factory.newGroup()
.append("x", x);
context.write(null,group)
With the following scheme:
String writeSchema = "message example {\n" +
"optional binary x;\n" +
"}";<br>
But I get NullPointerException in the append line. Maybe I am missing something in the scheme?
Here the String object itself is null. While writing to the filesystem it tries to get the value of the object which is causing the NullPointerExeception.
String x =null;
System.out.println(x.toString()); // Will cause a NullPointerExeception
Similarly any function call to the object will cause the same.
Try using String x ="null" instead

'StartsWith' not working in Linq-To-EF

I have implemented a Linq-to-EF expression using the sting comparison 'StartsWith', but it is behaving like the string comparison 'Contains'... my code is:
string ubi = '12';
return (from u in _dataContext.Notice
where u.UB.StartsWith(ubi)
select new AutoCompleteData { Value = u.UB }).Distinct().Take(50);
I would expect the data returned to be only values that start with '12'...but it returns values like '44412' and '312' as well as '1245' and '1299'.
Am I missing something ?

Passing Field Symbol value to Return parameter of method

I have the below code which uses a method. When I try to assign the Field Symbol value [Type ANY] to the return parameter RO_TAB [Type Ref to Data], I am getting an error message OBJECTS_MOVE_NOT SUPPORTED [Conversion of type "l" to type "g" not supported.].
The issue is happening after a BW system upgrade along with which we also moved to ABAP objects. The code executes perfectly in the older version of ABAP.
The dump occurs in the below line:
RO_TAB = <lf_storage>.
I have no idea why.
method GET_LU_STORAGE_FOR_ODS.
* IMPORTS
* IF_ODS TYPE RSODSTECH
* IF_ODS_TABLE_TYPE TYPE ZODS_TAB_TYPE
* RETURNS
* RO_TAB TYPE REF TO DATA
FIELD-SYMBOLS:
<lf_storage> TYPE ANY.
DATA:
lf_index TYPE SY-TABIX,
lf_sindex TYPE STRING,
lf_name TYPE STRING.
lf_index = GET_LU_STORAGE_INDEX(
IF_ODS = IF_ODS
IF_ODS_TABLE_TYPE = IF_ODS_TABLE_TYPE ).
lf_sindex = lf_index.
CONCATENATE
'MO_LU_DATA_'
lf_sindex
INTO lf_name.
ASSIGN lf_name TO <lf_storage>.
RO_TAB = <lf_storage>.
endmethod.
You need to create a data object first, using the CREATE DATA statement. Then you can ASSIGN a field symbol to work with the dynamically created data object. There's an example in the online manual. A field symbol is not a reference, it simply places the variable assigned to it in its position. You're effectively trying to move a string (which is what lf_name is) to a reference variable, and that won't work.
You cannot assign a variable of type STRING to a variable of type REF TO DATA.
The following code snippet shows how it should be done.
DATA: lf_name TYPE string.
DATA: lo_tab TYPE REF TO DATA.
FIELD-SYMBOLS: <lf_name> TYPE string.
lf_name = 'test'.
GET REFERENCE OF lf_name INTO lo_tab.
*lf_name = lo_tab. "this is not allowed
ASSIGN lo_tab->* TO <lf_name>.
So in your case it would be sufficient to define a field symbol.
FIELD-SYMBOLS: <lf_name> TYPE STRING.
then assign the contents referenced by RO_TAB to this field symbol.
ASSIGN ro_tab->* TO <lf_name>.
and finally do the concatenation.
CONCATENATE
'MO_LU_DATA_'
lf_index
INTO <lf_name>.
That's all! No further assignments should be required.
How about just this?
lf_sindex = lf_index.
CONCATENATE
'MO_LU_DATA_'
lf_sindex
INTO RO_TAB.

How to get XPages and JSON to not put variable names in Uppercase

I'm trying to do the following update using XPages Extension Library.
#{javascript:var mydata = {
product: getComponent("inputProduct").getValue()
};
var params = [1, 2];,
#JdbcUpdate("mssql","table_name",mydata,"order_no=? AND order_line_no=?",params)};
I get the error:
Error while executing JavaScript action expression
Script interpreter error, line=6, col=1: Error while executing function '#JdbcUpdate'
Invalid column name 'PRODUCT'.
The problem is that XPages when it converts the JSON it puts product to PRODUCT.
Can you set the extension library to respect the case of the JSON and not convert to Uppercase? Or can anyone point to where this setting could be set if not the extension library?
Thanks
The problem is com.ibm.xsp.extlib.util.JdbcUtil.appendColumnName()
public static void appendColumnName(StringBuilder b, String colName) {
colName = colName.toUpperCase();
b.append(colName);
}
This just needs changing to not upper case the variable.
There may be other methods that need changing if other variables are getting upper cased.

Resources