org.apache.spark.sql.catalyst.expressions.Ascending Scala Examples
The following examples show how to use org.apache.spark.sql.catalyst.expressions.Ascending.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: GroupedIterator.scala From drizzle-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute, Expression, SortOrder} import org.apache.spark.sql.catalyst.expressions.codegen.{GenerateOrdering, GenerateUnsafeProjection} object GroupedIterator { def apply( input: Iterator[InternalRow], keyExpressions: Seq[Expression], inputSchema: Seq[Attribute]): Iterator[(InternalRow, Iterator[InternalRow])] = { if (input.hasNext) { new GroupedIterator(input.buffered, keyExpressions, inputSchema) } else { Iterator.empty } } } def hasNext: Boolean = currentIterator != null || fetchNextGroupIterator def next(): (InternalRow, Iterator[InternalRow]) = { assert(hasNext) // Ensure we have fetched the next iterator. val ret = (keyProjection(currentGroup), currentIterator) currentIterator = null ret } private def fetchNextGroupIterator(): Boolean = { assert(currentIterator == null) if (currentRow == null && input.hasNext) { currentRow = input.next() } if (currentRow == null) { // These is no data left, return false. false } else { // Skip to next group. // currentRow may be overwritten by `hasNext`, so we should compare them first. while (keyOrdering.compare(currentGroup, currentRow) == 0 && input.hasNext) { currentRow = input.next() } if (keyOrdering.compare(currentGroup, currentRow) == 0) { // We are in the last group, there is no more groups, return false. false } else { // Now the `currentRow` is the first row of next group. currentGroup = currentRow.copy() currentIterator = createGroupValuesIterator() true } } } private def createGroupValuesIterator(): Iterator[InternalRow] = { new Iterator[InternalRow] { def hasNext: Boolean = currentRow != null || fetchNextRowInGroup() def next(): InternalRow = { assert(hasNext) val res = currentRow currentRow = null res } private def fetchNextRowInGroup(): Boolean = { assert(currentRow == null) if (input.hasNext) { // The inner iterator should NOT consume the input into next group, here we use `head` to // peek the next input, to see if we should continue to process it. if (keyOrdering.compare(currentGroup, input.head) == 0) { // Next input is in the current group. Continue the inner iterator. currentRow = input.next() true } else { // Next input is not in the right group. End this inner iterator. false } } else { // There is no more data, return false. false } } } } }
Example 2
Source File: CoGroupedIterator.scala From drizzle-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute, SortOrder} import org.apache.spark.sql.catalyst.expressions.codegen.GenerateOrdering class CoGroupedIterator( left: Iterator[(InternalRow, Iterator[InternalRow])], right: Iterator[(InternalRow, Iterator[InternalRow])], groupingSchema: Seq[Attribute]) extends Iterator[(InternalRow, Iterator[InternalRow], Iterator[InternalRow])] { private val keyOrdering = GenerateOrdering.generate(groupingSchema.map(SortOrder(_, Ascending)), groupingSchema) private var currentLeftData: (InternalRow, Iterator[InternalRow]) = _ private var currentRightData: (InternalRow, Iterator[InternalRow]) = _ override def hasNext: Boolean = { if (currentLeftData == null && left.hasNext) { currentLeftData = left.next() } if (currentRightData == null && right.hasNext) { currentRightData = right.next() } currentLeftData != null || currentRightData != null } override def next(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { assert(hasNext) if (currentLeftData.eq(null)) { // left is null, right is not null, consume the right data. rightOnly() } else if (currentRightData.eq(null)) { // left is not null, right is null, consume the left data. leftOnly() } else if (currentLeftData._1 == currentRightData._1) { // left and right have the same grouping key, consume both of them. val result = (currentLeftData._1, currentLeftData._2, currentRightData._2) currentLeftData = null currentRightData = null result } else { val compare = keyOrdering.compare(currentLeftData._1, currentRightData._1) assert(compare != 0) if (compare < 0) { // the grouping key of left is smaller, consume the left data. leftOnly() } else { // the grouping key of right is smaller, consume the right data. rightOnly() } } } private def leftOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentLeftData._1, currentLeftData._2, Iterator.empty) currentLeftData = null result } private def rightOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentRightData._1, Iterator.empty, currentRightData._2) currentRightData = null result } }
Example 3
Source File: GroupedIterator.scala From XSQL with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute, Expression, SortOrder} import org.apache.spark.sql.catalyst.expressions.codegen.{GenerateOrdering, GenerateUnsafeProjection} object GroupedIterator { def apply( input: Iterator[InternalRow], keyExpressions: Seq[Expression], inputSchema: Seq[Attribute]): Iterator[(InternalRow, Iterator[InternalRow])] = { if (input.hasNext) { new GroupedIterator(input.buffered, keyExpressions, inputSchema) } else { Iterator.empty } } } def hasNext: Boolean = currentIterator != null || fetchNextGroupIterator def next(): (InternalRow, Iterator[InternalRow]) = { assert(hasNext) // Ensure we have fetched the next iterator. val ret = (keyProjection(currentGroup), currentIterator) currentIterator = null ret } private def fetchNextGroupIterator(): Boolean = { assert(currentIterator == null) if (currentRow == null && input.hasNext) { currentRow = input.next() } if (currentRow == null) { // These is no data left, return false. false } else { // Skip to next group. // currentRow may be overwritten by `hasNext`, so we should compare them first. while (keyOrdering.compare(currentGroup, currentRow) == 0 && input.hasNext) { currentRow = input.next() } if (keyOrdering.compare(currentGroup, currentRow) == 0) { // We are in the last group, there is no more groups, return false. false } else { // Now the `currentRow` is the first row of next group. currentGroup = currentRow.copy() currentIterator = createGroupValuesIterator() true } } } private def createGroupValuesIterator(): Iterator[InternalRow] = { new Iterator[InternalRow] { def hasNext: Boolean = currentRow != null || fetchNextRowInGroup() def next(): InternalRow = { assert(hasNext) val res = currentRow currentRow = null res } private def fetchNextRowInGroup(): Boolean = { assert(currentRow == null) if (input.hasNext) { // The inner iterator should NOT consume the input into next group, here we use `head` to // peek the next input, to see if we should continue to process it. if (keyOrdering.compare(currentGroup, input.head) == 0) { // Next input is in the current group. Continue the inner iterator. currentRow = input.next() true } else { // Next input is not in the right group. End this inner iterator. false } } else { // There is no more data, return false. false } } } } }
Example 4
Source File: CoGroupedIterator.scala From XSQL with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute, SortOrder} import org.apache.spark.sql.catalyst.expressions.codegen.GenerateOrdering class CoGroupedIterator( left: Iterator[(InternalRow, Iterator[InternalRow])], right: Iterator[(InternalRow, Iterator[InternalRow])], groupingSchema: Seq[Attribute]) extends Iterator[(InternalRow, Iterator[InternalRow], Iterator[InternalRow])] { private val keyOrdering = GenerateOrdering.generate(groupingSchema.map(SortOrder(_, Ascending)), groupingSchema) private var currentLeftData: (InternalRow, Iterator[InternalRow]) = _ private var currentRightData: (InternalRow, Iterator[InternalRow]) = _ override def hasNext: Boolean = { if (currentLeftData == null && left.hasNext) { currentLeftData = left.next() } if (currentRightData == null && right.hasNext) { currentRightData = right.next() } currentLeftData != null || currentRightData != null } override def next(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { assert(hasNext) if (currentLeftData.eq(null)) { // left is null, right is not null, consume the right data. rightOnly() } else if (currentRightData.eq(null)) { // left is not null, right is null, consume the left data. leftOnly() } else if (currentLeftData._1 == currentRightData._1) { // left and right have the same grouping key, consume both of them. val result = (currentLeftData._1, currentLeftData._2, currentRightData._2) currentLeftData = null currentRightData = null result } else { val compare = keyOrdering.compare(currentLeftData._1, currentRightData._1) assert(compare != 0) if (compare < 0) { // the grouping key of left is smaller, consume the left data. leftOnly() } else { // the grouping key of right is smaller, consume the right data. rightOnly() } } } private def leftOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentLeftData._1, currentLeftData._2, Iterator.empty) currentLeftData = null result } private def rightOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentRightData._1, Iterator.empty, currentRightData._2) currentRightData = null result } }
Example 5
Source File: CoGroupedIterator.scala From sparkoscope with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute, SortOrder} import org.apache.spark.sql.catalyst.expressions.codegen.GenerateOrdering class CoGroupedIterator( left: Iterator[(InternalRow, Iterator[InternalRow])], right: Iterator[(InternalRow, Iterator[InternalRow])], groupingSchema: Seq[Attribute]) extends Iterator[(InternalRow, Iterator[InternalRow], Iterator[InternalRow])] { private val keyOrdering = GenerateOrdering.generate(groupingSchema.map(SortOrder(_, Ascending)), groupingSchema) private var currentLeftData: (InternalRow, Iterator[InternalRow]) = _ private var currentRightData: (InternalRow, Iterator[InternalRow]) = _ override def hasNext: Boolean = { if (currentLeftData == null && left.hasNext) { currentLeftData = left.next() } if (currentRightData == null && right.hasNext) { currentRightData = right.next() } currentLeftData != null || currentRightData != null } override def next(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { assert(hasNext) if (currentLeftData.eq(null)) { // left is null, right is not null, consume the right data. rightOnly() } else if (currentRightData.eq(null)) { // left is not null, right is null, consume the left data. leftOnly() } else if (currentLeftData._1 == currentRightData._1) { // left and right have the same grouping key, consume both of them. val result = (currentLeftData._1, currentLeftData._2, currentRightData._2) currentLeftData = null currentRightData = null result } else { val compare = keyOrdering.compare(currentLeftData._1, currentRightData._1) assert(compare != 0) if (compare < 0) { // the grouping key of left is smaller, consume the left data. leftOnly() } else { // the grouping key of right is smaller, consume the right data. rightOnly() } } } private def leftOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentLeftData._1, currentLeftData._2, Iterator.empty) currentLeftData = null result } private def rightOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentRightData._1, Iterator.empty, currentRightData._2) currentRightData = null result } }
Example 6
Source File: CoGroupedIterator.scala From multi-tenancy-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute, SortOrder} import org.apache.spark.sql.catalyst.expressions.codegen.GenerateOrdering class CoGroupedIterator( left: Iterator[(InternalRow, Iterator[InternalRow])], right: Iterator[(InternalRow, Iterator[InternalRow])], groupingSchema: Seq[Attribute]) extends Iterator[(InternalRow, Iterator[InternalRow], Iterator[InternalRow])] { private val keyOrdering = GenerateOrdering.generate(groupingSchema.map(SortOrder(_, Ascending)), groupingSchema) private var currentLeftData: (InternalRow, Iterator[InternalRow]) = _ private var currentRightData: (InternalRow, Iterator[InternalRow]) = _ override def hasNext: Boolean = { if (currentLeftData == null && left.hasNext) { currentLeftData = left.next() } if (currentRightData == null && right.hasNext) { currentRightData = right.next() } currentLeftData != null || currentRightData != null } override def next(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { assert(hasNext) if (currentLeftData.eq(null)) { // left is null, right is not null, consume the right data. rightOnly() } else if (currentRightData.eq(null)) { // left is not null, right is null, consume the left data. leftOnly() } else if (currentLeftData._1 == currentRightData._1) { // left and right have the same grouping key, consume both of them. val result = (currentLeftData._1, currentLeftData._2, currentRightData._2) currentLeftData = null currentRightData = null result } else { val compare = keyOrdering.compare(currentLeftData._1, currentRightData._1) assert(compare != 0) if (compare < 0) { // the grouping key of left is smaller, consume the left data. leftOnly() } else { // the grouping key of right is smaller, consume the right data. rightOnly() } } } private def leftOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentLeftData._1, currentLeftData._2, Iterator.empty) currentLeftData = null result } private def rightOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentRightData._1, Iterator.empty, currentRightData._2) currentRightData = null result } }
Example 7
Source File: CoGroupedIterator.scala From Spark-2.3.1 with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute, SortOrder} import org.apache.spark.sql.catalyst.expressions.codegen.GenerateOrdering class CoGroupedIterator( left: Iterator[(InternalRow, Iterator[InternalRow])], right: Iterator[(InternalRow, Iterator[InternalRow])], groupingSchema: Seq[Attribute]) extends Iterator[(InternalRow, Iterator[InternalRow], Iterator[InternalRow])] { private val keyOrdering = GenerateOrdering.generate(groupingSchema.map(SortOrder(_, Ascending)), groupingSchema) private var currentLeftData: (InternalRow, Iterator[InternalRow]) = _ private var currentRightData: (InternalRow, Iterator[InternalRow]) = _ override def hasNext: Boolean = { if (currentLeftData == null && left.hasNext) { currentLeftData = left.next() } if (currentRightData == null && right.hasNext) { currentRightData = right.next() } currentLeftData != null || currentRightData != null } override def next(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { assert(hasNext) if (currentLeftData.eq(null)) { // left is null, right is not null, consume the right data. rightOnly() } else if (currentRightData.eq(null)) { // left is not null, right is null, consume the left data. leftOnly() } else if (currentLeftData._1 == currentRightData._1) { // left and right have the same grouping key, consume both of them. val result = (currentLeftData._1, currentLeftData._2, currentRightData._2) currentLeftData = null currentRightData = null result } else { val compare = keyOrdering.compare(currentLeftData._1, currentRightData._1) assert(compare != 0) if (compare < 0) { // the grouping key of left is smaller, consume the left data. leftOnly() } else { // the grouping key of right is smaller, consume the right data. rightOnly() } } } private def leftOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentLeftData._1, currentLeftData._2, Iterator.empty) currentLeftData = null result } private def rightOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentRightData._1, Iterator.empty, currentRightData._2) currentRightData = null result } }
Example 8
Source File: CoGroupedIterator.scala From BigDatalog with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.execution import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{Ascending, SortOrder, Attribute} import org.apache.spark.sql.catalyst.expressions.codegen.GenerateOrdering class CoGroupedIterator( left: Iterator[(InternalRow, Iterator[InternalRow])], right: Iterator[(InternalRow, Iterator[InternalRow])], groupingSchema: Seq[Attribute]) extends Iterator[(InternalRow, Iterator[InternalRow], Iterator[InternalRow])] { private val keyOrdering = GenerateOrdering.generate(groupingSchema.map(SortOrder(_, Ascending)), groupingSchema) private var currentLeftData: (InternalRow, Iterator[InternalRow]) = _ private var currentRightData: (InternalRow, Iterator[InternalRow]) = _ override def hasNext: Boolean = { if (currentLeftData == null && left.hasNext) { currentLeftData = left.next() } if (currentRightData == null && right.hasNext) { currentRightData = right.next() } currentLeftData != null || currentRightData != null } override def next(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { assert(hasNext) if (currentLeftData.eq(null)) { // left is null, right is not null, consume the right data. rightOnly() } else if (currentRightData.eq(null)) { // left is not null, right is null, consume the left data. leftOnly() } else if (currentLeftData._1 == currentRightData._1) { // left and right have the same grouping key, consume both of them. val result = (currentLeftData._1, currentLeftData._2, currentRightData._2) currentLeftData = null currentRightData = null result } else { val compare = keyOrdering.compare(currentLeftData._1, currentRightData._1) assert(compare != 0) if (compare < 0) { // the grouping key of left is smaller, consume the left data. leftOnly() } else { // the grouping key of right is smaller, consume the right data. rightOnly() } } } private def leftOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentLeftData._1, currentLeftData._2, Iterator.empty) currentLeftData = null result } private def rightOnly(): (InternalRow, Iterator[InternalRow], Iterator[InternalRow]) = { val result = (currentRightData._1, Iterator.empty, currentRightData._2) currentRightData = null result } }