Writing null values into parquet file with mapper - hadoop

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

Related

Convert hex value "2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36" to decimal using fromRadix() NiFi function

I am trying to convert the hex value (coming as part of content of the flowfile) 2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36 using fromRadix() EL in UpdateRecord processor. Below is the code I have used
${field.value:isEmpty():not():ifElse('${field.value:fromRadix(16)}','${literal("")}')}
But am getting error, "will route to failure: For input String "2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36"
I tried it through Groovy with the below code, it is working fine.
def data1 = '2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36'
BigInteger x = new BigInteger(data1,16)
println "original output: " + x
Output is coming as
original output: 19928446223359820201840237302010524452213876686816802601399388669528806869558
Would like to know what is wrong with my UpdateRecord processor code using fromRadix(16)
I ran into something very similar, it seems like the NiFi expression language throws an error when the input value (hex in this case) is a big string.
Instead of this "2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36" try running it for "2c0f19d10da" (subtring of your input) and it works.

Validation fails when passing a file path as Input Argument to Orchestrator API StartJobs

I am trying to use file name path (Ex: C:\Document\Report.txt) as a parameter through uipath orchastrator api. I tried different approach and In each approach I am getting Bad request error "{"message":"Argument Values validation failed.","errorCode":2003,"resourceIds":null}"
Below is my Example code
FileListUploaded ="C\\Documents\\report.txt";
string parameter1 = "{\"startInfo\": {\"ReleaseKey\": \"xxxxx-xxx-xxx-xxx-xxxxxx\"," +
"\"RobotIds\": [xxxxx]," +
"\"JobsCount\": 0," +
"\"InputArguments\": \"{ "+
"\\\"reports_or_other_files\\\": \\\" + FileListUploaded + \\\"}\"}}";
request_startRobot.AddParameter("application/json; charset=utf-16", parameter, ParameterType.RequestBody);
IRestResponse response_startRobot = client_startRobot.Execute(request_startRobot);
That's a bit messy to look at, but it appears you are not quoting and escaping your JSON correctly.
I might suggest building an array and serializing it into JSON to make it easier to read, or using a HEREDOC or string formatting. If you do continue to concatenate your JSON body string together, dump out the results to see how it is coming together.
The final results of the JSON should look something like
{
"startInfo": {
"ReleaseKey":"{{uipath_releaseKey}}",
"Strategy":"JobsCount",
"JobsCount":1,
"InputArguments":"{\"reports_or_other_files\":\"C:\\\\Documents\\\\report.txt\"}"
}
}
With the InputArguments:
Looks like you are missing some quotes
Might need to double escape your backslashes in the FileListUploaded variable
Missing a colon after the C in the path

JMeter BeanShell Assertion: Getting error when convert String to Long

Have a need to change the value from String to Long in BeanShell Assertion to do verification.
First Apporach
long balance_after_credit = Long.parseLong(String.valueOf("${balance_after_credit_from_db}"));
Second Approach
long balance_after_credit = Long.parseLong(vars.get("balance_after_credit_from_db"));
For instance, consider am getting a value as '743432545' for the variable balance_after_credit_from_db.
Error
org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``long token_balance_after_credit = Long.parseLong(vars.get("token_balance_after_c . . . '' : Typed variable declaration : Method Invocation Long.parseLong
Weird thing is sometimes, I didn't get errors and the script is getting passed.
Can anyone please point out where am doing a mistake. TIA.
Inlining JMeter variables into code-based scripts is not something recommended so go for 2nd approach.
How do you know that exactly String is being returned from the database all the time? It easily can be any other object type, in fact any of described in the Mapping SQL and Java Types article. The way more safe approach will be something like:
if (vars.getObject("balance_after_credit_from_db") instanceof String) {
long balance_after_credit = Long.parseLong(vars.get("balance_after_credit_from_db"));
}
else {
log.error("Unexpected \balance_after_credit_from_db\" variable type");
log.error("Expected: String, Actual: " + vars.getObject("balance_after_credit_from_db").getClass().getName());
throw new Exception("Unexpected variable type");
}
So in case of non-String JDBC query result you will be able to see the relevant message in jmeter.log file
See Debugging JDBC Sampler Results in JMeter article for more information on working with the entities coming from databases in JMeter tests
The second option
long balance_after_credit = Long.parseLong(vars.get("balance_after_credit_from_db"));
should work, provided you have a valid numeric variable value. For instance try to run something like this:
vars.put("x", "743432545");
long balance_after_credit = Long.parseLong(vars.get("x"));
It won't return any exception.
The problem is when the variable is not defined, has empty or non-numeric value. Then Long.parseLong will throw a NumberFormatException, which you shold catch and make use of (treat it as assertion failure):
String rawValue = vars.get("balance_after_credit_from_db");
long balance_after_credit = Long.MAX_VALUE; // initialize with some unrealistic value
try {
balance_after_credit = Long.parseLong(rawValue);
}
catch(NumberFormatException e) {
Failure = true;
FailureMessage = "Variable does not contain a valid long. It was " + rawValue + " instead";
}

Evaluate String value in jmeter

I want to evaluate the value of SEATID.
Find my code below.
String res2[0] = "40B";
vars.put("SEAT_ID",res2[0]);
When i am trying the get the value of SEATID in a string i am not getting the actual value of SEATID.
String otherSampler = vars.get("{"seatCode":"${SEAT_ID}");
Output is coming as : {"seatCode":"${SEAT_ID}
Expected output : {"seatCode":"40B"}
I am wring the code in Beanshell pre processor. Please help.
You need to use vars.get on SEAT_ID
String otherSampler = "{\"seatCode\":\"" + vars.get("SEAT_ID") + "\"}"
Your code is wrong. Try using this for declaring SEAT_ID variable:
vars.put("SEAT_ID","{\"seatCode\":\"" + res2[0] + "\"}");
Then you could use:
String otherSampler = vars.get(SEAT_ID);
To get:
{"seatCode":"40B"}

'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 ?

Resources