How to deal with NullPointerException error in row.getlong in spark – sparksql

Error: when the value of row is obtained in sparksql and the field of row allows null, null is obtained when the value is taken and assigned to a new variable name. A NullPointerException error will be reported

Solution: you can first use row. Isnullat (index) to determine whether the value of the field is empty

Specific cases are as follows:

First, make mistakes

If row. Isnullat (6) is not empty, the value will be assigned to the variable

When you get a value from row, you often encounter the problem of being empty.
the simple summary is as follows:
get value type: if it is empty, it will be converted to 0
to judge null. It is recommended to use row.isnullat (index)

Get string type: if it is empty, it will be null
if it is empty, it is recommended to use: stringutils. Isempty() (in case of ″)

Summary: getast
is used to get values, row. Isnullat
and stringutils. Isempty ()

Read More: