public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4); arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 100, 200, 300)); return blockBuilder.build(); }
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 100, 200, 300)); return blockBuilder.build(); }
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 100, 200, 300)); return blockBuilder.build(); }
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 100, 200, 300)); return blockBuilder.build(); }
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4); arrayType.writeObject(blockBuilder, arrayBlockOf(TINYINT, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(TINYINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(TINYINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(TINYINT, 100, 110, 127)); return blockBuilder.build(); }
@Override public Block[] getSequenceBlocks(int start, int length) { ArrayType arrayType = new ArrayType(BIGINT); BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, length); for (int i = start; i < start + length; i++) { arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, i)); } return new Block[] {blockBuilder.build()}; }
@Test public void testUnnestWithArray() { MetadataManager metadata = createTestMetadataManager(); Type arrayType = metadata.getType(parseTypeSignature("array(array(bigint))")); Type mapType = metadata.getType(parseTypeSignature("map(array(bigint),array(bigint))")); List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType) .row( 1L, arrayBlockOf(new ArrayType(BIGINT), ImmutableList.of(2, 4), ImmutableList.of(3, 6)), mapBlockOf(new ArrayType(BIGINT), new ArrayType(BIGINT), ImmutableMap.of(ImmutableList.of(4, 8), ImmutableList.of(5, 10)))) .row(2L, arrayBlockOf(new ArrayType(BIGINT), ImmutableList.of(99, 198)), null) .row(3L, null, null) .pageBreak() .row( 6, arrayBlockOf(new ArrayType(BIGINT), ImmutableList.of(7, 14), ImmutableList.of(8, 16)), mapBlockOf(new ArrayType(BIGINT), new ArrayType(BIGINT), ImmutableMap.of(ImmutableList.of(9, 18), ImmutableList.of(10, 20), ImmutableList.of(11, 22), ImmutableList.of(12, 24)))) .build(); OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false); MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, new ArrayType(BIGINT), new ArrayType(BIGINT), new ArrayType(BIGINT)) .row(1L, ImmutableList.of(2L, 4L), ImmutableList.of(4L, 8L), ImmutableList.of(5L, 10L)) .row(1L, ImmutableList.of(3L, 6L), null, null) .row(2L, ImmutableList.of(99L, 198L), null, null) .row(6L, ImmutableList.of(7L, 14L), ImmutableList.of(9L, 18L), ImmutableList.of(10L, 20L)) .row(6L, ImmutableList.of(8L, 16L), ImmutableList.of(11L, 22L), ImmutableList.of(12L, 24L)) .build(); assertOperatorEquals(operatorFactory, driverContext, input, expected); }
@Test public void test() { TypeManager typeManager = new TypeRegistry(); FunctionRegistry functionRegistry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); ArrayType arrayOfBigintType = new ArrayType(BIGINT); FieldSetFilteringRecordSet fieldSetFilteringRecordSet = new FieldSetFilteringRecordSet( functionRegistry, new InMemoryRecordSet( ImmutableList.of(BIGINT, BIGINT, TIMESTAMP_WITH_TIME_ZONE, TIMESTAMP_WITH_TIME_ZONE, arrayOfBigintType, arrayOfBigintType), ImmutableList.of( ImmutableList.of( 100L, 100L, // test same time in different time zone to make sure equal check was done properly packDateTimeWithZone(100, getTimeZoneKeyForOffset(123)), packDateTimeWithZone(100, getTimeZoneKeyForOffset(234)), // test structural type arrayBlockOf(BIGINT, 12, 34, 56), arrayBlockOf(BIGINT, 12, 34, 56)))), ImmutableList.of(ImmutableSet.of(0, 1), ImmutableSet.of(2, 3), ImmutableSet.of(4, 5))); RecordCursor recordCursor = fieldSetFilteringRecordSet.cursor(); assertTrue(recordCursor.advanceNextPosition()); } }
@Test public void testUnnestWithArrayOfRows() { MetadataManager metadata = createTestMetadataManager(); Type arrayOfRowType = metadata.getType(parseTypeSignature("array(row(bigint, double, varchar))")); Type elementType = RowType.anonymous(ImmutableList.of(BIGINT, DOUBLE, VARCHAR)); List<Page> input = rowPagesBuilder(BIGINT, arrayOfRowType) .row(1, arrayBlockOf(elementType, ImmutableList.of(2, 4.2, "abc"), ImmutableList.of(3, 6.6, "def"))) .row(2, arrayBlockOf(elementType, ImmutableList.of(99, 3.14, "pi"), null)) .row(3, null) .pageBreak() .row(6, arrayBlockOf(elementType, null, ImmutableList.of(8, 1.111, "tt"))) .build(); OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1), ImmutableList.of(arrayOfRowType), false); MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, DOUBLE, VARCHAR) .row(1L, 2L, 4.2, "abc") .row(1L, 3L, 6.6, "def") .row(2L, 99L, 3.14, "pi") .row(2L, null, null, null) .row(6L, null, null, null) .row(6L, 8L, 1.111, "tt") .build(); assertOperatorEquals(operatorFactory, driverContext, input, expected); } }
3.0, ImmutableList.of("e", "f"), 4.0, ImmutableList.of("r", "s")), arrayBlockOf( mapType, mapBlockOf( 2.0, ImmutableMap.of("c", "d"), 3.0, ImmutableMap.of("e", "f")), arrayBlockOf( mapType, mapBlockOf( ImmutableList.of("c", "d"), 2.0, ImmutableList.of("e", "f"), 3.0), arrayBlockOf( mapType, mapBlockOf(
@Test public void testUnnestWithOrdinality() { MetadataManager metadata = createTestMetadataManager(); Type arrayType = metadata.getType(parseTypeSignature("array(bigint)")); Type mapType = metadata.getType(parseTypeSignature("map(bigint,bigint)")); List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType) .row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))) .row(2L, arrayBlockOf(BIGINT, 99), null) .row(3L, null, null) .pageBreak() .row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))) .build(); OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), true); MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT) .row(1L, 2L, 4L, 5L, 1L) .row(1L, 3L, null, null, 2L) .row(2L, 99L, null, null, 1L) .row(6L, 7L, 9L, 10L, 1L) .row(6L, 8L, 11L, 12L, 2L) .build(); assertOperatorEquals(operatorFactory, driverContext, input, expected); }
@Test public void testUnnest() { MetadataManager metadata = createTestMetadataManager(); Type arrayType = metadata.getType(parseTypeSignature("array(bigint)")); Type mapType = metadata.getType(parseTypeSignature("map(bigint,bigint)")); List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType) .row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))) .row(2L, arrayBlockOf(BIGINT, 99), null) .row(3L, null, null) .pageBreak() .row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))) .build(); OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false); MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT) .row(1L, 2L, 4L, 5L) .row(1L, 3L, null, null) .row(2L, 99L, null, null) .row(6L, 7L, 9L, 10L) .row(6L, 8L, 11L, 12L) .build(); assertOperatorEquals(operatorFactory, driverContext, input, expected); }
aggFunc, ImmutableMap.of(23.0, "aaa", 33.0, "bbb", 43.0, "ccc", 53.0, "ddd", 13.0, "eee"), arrayBlockOf( mapType, mapBlockOf(DOUBLE, VARCHAR, ImmutableMap.of(23.0, "aaa", 33.0, "bbb", 53.0, "ddd")), aggFunc, ImmutableMap.of(1.0, 99L, 2.0, 99L, 3.0, 99L, 4.0, 44L), arrayBlockOf( mapType, mapBlockOf(DOUBLE, BIGINT, ImmutableMap.of(1.0, 99L, 2.0, 99L, 3.0, 99L)), aggFunc, ImmutableMap.of(false, 12L, true, 13L), arrayBlockOf( mapType, mapBlockOf(BOOLEAN, BIGINT, ImmutableMap.of(false, 12L)),
@Test public void testUnnestNonNumericDoubles() { MetadataManager metadata = createTestMetadataManager(); Type arrayType = metadata.getType(parseTypeSignature("array(double)")); Type mapType = metadata.getType(parseTypeSignature("map(bigint,double)")); List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType) .row(1L, arrayBlockOf(DOUBLE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NaN), mapBlockOf(BIGINT, DOUBLE, ImmutableMap.of(1, NEGATIVE_INFINITY, 2, POSITIVE_INFINITY, 3, NaN))) .build(); OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false); MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE, BIGINT, DOUBLE) .row(1L, NEGATIVE_INFINITY, 1L, NEGATIVE_INFINITY) .row(1L, POSITIVE_INFINITY, 2L, POSITIVE_INFINITY) .row(1L, NaN, 3L, NaN) .build(); assertOperatorEquals(operatorFactory, driverContext, input, expected); }
@Test public void testStackRepresentation() { Block actualBlock = arrayBlockOf(new ArrayType(BIGINT), arrayBlockOf(BIGINT, 1L, 2L), arrayBlockOf(BIGINT, 3L)); DynamicSliceOutput actualSliceOutput = new DynamicSliceOutput(100); writeBlock(functionAssertions.getMetadata().getBlockEncodingSerde(), actualSliceOutput, actualBlock); Block expectedBlock = new ArrayType(BIGINT) .createBlockBuilder(null, 3) .appendStructure(BIGINT.createBlockBuilder(null, 2).writeLong(1).closeEntry().writeLong(2).closeEntry().build()) .appendStructure(BIGINT.createBlockBuilder(null, 1).writeLong(3).closeEntry().build()) .build(); DynamicSliceOutput expectedSliceOutput = new DynamicSliceOutput(100); writeBlock(functionAssertions.getMetadata().getBlockEncodingSerde(), expectedSliceOutput, expectedBlock); assertEquals(actualSliceOutput.slice(), expectedSliceOutput.slice()); }
Type elementType = arrayType.getElementType(); Object elementNonNullValue = getNonNullValueForType(elementType); return arrayBlockOf(elementType, elementNonNullValue);
@Test public void testSimpleWithNulls() { MapType mapType = mapType(DOUBLE, VARCHAR); InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), mapType.getTypeSignature())); Map<Object, Object> expected = mapOf(23.0, "aaa", 33.0, null, 43.0, "ccc", 53.0, "ddd"); assertAggregation( aggFunc, expected, arrayBlockOf( mapType, mapBlockOf(DOUBLE, VARCHAR, mapOf(23.0, "aaa", 33.0, null, 53.0, "ddd")), null, mapBlockOf(DOUBLE, VARCHAR, mapOf(43.0, "ccc", 53.0, "ddd")))); }
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 4); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 100, 200, 300)); return blockBuilder.build(); }
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 4); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 100, 200, 300)); return blockBuilder.build(); }
@Override public Block[] getSequenceBlocks(int start, int length) { ArrayType arrayType = new ArrayType(BIGINT); BlockBuilder blockBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), length); for (int i = start; i < start + length; i++) { arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, i)); } return new Block[] {blockBuilder.build()}; }