Java Code Examples for io.airlift.slice.Slices#EMPTY_SLICE

The following examples show how to use io.airlift.slice.Slices#EMPTY_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: DecimalInputStream.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public void seekToCheckpoint(DecimalStreamCheckpoint checkpoint)
        throws IOException
{
    long newCheckpoint = checkpoint.getInputStreamCheckpoint();
    // if checkpoint starts at the same compressed position...
    // (we're checking for an empty block because empty blocks signify that we possibly read all the data in the existing
    // buffer, so last checkpoint is no longer valid)
    if (block.length() > 0 && decodeCompressedBlockOffset(newCheckpoint) == decodeCompressedBlockOffset(lastCheckpoint)) {
        // and decompressed position is within our block, reposition in the block directly
        int blockOffset = decodeDecompressedOffset(newCheckpoint) - decodeDecompressedOffset(lastCheckpoint);
        if (blockOffset >= 0 && blockOffset < block.length()) {
            this.blockOffset = blockOffset;
            // do not change last checkpoint because we have not moved positions
            return;
        }
    }
    chunkLoader.seekToCheckpoint(newCheckpoint);
    lastCheckpoint = newCheckpoint;
    block = Slices.EMPTY_SLICE;
    blockOffset = 0;
}
 
Example 2
Source File: SliceData.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Block toBlock(Type desiredType)
{
    checkArgument(desiredType.getJavaType() == Slice.class, "type doesn't match: %s", desiredType);
    Slice values = bytes == null ? Slices.EMPTY_SLICE : Slices.wrappedBuffer(bytes);
    int numberOfRecords = numberOfRecords();
    return new VariableWidthBlock(
            numberOfRecords,
            values,
            calculateOffsets(sizes, nulls, numberOfRecords),
            Optional.ofNullable(nulls));
}
 
Example 3
Source File: UrlFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Extract query parameter from url")
@ScalarFunction
@LiteralParameters({"x", "y"})
@SqlType("varchar(x)")
public static Slice urlExtractParameter(@SqlType("varchar(x)") Slice url, @SqlType("varchar(y)") Slice parameterName)
{
    URI uri = parseUrl(url);
    if ((uri == null) || (uri.getRawQuery() == null)) {
        return null;
    }

    String parameter = parameterName.toStringUtf8();
    Iterable<String> queryArgs = QUERY_SPLITTER.split(uri.getRawQuery());

    for (String queryArg : queryArgs) {
        Iterator<String> arg = ARG_SPLITTER.split(queryArg).iterator();
        if (arg.next().equals(parameter)) {
            if (arg.hasNext()) {
                return decodeUrl(arg.next());
            }
            // first matched key is empty
            return Slices.EMPTY_SLICE;
        }
    }

    // no key matched
    return null;
}
 
Example 4
Source File: Varchars.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Slice truncateToLength(Slice slice, int maxLength)
{
    requireNonNull(slice, "slice is null");
    if (maxLength < 0) {
        throw new IllegalArgumentException("Max length must be greater or equal than zero");
    }
    if (maxLength == 0) {
        return Slices.EMPTY_SLICE;
    }

    return slice.slice(0, byteCount(slice, 0, slice.length(), maxLength));
}
 
Example 5
Source File: PinotSegmentPageSource.java    From presto with Apache License 2.0 5 votes vote down vote up
Slice getSlice(int rowIndex, int columnIndex)
{
    Type prestoType = getType(columnIndex);
    if (prestoType instanceof VarcharType) {
        String field = currentDataTable.getDataTable().getString(rowIndex, columnIndex);
        return getUtf8Slice(field);
    }
    else if (prestoType instanceof VarbinaryType) {
        return Slices.wrappedBuffer(toBytes(currentDataTable.getDataTable().getString(rowIndex, columnIndex)));
    }
    return Slices.EMPTY_SLICE;
}
 
Example 6
Source File: PinotSegmentPageSource.java    From presto with Apache License 2.0 5 votes vote down vote up
Slice getUtf8Slice(String value)
{
    if (isNullOrEmpty(value)) {
        return Slices.EMPTY_SLICE;
    }
    return Slices.utf8Slice(value);
}
 
Example 7
Source File: RawKinesisFieldDecoder.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public Slice getSlice()
{
    if (isNull()) {
        return Slices.EMPTY_SLICE;
    }

    if (fieldType == FieldType.BYTE) {
        return Slices.wrappedBuffer(value.slice());
    }

    throw new PrestoException(KINESIS_CONVERSION_NOT_SUPPORTED, format("conversion %s to Slice not supported", fieldType));
}
 
Example 8
Source File: KinesisRecordSet.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public Slice getSlice(int field)
{
    checkArgument(field < columnHandles.size(), "Invalid field index");

    checkFieldType(field, Slice.class);
    return isNull(field) ? Slices.EMPTY_SLICE : fieldValueProviders[field].getSlice();
}
 
Example 9
Source File: SliceDictionaryStreamReader.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void readDictionary(
            @Nullable ByteArrayStream dictionaryDataStream,
            int dictionarySize,
            int[] dictionaryLength,
            int dictionaryOutputOffset,
            Slice[] dictionary,
            DataType type)
            throws IOException
    {
        // build dictionary slices
        for (int i = 0; i < dictionarySize; i++) {
            int length = dictionaryLength[i];
            if (length == 0) {
                dictionary[dictionaryOutputOffset + i] = Slices.EMPTY_SLICE;
            }
            else {
                Slice value = Slices.wrappedBuffer(dictionaryDataStream.next(length));
                /* DO WE NEED THIS?
                if (isVarcharType(type)) {
                    value = truncateToLength(value, type);
                }
                if (isCharType(type)) {
                    value = trimSpacesAndTruncateToLength(value, type);
                }
                */
//                System.out.println(String.format("Reading Dictionary (%s,%s)",dictionaryOutputOffset + i,value.toStringUtf8()));
                dictionary[dictionaryOutputOffset + i] = value;
            }
        }
    }
 
Example 10
Source File: CachingOrcDataSource.java    From presto with Apache License 2.0 4 votes vote down vote up
public CachingOrcDataSource(OrcDataSource dataSource, RegionFinder regionFinder)
{
    this.dataSource = requireNonNull(dataSource, "dataSource is null");
    this.regionFinder = requireNonNull(regionFinder, "regionFinder is null");
    this.cache = Slices.EMPTY_SLICE;
}
 
Example 11
Source File: KinesisInternalFieldDescription.java    From presto-kinesis with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice()
{
    return isNull() ? Slices.EMPTY_SLICE : Slices.wrappedBuffer(value);
}
 
Example 12
Source File: SecondsSinceEpochJsonKinesisFieldDecoder.java    From presto-kinesis with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice()
{
    return isNull() ? Slices.EMPTY_SLICE : utf8Slice(FORMATTER.print(value.asLong() * 1000L));
}
 
Example 13
Source File: RE2.java    From hive-third-functions with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@link Slice} holding the text of the leftmost match in
 * {@code s} of this regular expression.
 *
 * <p>If there is no match, the return value is an empty {@link Slice}, but it
 * will also be empty if the regular expression successfully matches
 * an empty {@link Slice}.  Use {@link #findIndex} or
 * {@link #findSubmatch} if it is necessary to distinguish these
 * cases.
 */
// This is visible for testing.
Slice find(Slice s) {
    int[] a = doExecute(com.github.aaronshan.functions.regexp.re2j.MachineInput.fromUTF8(s), 0, Anchor.UNANCHORED, 2);
    if (a == null) {
        return Slices.EMPTY_SLICE;
    }
    return s.slice(a[0], a[1] - a[0]);
}