当前位置: 首页>>代码示例>>Java>>正文


Java Slice.length方法代码示例

本文整理汇总了Java中io.airlift.slice.Slice.length方法的典型用法代码示例。如果您正苦于以下问题:Java Slice.length方法的具体用法?Java Slice.length怎么用?Java Slice.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.airlift.slice.Slice的用法示例。


在下文中一共展示了Slice.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseRgb

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@VisibleForTesting
static int parseRgb(Slice color)
{
    if (color.length() != 4 || color.getByte(0) != '#') {
        return -1;
    }

    int red = Character.digit((char) color.getByte(1), 16);
    int green = Character.digit((char) color.getByte(2), 16);
    int blue = Character.digit((char) color.getByte(3), 16);

    if (red == -1 || green == -1 || blue == -1) {
        return -1;
    }

    // replicate the nibbles to turn a color of the form #rgb => #rrggbb (css semantics)
    red = (red << 4) | red;
    green = (green << 4) | green;
    blue = (blue << 4) | blue;

    return (int) rgb(red, green, blue);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:23,代码来源:ColorFunctions.java

示例2: serializedSize

import io.airlift.slice.Slice; //导入方法依赖的package包/类
private static int serializedSize(List<? extends Type> types, Page expectedPage)
{
    DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024);
    writePages(blockEncodingManager, sliceOutput, expectedPage);
    Slice slice = sliceOutput.slice();

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

    return slice.length();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:18,代码来源:TestPagesSerde.java

示例3: FixedWidthBlock

import io.airlift.slice.Slice; //导入方法依赖的package包/类
public FixedWidthBlock(int fixedSize, int positionCount, Slice slice, Slice valueIsNull)
{
    super(fixedSize);

    if (positionCount < 0) {
        throw new IllegalArgumentException("positionCount is negative");
    }
    this.positionCount = positionCount;

    this.slice = Objects.requireNonNull(slice, "slice is null");

    if (valueIsNull.length() < positionCount) {
        throw new IllegalArgumentException("valueIsNull length is less than positionCount");
    }
    this.valueIsNull = valueIsNull;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:17,代码来源:FixedWidthBlock.java

示例4: hashBytes

import io.airlift.slice.Slice; //导入方法依赖的package包/类
private static int hashBytes(int initialValue, Slice bytes)
{
    int result = initialValue;
    for (int i = 0; i < bytes.length(); i++) {
        result = result * 31 + bytes.getByte(i);
    }
    return result;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:9,代码来源:HiveBucketing.java

示例5: decompressSnappy

import io.airlift.slice.Slice; //导入方法依赖的package包/类
private int decompressSnappy(Slice in)
        throws IOException
{
    byte[] inArray = (byte[]) in.getBase();
    int inOffset = (int) (in.getAddress() - ARRAY_BYTE_BASE_OFFSET);
    int inLength = in.length();

    int uncompressedLength = Snappy.getUncompressedLength(inArray, inOffset);
    checkArgument(uncompressedLength <= maxBufferSize, "Snappy requires buffer (%s) larger than max size (%s)", uncompressedLength, maxBufferSize);
    allocateOrGrowBuffer(uncompressedLength, false);

    return Snappy.uncompress(inArray, inOffset, inLength, buffer, 0);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:14,代码来源:OrcInputStream.java

示例6: render

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction
@SqlType(StandardTypes.VARCHAR)
public static Slice render(@SqlType(StandardTypes.VARCHAR) Slice value, @SqlType(ColorType.NAME) long color)
{
    StringBuilder builder = new StringBuilder(value.length());

    // color
    builder.append(ansiColorEscape(color))
            .append(value.toStringUtf8())
            .append(ANSI_RESET);

    return utf8Slice(builder.toString());
}
 
开发者ID:y-lan,项目名称:presto,代码行数:14,代码来源:ColorFunctions.java

示例7: substring

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@Description("returns index of first occurrence of a substring (or 0 if not found)")
@ScalarFunction("strpos")
@SqlType(StandardTypes.BIGINT)
public static long stringPosition(@SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice substring)
{
    if (substring.length() == 0) {
        return 1;
    }

    int index = string.indexOf(substring);
    if (index < 0) {
        return 0;
    }
    return countCodePoints(string, 0, index) + 1;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:16,代码来源:StringFunctions.java

示例8: split

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction
@SqlType("array<varchar>")
public static Block split(@SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice delimiter, @SqlType(StandardTypes.BIGINT) long limit)
{
    checkCondition(limit > 0, INVALID_FUNCTION_ARGUMENT, "Limit must be positive");
    checkCondition(limit <= Integer.MAX_VALUE, INVALID_FUNCTION_ARGUMENT, "Limit is too large");
    checkCondition(delimiter.length() > 0, INVALID_FUNCTION_ARGUMENT, "The delimiter may not be the empty string");
    BlockBuilder parts = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 1, string.length());
    // If limit is one, the last and only element is the complete string
    if (limit == 1) {
        VARCHAR.writeSlice(parts, string);
        return parts.build();
    }

    int index = 0;
    while (index < string.length()) {
        int splitIndex = string.indexOf(delimiter, index);
        // Found split?
        if (splitIndex < 0) {
            break;
        }
        // Add the part from current index to found split
        VARCHAR.writeSlice(parts, string, index, splitIndex - index);
        // Continue searching after delimiter
        index = splitIndex + delimiter.length();
        // Reached limit-1 parts so we can stop
        if (parts.getPositionCount() == limit - 1) {
            break;
        }
    }
    // Rest of string
    VARCHAR.writeSlice(parts, string, index, string.length() - index);

    return parts.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:36,代码来源:StringFunctions.java

示例9: castToRegexp

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarOperator(OperatorType.CAST)
@SqlType(RegexpType.NAME)
public static Regex castToRegexp(@SqlType(StandardTypes.VARCHAR) Slice pattern)
{
    Regex regex;
    try {
        // When normal UTF8 encoding instead of non-strict UTF8) is used, joni can infinite loop when invalid UTF8 slice is supplied to it.
        regex = new Regex(pattern.getBytes(), 0, pattern.length(), Option.DEFAULT, NonStrictUTF8Encoding.INSTANCE, Syntax.Java);
    }
    catch (Exception e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
    }
    return regex;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:15,代码来源:RegexpFunctions.java

示例10: regexpReplace

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@Description("replaces substrings matching a regular expression by given string")
@ScalarFunction
@SqlType(StandardTypes.VARCHAR)
public static Slice regexpReplace(@SqlType(StandardTypes.VARCHAR) Slice source, @SqlType(RegexpType.NAME) Regex pattern, @SqlType(StandardTypes.VARCHAR) Slice replacement)
{
    Matcher matcher = pattern.matcher(source.getBytes());
    SliceOutput sliceOutput = new DynamicSliceOutput(source.length() + replacement.length() * 5);

    int lastEnd = 0;
    int nextStart = 0; // nextStart is the same as lastEnd, unless the last match was zero-width. In such case, nextStart is lastEnd + 1.
    while (true) {
        int offset = matcher.search(nextStart, source.length(), Option.DEFAULT);
        if (offset == -1) {
            break;
        }
        if (matcher.getEnd() == matcher.getBegin()) {
            nextStart = matcher.getEnd() + 1;
        }
        else {
            nextStart = matcher.getEnd();
        }
        Slice sliceBetweenReplacements = source.slice(lastEnd, matcher.getBegin() - lastEnd);
        lastEnd = matcher.getEnd();
        sliceOutput.appendBytes(sliceBetweenReplacements);
        appendReplacement(sliceOutput, source, pattern, matcher.getEagerRegion(), replacement);
    }
    sliceOutput.appendBytes(source.slice(lastEnd, source.length() - lastEnd));

    return sliceOutput.slice();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:31,代码来源:RegexpFunctions.java

示例11: length

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@Description("length of the given binary")
@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long length(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
    return slice.length();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:8,代码来源:VarbinaryFunctions.java

示例12: fromHexVarchar

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@Description("decode hex encoded binary data")
@ScalarFunction("from_hex")
@SqlType(StandardTypes.VARBINARY)
public static Slice fromHexVarchar(@SqlType(StandardTypes.VARCHAR) Slice slice)
{
    if (slice.length() % 2 != 0) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "invalid input length " + slice.length());
    }

    byte[] result = new byte[slice.length() / 2];
    for (int i = 0; i < slice.length(); i += 2) {
        result[i / 2] = (byte) ((hexDigitCharToInt(slice.getByte(i)) << 4) | hexDigitCharToInt(slice.getByte(i + 1)));
    }
    return Slices.wrappedBuffer(result);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:16,代码来源:VarbinaryFunctions.java

示例13: set

import io.airlift.slice.Slice; //导入方法依赖的package包/类
/**
 * Sets the element of this big array at specified index.
 *
 * @param index a position in this big array.
 */
public void set(long index, Slice value)
{
    Slice currentValue = array.get(index);
    if (currentValue != null) {
        sizeOfSlices -= currentValue.length();
    }
    if (value != null) {
        sizeOfSlices += value.length();
    }
    array.set(index, value);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:17,代码来源:SliceBigArray.java

示例14: castToBoolean

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarOperator(CAST)
@SqlType(StandardTypes.BOOLEAN)
public static boolean castToBoolean(@SqlType(StandardTypes.VARCHAR) Slice value)
{
    if (value.length() == 1) {
        byte character = toUpperCase(value.getByte(0));
        if (character == 'T' || character == '1') {
            return true;
        }
        if (character == 'F' || character == '0') {
            return false;
        }
    }
    if ((value.length() == 4) &&
            (toUpperCase(value.getByte(0)) == 'T') &&
            (toUpperCase(value.getByte(1)) == 'R') &&
            (toUpperCase(value.getByte(2)) == 'U') &&
            (toUpperCase(value.getByte(3)) == 'E')) {
        return true;
    }
    if ((value.length() == 5) &&
            (toUpperCase(value.getByte(0)) == 'F') &&
            (toUpperCase(value.getByte(1)) == 'A') &&
            (toUpperCase(value.getByte(2)) == 'L') &&
            (toUpperCase(value.getByte(3)) == 'S') &&
            (toUpperCase(value.getByte(4)) == 'E')) {
        return false;
    }
    throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to BOOLEAN", value.toStringUtf8()));
}
 
开发者ID:y-lan,项目名称:presto,代码行数:31,代码来源:VarcharOperators.java

示例15: testSizeInBytes

import io.airlift.slice.Slice; //导入方法依赖的package包/类
@Test
public void testSizeInBytes()
        throws Exception
{
    Slice[] expectedValues = createExpectedValues(10);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);

    int sizeInBytes = 0;
    for (Slice expectedValue : expectedValues) {
        sizeInBytes += expectedValue.length();
    }
    assertEquals(dictionaryBlock.getSizeInBytes(), sizeInBytes + (100 * SIZE_OF_INT));
}
 
开发者ID:y-lan,项目名称:presto,代码行数:14,代码来源:TestDictionaryBlock.java


注:本文中的io.airlift.slice.Slice.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。