-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Simplify BlockBuilder #17342
Simplify BlockBuilder #17342
Conversation
c78127f
to
9576f50
Compare
9576f50
to
7d2286a
Compare
7d2286a
to
88a3f4a
Compare
52abc41
to
3b88983
Compare
3b88983
to
b73e9f6
Compare
b73e9f6
to
4ee092a
Compare
int startSize = keyBlockBuilder.getPositionCount(); | ||
|
||
// build the map | ||
builder.build(keyBlockBuilder, valueBlockBuilder); |
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.
We need to catch E | RuntimeException
here and even out the blocks using the code below
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.
Turns out you can't catch a type variable, but for this case we are catching and rethrowing so we can just use Exception
core/trino-main/src/main/java/io/trino/operator/scalar/RowToRowCast.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/gen/RowConstructorCodeGenerator.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/block/MapBlockBuilder.java
Outdated
Show resolved
Hide resolved
@@ -430,4 +456,9 @@ private static boolean indeterminate(MethodHandle valueIndeterminateFunction, Bl | |||
} | |||
return false; | |||
} | |||
|
|||
private static boolean not(boolean value) |
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 already exists in CompilerOperations
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.
That class is not available in the SPI
...ino-main/src/main/java/io/trino/operator/aggregation/listagg/ListaggAggregationFunction.java
Outdated
Show resolved
Hide resolved
The Slice methods on ArrayType date back to the first implementation of array and have been replaced by methods operating on Block
Support using NOT DISTINCT FROM to build the map hash table. This rejects less key than the current strict mode, which uses EQUALS.
The beginEntry paradigm is confusing and inefficient. It requires array, map, and row block builders to use a synthetic wrapper block during the build, and this wrapper is inefficient due to call site pollution, but also make it difficult to extend blocks with new behavior, as the wrappers would have to pass through the extended behaviors.
Replace VariableWidthBlockBuilder beginEntry, write*, closeEntry with buildEntry Replace Block writeBytesTo with Block getSlice with SliceOutput argument
4ee092a
to
e9294dc
Compare
core/trino-spi/src/main/java/io/trino/spi/block/MapBlockBuilder.java
Outdated
Show resolved
Hide resolved
fyi @osscm .. this one made it into 421 |
The developer guide still references |
Description
This PR simplifies
BlockBuilder
by removing all write methods from theinterface. Each
BlockBuilder
implementation still has awrite
method, andType
implementations simply downcast the expected implementation type.This change is only possible with the removal of the wrapper
BlockBuilder
types SingleArrayBlockWriter, SingleMapBlockWriter, and SingleRowBlockWriter.
These classes have been replaced with a single lambda
writeEntry
methodon
ArrayBlockBuilder
,MapBlockBuilder
, andRowBlockBuilder
, that callsback with the nested field builders. Since there is now a single
writeEntry
method, there is no need for the
beginBlockEntry
andcloseEntry
methods.To simplify the transition to the new
writeEntry
method, this PR includesa new helper class for building array, map, and row values in functions. The
ArrayValueBuilder
,MapValueBuilder
, andRowValueBuilder
interfaces havea simple build value method to build a single value of related kind, and each
of these has a related buffered class that can be used to share allocation
buffers across multiple value build calls. This replaces the pattern of
using a
PageBuilder
as a buffer in function implementations.Additionally,
MapBlockBuilder
has been extended with astrictNotDistinctFrom
that builds the map hash table using
NOT DISTINCT FROM
semantics. This isremoves the need to use
TypedSet
to determine duplicates, and is much moreefficient. This behavior is also supported in
BufferedMapValueBuilder
withthe
createBufferedDistinctStrict
static factory method.Added
Int128BlockBuilder.writeInt128
Fixed12BlockBuilder.writeFixed12
Block.getSlice
withSliceOutput
argument (to replaceBlock.writeBytesTo
)ArrayValueBuilder.buildArrayValue
andBufferedArrayValueBuilder
MapValueBuilder.buildMapValue
andBufferedMapValueBuilder
RowValueBuilder.buildRowValue
andBufferedRowValueBuilder
NOT DISTINCT FROM
support inMapBlockBuilder
andBufferedMapValueBuilder
ArrayBlockBuilder.writeEntry
MapBlockBuilder.writeEntry
RowBlockBuilder.writeEntry
LambdaMetafactoryGenerator
to simplify bytecode generation of lambda method callsRemoved
BlockBuilder.writeBytes
BlockBuilder.writeShort
BlockBuilder.writeInt
BlockBuilder.writeLong
BlockBuilder.beginBlockEntry
BlockBuilder.closeEntry
SingleArrayBlockWriter
SingleMapBlockWriter
SingleRowBlockWriter
Release notes
(X) Release notes are required, with the following suggested text: