@Test public void testBlock() { for (Entry<Integer, Object> entry : expectedStackValues.entrySet()) { assertPositionEquals(testBlock, entry.getKey(), entry.getValue(), expectedObjectValues.get(entry.getKey())); } for (Entry<Integer, Object> entry : expectedStackValues.entrySet()) { assertPositionEquals(testBlockWithNulls, entry.getKey() * 2, entry.getValue(), expectedObjectValues.get(entry.getKey())); assertPositionEquals(testBlockWithNulls, (entry.getKey() * 2) + 1, null, null); } }
protected void assertPositionEquals(Block block, int position, Object expectedStackValue, Object expectedObjectValue) { long hash = 0; if (type.isComparable()) { hash = hashPosition(type, block, position); } assertPositionValue(block, position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, 1), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedStackValue, hash, expectedObjectValue); BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); type.appendTo(block, position, blockBuilder); assertPositionValue(blockBuilder.build(), 0, expectedStackValue, hash, expectedObjectValue); }
protected AbstractTestType(Type type, Class<?> objectValueType, Block testBlock, Block expectedValues) { this.type = requireNonNull(type, "type is null"); this.objectValueType = requireNonNull(objectValueType, "objectValueType is null"); this.testBlock = requireNonNull(testBlock, "testBlock is null"); requireNonNull(expectedValues, "expectedValues is null"); this.expectedStackValues = indexStackValues(type, expectedValues); this.expectedObjectValues = indexObjectValues(type, expectedValues); this.testBlockWithNulls = createAlternatingNullsBlock(testBlock); }
Block expectedBlock = createBlock(type, expectedStackValue); if (type.isComparable()) { assertTrue(positionEqualsPosition(type, block, position, block, position)); verifyInvalidPositionHandling(block); Block nonNullValue = toBlock(getNonNullValue()); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, nonNullValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, nonNullValue, 0) > 0); Block greaterValue = toBlock(getGreaterValue(expectedStackValue)); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, greaterValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, greaterValue, 0) < 0);
Block other = toBlock(getNonNullValue()); try { type.equalTo(block, -1, other, 0); Block other = toBlock(getNonNullValue()); try { ASC_NULLS_FIRST.compareBlockValue(type, block, -1, other, 0);
/** * @return a non-null value, represented in native container type */ protected Object getNonNullValue() { return getNonNullValueForType(type); }
Block expectedBlock = createBlock(type, expectedStackValue); if (type.isComparable()) { assertTrue(positionEqualsPosition(type, block, position, block, position)); verifyInvalidPositionHandling(block); Block nonNullValue = toBlock(getNonNullValue()); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, nonNullValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, nonNullValue, 0) > 0); Block greaterValue = toBlock(getGreaterValue(expectedStackValue)); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, greaterValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, greaterValue, 0) < 0);
Block other = toBlock(getNonNullValue()); try { type.equalTo(block, -1, other, 0); Block other = toBlock(getNonNullValue()); try { ASC_NULLS_FIRST.compareBlockValue(type, block, -1, other, 0);
ArrayType arrayType = (ArrayType) type; Type elementType = arrayType.getElementType(); Object elementNonNullValue = getNonNullValueForType(elementType); return arrayBlockOf(elementType, elementNonNullValue); Type keyType = mapType.getKeyType(); Type valueType = mapType.getValueType(); Object keyNonNullValue = getNonNullValueForType(keyType); Object valueNonNullValue = getNonNullValueForType(valueType); Map map = ImmutableMap.of(keyNonNullValue, valueNonNullValue); return mapBlockOf(keyType, valueType, map);
protected AbstractTestType(Type type, Class<?> objectValueType, Block testBlock, Block expectedValues) { this.type = requireNonNull(type, "type is null"); this.objectValueType = requireNonNull(objectValueType, "objectValueType is null"); this.testBlock = requireNonNull(testBlock, "testBlock is null"); requireNonNull(expectedValues, "expectedValues is null"); this.expectedStackValues = indexStackValues(type, expectedValues); this.expectedObjectValues = indexObjectValues(type, expectedValues); this.testBlockWithNulls = createAlternatingNullsBlock(testBlock); }
protected Object getNonNullValue() { return getNonNullValueForType(type); }
@Test public void testBlock() { for (Entry<Integer, Object> entry : expectedStackValues.entrySet()) { assertPositionEquals(testBlock, entry.getKey(), entry.getValue(), expectedObjectValues.get(entry.getKey())); } for (Entry<Integer, Object> entry : expectedStackValues.entrySet()) { assertPositionEquals(testBlockWithNulls, entry.getKey() * 2, entry.getValue(), expectedObjectValues.get(entry.getKey())); assertPositionEquals(testBlockWithNulls, (entry.getKey() * 2) + 1, null, null); } }
protected void assertPositionEquals(Block block, int position, Object expectedStackValue, Object expectedObjectValue) { int hash = 0; if (type.isComparable()) { hash = hashPosition(type, block, position); } assertPositionValue(block, position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, 1), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedStackValue, hash, expectedObjectValue); BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 1); type.appendTo(block, position, blockBuilder); assertPositionValue(blockBuilder.build(), 0, expectedStackValue, hash, expectedObjectValue); }
ArrayType arrayType = (ArrayType) type; Type elementType = arrayType.getElementType(); Object elementNonNullValue = getNonNullValueForType(elementType); return arrayBlockOf(elementType, elementNonNullValue); Type keyType = mapType.getKeyType(); Type valueType = mapType.getValueType(); Object keyNonNullValue = getNonNullValueForType(keyType); Object valueNonNullValue = getNonNullValueForType(valueType); Map map = ImmutableMap.of(keyNonNullValue, valueNonNullValue); return mapBlockOf(keyType, valueType, map);