Skip to content

Commit

Permalink
JIT hax.
Browse files Browse the repository at this point in the history
  • Loading branch information
marmbrus committed Aug 19, 2014
1 parent 3868f6c commit db44a30
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,335 @@ class JoinedRow extends Row {
s"[${row.mkString(",")}]"
}
}

/**
* JIT HACK: Replace with macros
*/
class JoinedRow2 extends Row {
private[this] var row1: Row = _
private[this] var row2: Row = _

def this(left: Row, right: Row) = {
this()
row1 = left
row2 = right
}

/** Updates this JoinedRow to used point at two new base rows. Returns itself. */
def apply(r1: Row, r2: Row): Row = {
row1 = r1
row2 = r2
this
}

/** Updates this JoinedRow by updating its left base row. Returns itself. */
def withLeft(newLeft: Row): Row = {
row1 = newLeft
this
}

/** Updates this JoinedRow by updating its right base row. Returns itself. */
def withRight(newRight: Row): Row = {
row2 = newRight
this
}

def iterator = row1.iterator ++ row2.iterator

def length = row1.length + row2.length

def apply(i: Int) =
if (i < row1.size) row1(i) else row2(i - row1.size)

def isNullAt(i: Int) =
if (i < row1.size) row1.isNullAt(i) else row2.isNullAt(i - row1.size)

def getInt(i: Int): Int =
if (i < row1.size) row1.getInt(i) else row2.getInt(i - row1.size)

def getLong(i: Int): Long =
if (i < row1.size) row1.getLong(i) else row2.getLong(i - row1.size)

def getDouble(i: Int): Double =
if (i < row1.size) row1.getDouble(i) else row2.getDouble(i - row1.size)

def getBoolean(i: Int): Boolean =
if (i < row1.size) row1.getBoolean(i) else row2.getBoolean(i - row1.size)

def getShort(i: Int): Short =
if (i < row1.size) row1.getShort(i) else row2.getShort(i - row1.size)

def getByte(i: Int): Byte =
if (i < row1.size) row1.getByte(i) else row2.getByte(i - row1.size)

def getFloat(i: Int): Float =
if (i < row1.size) row1.getFloat(i) else row2.getFloat(i - row1.size)

def getString(i: Int): String =
if (i < row1.size) row1.getString(i) else row2.getString(i - row1.size)

def copy() = {
val totalSize = row1.size + row2.size
val copiedValues = new Array[Any](totalSize)
var i = 0
while(i < totalSize) {
copiedValues(i) = apply(i)
i += 1
}
new GenericRow(copiedValues)
}

override def toString() = {
val row = (if (row1 != null) row1 else Seq[Any]()) ++ (if (row2 != null) row2 else Seq[Any]())
s"[${row.mkString(",")}]"
}
}

/**
* JIT HACK: Replace with macros
*/
class JoinedRow3 extends Row {
private[this] var row1: Row = _
private[this] var row2: Row = _

def this(left: Row, right: Row) = {
this()
row1 = left
row2 = right
}

/** Updates this JoinedRow to used point at two new base rows. Returns itself. */
def apply(r1: Row, r2: Row): Row = {
row1 = r1
row2 = r2
this
}

/** Updates this JoinedRow by updating its left base row. Returns itself. */
def withLeft(newLeft: Row): Row = {
row1 = newLeft
this
}

/** Updates this JoinedRow by updating its right base row. Returns itself. */
def withRight(newRight: Row): Row = {
row2 = newRight
this
}

def iterator = row1.iterator ++ row2.iterator

def length = row1.length + row2.length

def apply(i: Int) =
if (i < row1.size) row1(i) else row2(i - row1.size)

def isNullAt(i: Int) =
if (i < row1.size) row1.isNullAt(i) else row2.isNullAt(i - row1.size)

def getInt(i: Int): Int =
if (i < row1.size) row1.getInt(i) else row2.getInt(i - row1.size)

def getLong(i: Int): Long =
if (i < row1.size) row1.getLong(i) else row2.getLong(i - row1.size)

def getDouble(i: Int): Double =
if (i < row1.size) row1.getDouble(i) else row2.getDouble(i - row1.size)

def getBoolean(i: Int): Boolean =
if (i < row1.size) row1.getBoolean(i) else row2.getBoolean(i - row1.size)

def getShort(i: Int): Short =
if (i < row1.size) row1.getShort(i) else row2.getShort(i - row1.size)

def getByte(i: Int): Byte =
if (i < row1.size) row1.getByte(i) else row2.getByte(i - row1.size)

def getFloat(i: Int): Float =
if (i < row1.size) row1.getFloat(i) else row2.getFloat(i - row1.size)

def getString(i: Int): String =
if (i < row1.size) row1.getString(i) else row2.getString(i - row1.size)

def copy() = {
val totalSize = row1.size + row2.size
val copiedValues = new Array[Any](totalSize)
var i = 0
while(i < totalSize) {
copiedValues(i) = apply(i)
i += 1
}
new GenericRow(copiedValues)
}

override def toString() = {
val row = (if (row1 != null) row1 else Seq[Any]()) ++ (if (row2 != null) row2 else Seq[Any]())
s"[${row.mkString(",")}]"
}
}

/**
* JIT HACK: Replace with macros
*/
class JoinedRow4 extends Row {
private[this] var row1: Row = _
private[this] var row2: Row = _

def this(left: Row, right: Row) = {
this()
row1 = left
row2 = right
}

/** Updates this JoinedRow to used point at two new base rows. Returns itself. */
def apply(r1: Row, r2: Row): Row = {
row1 = r1
row2 = r2
this
}

/** Updates this JoinedRow by updating its left base row. Returns itself. */
def withLeft(newLeft: Row): Row = {
row1 = newLeft
this
}

/** Updates this JoinedRow by updating its right base row. Returns itself. */
def withRight(newRight: Row): Row = {
row2 = newRight
this
}

def iterator = row1.iterator ++ row2.iterator

def length = row1.length + row2.length

def apply(i: Int) =
if (i < row1.size) row1(i) else row2(i - row1.size)

def isNullAt(i: Int) =
if (i < row1.size) row1.isNullAt(i) else row2.isNullAt(i - row1.size)

def getInt(i: Int): Int =
if (i < row1.size) row1.getInt(i) else row2.getInt(i - row1.size)

def getLong(i: Int): Long =
if (i < row1.size) row1.getLong(i) else row2.getLong(i - row1.size)

def getDouble(i: Int): Double =
if (i < row1.size) row1.getDouble(i) else row2.getDouble(i - row1.size)

def getBoolean(i: Int): Boolean =
if (i < row1.size) row1.getBoolean(i) else row2.getBoolean(i - row1.size)

def getShort(i: Int): Short =
if (i < row1.size) row1.getShort(i) else row2.getShort(i - row1.size)

def getByte(i: Int): Byte =
if (i < row1.size) row1.getByte(i) else row2.getByte(i - row1.size)

def getFloat(i: Int): Float =
if (i < row1.size) row1.getFloat(i) else row2.getFloat(i - row1.size)

def getString(i: Int): String =
if (i < row1.size) row1.getString(i) else row2.getString(i - row1.size)

def copy() = {
val totalSize = row1.size + row2.size
val copiedValues = new Array[Any](totalSize)
var i = 0
while(i < totalSize) {
copiedValues(i) = apply(i)
i += 1
}
new GenericRow(copiedValues)
}

override def toString() = {
val row = (if (row1 != null) row1 else Seq[Any]()) ++ (if (row2 != null) row2 else Seq[Any]())
s"[${row.mkString(",")}]"
}
}

/**
* JIT HACK: Replace with macros
*/
class JoinedRow5 extends Row {
private[this] var row1: Row = _
private[this] var row2: Row = _

def this(left: Row, right: Row) = {
this()
row1 = left
row2 = right
}

/** Updates this JoinedRow to used point at two new base rows. Returns itself. */
def apply(r1: Row, r2: Row): Row = {
row1 = r1
row2 = r2
this
}

/** Updates this JoinedRow by updating its left base row. Returns itself. */
def withLeft(newLeft: Row): Row = {
row1 = newLeft
this
}

/** Updates this JoinedRow by updating its right base row. Returns itself. */
def withRight(newRight: Row): Row = {
row2 = newRight
this
}

def iterator = row1.iterator ++ row2.iterator

def length = row1.length + row2.length

def apply(i: Int) =
if (i < row1.size) row1(i) else row2(i - row1.size)

def isNullAt(i: Int) =
if (i < row1.size) row1.isNullAt(i) else row2.isNullAt(i - row1.size)

def getInt(i: Int): Int =
if (i < row1.size) row1.getInt(i) else row2.getInt(i - row1.size)

def getLong(i: Int): Long =
if (i < row1.size) row1.getLong(i) else row2.getLong(i - row1.size)

def getDouble(i: Int): Double =
if (i < row1.size) row1.getDouble(i) else row2.getDouble(i - row1.size)

def getBoolean(i: Int): Boolean =
if (i < row1.size) row1.getBoolean(i) else row2.getBoolean(i - row1.size)

def getShort(i: Int): Short =
if (i < row1.size) row1.getShort(i) else row2.getShort(i - row1.size)

def getByte(i: Int): Byte =
if (i < row1.size) row1.getByte(i) else row2.getByte(i - row1.size)

def getFloat(i: Int): Float =
if (i < row1.size) row1.getFloat(i) else row2.getFloat(i - row1.size)

def getString(i: Int): String =
if (i < row1.size) row1.getString(i) else row2.getString(i - row1.size)

def copy() = {
val totalSize = row1.size + row2.size
val copiedValues = new Array[Any](totalSize)
var i = 0
while(i < totalSize) {
copiedValues(i) = apply(i)
i += 1
}
new GenericRow(copiedValues)
}

override def toString() = {
val row = (if (row1 != null) row1 else Seq[Any]()) ++ (if (row2 != null) row2 else Seq[Any]())
s"[${row.mkString(",")}]"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ case class Aggregate(
private[this] val resultProjection =
new InterpretedMutableProjection(
resultExpressions, computedSchema ++ namedGroups.map(_._2))
private[this] val joinedRow = new JoinedRow
private[this] val joinedRow = new JoinedRow4

override final def hasNext: Boolean = hashTableIter.hasNext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ case class GeneratedAggregate(
(namedGroups.map(_._2.toAttribute) ++ computationSchema).toSeq)
log.info(s"Result Projection: ${resultExpressions.mkString(",")}")

val joinedRow = new JoinedRow
val joinedRow = new JoinedRow3

if (groupingExpressions.isEmpty) {
// TODO: Codegening anything other than the updateProjection is probably over kill.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ trait HashJoin {
private[this] var currentMatchPosition: Int = -1

// Mutable per row objects.
private[this] val joinRow = new JoinedRow
private[this] val joinRow = new JoinedRow2

private[this] val joinKeys = streamSideKeyGenerator()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ case class ParquetTableScan(
partOutput.map(a => Cast(Literal(partValues(a.name)), a.dataType).eval(EmptyRow))

new Iterator[Row] {
private[this] val joinedRow = new JoinedRow(Row(partitionRowValues:_*), null)
private[this] val joinedRow = new JoinedRow5(Row(partitionRowValues:_*), null)

def hasNext = iter.hasNext

Expand Down

0 comments on commit db44a30

Please sign in to comment.