本文整理汇总了Java中io.airlift.slice.Slice类的典型用法代码示例。如果您正苦于以下问题:Java Slice类的具体用法?Java Slice怎么用?Java Slice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Slice类属于io.airlift.slice包,在下文中一共展示了Slice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseAgent
import io.airlift.slice.Slice; //导入依赖的package包/类
@ScalarFunction("parse_agent")
@Description("Returns Map, which has keys such as 'category', 'name', 'os', 'version', 'vendor' and 'os_version'")
@SqlType("map<varchar,varchar>")
public Block parseAgent(@TypeParameter("map<varchar,varchar>") Type mapType, @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
Map<String, String> stringMap = Classifier.parse(argument);
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
BlockBuilder singleMapBlockBuilder = blockBuilder.beginBlockEntry();
for (Map.Entry<String, String> entry : stringMap.entrySet()) {
VARCHAR.writeSlice(singleMapBlockBuilder, Slices.utf8Slice(entry.getKey()));
VARCHAR.writeSlice(singleMapBlockBuilder, Slices.utf8Slice(entry.getValue()));
}
blockBuilder.closeEntry();
pageBuilder.declarePosition();
return (Block) mapType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1);
}
示例2: getSliceExpressedValue
import io.airlift.slice.Slice; //导入依赖的package包/类
private static Slice getSliceExpressedValue(Object value, Type type) {
Slice sliceValue;
if (value instanceof String) {
sliceValue = Slices.utf8Slice((String) value);
} else if (value instanceof byte[]) {
sliceValue = Slices.wrappedBuffer((byte[]) value);
} else if (value instanceof Integer) {
sliceValue = Slices.utf8Slice(value.toString());
} else {
throw new IllegalStateException("unsupported string field type: " + value.getClass().getName());
}
if (isVarcharType(type)) {
sliceValue = truncateToLength(sliceValue, type);
}
if (isCharType(type)) {
sliceValue = trimSpacesAndTruncateToLength(sliceValue, type);
}
return sliceValue;
}
示例3: geohash_encode_dec
import io.airlift.slice.Slice; //导入依赖的package包/类
@SqlType(StandardTypes.VARCHAR)
@TypeParameterContainer({@TypeParameter("decimal(lat_precision, lat_scale)")
, @TypeParameter("decimal(lng_precision, lng_scale)")}
)
@Nullable
public static Slice geohash_encode_dec(
@TypeParameter("decimal(lat_precision, lat_scale)") DecimalType latParameter,
@TypeParameter("decimal(lng_precision, lng_scale)") DecimalType lngParameter,
@SqlType("decimal(lat_precision, lat_scale)") Slice lat,
@SqlType("decimal(lng_precision, lng_scale)") Slice lng,
@SqlType(StandardTypes.INTEGER) long precision) {
BigDecimal biglat = new BigDecimal(Decimals.decodeUnscaledValue(lat), latParameter.getScale());
BigDecimal bigLng = new BigDecimal(Decimals.decodeUnscaledValue(lng), lngParameter.getScale());
return GeohashEncode.geohash_encode(biglat.doubleValue(), bigLng.doubleValue(), precision);
}
示例4: getRegion
import io.airlift.slice.Slice; //导入依赖的package包/类
@Override
public Block getRegion(int positionOffset, int length)
{
int positionCount = getPositionCount();
if (positionOffset < 0 || length < 0 || positionOffset + length > positionCount) {
throw new IndexOutOfBoundsException("Invalid position " + positionOffset + " in block with " + positionCount + " positions");
}
assureLoaded();
if (dictionary) {
List<Integer> positions = IntStream.range(positionOffset, positionOffset + length).boxed().collect(toList());
return compactAndGet(positions, false);
}
Slice[] newValues = Arrays.copyOfRange(values, positionOffset, positionOffset + length);
return new SliceArrayBlock(length, newValues);
}
示例5: contains
import io.airlift.slice.Slice; //导入依赖的package包/类
public static Boolean contains(Type elementType, MethodHandle equals, Block arrayBlock, Slice value)
{
boolean foundNull = false;
for (int i = 0; i < arrayBlock.getPositionCount(); i++) {
if (arrayBlock.isNull(i)) {
foundNull = true;
continue;
}
try {
if ((boolean) equals.invokeExact(elementType.getSlice(arrayBlock, i), value)) {
return true;
}
}
catch (Throwable t) {
Throwables.propagateIfInstanceOf(t, Error.class);
Throwables.propagateIfInstanceOf(t, PrestoException.class);
throw new PrestoException(INTERNAL_ERROR, t);
}
}
if (foundNull) {
return null;
}
return false;
}
示例6: regexpExtract
import io.airlift.slice.Slice; //导入依赖的package包/类
@Nullable
@Description("returns regex group of extracted string with a pattern")
@ScalarFunction
@SqlType(StandardTypes.VARCHAR)
public static Slice regexpExtract(@SqlType(StandardTypes.VARCHAR) Slice source, @SqlType(RegexpType.NAME) Regex pattern, @SqlType(StandardTypes.BIGINT) long groupIndex)
{
Matcher matcher = pattern.matcher(source.getBytes());
validateGroup(groupIndex, matcher.getEagerRegion());
int group = Ints.checkedCast(groupIndex);
int offset = matcher.search(0, source.length(), Option.DEFAULT);
if (offset == -1) {
return null;
}
Region region = matcher.getEagerRegion();
int beg = region.beg[group];
int end = region.end[group];
if (beg == -1) {
// end == -1 must be true
return null;
}
Slice slice = source.slice(beg, end - beg);
return slice;
}
示例7: readBlock
import io.airlift.slice.Slice; //导入依赖的package包/类
@Override
public Block readBlock(SliceInput sliceInput)
{
int positionCount = sliceInput.readInt();
// offsets
Slice offsets = Slices.allocate((positionCount + 1) * SIZE_OF_INT);
sliceInput.readBytes(offsets, SIZE_OF_INT, positionCount * SIZE_OF_INT);
boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount);
int blockSize = sliceInput.readInt();
Slice slice = sliceInput.readSlice(blockSize);
return new VariableWidthBlock(positionCount, slice, offsets, Slices.wrappedBooleanArray(valueIsNull));
}
示例8: writeField
import io.airlift.slice.Slice; //导入依赖的package包/类
private void writeField(int position, Block block, Type type)
{
if (block.isNull(position)) {
recordSink.appendNull();
return;
}
if (type.getJavaType() == boolean.class) {
recordSink.appendBoolean(type.getBoolean(block, position));
}
else if (type.getJavaType() == long.class) {
recordSink.appendLong(type.getLong(block, position));
}
else if (type.getJavaType() == double.class) {
recordSink.appendDouble(type.getDouble(block, position));
}
else if (type.getJavaType() == Slice.class) {
recordSink.appendString(type.getSlice(block, position).getBytes());
}
else {
recordSink.appendObject(type.getObject(block, position));
}
}
示例9: 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;
}
示例10: toMap
import io.airlift.slice.Slice; //导入依赖的package包/类
public static Block toMap(Type mapType, ConnectorSession connectorSession, Slice json)
{
try {
Map<?, ?> map = (Map<?, ?>) stackRepresentationToObject(connectorSession, json, mapType);
if (map == null) {
return null;
}
Type keyType = ((MapType) mapType).getKeyType();
Type valueType = ((MapType) mapType).getValueType();
BlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(keyType, valueType), new BlockBuilderStatus(), map.size() * 2);
for (Map.Entry<?, ?> entry : map.entrySet()) {
appendToBlockBuilder(keyType, entry.getKey(), blockBuilder);
appendToBlockBuilder(valueType, entry.getValue(), blockBuilder);
}
return blockBuilder.build();
}
catch (RuntimeException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to " + mapType, e);
}
}
示例11: commitCreateTable
import io.airlift.slice.Slice; //导入依赖的package包/类
@Override
public void commitCreateTable(JdbcOutputTableHandle handle, Collection<Slice> fragments)
{
StringBuilder sql = new StringBuilder()
.append("ALTER TABLE ")
.append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName()))
.append(" RENAME TO ")
.append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName()));
try (Connection connection = getConnection(handle)) {
execute(connection, sql.toString());
}
catch (SQLException e) {
throw new PrestoException(JDBC_ERROR, e);
}
}
示例12: indexStackValues
import io.airlift.slice.Slice; //导入依赖的package包/类
private static SortedMap<Integer, Object> indexStackValues(Type type, Block block)
{
SortedMap<Integer, Object> values = new TreeMap<>();
for (int position = 0; position < block.getPositionCount(); position++) {
if (block.isNull(position)) {
values.put(position, null);
}
else if (type.getJavaType() == boolean.class) {
values.put(position, type.getBoolean(block, position));
}
else if (type.getJavaType() == long.class) {
values.put(position, type.getLong(block, position));
}
else if (type.getJavaType() == double.class) {
values.put(position, type.getDouble(block, position));
}
else if (type.getJavaType() == Slice.class) {
values.put(position, type.getSlice(block, position));
}
else {
values.put(position, type.getObject(block, position));
}
}
return unmodifiableSortedMap(values);
}
示例13: readBlock
import io.airlift.slice.Slice; //导入依赖的package包/类
@Override
public Block readBlock(SliceInput sliceInput)
{
// positionCount
int positionCount = sliceInput.readInt();
// dictionary
Block dictionaryBlock = dictionaryEncoding.readBlock(sliceInput);
// ids
int lengthIdsSlice = sliceInput.readInt();
Slice ids = sliceInput.readSlice(lengthIdsSlice);
// instance id
long mostSignificantBits = sliceInput.readLong();
long leastSignificantBits = sliceInput.readLong();
long sequenceId = sliceInput.readLong();
// we always compact the dictionary before we send it
return new DictionaryBlock(positionCount, dictionaryBlock, ids, true, new DictionaryId(mostSignificantBits, leastSignificantBits, sequenceId));
}
示例14: isPC
import io.airlift.slice.Slice; //导入依赖的package包/类
@ScalarFunction("is_pc")
@Description("Returns Boolean: map['category'] is a pc or not.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean isPC(@SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
return Classifier.parse(argument).get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_PC);
}
示例15: IsSmartPhone
import io.airlift.slice.Slice; //导入依赖的package包/类
@ScalarFunction("is_smartphone")
@Description("Returns Boolean: map['category'] is a smartphone or not.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean IsSmartPhone(@SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
return Classifier.parse(argument).get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_SMARTPHONE);
}