Skip to content

Commit

Permalink
Extract inner PositionsAppender impls to top level classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-stec authored and sopel39 committed May 26, 2022
1 parent b71b5f0 commit 83cdee3
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 219 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.output;

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import it.unimi.dsi.fastutil.ints.IntArrayList;

public class BytePositionsAppender
implements PositionsAppender
{
@Override
public void appendTo(IntArrayList positions, Block block, BlockBuilder blockBuilder)
{
int[] positionArray = positions.elements();
if (block.mayHaveNull()) {
for (int i = 0; i < positions.size(); i++) {
int position = positionArray[i];
if (block.isNull(position)) {
blockBuilder.appendNull();
}
else {
blockBuilder.writeByte(block.getByte(position, 0)).closeEntry();
}
}
}
else {
for (int i = 0; i < positions.size(); i++) {
blockBuilder.writeByte(block.getByte(positionArray[i], 0)).closeEntry();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.output;

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import it.unimi.dsi.fastutil.ints.IntArrayList;

import static io.airlift.slice.SizeOf.SIZE_OF_LONG;

public class Int128PositionsAppender
implements PositionsAppender
{
@Override
public void appendTo(IntArrayList positions, Block block, BlockBuilder blockBuilder)
{
int[] positionArray = positions.elements();
if (block.mayHaveNull()) {
for (int i = 0; i < positions.size(); i++) {
int position = positionArray[i];
if (block.isNull(position)) {
blockBuilder.appendNull();
}
else {
blockBuilder.writeLong(block.getLong(position, 0));
blockBuilder.writeLong(block.getLong(position, SIZE_OF_LONG));
blockBuilder.closeEntry();
}
}
}
else {
for (int i = 0; i < positions.size(); i++) {
int position = positionArray[i];
blockBuilder.writeLong(block.getLong(position, 0));
blockBuilder.writeLong(block.getLong(position, SIZE_OF_LONG));
blockBuilder.closeEntry();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.output;

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import it.unimi.dsi.fastutil.ints.IntArrayList;

import static io.airlift.slice.SizeOf.SIZE_OF_LONG;

public class Int96PositionsAppender
implements PositionsAppender
{
@Override
public void appendTo(IntArrayList positions, Block block, BlockBuilder blockBuilder)
{
int[] positionArray = positions.elements();
if (block.mayHaveNull()) {
for (int i = 0; i < positions.size(); i++) {
int position = positionArray[i];
if (block.isNull(position)) {
blockBuilder.appendNull();
}
else {
blockBuilder.writeLong(block.getLong(position, 0));
blockBuilder.writeInt(block.getInt(position, SIZE_OF_LONG));
blockBuilder.closeEntry();
}
}
}
else {
for (int i = 0; i < positions.size(); i++) {
int position = positionArray[i];
blockBuilder.writeLong(block.getLong(position, 0));
blockBuilder.writeInt(block.getInt(position, SIZE_OF_LONG));
blockBuilder.closeEntry();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.output;

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import it.unimi.dsi.fastutil.ints.IntArrayList;

public class IntPositionsAppender
implements PositionsAppender
{
@Override
public void appendTo(IntArrayList positions, Block block, BlockBuilder blockBuilder)
{
int[] positionArray = positions.elements();
if (block.mayHaveNull()) {
for (int i = 0; i < positions.size(); i++) {
int position = positionArray[i];
if (block.isNull(position)) {
blockBuilder.appendNull();
}
else {
blockBuilder.writeInt(block.getInt(position, 0)).closeEntry();
}
}
}
else {
for (int i = 0; i < positions.size(); i++) {
blockBuilder.writeInt(block.getInt(positionArray[i], 0)).closeEntry();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.output;

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import it.unimi.dsi.fastutil.ints.IntArrayList;

public class LongPositionsAppender
implements PositionsAppender
{
@Override
public void appendTo(IntArrayList positions, Block block, BlockBuilder blockBuilder)
{
int[] positionArray = positions.elements();
if (block.mayHaveNull()) {
for (int i = 0; i < positions.size(); i++) {
int position = positionArray[i];
if (block.isNull(position)) {
blockBuilder.appendNull();
}
else {
blockBuilder.writeLong(block.getLong(position, 0)).closeEntry();
}
}
}
else {
for (int i = 0; i < positions.size(); i++) {
blockBuilder.writeLong(block.getLong(positionArray[i], 0)).closeEntry();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,4 @@
public interface PositionsAppender
{
void appendTo(IntArrayList positions, Block source, BlockBuilder target);

class TypedPositionsAppender
implements PositionsAppender
{
private final Type type;

public TypedPositionsAppender(Type type)
{
this.type = requireNonNull(type, "type is null");
}

@Override
public void appendTo(IntArrayList positions, Block source, BlockBuilder target)
{
int[] positionArray = positions.elements();
for (int i = 0; i < positions.size(); i++) {
type.appendTo(source, positionArray[i], target);
}
}
}
}
Loading

0 comments on commit 83cdee3

Please sign in to comment.