Skip to content

Commit

Permalink
fix dynamic schema data can't rollup correctly (apache#3949)
Browse files Browse the repository at this point in the history
* fix dynamic schema data can't rollup correctly

* add ut
  • Loading branch information
kaijianding authored and himanshug committed Feb 17, 2017
1 parent a029b33 commit 361d9d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -963,13 +963,28 @@ public int compare(TimeAndDims lhs, TimeAndDims rhs)
}

if (retVal == 0) {
return Ints.compare(lhs.dims.length, rhs.dims.length);
int lengthDiff = Ints.compare(lhs.dims.length, rhs.dims.length);
if (lengthDiff == 0) {
return 0;
}
Object[] largerDims = lengthDiff > 0 ? lhs.dims : rhs.dims;
return allNull(largerDims, numComparisons) ? 0 : lengthDiff;
}

return retVal;
}
}

private static boolean allNull(Object[] dims, int startPosition)
{
for (int i = startPosition; i < dims.length; i++) {
if (dims[i] != null) {
return false;
}
}
return true;
}

public static class FactsEntry implements Map.Entry<TimeAndDims, Integer>
{
TimeAndDims key = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,4 +781,38 @@ public void testgetDimensions()

Assert.assertEquals(Arrays.asList("dim0", "dim1"), incrementalIndex.getDimensionNames());
}

@Test
public void testDynamicSchemaRollup() throws IndexSizeExceededException
{
IncrementalIndex<Aggregator> index = new OnheapIncrementalIndex(
new IncrementalIndexSchema.Builder().withQueryGranularity(QueryGranularities.NONE).build(),
true,
10
);
closer.closeLater(index);
index.add(
new MapBasedInputRow(
1481871600000L,
Arrays.asList("name", "host"),
ImmutableMap.<String, Object>of("name", "name1", "host", "host")
)
);
index.add(
new MapBasedInputRow(
1481871670000L,
Arrays.asList("name", "table"),
ImmutableMap.<String, Object>of("name", "name2", "table", "table")
)
);
index.add(
new MapBasedInputRow(
1481871600000L,
Arrays.asList("name", "host"),
ImmutableMap.<String, Object>of("name", "name1", "host", "host")
)
);

Assert.assertEquals(2, index.size());
}
}

0 comments on commit 361d9d9

Please sign in to comment.