试图获取火花行的对象大小,java Instrumentation.getObjectSize returns 空指针异常
Trying to fetch object Size of a spark Row , java Instrumentation.getObjectSize returns Null Pointer Exception
我正在尝试按照以下步骤获取这样的火花行大小。
转换为 rdd 会带来更多问题,因此我尝试使用 toSeq 并继续获取对象大小。
private[spark] def getEventSize(row: ssql.Row): Long = {
ObjectSizeFetcher.getObjectSize(row.toSeq)
}
虽然看起来打印了数据,但是对于同一个对象抛出空指针异常
oWrappedArray(1, 1, 2, 2, 2.0, Map(a -> 1), a, a, 0, 1, Map(1 -> 1), 1, 1, 1.0, 0.0, 0, 1, 1.0)
异常
java.lang.NullPointerException:
at com.expediagroup.dataquality.polaris.batchprofiler.utils.ObjectSizeFetcher.getObjectSize(ObjectSizeFetcher.java:16)
我正在使用 Instrumentation.getObjectSize 获取火花行的大小
import java.lang.instrument.Instrumentation;
public class ObjectSizeFetcher {
private static Instrumentation instrumentation;
public static void premain(String args, Instrumentation inst) {
instrumentation = inst;
}
public static long getObjectSize(Object o) {
System.out.println("o" + o);
if(o==null)
return 0;
return instrumentation.getObjectSize(o);
}
}
感谢任何帮助
我使用了 import SizeEstimator 而不是它现在似乎可以工作
import org.apache.spark.util.SizeEstimator
.
.
.
private[spark] def getEventSize(row: ssql.Row): Long = {
SizeEstimator.estimate(row)
}
我正在尝试按照以下步骤获取这样的火花行大小。
转换为 rdd 会带来更多问题,因此我尝试使用 toSeq 并继续获取对象大小。
private[spark] def getEventSize(row: ssql.Row): Long = {
ObjectSizeFetcher.getObjectSize(row.toSeq)
}
虽然看起来打印了数据,但是对于同一个对象抛出空指针异常
oWrappedArray(1, 1, 2, 2, 2.0, Map(a -> 1), a, a, 0, 1, Map(1 -> 1), 1, 1, 1.0, 0.0, 0, 1, 1.0)
异常
java.lang.NullPointerException:
at com.expediagroup.dataquality.polaris.batchprofiler.utils.ObjectSizeFetcher.getObjectSize(ObjectSizeFetcher.java:16)
我正在使用 Instrumentation.getObjectSize 获取火花行的大小
import java.lang.instrument.Instrumentation;
public class ObjectSizeFetcher {
private static Instrumentation instrumentation;
public static void premain(String args, Instrumentation inst) {
instrumentation = inst;
}
public static long getObjectSize(Object o) {
System.out.println("o" + o);
if(o==null)
return 0;
return instrumentation.getObjectSize(o);
}
}
感谢任何帮助
我使用了 import SizeEstimator 而不是它现在似乎可以工作
import org.apache.spark.util.SizeEstimator
.
.
.
private[spark] def getEventSize(row: ssql.Row): Long = {
SizeEstimator.estimate(row)
}