Skip to content

Instantly share code, notes, and snippets.

@yuzefovich
Created June 26, 2020 22:06
Show Gist options
  • Save yuzefovich/62996b2c0f64fa09cb129ee12d8475a6 to your computer and use it in GitHub Desktop.
Save yuzefovich/62996b2c0f64fa09cb129ee12d8475a6 to your computer and use it in GitHub Desktop.
// Check whether we need to update group vector.
//if helperBase.groupState.usesGroup {
// // It is possible the tuples that mark the beginning of new groups have
// // been filtered out, so we need to update group vector accordingly.
// groupToUpdate := helperBase.groupState.group
// groupCopy := helperBase.groupState.groupCopy
// // We don't need to check whether newSel is non-nil because we know it
// // is not - the filtering operator will always set the selection on the
// // batch.
// newSel := newBatch.Selection()
// newLen := newBatch.Length()
// if newLen > 0 {
// // We might have a "group start carry" from the previous batch, so
// // we need to update the group vector accordingly.
// groupToUpdate[newSel[0]] = groupToUpdate[newSel[0]] || h.groupStartedInPreviousBatch
// h.groupStartedInPreviousBatch = false
// }
// if oldLen == newLen {
// // The length of the batch hasn't changed which means that no
// // tuples have been filtered out, so we can short-circuit.
// return newBatch
// }
// // Some tuples have been filtered out. We will iterate over all tuple
// // indices in both old and new selection vectors and will adjust group
// // vector to make sure that group boundaries are still respected. Note
// // that when the whole group is filtered out, we need to notify the
// // aggregation function about that.
// // TODO(yuzefovich): add the filtered out group handling logic. Also,
// // handle the leftover "group start carry".
// oldIdx, newIdx := 0, 0
// // TODO(yuzefovich): consider templating out sel vs no-sel cases.
// oldSel := helperBase.batchState.origSel
// if !helperBase.batchState.usesSel {
// // There was no selection vector originally, so in order to reuse
// // the code we use the default selection (for now).
// oldSel = defaultSelection
// }
// for oldIdx < oldLen && newIdx < newLen {
// if newSel[newIdx] != oldSel[oldIdx] {
// // oldIdx tuple has been filtered out.
// if groupCopy[oldSel[oldIdx]] {
// // The beginning of the group has been filtered out. The
// // current new tuple then definitely marks a start of the
// // new group (either the same that the old tuple started or
// // the new one).
// groupToUpdate[newSel[newIdx]] = true
// // We skip all old tuples until we see the new one in the
// // selection vector. Note that we don't need to check that
// // oldIdx is in bounds because the new tuple is yet to be
// // seen in oldSel.
// // TODO(yuzefovich): when templating sel vs no-sel case,
// // for no-sel we will be able to jump straight to the new
// // tuple.
// for oldSel[oldIdx] != newSel[newIdx] {
// oldIdx++
// }
// oldIdx++
// newIdx++
// } else {
// // It was not a group start, so we don't need to do
// // anything special and simply advance the old index.
// oldIdx++
// }
// } else {
// // oldIdx tuple is still present, so we advance both
// // indices.
// oldIdx++
// newIdx++
// }
// }
// // There is one additional thing we need to handle: it is possible
// // that there is an incomplete group that is the last in the batch
// // for which all tuples have been filtered out. We need to remember
// // that there is a "group start carry" between batches if so.
// for ; oldIdx < oldLen; oldIdx++ {
// if groupCopy[oldSel[oldIdx]] {
// h.groupStartedInPreviousBatch = true
// break
// }
// }
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment