@Override public void log( @Nonnull String format, @Nullable Object... arguments ) { requireNonNull( format, "format must not be null" ); if ( arguments == null || arguments.length == 0 ) { log( format ); return; } String message = String.format( format, arguments ); PrintWriter writer; synchronized ( lock ) { writer = writerSupplier.get(); writeLog( writer, message ); } maybeFlush( writer ); }
@Setup public void setup() { MetadataManager metadata = MetadataManager.createTestMetadataManager(); ExpressionCompiler expressionCompiler = new ExpressionCompiler( metadata, new PageFunctionCompiler(metadata, 0)); RowExpression projection = generateComplexComparisonProjection(FIELDS_COUNT, COMPARISONS_COUNT); compiledProcessor = expressionCompiler.compilePageProcessor(Optional.empty(), ImmutableList.of(projection)).get(); }
@Setup public void setup() { MetadataManager metadata = MetadataManager.createTestMetadataManager(); metadata.addFunctions(extractFunctions(BenchmarkArrayDistinct.class)); ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)); 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(field(i, arrayType)))); blocks[i] = createChannel(POSITIONS, ARRAY_SIZE, arrayType); } ImmutableList<RowExpression> projections = projectionsBuilder.build(); pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get(); page = new Page(blocks); }
private static <T, S extends Publisher<T>> S readWithMessageReaders( ReactiveHttpInputMessage message, BodyExtractor.Context context, ResolvableType elementType, Function<HttpMessageReader<T>, S> readerFunction, Function<UnsupportedMediaTypeException, S> errorFunction, Supplier<S> emptySupplier) { if (VOID_TYPE.equals(elementType)) { return emptySupplier.get(); } MediaType contentType = Optional.ofNullable(message.getHeaders().getContentType()) .orElse(MediaType.APPLICATION_OCTET_STREAM); return context.messageReaders().stream() .filter(reader -> reader.canRead(elementType, contentType)) .findFirst() .map(BodyExtractors::<T>cast) .map(readerFunction) .orElseGet(() -> { List<MediaType> mediaTypes = context.messageReaders().stream() .flatMap(reader -> reader.getReadableMediaTypes().stream()) .collect(Collectors.toList()); return errorFunction.apply( new UnsupportedMediaTypeException(contentType, mediaTypes, elementType)); }); }
@Test public void testSanityColumnarDictionary() { PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, VARCHAR)), MAX_BATCH_SIZE).get(); Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100)); Page outputPage = getOnlyElement( processor.process( null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)) .orElseThrow(() -> new AssertionError("page is not present")); assertEquals(outputPage.getPositionCount(), 100); assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock); DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0); assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10); }
/** * Runs the callback function if the current env matches the given name. * * @param name A name to test for. * @param fn A callback function. * @param <T> A resulting type. * @return A resulting object. */ @Nonnull default <T> Optional<T> ifMode(final String name, final Supplier<T> fn) { if (name().equals(name)) { return Optional.of(fn.get()); } return Optional.empty(); }
private Optional<LocalMemoryContext> getSystemMemoryContext() { try { return Optional.of(systemMemoryContextSupplier.get()); } catch (RuntimeException ignored) { // This is possible with races, e.g., a task is created and then immediately aborted, // so that the task context hasn't been created yet (as a result there's no memory context available). } return Optional.empty(); } }
@Setup public void setup() { inputPage = createInputPage(); MetadataManager metadata = MetadataManager.createTestMetadataManager(); compiledProcessor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)).compilePageProcessor(Optional.of(FILTER), ImmutableList.of(PROJECT)).get(); }
@Test public void testNoCaching() { 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(field(0, arrayType), field(1, arrayType)))); ImmutableList<RowExpression> projections = projectionsBuilder.build(); PageProcessor pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get(); PageProcessor pageProcessor2 = compiler.compilePageProcessor(Optional.empty(), projections).get(); assertTrue(pageProcessor != pageProcessor2); }
public Heavy getHeavy() { return heavy.get(); }
@Test public void testSanityFilterOnRLE() { Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression filter = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT))); PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, BIGINT)), MAX_BATCH_SIZE).get(); Page page = new Page(createRLEBlock(5L, 100)); Page outputPage = getOnlyElement( processor.process( null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)) .orElseThrow(() -> new AssertionError("page is not present")); assertEquals(outputPage.getPositionCount(), 100); assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock); RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0); assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L); }
private <K, V> V loadValue(Cache<K, V> cache, K key, Supplier<V> valueSupplier) { if (replay) { return Optional.ofNullable(cache.getIfPresent(key)) .orElseThrow(() -> new PrestoException(NOT_FOUND, "Missing entry found for key: " + key)); } V value = valueSupplier.get(); cache.put(key, value); return value; }
private static KernelTransaction safeAcquireTransaction( Supplier<KernelTransaction> transactionSupplier ) { KernelTransaction transaction = transactionSupplier.get(); if ( transaction.isTerminated() ) { Status terminationReason = transaction.getReasonIfTerminated().orElse( Status.Transaction.Terminated ); throw new TransactionTerminatedException( terminationReason ); } return transaction; }
@Setup public void setup() { Type type = TYPE_MAP.get(this.type); for (int i = 0; i < columnCount; i++) { Symbol symbol = new Symbol(type.getDisplayName().toLowerCase(ENGLISH) + i); symbolTypes.put(symbol, type); sourceLayout.put(symbol, i); } List<RowExpression> projections = getProjections(type); types = projections.stream().map(RowExpression::getType).collect(toList()); MetadataManager metadata = createTestMetadataManager(); PageFunctionCompiler pageFunctionCompiler = new PageFunctionCompiler(metadata, 0); inputPage = createPage(types, dictionaryBlocks); pageProcessor = new ExpressionCompiler(metadata, pageFunctionCompiler).compilePageProcessor(Optional.of(getFilter(type)), projections).get(); recordSet = new PageRecordSet(types, inputPage); cursorProcessor = new ExpressionCompiler(metadata, pageFunctionCompiler).compileCursorProcessor(Optional.of(getFilter(type)), projections, "key").get(); }
@Test public void testGeneratedClassName() { PageFunctionCompiler functionCompiler = new PageFunctionCompiler(createTestMetadataManager(), 0); String planNodeId = "7"; String stageId = "20170707_223500_67496_zguwn.2"; String classSuffix = stageId + "_" + planNodeId; Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(ADD_10_EXPRESSION, Optional.of(classSuffix)); PageProjection projection = projectionSupplier.get(); Work<Block> work = projection.project(SESSION, new DriverYieldSignal(), createLongBlockPage(0), SelectedPositions.positionsRange(0, 1)); // class name should look like PageProjectionOutput_20170707_223500_67496_zguwn_2_7_XX assertTrue(work.getClass().getSimpleName().startsWith("PageProjectionWork_" + stageId.replace('.', '_') + "_" + planNodeId)); }
@Test public void testNoValue() { B statisticsBuilder = statisticsBuilderSupplier.get(); AggregateColumnStatistics aggregateColumnStatistics = new AggregateColumnStatistics(); assertNoColumnStatistics(statisticsBuilder.buildColumnStatistics(), 0); aggregateColumnStatistics.add(statisticsBuilder.buildColumnStatistics()); assertNoColumnStatistics(aggregateColumnStatistics.getMergedColumnStatistics(Optional.empty()), 0); assertNoColumnStatistics(statisticsBuilder.buildColumnStatistics(), 0); aggregateColumnStatistics.add(statisticsBuilder.buildColumnStatistics()); assertNoColumnStatistics(aggregateColumnStatistics.getMergedColumnStatistics(Optional.empty()), 0); assertNoColumnStatistics(statisticsBuilder.buildColumnStatistics(), 0); aggregateColumnStatistics.add(statisticsBuilder.buildColumnStatistics()); assertNoColumnStatistics(aggregateColumnStatistics.getMergedColumnStatistics(Optional.empty()), 0); }