Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
eabb65b
WIP nothing worked, just recording the progress
HeartSaVioR Sep 4, 2018
c3076d2
WIP not working yet... lots of implementations needed
HeartSaVioR Sep 6, 2018
9d59c7a
WIP Finished implementing UpdatingSessionIterator
HeartSaVioR Sep 6, 2018
b38f2b9
WIP add verification on precondition "rows in iterator are sorted by …
HeartSaVioR Sep 7, 2018
668c1f5
Rename SymmetricHashJoinStateManager to MultiValuesStateManager
HeartSaVioR Sep 8, 2018
9f63a3c
Move package of UpdatingSessionIterator
HeartSaVioR Sep 8, 2018
5d17ac8
WIP add MergingSortWithMultiValuesStateIterator, now integrating with…
HeartSaVioR Sep 10, 2018
ec33265
WIP the first version of working one! Still have lots of TODOs and FI…
HeartSaVioR Sep 13, 2018
8b210d5
Add more explanations
HeartSaVioR Sep 13, 2018
7255bca
Silly bugfix & block session window for batch query as of now
HeartSaVioR Sep 13, 2018
7b57fe5
More works: majorly split out updating session to individual physical…
HeartSaVioR Sep 13, 2018
969859b
Fix a silly bug and also add check for session window against batch q…
HeartSaVioR Sep 13, 2018
f5ecbdd
WIP Fixed eviction on update mode
HeartSaVioR Sep 13, 2018
b180772
WIP found root reason of broken UT... fixed it
HeartSaVioR Sep 13, 2018
0a2d731
WIP remove printing "explain" on UTs
HeartSaVioR Sep 13, 2018
6ee901e
WIP address session to batch query (+ python) as well... not having t…
HeartSaVioR Sep 13, 2018
395606b
WIP add more test on session batch query
HeartSaVioR Sep 13, 2018
f6bb34d
WIP add UT for sessions with keys overlapped
HeartSaVioR Sep 14, 2018
22fffd2
WIP refactor a bit
HeartSaVioR Sep 14, 2018
847f69e
WIP add more FIXMEs for javadoc, and remove invalid FIXMEs
HeartSaVioR Sep 14, 2018
104df13
WIP Repackage & remove unnecessary field
HeartSaVioR Sep 17, 2018
8108fc5
WIP addressed UPDATE mode, but doesn't look like performant
HeartSaVioR Sep 17, 2018
35c8fef
WIP remove FIXME since it is not relevant
HeartSaVioR Sep 17, 2018
6b1d1e0
WIP update numOutputRows for Append mode
HeartSaVioR Sep 17, 2018
86b3060
WIP apply aggregations when merging sessions
HeartSaVioR Sep 18, 2018
f7c2deb
WIP simplify the code a bit
HeartSaVioR Sep 18, 2018
a81616b
WIP address batch distinct query for sessionization
HeartSaVioR Sep 18, 2018
013785d
WIP remove debug statements for test code
HeartSaVioR Sep 18, 2018
37fffef
WIP remove debug informations
HeartSaVioR Sep 18, 2018
df95e72
WIP port Sessionization example to UT of session window
HeartSaVioR Sep 18, 2018
16d6421
WIP remove unnecessary thing
HeartSaVioR Sep 18, 2018
dc43300
WIP fix all the issues with sessionization example UTs
HeartSaVioR Sep 19, 2018
3637f60
WIP apply merging session in each partition before shuffling
HeartSaVioR Sep 19, 2018
0d53831
Fix scala checkstyle
HeartSaVioR Sep 20, 2018
a781400
Fix python style check
HeartSaVioR Sep 20, 2018
918dad2
WIP add complete mode, fix tricky bugs, apply ExternalAppendOnlyUnsaf…
HeartSaVioR Oct 8, 2018
fd6377b
WIP add "session" function to exclude list for description
HeartSaVioR Oct 8, 2018
e029e12
WIP rename function & column name "session" to "session_window"
HeartSaVioR Oct 10, 2018
a2fc652
WIP reducing unnecessary codegen which seriously harmed performance
HeartSaVioR Oct 15, 2018
2dc413b
WIP reduce codegen once again for MergingSessionsIterator
HeartSaVioR Oct 15, 2018
4dd0e89
WIP optimize a bit more on codegen...
HeartSaVioR Oct 15, 2018
cf52044
WIP make the feature "merge session in local partition" optional
HeartSaVioR Oct 15, 2018
5c74609
WIP add "session_window" to exclude list
HeartSaVioR Oct 17, 2018
fb6c59f
WIP Enable versioning of session window state format
HeartSaVioR Oct 18, 2018
dd29af2
WIP some correction in comment
HeartSaVioR Oct 19, 2018
1f6e496
WIP cover all the cases for session window in UTs
HeartSaVioR Oct 20, 2018
0673b6e
WIP Add Linked List data structure for storing session windows
HeartSaVioR Oct 23, 2018
4698f6d
WIP add SessionWindowLinkedListStateStoreRDD
HeartSaVioR Oct 23, 2018
5c67f72
WIP add more functionalities to SessionWindowLinkedListState
HeartSaVioR Oct 24, 2018
7bb0060
WIP it works but a bit suboptimal
HeartSaVioR Oct 25, 2018
35c9712
WIP optimized!
HeartSaVioR Oct 25, 2018
ede078a
WIP remove requirement on sort, add UT to test linked list state with…
HeartSaVioR Oct 27, 2018
f8e8ff6
WIP add code to print out information when task crashes with dangling…
HeartSaVioR Oct 27, 2018
b05abc7
WIP fixed the issue with benchmark run
HeartSaVioR Oct 29, 2018
17570f2
WIP optimize a bit on storing new sessions
HeartSaVioR Oct 30, 2018
958de31
WIP Fixed critical bug which tasks don't respect preference on state …
HeartSaVioR Oct 31, 2018
ee67bca
WIP Fix critical perf. issue: remove codegen on generating session ro…
HeartSaVioR Nov 1, 2018
8a0331e
WIP Rolling back unnecessary changes
HeartSaVioR Nov 2, 2018
b6ccecd
WIP Apply removing codegen to UpdatingSessionIterator as well
HeartSaVioR Nov 2, 2018
75c7611
WIP remove state version for now: it will be reintroduced when actual…
HeartSaVioR Nov 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More works: majorly split out updating session to individual physical…
… node

