-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
rework cursor creation #16533
base: master
Are you sure you want to change the base?
rework cursor creation #16533
Conversation
changes: * Added `CursorBuildSpec` which captures all of the 'interesting' stuff that goes into producing a cursor as a replacement for the method arguments of `CursorFactory.canVectorize`, `CursorFactory.makeCursors`, and `CursorFactory.makeVectorCursors` * added new interfaces `CursorMaker` and new method `asCursorMaker` to `CursorFactory`, which takes a `CursorBuildSpec` as an argument and replaces `CursorFactory.canVectorize`, `CursorFactory.makeCursors`, and `CursorFactory.makeVectorCursors` * Deprecated `CursorFactory.canVectorize`, `CursorFactory.makeCursors`, and `CursorFactory.makeVectorCursors` * updated all `CursorFactory` implementations to implement `asCursorMaker` * updated all query engines to use `asCursorMaker`
@Override | ||
public boolean canVectorize() | ||
{ | ||
return CursorFactory.this.canVectorize(spec.getFilter(), spec.getVirtualColumns(), spec.isDescending()); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
CursorFactory.canVectorize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is intended so that existing CursorFactory
/StorageAdapter
implementations can keep working with query engines without implementing asCursorMaker
return CursorFactory.this.makeCursors( | ||
spec.getFilter(), | ||
spec.getInterval(), | ||
spec.getVirtualColumns(), | ||
spec.getGranularity(), | ||
spec.isDescending(), | ||
spec.getQueryMetrics() | ||
); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
CursorFactory.makeCursors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is intended so that existing CursorFactory
/StorageAdapter
implementations can keep working with query engines without implementing asCursorMaker
return CursorFactory.this.makeVectorCursor( | ||
spec.getFilter(), | ||
spec.getInterval(), | ||
spec.getVirtualColumns(), | ||
spec.isDescending(), | ||
spec.getQueryContext().getVectorSize(), | ||
spec.getQueryMetrics() | ||
); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
CursorFactory.makeVectorCursor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is intended so that existing CursorFactory
/StorageAdapter
implementations can keep working with query engines without implementing asCursorMaker
@@ -668,4 +724,43 @@ | |||
return new DescendingTimestampCheckingOffset(baseOffset.clone(), timestamps, timeLimit, allWithinThreshold); | |||
} | |||
} | |||
|
|||
private final class CursorResources implements Closeable |
Check notice
Code scanning / CodeQL
Inner class could be static Note
newFilter = null; | ||
} | ||
} else { | ||
newFilter = new AndFilter(ImmutableList.of(spec.getFilter(), filterOnDataSource.toFilter())); |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning
filterOnDataSource
this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method needs to be removed as it is never used to pass the intellij-inspections
check in Github Action
Description
This PR reworks
Cursor
andVectorCursor
creation fromCursorFactory
(StorageAdapter
) to be more efficient and push additional details about the query into the process with a newly introducedCursorBuildSpec
. A newCursorMaker
interfaceCursorMaker
has been added that is constructed by a new methodCursorFactory.asCursorMaker
, which accepts theCursorBuildSpec
and replaces the arguments ofCursorFactory.makeCursors
andCursorFactory.makeVectorCursors
.The primary goal here is to make it easy to push these details down to cursor creation for an upcoming feature under development, projections, which are effectively a type of materialized views that live within segments and will be created at ingestion time. More details on this coming later once I finish writing the proposal, but basically we need to know stuff like what grouping columns, filters, aggregations, etc, are involved in a query in order to be able to automatically select the appropriate projection available within the segment, or using the regular default segment rows if no matching projections are available.
In addition to the primary goal, this refactor also allows cursor creation to be more efficient. Since
CursorMaker
is created from theCursorBuildSpec
, thecanVectorize
,makeCursors
, andmakeVectorCursor
methods can all share and re-use the same resources.StorageAdapter
is a@PublicApi
, and extendsCursorFactory
, so a default implmentation ofCursorMaker
that is backed by the oldcanVectorize
,makeCursors
, andmakeVectorCursor
methods is provided. That said, all of the built-in query engines and tests have been migrated to useasCursorMaker
, allCursorFactory
implementations have implementedasCursorMaker
, and the old methods ofCursorFactory
have been marked as@Deprecated
.summary of changes
CursorBuildSpec
which captures all of the 'interesting' stuff that goes into producing a cursor as a replacement for the method arguments ofCursorFactory.canVectorize
,CursorFactory.makeCursors
, andCursorFactory.makeVectorCursors
CursorMaker
and new methodasCursorMaker
toCursorFactory
, which takes aCursorBuildSpec
as an argument and replacesCursorFactory.canVectorize
,CursorFactory.makeCursors
, andCursorFactory.makeVectorCursors
CursorFactory.canVectorize
,CursorFactory.makeCursors
, andCursorFactory.makeVectorCursors
CursorFactory
implementations to implementasCursorMaker
asCursorMaker
Release note
(for developers)
There is a change to the
StorageAdapter
interface, which is a 'public' api for extension writers to add additional types of segments to participate in Druids query engines.StorageAdapter
extends theCursorFactory
interface, whose methodscanVectorize
,makeCursors
, andmakeVectorCursor
have been deprecated. These methods are replaced with a new method,asCursorMaker
, which accepts aCursorBuildSpec
and returns a new interfaceCursorMaker
which defines no argument versions ofcanVectorize
,makeCursors
, andmakeVectorCursor
. A default implementation ofasCursorMaker
is provided that uses the existing deprecated methods, so no immediate action is needed forStorageAdapter
implementors on upgrade, but implementors should plan in the future to migrate to implementingasCursorMaker
directly.Key changed/added classes in this PR
CursorFactory
CursorMaker
CursorBuildSpec
This PR has: