本文整理汇总了Java中io.airlift.slice.Slice.toStringUtf8方法的典型用法代码示例。如果您正苦于以下问题:Java Slice.toStringUtf8方法的具体用法?Java Slice.toStringUtf8怎么用?Java Slice.toStringUtf8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.airlift.slice.Slice
的用法示例。
在下文中一共展示了Slice.toStringUtf8方法的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: input
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@InputFunction
public static void input(EvaluateClassifierPredictionsState state, @SqlType(StandardTypes.VARCHAR) Slice truth, @SqlType(StandardTypes.VARCHAR) Slice prediction)
{
if (truth.equals(prediction)) {
String key = truth.toStringUtf8();
if (!state.getTruePositives().containsKey(key)) {
state.addMemoryUsage(truth.length() + SIZE_OF_INT);
}
state.getTruePositives().put(key, state.getTruePositives().getOrDefault(key, 0) + 1);
}
else {
String truthKey = truth.toStringUtf8();
String predictionKey = prediction.toStringUtf8();
if (!state.getFalsePositives().containsKey(predictionKey)) {
state.addMemoryUsage(prediction.length() + SIZE_OF_INT);
}
state.getFalsePositives().put(predictionKey, state.getFalsePositives().getOrDefault(predictionKey, 0) + 1);
if (!state.getFalseNegatives().containsKey(truthKey)) {
state.addMemoryUsage(truth.length() + SIZE_OF_INT);
}
state.getFalseNegatives().put(truthKey, state.getFalseNegatives().getOrDefault(truthKey, 0) + 1);
}
}
示例3: 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);
}
示例4: 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);
}
示例5: IsMobilePhone
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction("is_mobilephone")
@Description("Returns Boolean: map['category'] is a mobilephone or not.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean IsMobilePhone(@SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
return Classifier.parse(argument).get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_MOBILEPHONE);
}
示例6: IsAppliance
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction("is_appliance")
@Description("Returns Boolean: map['category'] is a appliance or not.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean IsAppliance(@SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
return Classifier.parse(argument).get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_APPLIANCE);
}
示例7: IsCrawler
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction("is_crawler")
@Description("Returns Boolean: map['category'] is a crawler or not.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean IsCrawler(@SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
return Classifier.parse(argument).get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_CRAWLER);
}
示例8: IsMisc
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction("is_misc")
@Description("Returns Boolean: map['category'] is a misc or not.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean IsMisc(@SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
return Classifier.parse(argument).get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_MISC);
}
示例9: IsUnknown
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@ScalarFunction("is_unknown")
@Description("Returns Boolean: map['category'] is a unknown or not.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean IsUnknown(@SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
return Classifier.parse(argument).get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.VALUE_UNKNOWN);
}
示例10: shuffle_string
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@SqlType(StandardTypes.VARCHAR)
public static Slice shuffle_string(@SqlType(StandardTypes.VARCHAR) Slice string) {
String id = string.toStringUtf8();
Random rnd = new Random(id.charAt(0));
byte[] bytes = id.getBytes();
for (int i = bytes.length; i > 1; i--) {
swap(bytes, i - 1, rnd.nextInt(i));
}
return Slices.wrappedBuffer(bytes);
}
示例11: to_cuebiq_week_format
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@SqlType(StandardTypes.VARCHAR)
public static Slice to_cuebiq_week_format(@SqlType(StandardTypes.DATE) Slice date, @SqlType(StandardTypes.VARCHAR) Slice dateFormat) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat.toStringUtf8());
Calendar calendar = Calendar.getInstance();
calendar.setMinimalDaysInFirstWeek(4);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(formatter.parse(date.toStringUtf8()));
int week = calendar.get(Calendar.WEEK_OF_YEAR);
int year = calendar.getWeekYear();
return Slices.utf8Slice(year + "-W" + (week < 10 ? "0" + week : week) + "-1");
}
示例12: indexString
import io.airlift.slice.Slice; //导入方法依赖的package包/类
private static ColumnStats indexString(Type type, OrcRecordReader reader, int columnIndex, long columnId)
throws IOException
{
boolean minSet = false;
boolean maxSet = false;
Slice min = null;
Slice max = null;
while (true) {
int batchSize = reader.nextBatch();
if (batchSize <= 0) {
break;
}
Block block = reader.readBlock(type, columnIndex);
for (int i = 0; i < batchSize; i++) {
if (block.isNull(i)) {
continue;
}
Slice slice = type.getSlice(block, i);
slice = truncateIndexValue(slice);
if (!minSet || (slice.compareTo(min) < 0)) {
minSet = true;
min = slice;
}
if (!maxSet || (slice.compareTo(max) > 0)) {
maxSet = true;
max = slice;
}
}
}
return new ColumnStats(columnId,
minSet ? min.toStringUtf8() : null,
maxSet ? max.toStringUtf8() : null);
}
示例13: parseDatetime
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@Description("parses the specified date/time by the given format")
@ScalarFunction
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long parseDatetime(ConnectorSession session, @SqlType(StandardTypes.VARCHAR) Slice datetime, @SqlType(StandardTypes.VARCHAR) Slice formatString)
{
String pattern = formatString.toStringUtf8();
DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern)
.withChronology(getChronology(session.getTimeZoneKey()))
.withOffsetParsed()
.withLocale(session.getLocale());
String datetimeString = datetime.toStringUtf8();
return packDateTimeWithZone(parseDateTimeHelper(formatter, datetimeString));
}
示例14: formatDatetime
import io.airlift.slice.Slice; //导入方法依赖的package包/类
private static Slice formatDatetime(ISOChronology chronology, Locale locale, long timestamp, Slice formatString)
{
String pattern = formatString.toStringUtf8();
DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern)
.withChronology(chronology)
.withLocale(locale);
String datetimeString = formatter.print(timestamp);
return utf8Slice(datetimeString);
}
示例15: urlExtractParameter
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@Nullable
@Description("extract query parameter from url")
@ScalarFunction
@SqlType(StandardTypes.VARCHAR)
public static Slice urlExtractParameter(@SqlType(StandardTypes.VARCHAR) Slice url, @SqlType(StandardTypes.VARCHAR) Slice parameterName)
{
URI uri = parseUrl(url);
if ((uri == null) || (uri.getQuery() == null)) {
return null;
}
Slice query = slice(uri.getQuery());
String parameter = parameterName.toStringUtf8();
Iterable<String> queryArgs = QUERY_SPLITTER.split(query.toStringUtf8());
for (String queryArg : queryArgs) {
Iterator<String> arg = ARG_SPLITTER.split(queryArg).iterator();
if (arg.next().equals(parameter)) {
if (arg.hasNext()) {
return utf8Slice(arg.next());
}
// first matched key is empty
return Slices.EMPTY_SLICE;
}
}
// no key matched
return null;
}