* we will leverage such node for batch case if we want
  • Loading branch information
HeartSaVioR committed Oct 10, 2018
commit 7b57fe5d4fb1ca4a62ae9ed8d7851ffee6633fb9
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.sql.execution.aggregate
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.aggregate._
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.execution.streaming.{SessionWindowStateStoreRestoreExec, SessionWindowStateStoreSaveExec, StateStoreRestoreExec, StateStoreSaveExec}
import org.apache.spark.sql.execution.streaming._

/**
* Utility functions used by the query planner to convert our plan to new aggregation code path.
Expand Down Expand Up @@ -115,8 +115,6 @@ object AggUtils {
finalAggregate :: Nil
}

// FIXME: distinct in session makes sense?

def planAggregateWithOneDistinct(
groupingExpressions: Seq[NamedExpression],
functionsWithDistinct: Seq[AggregateExpression],
Expand Down Expand Up @@ -348,7 +346,9 @@ object AggUtils {
* - Shuffle & Sort (distribution: keys "without" session, sort: all keys)
* - SessionWindowStateStoreRestore (group: keys "without" session)
* - merge input tuples with stored tuples (sessions) respecting sort order
* - UpdatingSessionExec
* - calculate session among tuples, and update all tuples to get correct session range
* - NOTE: it leverages the fact that the output of SessionWindowStateStoreRestore is sorted
* - PartialMerge (group: all keys)
* - now there is at most 1 tuple per group
* - SessionWindowStateStoreSave (group: keys "without" session)
Expand Down Expand Up @@ -389,6 +389,10 @@ object AggUtils {
val restored = SessionWindowStateStoreRestoreExec(groupingWithoutSessionAttributes,
sessionExpression.toAttribute, stateInfo = None, eventTimeWatermark = None, partialAggregate)

val updatedSession = UpdatingSessionExec(groupingWithoutSessionAttributes,
sessionExpression.toAttribute, optRequiredChildDistribution = None,
optRequiredChildOrdering = None, restored)

val partialMerged: SparkPlan = {
val aggregateExpressions = functionsWithoutDistinct.map(_.copy(mode = PartialMerge))
val aggregateAttributes = aggregateExpressions.map(_.resultAttribute)
Expand All @@ -401,7 +405,7 @@ object AggUtils {
initialInputBufferOffset = groupingAttributes.length,
resultExpressions = groupingAttributes ++
aggregateExpressions.flatMap(_.aggregateFunction.inputAggBufferAttributes),
child = restored)
child = updatedSession)
}

// Note: stateId and returnAllStates are filled in later with preparation rules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.sql.execution.aggregate

import org.apache.spark.TaskContext

import org.apache.spark.rdd.RDD
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.{Attribute, SortOrder}
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
import org.apache.spark.sql.catalyst.plans.physical.{Distribution, Partitioning}
import org.apache.spark.sql.execution.{SparkPlan, UnaryExecNode}
import org.apache.spark.sql.execution.streaming.UpdatingSessionIterator

// FIXME: javadoc should provide precondition that input must be sorted
// or both required child distribution as well as required child ordering should be presented
// to guarantee input will be sorted
case class UpdatingSessionExec(
keyExpressions: Seq[Attribute],
sessionExpression: Attribute,
optRequiredChildDistribution: Option[Seq[Distribution]],
optRequiredChildOrdering: Option[Seq[Seq[SortOrder]]],
child: SparkPlan) extends UnaryExecNode {

override protected def doExecute(): RDD[InternalRow] = {
child.execute().mapPartitions { iter =>
val newIter = new UpdatingSessionIterator(iter, keyExpressions, sessionExpression,
child.output)

val debugIter = newIter.map { row =>
val keysProjection = GenerateUnsafeProjection.generate(keyExpressions, child.output)
val sessionProjection = GenerateUnsafeProjection.generate(
Seq(sessionExpression), child.output)
val rowProjection = GenerateUnsafeProjection.generate(child.output, child.output)

// FIXME: remove
val debugPartitionId = TaskContext.get().partitionId()

logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - keys ${keysProjection(row)}")
logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - session ${sessionProjection(row)}")
logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - row (proj) ${rowProjection(row)}")
logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - row ${row}")

row
}

debugIter
}
}

override def output: Seq[Attribute] = child.output

override def outputPartitioning: Partitioning = child.outputPartitioning

override def requiredChildDistribution: Seq[Distribution] = optRequiredChildDistribution match {
case Some(distribution) => distribution
case None => super.requiredChildDistribution
}

override def requiredChildOrdering: Seq[Seq[SortOrder]] = optRequiredChildOrdering match {
case Some(ordering) => ordering
case None => super.requiredChildOrdering
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class IncrementalExecution(
Some(aggStateInfo),
stateFormatVersion,
child) :: Nil))
/*

case SessionWindowStateStoreSaveExec(keys, session, None, None, None,
UnaryExecNode(agg,
UnaryExecNode(agg2,
Expand All @@ -138,25 +138,6 @@ class IncrementalExecution(
Some(aggStateInfo),
Some(offsetSeqMetadata.batchWatermarkMs),
child) :: Nil) :: Nil))
*/

