Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Slice support to reduce_agg function
- Loading branch information
Showing
4 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
core/trino-main/src/main/java/io/trino/operator/aggregation/state/GenericSliceState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed 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 io.trino.operator.aggregation.state; | ||
|
||
import io.airlift.slice.Slice; | ||
import io.trino.spi.block.BlockBuilder; | ||
import io.trino.spi.function.AccumulatorState; | ||
import io.trino.spi.function.AccumulatorStateMetadata; | ||
import io.trino.spi.type.Type; | ||
|
||
@AccumulatorStateMetadata(stateSerializerClass = GenericSliceStateSerializer.class) | ||
public interface GenericSliceState | ||
extends AccumulatorState | ||
{ | ||
Slice getValue(); | ||
|
||
void setValue(Slice value); | ||
|
||
@InitialBooleanValue(true) | ||
boolean isNull(); | ||
|
||
void setNull(boolean value); | ||
|
||
default void set(GenericSliceState state) | ||
{ | ||
setValue(state.getValue()); | ||
setNull(state.isNull()); | ||
} | ||
|
||
static void write(Type type, GenericSliceState state, BlockBuilder out) | ||
{ | ||
if (state.isNull()) { | ||
out.appendNull(); | ||
} | ||
else { | ||
type.writeSlice(out, state.getValue()); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...o-main/src/main/java/io/trino/operator/aggregation/state/GenericSliceStateSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed 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 io.trino.operator.aggregation.state; | ||
|
||
import io.trino.spi.block.Block; | ||
import io.trino.spi.block.BlockBuilder; | ||
import io.trino.spi.function.AccumulatorStateSerializer; | ||
import io.trino.spi.type.Type; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class GenericSliceStateSerializer | ||
implements AccumulatorStateSerializer<GenericSliceState> | ||
{ | ||
private final Type serializedType; | ||
|
||
public GenericSliceStateSerializer(Type serializedType) | ||
{ | ||
this.serializedType = requireNonNull(serializedType, "serializedType is null"); | ||
} | ||
|
||
@Override | ||
public Type getSerializedType() | ||
{ | ||
return serializedType; | ||
} | ||
|
||
@Override | ||
public void serialize(GenericSliceState state, BlockBuilder out) | ||
{ | ||
if (state.isNull()) { | ||
out.appendNull(); | ||
} | ||
else { | ||
serializedType.writeSlice(out, state.getValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void deserialize(Block block, int index, GenericSliceState state) | ||
{ | ||
state.setNull(false); | ||
state.setValue(serializedType.getSlice(block, index)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters