Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -125,33 +125,32 @@ class IndexerDoubleColumnSelector implements DoubleColumnSelector
@Override
public boolean isNull()
{
final Object[] dims = currEntry.get().getDims();
return hasNulls && (dimIndex >= dims.length || dims[dimIndex] == null);
return hasNulls && currEntry.get().isDimNull(dimIndex);
}

@Override
public double getDouble()
{
final Object[] dims = currEntry.get().getDims();
final Object dim = currEntry.get().getDim(dimIndex);

if (dimIndex >= dims.length || dims[dimIndex] == null) {
if (dim == null) {
assert NullHandling.replaceWithDefault();
return 0.0;
}
return (Double) dims[dimIndex];
return (Double) dim;
}

@SuppressWarnings("deprecation")
@Nullable
@Override
public Double getObject()
{
final Object[] dims = currEntry.get().getDims();
final Object dim = currEntry.get().getDim(dimIndex);

if (dimIndex >= dims.length || dims[dimIndex] == null) {
if (dim == null) {
return NullHandling.defaultDoubleValue();
}
return (Double) dims[dimIndex];
return (Double) dim;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,34 @@ class IndexerFloatColumnSelector implements FloatColumnSelector
@Override
public boolean isNull()
{
final Object[] dims = currEntry.get().getDims();
return hasNulls && (dimIndex >= dims.length || dims[dimIndex] == null);
return hasNulls && currEntry.get().isDimNull(dimIndex);
}

@Override
public float getFloat()
{
final Object[] dims = currEntry.get().getDims();
final Object dim = currEntry.get().getDim(dimIndex);

if (dimIndex >= dims.length || dims[dimIndex] == null) {
if (dim == null) {
assert NullHandling.replaceWithDefault();
return 0.0f;
}

return (Float) dims[dimIndex];
return (Float) dim;
}

@SuppressWarnings("deprecation")
@Nullable
@Override
public Float getObject()
{
final Object[] dims = currEntry.get().getDims();
final Object dim = currEntry.get().getDim(dimIndex);

if (dimIndex >= dims.length || dims[dimIndex] == null) {
if (dim == null) {
return NullHandling.defaultFloatValue();
}

return (Float) dims[dimIndex];
return (Float) dim;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,34 @@ class IndexerLongColumnSelector implements LongColumnSelector
@Override
public boolean isNull()
{
final Object[] dims = currEntry.get().getDims();
return hasNulls && (dimIndex >= dims.length || dims[dimIndex] == null);
return hasNulls && currEntry.get().isDimNull(dimIndex);
}

@Override
public long getLong()
{
final Object[] dims = currEntry.get().getDims();
final Object dim = currEntry.get().getDim(dimIndex);

if (dimIndex >= dims.length || dims[dimIndex] == null) {
if (dim == null) {
assert NullHandling.replaceWithDefault();
return 0;
}

return (Long) dims[dimIndex];
return (Long) dim;
}

@SuppressWarnings("deprecation")
@Nullable
@Override
public Long getObject()
{
final Object[] dims = currEntry.get().getDims();
final Object dim = currEntry.get().getDim(dimIndex);

if (dimIndex >= dims.length || dims[dimIndex] == null) {
if (dim == null) {
return NullHandling.defaultLongValue();
}

return (Long) dims[dimIndex];
return (Long) dim;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,57 +281,62 @@ public DimensionSelector makeDimensionSelector(

class IndexerDimensionSelector implements DimensionSelector, IdLookup
{
private final ArrayBasedIndexedInts indexedInts = new ArrayBasedIndexedInts();
private final ArrayBasedIndexedInts defaultIndexedInts = new ArrayBasedIndexedInts();

@Nullable
@MonotonicNonNull
private IndexedInts cachedIndexedInts;

@Nullable
@MonotonicNonNull
private int[] nullIdIntArray;

@Override
public IndexedInts getRow()
/**
* Tries to fetch the dimention as an IndexedInts.
* If the dim is null or with zero length, the value is considered null.
* It may be null or empty due to currEntry's rowIndex being smaller than the row's rowIndex in which this
* dim first appears.
*
* @return IndexedInts instance, or null if the dim is null.
*/
@Nullable
private IndexedInts getRowOrNull()
{
final Object[] dims = currEntry.get().getDims();

int[] indices;
if (dimIndex < dims.length) {
indices = (int[]) dims[dimIndex];
} else {
indices = null;
IndexedInts ret = currEntry.get().getIndexedDim(dimIndex, cachedIndexedInts);
if (ret != null) {
cachedIndexedInts = ret;
return ret.size() > 0 ? ret : null;
}
return null;
}

int[] row = null;
int rowSize = 0;

// usually due to currEntry's rowIndex is smaller than the row's rowIndex in which this dim first appears
if (indices == null || indices.length == 0) {
if (hasMultipleValues) {
row = IntArrays.EMPTY_ARRAY;
rowSize = 0;
} else {
final int nullId = getEncodedValue(null, false);
if (nullId >= 0 && nullId < maxId) {
// null was added to the dictionary before this selector was created; return its ID.
if (nullIdIntArray == null) {
nullIdIntArray = new int[]{nullId};
}
row = nullIdIntArray;
rowSize = 1;
} else {
// null doesn't exist in the dictionary; return an empty array.
// Choose to use ArrayBasedIndexedInts later, instead of special "empty" IndexedInts, for monomorphism
row = IntArrays.EMPTY_ARRAY;
rowSize = 0;
private IndexedInts getDefaultIndexedInts()
{
if (hasMultipleValues) {
defaultIndexedInts.setValues(IntArrays.EMPTY_ARRAY, 0);
} else {
final int nullId = getEncodedValue(null, false);
if (nullId >= 0 && nullId < maxId) {
// null was added to the dictionary before this selector was created; return its ID.
if (nullIdIntArray == null) {
nullIdIntArray = new int[]{nullId};
}
defaultIndexedInts.setValues(nullIdIntArray, 1);
} else {
// null doesn't exist in the dictionary; return an empty array.
// Choose to use ArrayBasedIndexedInts later, instead of special "empty" IndexedInts, for monomorphism
defaultIndexedInts.setValues(IntArrays.EMPTY_ARRAY, 0);
}
}

if (row == null && indices != null && indices.length > 0) {
row = indices;
rowSize = indices.length;
}
return defaultIndexedInts;
}

indexedInts.setValues(row, rowSize);
return indexedInts;
@Override
public IndexedInts getRow()
{
IndexedInts ret = getRowOrNull();
return ret != null ? ret : getDefaultIndexedInts();
}

@Override
Expand All @@ -345,18 +350,14 @@ public ValueMatcher makeValueMatcher(final String value)
@Override
public boolean matches()
{
Object[] dims = currEntry.get().getDims();
if (dimIndex >= dims.length) {
IndexedInts dimsInt = getRowOrNull();
if (dimsInt == null) {
return value == null;
}

int[] dimsInt = (int[]) dims[dimIndex];
if (dimsInt == null || dimsInt.length == 0) {
return value == null;
}

for (int id : dimsInt) {
if (id == valueId) {
int size = dimsInt.size();
for (int i = 0; i < size; i++) {
if (dimsInt.get(i) == valueId) {
return true;
}
}
Expand Down Expand Up @@ -391,17 +392,14 @@ public ValueMatcher makeValueMatcher(final Predicate<String> predicate)
@Override
public boolean matches()
{
Object[] dims = currEntry.get().getDims();
if (dimIndex >= dims.length) {
return matchNull;
}

int[] dimsInt = (int[]) dims[dimIndex];
if (dimsInt == null || dimsInt.length == 0) {
IndexedInts dimsInt = getRowOrNull();
if (dimsInt == null) {
return matchNull;
}

for (int id : dimsInt) {
int size = dimsInt.size();
for (int i = 0; i < size; i++) {
int id = dimsInt.get(i);
if (checkedIds.get(id)) {
if (matchingIds.get(id)) {
return true;
Expand Down Expand Up @@ -486,12 +484,12 @@ public Object getObject()
return null;
}

Object[] dims = key.getDims();
if (dimIndex >= dims.length) {
Object dim = key.getDim(dimIndex);
if (dim == null) {
return null;
}

return convertUnsortedEncodedKeyComponentToActualList((int[]) dims[dimIndex]);
return convertUnsortedEncodedKeyComponentToActualList((int[]) dim);
}

@SuppressWarnings("deprecation")
Expand Down
Loading