I have a small problem .. I read data from kafka a...
# troubleshooting
a
I have a small problem .. I read data from kafka and deserializing using POJO class and after that I want to parse field in pojo to Long It gets this error , why it read it as "" "" and if I want skip this "" "" what i will do
Copy code
java.lang.NumberFormatException: For input string: ""201275004137""
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Long.parseLong(Long.java:578)
	at java.lang.Long.parseLong(Long.java:631)
	at org.orangeFlinkDS.Main$2.filter(Main.java:111)
	at org.orangeFlinkDS.Main$2.filter(Main.java:108)
	at org.apache.flink.streaming.api.operators.StreamFilter.processElement(StreamFilter.java:39)
	at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:71)
n
how does it look like the input data ?
a
It’s csv records from kafka and the field is “value”
This is the field I want to extract "121223173722"
It is like this on the message
n
That field is being interpreted by the reader as a string and is escaping the double quotes by adding
\"
. i.e
jshell> var test1 = "456"
test1 ==> "456"
jshell> Long.parseLong(test1)
$8 ==> 456
jshell> var  test2 = ""789""
|  Error:
|  ';' expected
|  var  test2 = ""789"";
|                 ^
jshell> var test3 = "\"10\""
test3 ==> "\"10\""
jshell> Long.parseLong(test3)
|  Exception java.lang.NumberFormatException: For input string: ""10""
|        at NumberFormatException.forInputString (NumberFormatException.java:67)
|        at Long.parseLong (Long.java:697)
|        at Long.parseLong (Long.java:836)
|        at (#10:1)
now, knowing the probable root cause, let-s un-escape
jshell> var test4 = test3.replace("\"", "")
test4 ==> "10"
jshell> Long.parseLong(test4)
$13 ==> 10
a
If I escape it would get empty string and gets an error but for input string =“” and if not it get the previous error
n
that is another scenario
a
Let’s explain more I read kafka records and by splitting the message into list of strings , I set the pojo object like this This.name = field[1] and so on After that I parse the string into long
n
This.name = field[1] and so on
I'm not talking about previous steps
After that I parse the string into long
My suggestion targets this step. if you un-escape the " from the input value and is empty, then don-t parse it to long. That means that probably you should represent that field in the subsequent pojo/etc as optional
a
1-If I unescape it , it gets an error message that it is "12121212" can't parsed 2- If I escape it , it gets the same error message but for empty string
I tried to debug it using IDE locally and it worked without any workaround .. I don't know where is the problem
I figured it .. the problem relies on producer .. sometimes it send “” and sometimes “” “” so I made a if statement to handle both cases and worked right
🙌 1