本文整理汇总了Java中io.airlift.slice.Slice.getBytes方法的典型用法代码示例。如果您正苦于以下问题:Java Slice.getBytes方法的具体用法?Java Slice.getBytes怎么用?Java Slice.getBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.airlift.slice.Slice
的用法示例。
在下文中一共展示了Slice.getBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bloomFilterPersist
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@SqlType(StandardTypes.BOOLEAN)
@Nullable
@SqlNullable
public static Boolean bloomFilterPersist(@SqlNullable @SqlType(BloomFilterType.TYPE) Slice bloomFilterSlice, @SqlType(StandardTypes.VARCHAR) Slice urlSlice) throws Exception
{
// Nothing todo
if (urlSlice == null) {
return true;
}
BloomFilter bf = getOrLoadBloomFilter(bloomFilterSlice);
// Persist
// we do not try catch here to make sure that errors are communicated clearly to the client
// and typical retry logic continues to work
String url = new String(urlSlice.getBytes());
if (!HTTP_CLIENT.isStarted()) {
log.warn("Http client was not started, trying to start");
HTTP_CLIENT.start();
}
Request post = HTTP_CLIENT.POST(url);
post.content(new StringContentProvider(new String(bf.toBase64())));
post.method("PUT");
post.send();
log.info("Persisted " + bf.toString() + " " + url);
return true;
}
示例2: mightContain
import io.airlift.slice.Slice; //导入方法依赖的package包/类
public boolean mightContain(Slice s)
{
byte[] b = s.getBytes();
if (USE_PRE_FILTER) {
if (instancePreFilter.contains(b)) {
return instance.contains(b);
}
else {
preMiss++;
return false;
}
}
else {
return instance.contains(b);
}
}
示例3: jsonParse
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction
@SqlType(StandardTypes.JSON)
public static Slice jsonParse(@SqlType(StandardTypes.VARCHAR) Slice slice)
{
try {
byte[] in = slice.getBytes();
SliceOutput dynamicSliceOutput = new DynamicSliceOutput(in.length);
SORTED_MAPPER.writeValue(dynamicSliceOutput, SORTED_MAPPER.readValue(in, Object.class));
return dynamicSliceOutput.slice();
}
catch (Exception e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Cannot convert '%s' to JSON", slice.toStringUtf8()));
}
}
示例4: 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;
}
示例5: put
import io.airlift.slice.Slice; //导入方法依赖的package包/类
public BloomFilter put(Slice s)
{
if (s == null) {
return this;
}
byte[] b = s.getBytes();
if (b.length < 1) {
return this;
}
instance.add(b);
if (USE_PRE_FILTER) {
instancePreFilter.add(b);
}
return this;
}
示例6: nativeContainerToOrcValue
import io.airlift.slice.Slice; //导入方法依赖的package包/类
private static Object nativeContainerToOrcValue(Type type, Object nativeValue)
{
if (nativeValue == null) {
return null;
}
if (type.getJavaType() == boolean.class) {
return nativeValue;
}
if (type.getJavaType() == long.class) {
return nativeValue;
}
if (type.getJavaType() == double.class) {
return nativeValue;
}
if (type.getJavaType() == Slice.class) {
Slice slice = (Slice) nativeValue;
return type.equals(VARCHAR) ? slice.toStringUtf8() : slice.getBytes();
}
if (isArrayType(type)) {
Block arrayBlock = (Block) nativeValue;
Type elementType = type.getTypeParameters().get(0);
List<Object> list = new ArrayList<>();
for (int i = 0; i < arrayBlock.getPositionCount(); i++) {
list.add(nativeContainerToOrcValue(elementType, getNativeContainerValue(elementType, arrayBlock, i)));
}
return list;
}
if (isMapType(type)) {
Block mapBlock = (Block) nativeValue;
Type keyType = type.getTypeParameters().get(0);
Type valueType = type.getTypeParameters().get(1);
Map<Object, Object> map = new HashMap<>();
for (int i = 0; i < mapBlock.getPositionCount(); i += 2) {
Object key = nativeContainerToOrcValue(keyType, getNativeContainerValue(keyType, mapBlock, i));
Object value = nativeContainerToOrcValue(valueType, getNativeContainerValue(valueType, mapBlock, i + 1));
map.put(key, value);
}
return map;
}
throw new PrestoException(INTERNAL_ERROR, "Unimplemented type: " + type);
}
示例7: appendReplacement
import io.airlift.slice.Slice; //导入方法依赖的package包/类
private static void appendReplacement(SliceOutput result, Slice source, Regex pattern, Region region, Slice replacement)
{
// Handle the following items:
// 1. ${name};
// 2. $0, $1, $123 (group 123, if exists; or group 12, if exists; or group 1);
// 3. \\, \$, \t (literal 't').
// 4. Anything that doesn't starts with \ or $ is considered regular bytes
int idx = 0;
while (idx < replacement.length()) {
byte nextByte = replacement.getByte(idx);
if (nextByte == '$') {
idx++;
if (idx == replacement.length()) { // not using checkArgument because `.toStringUtf8` is expensive
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal replacement sequence: " + replacement.toStringUtf8());
}
nextByte = replacement.getByte(idx);
int backref;
if (nextByte == '{') { // case 1 in the above comment
idx++;
int startCursor = idx;
while (idx < replacement.length()) {
nextByte = replacement.getByte(idx);
if (nextByte == '}') {
break;
}
idx++;
}
byte[] groupName = replacement.getBytes(startCursor, idx - startCursor);
try {
backref = pattern.nameToBackrefNumber(groupName, 0, groupName.length, region);
}
catch (ValueException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal replacement sequence: unknown group { " + new String(groupName, StandardCharsets.UTF_8) + " }");
}
idx++;
}
else { // case 2 in the above comment
backref = nextByte - '0';
if (backref < 0 || backref > 9) { // not using checkArgument because `.toStringUtf8` is expensive
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal replacement sequence: " + replacement.toStringUtf8());
}
if (region.numRegs <= backref) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal replacement sequence: unknown group " + backref);
}
idx++;
while (idx < replacement.length()) { // Adaptive group number: find largest group num that is not greater than actual number of groups
int nextDigit = replacement.getByte(idx) - '0';
if (nextDigit < 0 || nextDigit > 9) {
break;
}
int newBackref = (backref * 10) + nextDigit;
if (region.numRegs <= newBackref) {
break;
}
backref = newBackref;
idx++;
}
}
int beg = region.beg[backref];
int end = region.end[backref];
if (beg != -1 && end != -1) { // the specific group doesn't exist in the current match, skip
result.appendBytes(source.slice(beg, end - beg));
}
}
else { // case 3 and 4 in the above comment
if (nextByte == '\\') {
idx++;
if (idx == replacement.length()) { // not using checkArgument because `.toStringUtf8` is expensive
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal replacement sequence: " + replacement.toStringUtf8());
}
nextByte = replacement.getByte(idx);
}
result.appendByte(nextByte);
idx++;
}
}
}