Java Code Examples for io.airlift.slice.DynamicSliceOutput#slice()

The following examples show how to use io.airlift.slice.DynamicSliceOutput#slice() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncodedPolylineFunctions.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Slice encodePolyline(MultiVertexGeometry multiVertexGeometry)
{
    long lastLatitude = 0;
    long lastLongitude = 0;

    DynamicSliceOutput output = new DynamicSliceOutput(0);

    for (int i = 0; i < multiVertexGeometry.getPointCount(); i++) {
        Point point = multiVertexGeometry.getPoint(i);

        long latitude = Math.round(point.getY() * 1e5);
        long longitude = Math.round(point.getX() * 1e5);

        long latitudeDelta = latitude - lastLatitude;
        long longitudeDelta = longitude - lastLongitude;

        encode(latitudeDelta, output);
        encode(longitudeDelta, output);

        lastLatitude = latitude;
        lastLongitude = longitude;
    }
    return output.slice();
}
 
Example 2
Source File: TestPagesSerde.java    From presto with Apache License 2.0 6 votes vote down vote up
private static int serializedSize(List<? extends Type> types, Page expectedPage)
{
    PagesSerde serde = new TestingPagesSerdeFactory().createPagesSerde();
    DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024);
    writePages(serde, sliceOutput, expectedPage);
    Slice slice = sliceOutput.slice();

    Iterator<Page> pageIterator = readPages(serde, slice.getInput());
    if (pageIterator.hasNext()) {
        assertPageEquals(types, pageIterator.next(), expectedPage);
    }
    else {
        assertEquals(expectedPage.getPositionCount(), 0);
    }
    assertFalse(pageIterator.hasNext());

    return slice.length();
}
 
Example 3
Source File: AbstractTestBlock.java    From presto with Apache License 2.0 5 votes vote down vote up
protected static Slice createExpectedValue(int length)
{
    DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(16);
    for (int index = 0; index < length; index++) {
        dynamicSliceOutput.writeByte(length * (index + 1));
    }
    return dynamicSliceOutput.slice();
}
 
Example 4
Source File: ParquetWriter.java    From presto with Apache License 2.0 5 votes vote down vote up
static Slice getFooter(List<RowGroup> rowGroups, MessageType messageType)
        throws IOException
{
    FileMetaData fileMetaData = new FileMetaData();
    fileMetaData.setVersion(1);
    fileMetaData.setSchema(MessageTypeConverter.toParquetSchema(messageType));
    long totalRows = rowGroups.stream().mapToLong(RowGroup::getNum_rows).sum();
    fileMetaData.setNum_rows(totalRows);
    fileMetaData.setRow_groups(ImmutableList.copyOf(rowGroups));

    DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(40);
    Util.writeFileMetaData(fileMetaData, dynamicSliceOutput);
    return dynamicSliceOutput.slice();
}
 
Example 5
Source File: GeometrySerde.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Slice serialize(Envelope envelope)
{
    requireNonNull(envelope, "envelope is null");
    verify(!envelope.isEmpty());
    DynamicSliceOutput output = new DynamicSliceOutput(100);
    output.appendByte(GeometrySerializationType.ENVELOPE.code());
    writeEnvelopeCoordinates(output, envelope);
    return output.slice();
}
 
Example 6
Source File: GeometrySerde.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Slice serialize(OGCGeometry input)
{
    requireNonNull(input, "input is null");
    DynamicSliceOutput output = new DynamicSliceOutput(100);
    writeGeometry(output, input);
    return output.slice();
}
 
Example 7
Source File: JtsGeometrySerde.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * Serialize JTS {@link Geometry} shape into an ESRI shape
 */
public static Slice serialize(Geometry geometry)
{
    requireNonNull(geometry, "input is null");
    DynamicSliceOutput output = new DynamicSliceOutput(100);
    writeGeometry(geometry, output);
    return output.slice();
}
 
Example 8
Source File: TestPage.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Slice createExpectedValue(int length)
{
    DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(16);
    for (int index = 0; index < length; index++) {
        dynamicSliceOutput.writeByte(length * (index + 1));
    }
    return dynamicSliceOutput.slice();
}
 
