public PageFunctionCompiler(Metadata metadata, int expressionCacheSize) { this.metadata = requireNonNull(metadata, "metadata is null"); this.determinismEvaluator = new DeterminismEvaluator(metadata.getFunctionRegistry()); if (expressionCacheSize > 0) { projectionCache = CacheBuilder.newBuilder() .recordStats() .maximumSize(expressionCacheSize) .build(CacheLoader.from(projection -> compileProjectionInternal(projection, Optional.empty()))); projectionCacheStats = new CacheStatsMBean(projectionCache); } else { projectionCache = null; projectionCacheStats = null; } if (expressionCacheSize > 0) { filterCache = CacheBuilder.newBuilder() .recordStats() .maximumSize(expressionCacheSize) .build(CacheLoader.from(filter -> compileFilterInternal(filter, Optional.empty()))); filterCacheStats = new CacheStatsMBean(filterCache); } else { filterCache = null; filterCacheStats = null; } }
@Test public void testNonDeterministicProject() { Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression random = new CallExpression( new Signature("random", SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT)), BIGINT, singletonList(constant(10L, BIGINT))); InputReferenceExpression col0 = field(0, BIGINT); CallExpression lessThanRandomExpression = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(col0, random)); PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get(); assertFalse(new DeterminismEvaluator(metadataManager.getFunctionRegistry()).isDeterministic(lessThanRandomExpression)); Page page = new Page(createLongDictionaryBlock(1, 100)); Page outputPage = getOnlyElement( processor.process( null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)) .orElseThrow(() -> new AssertionError("page is not present")); assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock); }
@Test public void testDeterminismEvaluator() { DeterminismEvaluator determinismEvaluator = new DeterminismEvaluator(createTestMetadataManager().getFunctionRegistry()); CallExpression random = new CallExpression( new Signature( "random", SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT)), BIGINT, singletonList(constant(10L, BIGINT))); assertFalse(determinismEvaluator.isDeterministic(random)); InputReferenceExpression col0 = field(0, BIGINT); Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression lessThanExpression = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(col0, constant(10L, BIGINT))); assertTrue(determinismEvaluator.isDeterministic(lessThanExpression)); CallExpression lessThanRandomExpression = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(col0, random)); assertFalse(determinismEvaluator.isDeterministic(lessThanRandomExpression)); } }
public PageProcessorCompiler(Metadata metadata) { this.metadata = metadata; this.determinismEvaluator = new DeterminismEvaluator(metadata.getFunctionRegistry()); }
@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 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)); } }