@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)); } }
private Supplier<PageProjection> compileProjectionInternal(RowExpression projection, Optional<String> classNameSuffix) { requireNonNull(projection, "projection is null"); if (projection instanceof InputReferenceExpression) { InputReferenceExpression input = (InputReferenceExpression) projection; InputPageProjection projectionFunction = new InputPageProjection(input.getField(), input.getType()); return () -> projectionFunction; } if (projection instanceof ConstantExpression) { ConstantExpression constant = (ConstantExpression) projection; ConstantPageProjection projectionFunction = new ConstantPageProjection(constant.getValue(), constant.getType()); return () -> projectionFunction; } PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(projection); CallSiteBinder callSiteBinder = new CallSiteBinder(); // generate Work ClassDefinition pageProjectionWorkDefinition = definePageProjectWorkClass(result.getRewrittenExpression(), callSiteBinder, classNameSuffix); Class<? extends Work> pageProjectionWorkClass; try { pageProjectionWorkClass = defineClass(pageProjectionWorkDefinition, Work.class, callSiteBinder.getBindings(), getClass().getClassLoader()); } catch (Exception e) { throw new PrestoException(COMPILER_ERROR, e); } return () -> new GeneratedPageProjection( result.getRewrittenExpression(), determinismEvaluator.isDeterministic(result.getRewrittenExpression()), result.getInputChannels(), constructorMethodHandle(pageProjectionWorkClass, BlockBuilder.class, ConnectorSession.class, Page.class, SelectedPositions.class)); }
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; } }
.append(constantBoolean(determinismEvaluator.isDeterministic(filter))) .retBoolean();
public PageProcessorCompiler(Metadata metadata) { this.metadata = metadata; this.determinismEvaluator = new DeterminismEvaluator(metadata.getFunctionRegistry()); }
@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); }
List<Integer> inputChannels = getInputChannels(projection); if (inputChannels.size() != 1 || !determinismEvaluator.isDeterministic(projection)) { body.append(thisVariable.invoke(projectColumnar, params) .ret());
@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)); } }
if (filterChannels.size() == 1 && determinismEvaluator.isDeterministic(filter)) { BytecodeBlock ifFilterOnDictionaryBlock = getBytecodeFilterOnDictionary(session, scope, blockVariables.get(0)); BytecodeBlock ifFilterOnRLEBlock = getBytecodeFilterOnRLE(session, scope, blockVariables.get(0));
@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); }
if (inputChannels.size() != 1 || !determinismEvaluator.isDeterministic(projection)) { body.append(thisVariable.invoke(projectColumnar, columnarParams) .ret());