case SessionWindowStateStoreSaveExec(keys, session, None, None, None,
UnaryExecNode(agg,
SessionWindowStateStoreRestoreExec(_, _, None, None, child))) =>
val aggStateInfo = nextStatefulOperationStateInfo
SessionWindowStateStoreSaveExec(
keys,
session,
Some(aggStateInfo),
Some(outputMode),
Some(offsetSeqMetadata.batchWatermarkMs),
agg.withNewChildren(
SessionWindowStateStoreRestoreExec(
keys,
session,
Some(aggStateInfo),
Some(offsetSeqMetadata.batchWatermarkMs),
child) :: Nil))

case StreamingDeduplicateExec(keys, child, None, None) =>
StreamingDeduplicateExec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.sql.execution.streaming
import scala.collection.mutable

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute, BindReferences, CreateNamedStruct, Expression, Literal, PreciseTimestampConversion, UnsafeRow}
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
import org.apache.spark.sql.types.{LongType, TimestampType}

Expand All @@ -47,7 +47,7 @@ class UpdatingSessionIterator(

val processedKeys: mutable.HashSet[InternalRow] = new mutable.HashSet[InternalRow]()

// FIXME: data loss seen... one data from input and one data from state
// FIXME: check whether it can be run with such situation: empty groupWithoutSessionExpressions

override def hasNext: Boolean = {
assertIteratorNotCorrupted()
Expand Down Expand Up @@ -191,8 +191,6 @@ class UpdatingSessionIterator(
returnRowsIter = returnRows.iterator
}

//returnRowsIter = returnRows.iterator

// FIXME: DEBUG
val (rIter, tmpReturnRowsIter) = returnRowsIter.duplicate
returnRowsIter = rIter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@ case class SessionWindowStateStoreRestoreExec(
}

val mergedIter = new MergingSortWithMultiValuesStateIterator(filteredIterator, stateManager,
keyExpressions, sessionExpression, watermarkPredicateForData, child.output)
keyExpressions, sessionExpression, watermarkPredicateForData, child.output).map { row =>
numOutputRows += 1
row
}

val debugMergedIter = mergedIter.map { row =>
val keysProjection = GenerateUnsafeProjection.generate(keyExpressions, child.output)
Expand All @@ -498,22 +501,7 @@ case class SessionWindowStateStoreRestoreExec(
row
}

new UpdatingSessionIterator(debugMergedIter, keyExpressions, sessionExpression,
child.output).map { row =>
numOutputRows += 1

val keysProjection = GenerateUnsafeProjection.generate(keyExpressions, child.output)
val sessionProjection = GenerateUnsafeProjection.generate(
Seq(sessionExpression), child.output)
val rowProjection = GenerateUnsafeProjection.generate(child.output, child.output)

logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - keys ${keysProjection(row)}")
logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - session ${sessionProjection(row)}")
logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - row (proj) ${rowProjection(row)}")
logWarning(s"DEBUG: partitionId $debugPartitionId - updated session row - row ${row}")

row
}
debugMergedIter
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.apache.spark.sql.{AnalysisException, Dataset}
import org.apache.spark.sql.catalyst.plans.logical.EventTimeWatermark
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.execution.streaming._
import org.apache.spark.sql.functions.{count, window, session}
import org.apache.spark.sql.functions.{count, session, window}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.streaming.OutputMode._
import org.apache.spark.util.Utils
Expand Down