Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;

import javax.annotation.Nullable;
import java.io.File;
Expand Down Expand Up @@ -201,6 +202,9 @@ public class AbstractParallelIndexSupervisorTaskTest extends IngestionTestBase
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();

@Rule
public final TestName testName = new TestName();

/**
* Transient task failure rate emulated by the taskKiller in {@link SimpleThreadingTaskRunner}.
* Per {@link SubTaskSpec}, there could be at most one task failure.
Expand Down Expand Up @@ -239,7 +243,7 @@ protected AbstractParallelIndexSupervisorTaskTest(
public void setUpAbstractParallelIndexSupervisorTaskTest() throws IOException
{
localDeepStorage = temporaryFolder.newFolder("localStorage");
taskRunner = new SimpleThreadingTaskRunner();
taskRunner = new SimpleThreadingTaskRunner(testName.getMethodName());
objectMapper = getObjectMapper();
indexingServiceClient = new LocalOverlordClient(objectMapper, taskRunner);
intermediaryDataManager = new LocalIntermediaryDataManager(
Expand Down Expand Up @@ -358,15 +362,14 @@ private void setActionClient(TestLocalTaskActionClient actionClient)
public class SimpleThreadingTaskRunner
{
private final ConcurrentMap<String, TaskContainer> tasks = new ConcurrentHashMap<>();
private final ListeningExecutorService service = MoreExecutors.listeningDecorator(
Execs.multiThreaded(5, "simple-threading-task-runner-%d")
);
private final ListeningExecutorService service;

private final ScheduledExecutorService taskKiller = Execs.scheduledSingleThreaded("simple-threading-task-killer");
private final Set<String> killedSubtaskSpecs = new HashSet<>();

SimpleThreadingTaskRunner()
SimpleThreadingTaskRunner(String threadNameBase)
{
service = MoreExecutors.listeningDecorator(Execs.multiThreaded(5, threadNameBase + "-%d"));
taskKiller.scheduleAtFixedRate(
() -> {
for (TaskContainer taskContainer : tasks.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public interface DataSource
/**
* Returns true if all servers have a full copy of this datasource. True for things like inline, lookup, etc, or
* for queries of those.
*
* <p>
* Currently this is coupled with joinability - if this returns true then the query engine expects there exists a
* {@link org.apache.druid.segment.join.JoinableFactory} which might build a
* {@link org.apache.druid.segment.join.Joinable} for this datasource directly. If a subquery 'inline' join is
* required to join this datasource on the right hand side, then this value must be false for now.
*
* <p>
* In the future, instead of directly using this method, the query planner and engine should consider
* {@link org.apache.druid.segment.join.JoinableFactory#isDirectlyJoinable(DataSource)} when determining if the
* right hand side is directly joinable, which would allow decoupling this property from joins.
Expand All @@ -97,7 +97,7 @@ public interface DataSource
/**
* Returns a segment function on to how to segment should be modified.
*
* @param query the input query
* @param query the input query
* @param cpuTimeAcc the cpu time accumulator
* @return the segment function
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ public int numRows()
}

@Override
protected int getActualCell(int cell)
protected int getActualValue(int rowNum)
{
int retVal = start + cell;
int retVal = start + rowNum;
if (retVal >= end) {
throw new ISE("Index out of bounds[%d] >= [%d], start[%s]", retVal, end, start);
}
return retVal;
}

@Override
protected boolean outsideBounds(int cell)
protected boolean outsideBounds(int rowNum)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
package org.apache.druid.query.operator;

import org.apache.druid.java.util.common.ISE;
import org.apache.druid.query.rowsandcols.DefaultSortedGroupPartitioner;
import org.apache.druid.query.rowsandcols.RowsAndColumns;
import org.apache.druid.query.rowsandcols.SortedGroupPartitioner;
import org.apache.druid.query.rowsandcols.semantic.DefaultSortedGroupPartitioner;
import org.apache.druid.query.rowsandcols.semantic.SortedGroupPartitioner;

import java.util.Iterator;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
@JsonSubTypes.Type(name = "last", value = WindowLastProcessor.class),
@JsonSubTypes.Type(name = "offset", value = WindowOffsetProcessor.class),
@JsonSubTypes.Type(name = "aggregate", value = WindowAggregateProcessor.class),
@JsonSubTypes.Type(name = "framedAgg", value = WindowFramedAggregateProcessor.class)
})
public interface Processor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.rowsandcols.AppendableRowsAndColumns;
import org.apache.druid.query.rowsandcols.DefaultOnHeapAggregatable;
import org.apache.druid.query.rowsandcols.OnHeapAggregatable;
import org.apache.druid.query.rowsandcols.OnHeapCumulativeAggregatable;
import org.apache.druid.query.rowsandcols.RowsAndColumns;
import org.apache.druid.query.rowsandcols.column.ConstantObjectColumn;
import org.apache.druid.query.rowsandcols.column.ObjectArrayColumn;
import org.apache.druid.query.rowsandcols.semantic.AppendableRowsAndColumns;
import org.apache.druid.query.rowsandcols.semantic.DefaultOnHeapAggregatable;
import org.apache.druid.query.rowsandcols.semantic.OnHeapAggregatable;

import javax.annotation.Nullable;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.druid.query.operator.window;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class WindowFrame

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, its a shame that "frame" really is the best name this; hopefully it wont be too confusing since it doesn't really have anything to do with the other one, https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/frame/Frame.java which should maybe be called DataFrame or... idk naming is just the worst 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataFrame is a thing in R too... I don't think it's far from what a org.apache.druid.frame.Frame is though, so maybe that's actually a good name?

{
@SuppressWarnings("unused")
public enum PeerType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worth a javadoc, it is described in some other places, such as FramedOnHeapAggregatable, but here would be nice too probably, is fine to defer until later when we have more support for this stuff though too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, word. This is a SQL concept stolen from... SQL, so I didn't think to document it as much as I probably should have. When we add support for RANGE peers, we can remove the suppression and actually document it.

{
ROWS,
RANGE
}

// Will likely need to add the order by columns to also be able to deal with RANGE peer type.
private final PeerType peerType;
private final boolean lowerUnbounded;
private final int lowerOffset;
private final boolean upperUnbounded;
private final int upperOffset;

@JsonCreator
public WindowFrame(
@JsonProperty("peerType") PeerType peerType,
@JsonProperty("lowUnbounded") boolean lowerUnbounded,
@JsonProperty("lowOffset") int lowerOffset,
@JsonProperty("uppUnbounded") boolean upperUnbounded,
@JsonProperty("uppOffset") int upperOffset
)
{
this.peerType = peerType;
this.lowerUnbounded = lowerUnbounded;
this.lowerOffset = lowerOffset;
this.upperUnbounded = upperUnbounded;
this.upperOffset = upperOffset;
}

@JsonProperty("peerType")
public PeerType getPeerType()
{
return peerType;
}

@JsonProperty("lowUnbounded")
public boolean isLowerUnbounded()
{
return lowerUnbounded;
}

@JsonProperty("lowOffset")
public int getLowerOffset()
{
return lowerOffset;
}

@JsonProperty("uppUnbounded")
public boolean isUpperUnbounded()
{
return upperUnbounded;
}

@JsonProperty("uppOffset")
public int getUpperOffset()
{
return upperOffset;
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (!(o instanceof WindowFrame)) {
return false;
}
WindowFrame that = (WindowFrame) o;
return lowerUnbounded == that.lowerUnbounded
&& lowerOffset == that.lowerOffset
&& upperUnbounded == that.upperUnbounded
&& upperOffset == that.upperOffset
&& peerType == that.peerType;
}

@Override
public int hashCode()
{
return Objects.hash(peerType, lowerUnbounded, lowerOffset, upperUnbounded, upperOffset);
}

@Override
public String toString()
{
return "WindowFrame{" +
"peerType=" + peerType +
", lowerUnbounded=" + lowerUnbounded +
", lowerOffset=" + lowerOffset +
", upperUnbounded=" + upperUnbounded +
", upperOffset=" + upperOffset +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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.druid.query.operator.window;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.rowsandcols.RowsAndColumns;
import org.apache.druid.query.rowsandcols.semantic.DefaultFramedOnHeapAggregatable;
import org.apache.druid.query.rowsandcols.semantic.FramedOnHeapAggregatable;

import javax.annotation.Nullable;
import java.util.Arrays;

public class WindowFramedAggregateProcessor implements Processor
{
@Nullable
private static <T> T[] emptyToNull(T[] arr)
{
if (arr == null || arr.length == 0) {
return null;
} else {
return arr;
}
}

private final WindowFrame frame;
private final AggregatorFactory[] aggregations;

@JsonCreator
public WindowFramedAggregateProcessor(
@JsonProperty("frame") WindowFrame frame,
@JsonProperty("aggregations") AggregatorFactory[] aggregations
)
{
this.frame = frame;
this.aggregations = emptyToNull(aggregations);
}

@JsonProperty("frame")
public WindowFrame getFrame()
{
return frame;
}

@JsonProperty("aggregations")
public AggregatorFactory[] getAggregations()
{
return aggregations;
}

@Override
public RowsAndColumns process(RowsAndColumns inputPartition)
{
FramedOnHeapAggregatable agger = inputPartition.as(FramedOnHeapAggregatable.class);
if (agger == null) {
agger = new DefaultFramedOnHeapAggregatable(RowsAndColumns.expectAppendable(inputPartition));
}

return agger.aggregateAll(frame, aggregations);
}

@Override
public boolean validateEquivalent(Processor otherProcessor)
{
if (otherProcessor instanceof WindowFramedAggregateProcessor) {
WindowFramedAggregateProcessor other = (WindowFramedAggregateProcessor) otherProcessor;
return frame.equals(other.frame) && Arrays.equals(aggregations, other.aggregations);
}
return false;
}


@Override
public String toString()
{
return "WindowFramedAggregateProcessor{" +
"frame=" + frame +
", aggregations=" + Arrays.toString(aggregations) +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import org.apache.druid.query.operator.window.Processor;
import org.apache.druid.query.rowsandcols.AppendableRowsAndColumns;
import org.apache.druid.query.rowsandcols.RowsAndColumns;
import org.apache.druid.query.rowsandcols.column.IntArrayColumn;
import org.apache.druid.query.rowsandcols.semantic.AppendableRowsAndColumns;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.query.operator.window.Processor;
import org.apache.druid.query.rowsandcols.AppendableRowsAndColumns;
import org.apache.druid.query.rowsandcols.DefaultSortedGroupPartitioner;
import org.apache.druid.query.rowsandcols.RowsAndColumns;
import org.apache.druid.query.rowsandcols.SortedGroupPartitioner;
import org.apache.druid.query.rowsandcols.column.Column;
import org.apache.druid.query.rowsandcols.semantic.AppendableRowsAndColumns;
import org.apache.druid.query.rowsandcols.semantic.DefaultSortedGroupPartitioner;
import org.apache.druid.query.rowsandcols.semantic.SortedGroupPartitioner;

import java.util.List;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.query.operator.window.Processor;
import org.apache.druid.query.rowsandcols.AppendableRowsAndColumns;
import org.apache.druid.query.rowsandcols.RowsAndColumns;
import org.apache.druid.query.rowsandcols.column.ColumnAccessor;
import org.apache.druid.query.rowsandcols.column.ColumnAccessorBasedColumn;
import org.apache.druid.query.rowsandcols.semantic.AppendableRowsAndColumns;
import org.apache.druid.segment.column.ColumnType;

public class WindowRowNumberProcessor implements Processor
Expand Down Expand Up @@ -105,7 +105,7 @@ public int getInt(int rowNum)
}

@Override
public int compareCells(int lhsRowNum, int rhsRowNum)
public int compareRows(int lhsRowNum, int rhsRowNum)
{
return Integer.compare(lhsRowNum, rhsRowNum);
}
Expand Down
Loading