本文整理了Java中io.airlift.slice.Slice.toStringUtf8()
方法的一些代码示例,展示了Slice.toStringUtf8()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.toStringUtf8()
方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:toStringUtf8
[英]Decodes the contents of this slice into a string using the UTF-8 character set.
[中]使用UTF-8字符集将该片段的内容解码为字符串。
代码示例来源:origin: prestodb/presto
@LiteralParameters("x")
@ScalarOperator(CAST)
@SqlType(StandardTypes.BIGINT)
public static long castToBigint(@SqlType("varchar(x)") Slice slice)
{
try {
return Long.parseLong(slice.toStringUtf8());
}
catch (Exception e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to BIGINT", slice.toStringUtf8()));
}
}
代码示例来源:origin: prestodb/presto
@SuppressWarnings("NumericCastThatLosesPrecision")
private static char getEscapeChar(Slice escape)
{
String escapeString = escape.toStringUtf8();
if (escapeString.isEmpty()) {
// escaping disabled
return (char) -1; // invalid character
}
if (escapeString.length() == 1) {
return escapeString.charAt(0);
}
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Escape string must be a single character");
}
}
代码示例来源:origin: prestodb/presto
@ScalarFunction("from_unixtime")
@LiteralParameters("x")
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long fromUnixTime(@SqlType(StandardTypes.DOUBLE) double unixTime, @SqlType("varchar(x)") Slice zoneId)
{
return packDateTimeWithZone(Math.round(unixTime * 1000), zoneId.toStringUtf8());
}
代码示例来源:origin: prestodb/presto
@Description("Throws an exception with a given message")
@ScalarFunction(value = "fail", hidden = true)
@SqlType("unknown")
public static boolean fail(@SqlType(StandardTypes.VARCHAR) Slice message)
{
throw new PrestoException(StandardErrorCode.GENERIC_USER_ERROR, message.toStringUtf8());
}
代码示例来源:origin: prestodb/presto
@Description("Creates a Bing tile from a QuadKey")
@ScalarFunction("bing_tile")
@SqlType(BingTileType.NAME)
public static long toBingTile(@SqlType(StandardTypes.VARCHAR) Slice quadKey)
{
checkQuadKey(quadKey);
return BingTile.fromQuadKey(quadKey.toStringUtf8()).encode();
}
代码示例来源:origin: prestodb/presto
@LiteralParameters("x")
@ScalarOperator(CAST)
@SqlType(StandardTypes.REAL)
public static long castToFloat(@SqlType("varchar(x)") Slice slice)
{
try {
return Float.floatToIntBits(Float.parseFloat(slice.toStringUtf8()));
}
catch (Exception e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to REAL", slice.toStringUtf8()));
}
}
代码示例来源:origin: prestodb/presto
private static OGCGeometry geometryFromText(Slice input)
{
OGCGeometry geometry;
try {
geometry = OGCGeometry.fromText(input.toStringUtf8());
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKT: " + input.toStringUtf8(), e);
}
geometry.setSpatialReference(null);
return geometry;
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(CAST)
@SqlNullable
@SqlType(BOOLEAN)
public static Boolean castToBoolean(@SqlType(JSON) Slice json)
{
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
parser.nextToken();
Boolean result = currentTokenAsBoolean(parser);
checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to BOOLEAN"); // check no trailing token
return result;
}
catch (IOException | JsonCastException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), BOOLEAN), e);
}
}
代码示例来源:origin: prestodb/presto
@SqlNullable
@Description("Returns TRUE if this Geometry is spatially related to another Geometry")
@ScalarFunction("ST_Relate")
@SqlType(BOOLEAN)
public static Boolean stRelate(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right, @SqlType(VARCHAR) Slice relation)
{
OGCGeometry leftGeometry = deserialize(left);
OGCGeometry rightGeometry = deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return leftGeometry.relate(rightGeometry, relation.toStringUtf8());
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(CAST)
@LiteralParameters("x")
@SqlType(StandardTypes.TIME_WITH_TIME_ZONE)
public static long castFromSlice(@SqlType("varchar(x)") Slice value)
{
return parseTimeWithTimeZone(value.toStringUtf8());
}
代码示例来源:origin: prestodb/presto
@LiteralParameters("x")
@ScalarOperator(CAST)
@SqlType(StandardTypes.INTEGER)
public static long castToInteger(@SqlType("varchar(x)") Slice slice)
{
try {
return Integer.parseInt(slice.toStringUtf8());
}
catch (Exception e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to INT", slice.toStringUtf8()));
}
}
代码示例来源:origin: prestodb/presto
private String getVarcharValue(Type type, Object value)
{
if (type instanceof VarcharType) {
return ((Slice) value).toStringUtf8();
}
if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType) {
return ((Long) value).toString();
}
if (type instanceof BooleanType) {
return ((Boolean) value).toString();
}
throw new PrestoException(NOT_SUPPORTED, format("Unsupported data type in EXPLAIN (TYPE IO): %s", type.getDisplayName()));
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(CAST)
@SqlNullable
@SqlType(BIGINT)
public static Long castToBigint(@SqlType(JSON) Slice json)
{
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
parser.nextToken();
Long result = currentTokenAsBigint(parser);
checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to BIGINT"); // check no trailing token
return result;
}
catch (IOException | JsonCastException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), BIGINT), e);
}
}
代码示例来源:origin: prestodb/presto
@InputFunction
public static void input(
@AggregationState LearnState state,
@SqlType(VARCHAR) Slice label,
@SqlType("map(bigint,double)") Block features,
@SqlType(VARCHAR) Slice parameters)
{
state.getLabels().add((double) state.enumerateLabel(label.toStringUtf8()));
FeatureVector featureVector = ModelUtils.toFeatures(features);
state.addMemoryUsage(featureVector.getEstimatedSize());
state.getFeatureVectors().add(featureVector);
state.setParameters(parameters);
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(OperatorType.CAST)
@SqlType(JsonPathType.NAME)
@LiteralParameters("x")
public static JsonPath castVarcharToJsonPath(@SqlType("varchar(x)") Slice pattern)
{
return new JsonPath(pattern.toStringUtf8());
}
代码示例来源:origin: prestodb/presto
@LiteralParameters("x")
@ScalarOperator(CAST)
@SqlType(StandardTypes.DOUBLE)
public static double castToDouble(@SqlType("varchar(x)") Slice slice)
{
try {
return Double.parseDouble(slice.toStringUtf8());
}
catch (Exception e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to DOUBLE", slice.toStringUtf8()));
}
}
代码示例来源:origin: prestodb/presto
private static RuntimeException throwMissingKeyException(Type type, InterpretedFunctionInvoker functionInvoker, Object value, ConnectorSession session)
{
String stringValue;
try {
stringValue = ((Slice) functionInvoker.invoke(castSignature(VarcharType.VARCHAR, type), session, value)).toStringUtf8();
}
catch (RuntimeException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key not present in map");
}
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Key not present in map: %s", stringValue));
}
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(CAST)
@SqlNullable
@SqlType(REAL)
public static Long castToReal(@SqlType(JSON) Slice json)
{
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
parser.nextToken();
Long result = currentTokenAsReal(parser);
checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to REAL"); // check no trailing token
return result;
}
catch (IOException | JsonCastException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), REAL), e);
}
}
代码示例来源:origin: prestodb/presto
@Description("mongodb ObjectId from the given string")
@ScalarFunction("objectid")
@SqlType("ObjectId")
public static Slice ObjectId(@SqlType(StandardTypes.VARCHAR) Slice value)
{
return Slices.wrappedBuffer(new ObjectId(CharMatcher.is(' ').removeFrom(value.toStringUtf8())).toByteArray());
}
代码示例来源:origin: prestodb/presto
@ScalarFunction(value = "at_timezone", hidden = true)
@LiteralParameters("x")
@SqlType(StandardTypes.TIME_WITH_TIME_ZONE)
public static long timeAtTimeZone(ConnectorSession session, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone, @SqlType("varchar(x)") Slice zoneId)
{
return timeAtTimeZone(session, timeWithTimeZone, getTimeZoneKey(zoneId.toStringUtf8()));
}
内容来源于网络,如有侵权,请联系作者删除!