MCPcopy Create free account
hub / github.com/apache/pig / getPigObjMemSize

Method getPigObjMemSize

src/org/apache/pig/data/SizeUtil.java:36–109  ·  view source on GitHub ↗
(Object o)

Source from the content-addressed store, hash-verified

34 private static final int MAP_MEM_PER_ENTRY = 32 + 120;
35
36 public static long getPigObjMemSize(Object o) {
37 // 12 is added to each to account for the object overhead and the
38 // pointer in the tuple.
39 switch (DataType.findType(o)) {
40 case DataType.BYTEARRAY: {
41 byte[] bytes = ((DataByteArray) o).get();
42 // bytearray size including rounding to 8 bytes
43 long byte_array_sz = roundToEight(bytes.length + 12);
44
45 return byte_array_sz + 16 /* 16 is additional size of DataByteArray */;
46 }
47
48 case DataType.CHARARRAY: {
49 String s = (String) o;
50 // See PIG-1443 for a reference for this formula
51 return roundToEight((s.length() * 2) + 38);
52 }
53
54 case DataType.TUPLE: {
55 Tuple t = (Tuple) o;
56 return t.getMemorySize();
57 }
58
59 case DataType.BAG: {
60 DataBag b = (DataBag) o;
61 return b.getMemorySize();
62 }
63
64 case DataType.INTEGER:
65 return 4 + 8 + 4/* +4 to round to 8 bytes */;
66
67 case DataType.LONG:
68 return 8 + 8;
69
70 case DataType.DATETIME:
71 return 8 + 2 + 8 + 6 /* one long (8) + one short (2) + 6 to round to 8 bytes */;
72
73 case DataType.MAP: {
74 @SuppressWarnings("unchecked")
75 Map<String, Object> m = (Map<String, Object>) o;
76 Iterator<Map.Entry<String, Object>> i = m.entrySet().iterator();
77 long sum = 0;
78 while (i.hasNext()) {
79 Entry<String, Object> entry = i.next();
80 sum += getMapEntrySize(entry.getKey(), entry.getValue());
81 }
82 return sum;
83 }
84
85 case DataType.FLOAT:
86 return 4 + 8 + 4/* +4 to round to 8 bytes */;
87
88 case DataType.DOUBLE:
89 return 8 + 8;
90
91 case DataType.BOOLEAN:
92 // boolean takes 1 byte , +7 to round it to 8
93 return 1 + 8 + 7;

Callers 3

getMemorySizeMethod · 0.95
getMapEntrySizeMethod · 0.95
execMethod · 0.95

Calls 12

findTypeMethod · 0.95
roundToEightMethod · 0.95
getMemorySizeMethod · 0.95
getMapEntrySizeMethod · 0.95
lengthMethod · 0.80
entrySetMethod · 0.80
getMethod · 0.65
iteratorMethod · 0.65
getValueMethod · 0.65
hasNextMethod · 0.45
nextMethod · 0.45
getKeyMethod · 0.45

Tested by

no test coverage detected