public static InputReferenceExpression field(int field, Type type) { return new InputReferenceExpression(field, type); }
@Setup public void setup() { MetadataManager metadata = MetadataManager.createTestMetadataManager(); ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)); ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder(); Block[] blocks = new Block[TYPES.size()]; Type returnType = new ArrayType(BOOLEAN); for (int i = 0; i < TYPES.size(); i++) { Type elementType = TYPES.get(i); ArrayType arrayType = new ArrayType(elementType); Signature signature = new Signature("transform", FunctionKind.SCALAR, returnType.getTypeSignature(), arrayType.getTypeSignature(), parseTypeSignature("function(bigint,boolean)")); Signature greaterThan = new Signature("$operator$" + GREATER_THAN.name(), FunctionKind.SCALAR, BOOLEAN.getTypeSignature(), BIGINT.getTypeSignature(), BIGINT.getTypeSignature()); projectionsBuilder.add(new CallExpression(signature, returnType, ImmutableList.of( new InputReferenceExpression(0, arrayType), new LambdaDefinitionExpression( ImmutableList.of(BIGINT), ImmutableList.of("x"), new CallExpression(greaterThan, BOOLEAN, ImmutableList.of(new VariableReferenceExpression("x", BIGINT), new ConstantExpression(0L, BIGINT))))))); blocks[i] = createChannel(POSITIONS, ARRAY_SIZE, arrayType); } ImmutableList<RowExpression> projections = projectionsBuilder.build(); pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get(); pageBuilder = new PageBuilder(projections.stream().map(RowExpression::getType).collect(Collectors.toList())); page = new Page(blocks); }
public static InputReferenceExpression field(int field, Type type) { return new InputReferenceExpression(field, type); }
@Override public RowExpression visitInputReference(InputReferenceExpression reference, Void context) { return new InputReferenceExpression(reference.getField(), targetType); }
private static IdentityProjectionInfo computeIdentityProjectionInfo(List<Symbol> symbols, Map<Symbol, Integer> inputLayout, Map<Symbol, Type> types) { Map<Symbol, Integer> outputMappings = new HashMap<>(); List<RowExpression> projections = new ArrayList<>(); int channel = 0; for (Symbol symbol : symbols) { Type type = types.get(symbol); RowExpression expression = new InputReferenceExpression(inputLayout.get(symbol), type); projections.add(expression); if (!outputMappings.containsKey(symbol)) { outputMappings.put(symbol, channel); channel++; } } return new IdentityProjectionInfo(projections, outputMappings); }
@Test public void testNoCaching() throws Throwable { MetadataManager metadata = METADATA_MANAGER; ExpressionCompiler compiler = new ExpressionCompiler(metadata); ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder(); ArrayType arrayType = new ArrayType(VARCHAR); Signature signature = new Signature("concat", SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature(), arrayType.getTypeSignature()); projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(new InputReferenceExpression(0, arrayType), new InputReferenceExpression(1, arrayType)))); ImmutableList<RowExpression> projections = projectionsBuilder.build(); PageProcessor pageProcessor = compiler.compilePageProcessor(new ConstantExpression(true, BOOLEAN), projections).get(); PageProcessor pageProcessor2 = compiler.compilePageProcessor(new ConstantExpression(true, BOOLEAN), projections).get(); assertTrue(pageProcessor != pageProcessor2); }
@Test public void testSanityFilterOnRLE() throws Exception { Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression filter = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(new InputReferenceExpression(0, BIGINT), new ConstantExpression(10L, BIGINT))); PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()) .compilePageProcessor(filter, ImmutableList.of(new InputReferenceExpression(0, BIGINT))).get(); Page page = new Page(createRLEBlock(5L, 100)); Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(BIGINT)); assertEquals(outputPage.getPositionCount(), 100); assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock); RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0); assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L); }
@Setup public void setup() { MetadataManager metadata = MetadataManager.createTestMetadataManager(); metadata.addFunctions(new FunctionListBuilder(metadata.getTypeManager()).scalar(BenchmarkArrayDistinct.class).getFunctions()); ExpressionCompiler compiler = new ExpressionCompiler(metadata); ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder(); Block[] blocks = new Block[TYPES.size()]; for (int i = 0; i < TYPES.size(); i++) { Type elementType = TYPES.get(i); ArrayType arrayType = new ArrayType(elementType); Signature signature = new Signature(name, FunctionKind.SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature()); projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(new InputReferenceExpression(i, arrayType)))); blocks[i] = createChannel(POSITIONS, ARRAY_SIZE, arrayType); } ImmutableList<RowExpression> projections = projectionsBuilder.build(); pageProcessor = compiler.compilePageProcessor(new ConstantExpression(true, BooleanType.BOOLEAN), projections).get(); pageBuilder = new PageBuilder(projections.stream().map(RowExpression::getType).collect(Collectors.toList())); page = new Page(blocks); }
@Test public void testSanityColumnarDictionary() throws Exception { PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()) .compilePageProcessor(new ConstantExpression(TRUE, BOOLEAN), ImmutableList.of(new InputReferenceExpression(0, VARCHAR))).get(); Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100)); Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR)); assertEquals(outputPage.getPositionCount(), 100); assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock); DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0); assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10); }
@Test public void testSanityRLE() throws Exception { PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()) .compilePageProcessor(new ConstantExpression(TRUE, BOOLEAN), ImmutableList.of(new InputReferenceExpression(0, BIGINT), new InputReferenceExpression(1, VARCHAR))).get(); Slice varcharValue = Slices.utf8Slice("hello"); Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 100)); Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(BIGINT, VARCHAR)); assertEquals(outputPage.getPositionCount(), 100); assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock); assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock); RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0); assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L); RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1); assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue); }
@Test public void testDeterminismEvaluator() throws Exception { DeterminismEvaluator determinismEvaluator = new DeterminismEvaluator(createTestMetadataManager().getFunctionRegistry()); CallExpression random = new CallExpression(new Signature("random", SCALAR, "bigint", "bigint"), BIGINT, singletonList(new ConstantExpression(10L, BIGINT))); assertFalse(determinismEvaluator.isDeterministic(random)); InputReferenceExpression col0 = new InputReferenceExpression(0, BIGINT); Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression lessThanExpression = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(col0, new ConstantExpression(10L, BIGINT))); assertTrue(determinismEvaluator.isDeterministic(lessThanExpression)); CallExpression lessThanRandomExpression = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(col0, random)); assertFalse(determinismEvaluator.isDeterministic(lessThanRandomExpression)); } }
@Test public void testNonDeterministicProject() throws Exception { Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression random = new CallExpression(new Signature("random", SCALAR, "bigint", "bigint"), BIGINT, singletonList(new ConstantExpression(10L, BIGINT))); InputReferenceExpression col0 = new InputReferenceExpression(0, BIGINT); CallExpression lessThanRandomExpression = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(col0, random)); PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()) .compilePageProcessor(new ConstantExpression(TRUE, BOOLEAN), ImmutableList.of(lessThanRandomExpression)).get(); assertFalse(new DeterminismEvaluator(METADATA_MANAGER.getFunctionRegistry()).isDeterministic(lessThanRandomExpression)); Page page = new Page(createLongDictionaryBlock(1, 100)); Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(BOOLEAN)); assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock); }
@Test public void testSanityFilterOnDictionary() throws Exception { CallExpression lengthVarchar = new CallExpression(new Signature("length", SCALAR, "bigint", "varchar"), BIGINT, ImmutableList.of(new InputReferenceExpression(0, VARCHAR))); Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression filter = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(lengthVarchar, new ConstantExpression(10L, BIGINT))); PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()) .compilePageProcessor(filter, ImmutableList.of(new InputReferenceExpression(0, VARCHAR))).get(); Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100)); Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR)); assertEquals(outputPage.getPositionCount(), 100); assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock); DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0); assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10); // test filter caching Page outputPage2 = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR)); assertEquals(outputPage2.getPositionCount(), 100); assertTrue(outputPage2.getBlock(0) instanceof DictionaryBlock); DictionaryBlock dictionaryBlock2 = (DictionaryBlock) outputPage2.getBlock(0); // both output pages must have the same dictionary assertEquals(dictionaryBlock2.getDictionary(), dictionaryBlock.getDictionary()); }