sharkint
来源:互联网 发布:健身软件推荐 编辑:程序博客网 时间:2024/06/08 09:01
1看 int 列 看出存储是列存储格式
class IntColumnBuilder extends ColumnBuilder[Int] {
private var _stats: ColumnStats.IntColumnStats = null
private var _arr: IntArrayList = null
override def initialize(initialSize: Int) {
_arr = new IntArrayList(initialSize)
_stats = new ColumnStats.IntColumnStats
super.initialize(initialSize)
}
override def append(o: Object, oi: ObjectInspector) {
if (o == null) {
appendNull()
} else {
val v = oi.asInstanceOf[IntObjectInspector].get(o)
append(v)
}
}
override def append(v: Int) {
_arr.add(v)
_stats.append(v)
}
override def appendNull() {
_arr.add(0)
_stats.appendNull()
}
override def stats = _stats
override def build: ByteBuffer = {
val buf = ByteBuffer.allocate(
/
_arr.size * 4 + ColumnIterator.COLUMN_TYPE_LENGTH + sizeOfNullBitmap)buf.order(ByteOrder.nativeOrder())
buf.putLong(ColumnIterator.INT)
//nullbitmap进行初始化
writeNullBitmap(buf)var i = 0
while (i < _arr.size) {
buf.putInt(_arr.get(i))
i += 1
}
buf.rewind()
buf
}
}
sealed trait ColumnStats[@specialized(Boolean, Byte, Short, Int, Long, Float, Double) T]
extends Serializable {
var _nullCount = 0
def append(v: T)
protected def _min: T
protected def _max: T
def appendNull() { _nullCount += 1 }
def nullCount: Int = _nullCount
def min: T = _min
def max: T = _max
override def toString = "[" + min + ", " + max + "]"
}