Example 9
Source File: TestBlockRetainedSizeBreakdown.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Block createVariableWidthBlock(int entries)
{
    int[] offsets = new int[entries + 1];
    DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(entries);
    for (int i = 0; i < entries; i++) {
        dynamicSliceOutput.writeByte(i);
        offsets[i + 1] = dynamicSliceOutput.size();
    }
    return new VariableWidthBlock(entries, dynamicSliceOutput.slice(), offsets, Optional.empty());
}
 
Example 10
Source File: CompressedMetadataWriter.java    From presto with Apache License 2.0 5 votes vote down vote up
public Slice writePostscript(int footerLength, int metadataLength, CompressionKind compression, int compressionBlockSize)
        throws IOException
{
    // postscript is not compressed
    DynamicSliceOutput output = new DynamicSliceOutput(64);
    metadataWriter.writePostscript(output, footerLength, metadataLength, compression, compressionBlockSize);
    return output.slice();
}
 
Example 11
Source File: AbstractTestBlock.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Slice createGreaterValue(Slice expectedValue, int offset, int length)
{
    DynamicSliceOutput greaterOutput = new DynamicSliceOutput(length + 1);
    greaterOutput.writeBytes(expectedValue, offset, length);
    greaterOutput.writeByte('_');
    return greaterOutput.slice();
}
 
Example 12
Source File: BenchmarkStringFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup()
{
    int[] codePointSet = ascii ? ASCII_CODE_POINTS : ALL_CODE_POINTS;
    ThreadLocalRandom random = ThreadLocalRandom.current();

    codePoints = new int[length];
    DynamicSliceOutput sliceOutput = new DynamicSliceOutput(length * 4);
    for (int i = 0; i < codePoints.length; i++) {
        int codePoint = codePointSet[random.nextInt(codePointSet.length)];
        codePoints[i] = codePoint;
        sliceOutput.appendBytes(new String(Character.toChars(codePoint)).getBytes(StandardCharsets.UTF_8));
    }
    slice = sliceOutput.slice();
}
 
Example 13
Source File: TestPageProcessorCompiler.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Slice createExpectedValue(int length)
{
    DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(16);
    for (int index = 0; index < length; index++) {
        dynamicSliceOutput.writeByte(length * (index + 1));
    }
    return dynamicSliceOutput.slice();
}
 
Example 14
Source File: LikeFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Slice unescapeLiteralLikePattern(Slice pattern, Optional<Slice> escape)
{
    if (escape.isEmpty()) {
        return pattern;
    }

    int escapeChar = getEscapeCharacter(escape)
            .map(c -> (int) c)
            .orElse(-1);

    @SuppressWarnings("resource")
    DynamicSliceOutput output = new DynamicSliceOutput(pattern.length());
    boolean escaped = false;
    int position = 0;
    while (position < pattern.length()) {
        int currentChar = getCodePointAt(pattern, position);
        int lengthOfCodePoint = lengthOfCodePoint(currentChar);
        if (!escaped && (currentChar == escapeChar)) {
            escaped = true;
        }
        else {
            output.writeBytes(pattern, position, lengthOfCodePoint);
            escaped = false;
        }
        position += lengthOfCodePoint;
    }
    checkEscape(!escaped);
    return output.slice();
}
 
Example 15
Source File: JsonExtract.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Slice extract(JsonParser jsonParser)
        throws IOException
{
    if (!jsonParser.hasCurrentToken()) {
        throw new JsonParseException(jsonParser, "Unexpected end of value");
    }

    DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(ESTIMATED_JSON_OUTPUT_SIZE);
    try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, dynamicSliceOutput)) {
        jsonGenerator.copyCurrentStructure(jsonParser);
    }
    return dynamicSliceOutput.slice();
}
 
Example 16
Source File: TestDecimalStream.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Slice encodeValues(List<BigInteger> values)
        throws IOException
{
    DynamicSliceOutput output = new DynamicSliceOutput(1);
    for (BigInteger value : values) {
        writeBigInteger(output, value);
    }

    return output.slice();
}
 
Example 17
Source File: CompressedMetadataWriter.java    From presto with Apache License 2.0 5 votes vote down vote up
private Slice getSliceOutput()
{
    buffer.close();
    DynamicSliceOutput output = new DynamicSliceOutput(toIntExact(buffer.getOutputDataSize()));
    buffer.writeDataTo(output);
    Slice slice = output.slice();
    buffer.reset();
    return slice;
}