Skip to content

Commit

Permalink
less objects
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshSingla committed Oct 3, 2023
1 parent 6c539fe commit d41d1b0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public ColumnValueSelector<?> makeColumnValueSelector(
{
return new NumericArrayFieldSelector<Double>(memory, fieldPointer)
{
final SettableFieldPointer fieldPointer = new SettableFieldPointer();
final ColumnValueSelector<?> columnValueSelector =
DoubleFieldReader.forArray().makeColumnValueSelector(memory, fieldPointer);

@Nullable
@Override
public Double getIndividualValueAtMemory(Memory memory, long position)
public Double getIndividualValueAtMemory(long position)
{
ColumnValueSelector<?> columnValueSelector =
DoubleFieldReader.forArray()
.makeColumnValueSelector(memory, new ConstantFieldPointer(position));
fieldPointer.setPosition(position);
if (columnValueSelector.isNull()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public ColumnValueSelector<?> makeColumnValueSelector(
{
return new NumericArrayFieldSelector<Float>(memory, fieldPointer)
{
final SettableFieldPointer fieldPointer = new SettableFieldPointer();
final ColumnValueSelector<?> columnValueSelector =
FloatFieldReader.forArray().makeColumnValueSelector(memory, fieldPointer);

@Nullable
@Override
public Float getIndividualValueAtMemory(Memory memory, long position)
public Float getIndividualValueAtMemory(long position)
{
ColumnValueSelector<?> columnValueSelector =
FloatFieldReader.forArray()
.makeColumnValueSelector(memory, new ConstantFieldPointer(position));
fieldPointer.setPosition(position);
if (columnValueSelector.isNull()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public ColumnValueSelector<?> makeColumnValueSelector(
{
return new NumericArrayFieldSelector<Long>(memory, fieldPointer)
{
final SettableFieldPointer fieldPointer = new SettableFieldPointer();
final ColumnValueSelector<?> columnValueSelector =
LongFieldReader.forArray().makeColumnValueSelector(memory, fieldPointer);

@Nullable
@Override
public Long getIndividualValueAtMemory(Memory memory, long position)
public Long getIndividualValueAtMemory(long position)
{
ColumnValueSelector<?> columnValueSelector =
LongFieldReader.forArray()
.makeColumnValueSelector(memory, new ConstantFieldPointer(position));
fieldPointer.setPosition(position);
if (columnValueSelector.isNull()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class NumericArrayFieldSelector<ElementType extends Number> impl
/**
* Memory containing the serialized values of the array
*/
private final Memory memory;
protected final Memory memory;

/**
* Pointer to location in the memory. The callers are expected to update the pointer's position to the start of the
Expand Down Expand Up @@ -134,7 +134,7 @@ public boolean isNull()
* Returns the value of the individual element written at the given position
*/
@Nullable
public abstract ElementType getIndividualValueAtMemory(Memory memory, long position);
public abstract ElementType getIndividualValueAtMemory(long position);

/**
* Returns the field size that each element in the reader array consumes. It is usually 1 + ElementType.SIZE, to hold
Expand Down Expand Up @@ -193,7 +193,7 @@ private void updateCurrentArray(final long fieldPosition)

// If terminator not seen, then read the field at that location, and increment the position by the element's field
// size to read the next element.
currentRow.add(getIndividualValueAtMemory(memory, position));
currentRow.add(getIndividualValueAtMemory(position));
position += getIndividualFieldSize();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.druid.frame.field;

/**
* A simple {@link ReadableFieldPointer} that returns the position that was set on its object.
*/
public class SettableFieldPointer implements ReadableFieldPointer
{

long position = 0;

public void setPosition(long position)
{
this.position = position;
}

@Override
public long position()
{
return position;
}
}

0 comments on commit d41d1b0

Please sign in to comment.