Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnest changes for moving the filter on right side of correlate to inside the unnest datasource #13934

Merged
merged 19 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
eeb88c6
Refactoring and bug fixes on top of unnest. The filter now is passed …
somu-imply Mar 10, 2023
586f3ee
Not pushing filters in now, will be done if needed later when we migr…
somu-imply Mar 11, 2023
75e8b77
Removing stale comments and updating docs
somu-imply Mar 13, 2023
dda7872
Temp changes for selector filter
somu-imply Mar 14, 2023
3cf5e72
Handling rules for a case where selector filters adds an extra layer …
somu-imply Mar 14, 2023
76aaed1
Trying to move filter inside unnest part 1
somu-imply Mar 14, 2023
dd4529f
Merge remote-tracking branch 'upstream/master' into unnest_changes1
somu-imply Mar 14, 2023
6227595
Some cleanup after merging with master
somu-imply Mar 14, 2023
65a6397
checkstyle fix and 1 test case with selector on virtual column throug…
somu-imply Mar 14, 2023
7e68d4c
Adding support for OR filters on unnested column and other columns
somu-imply Mar 15, 2023
1bd289b
Redesigning or filters for unnest, now an or will be optimized by cre…
somu-imply Mar 15, 2023
f930890
Refactoring for OR filter case and adding more comments and examples
somu-imply Mar 15, 2023
606396d
A change in the comments to be in sync with code
somu-imply Mar 15, 2023
59ce1ba
New test cases with or filters and slight refactoring bu removing And…
somu-imply Mar 16, 2023
9f5b276
Minor nits in comment + new test
somu-imply Mar 16, 2023
3838d6c
More tests now in storage adapter to check filers and improve coverage
somu-imply Mar 16, 2023
b3c02e7
Using matches in the rule now
somu-imply Mar 16, 2023
96524df
Fixing a NPE
somu-imply Mar 17, 2023
b446228
Refactoring in tests to allow validating the filters pushed down to t…
somu-imply Mar 22, 2023
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 @@ -23,12 +23,16 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.query.filter.DimFilter;
import org.apache.druid.query.planning.DataSourceAnalysis;
import org.apache.druid.segment.SegmentReference;
import org.apache.druid.segment.UnnestSegmentReference;
import org.apache.druid.segment.VirtualColumn;
import org.apache.druid.utils.JvmUtils;


import javax.annotation.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand All @@ -48,22 +52,29 @@ public class UnnestDataSource implements DataSource
private final DataSource base;
private final VirtualColumn virtualColumn;

@Nullable
private final DimFilter unnestFilter;

private UnnestDataSource(
DataSource dataSource,
VirtualColumn virtualColumn
VirtualColumn virtualColumn,
DimFilter unnestFilter
)
{
this.base = dataSource;
this.virtualColumn = virtualColumn;
this.unnestFilter = unnestFilter;
}

@JsonCreator
public static UnnestDataSource create(
@JsonProperty("base") DataSource base,
@JsonProperty("virtualColumn") VirtualColumn virtualColumn
@JsonProperty("virtualColumn") VirtualColumn virtualColumn,
@Nullable @JsonProperty("unnestFilter") DimFilter unnestFilter

)
{
return new UnnestDataSource(base, virtualColumn);
return new UnnestDataSource(base, virtualColumn, unnestFilter);
}

@JsonProperty("base")
Expand All @@ -78,6 +89,12 @@ public VirtualColumn getVirtualColumn()
return virtualColumn;
}

@JsonProperty("unnestFilter")
public DimFilter getUnnestFilter()
{
return unnestFilter;
}

@Override
public Set<String> getTableNames()
{
Expand All @@ -96,7 +113,8 @@ public DataSource withChildren(List<DataSource> children)
if (children.size() != 1) {
throw new IAE("Expected [1] child, got [%d]", children.size());
}
return new UnnestDataSource(children.get(0), virtualColumn);

return new UnnestDataSource(children.get(0), virtualColumn, unnestFilter);
}

@Override
Expand Down Expand Up @@ -133,15 +151,16 @@ public Function<SegmentReference, SegmentReference> createSegmentMapFunction(
baseSegment ->
new UnnestSegmentReference(
segmentMapFn.apply(baseSegment),
virtualColumn
virtualColumn,
unnestFilter
)
);
}

@Override
public DataSource withUpdatedDataSource(DataSource newSource)
{
return new UnnestDataSource(newSource, virtualColumn);
return new UnnestDataSource(newSource, virtualColumn, unnestFilter);
}

@Override
Expand All @@ -162,6 +181,17 @@ public DataSourceAnalysis getAnalysis()
return current.getAnalysis();
}


@Override
public String toString()
{
return "UnnestDataSource{" +
"base=" + base +
", column='" + virtualColumn + '\'' +
", unnestFilter='" + unnestFilter + '\'' +
'}';
}

@Override
public boolean equals(Object o)
{
Expand All @@ -172,25 +202,17 @@ public boolean equals(Object o)
return false;
}
UnnestDataSource that = (UnnestDataSource) o;
return virtualColumn.equals(that.virtualColumn)
&& base.equals(that.base);
return base.equals(that.base) && virtualColumn.equals(that.virtualColumn) && Objects.equals(
unnestFilter,
that.unnestFilter
);
}

@Override
public int hashCode()
{
return Objects.hash(base, virtualColumn);
}

@Override
public String toString()
{
return "UnnestDataSource{" +
"base=" + base +
", column='" + virtualColumn + '\'' +
'}';
return Objects.hash(base, virtualColumn, unnestFilter);
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public void inspectRuntimeShape(RuntimeShapeInspector inspector)
@Override
public boolean matches()
{
if (indexedIntsForCurrentRow == null) {
return false;
}
if (indexedIntsForCurrentRow.size() <= 0) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.druid.java.util.common.io.Closer;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.query.filter.DimFilter;
import org.apache.druid.timeline.SegmentId;
import org.apache.druid.utils.CloseableUtils;
import org.joda.time.Interval;
Expand All @@ -41,14 +42,20 @@ public class UnnestSegmentReference implements SegmentReference
private final SegmentReference baseSegment;
private final VirtualColumn unnestColumn;

@Nullable
private final DimFilter unnestFilter;



public UnnestSegmentReference(
SegmentReference baseSegment,
VirtualColumn unnestColumn
VirtualColumn unnestColumn,
DimFilter unnestFilter
)
{
this.baseSegment = baseSegment;
this.unnestColumn = unnestColumn;
this.unnestFilter = unnestFilter;
}

@Override
Expand Down Expand Up @@ -100,7 +107,8 @@ public StorageAdapter asStorageAdapter()
{
return new UnnestStorageAdapter(
baseSegment.asStorageAdapter(),
unnestColumn
unnestColumn,
unnestFilter
);
}

Expand Down
Loading