use of com.facebook.presto.spi.function.LiteralParameters in project presto by prestodb.
the class ApproximateSetAggregation method input.
@InputFunction
@LiteralParameters("x")
public static void input(@AggregationState HyperLogLogState state, @SqlType("varchar(x)") Slice value) {
HyperLogLog hll = getOrCreateHyperLogLog(state);
state.addMemoryUsage(-hll.estimatedInMemorySize());
hll.add(value);
state.addMemoryUsage(hll.estimatedInMemorySize());
}
use of com.facebook.presto.spi.function.LiteralParameters in project presto by prestodb.
the class AggregationCompiler method getLiteralParameter.
private static Set<String> getLiteralParameter(Method inputFunction) {
ImmutableSet.Builder<String> literalParametersBuilder = ImmutableSet.builder();
Annotation[] literalParameters = inputFunction.getAnnotations();
for (Annotation annotation : literalParameters) {
if (annotation instanceof LiteralParameters) {
for (String literal : ((LiteralParameters) annotation).value()) {
literalParametersBuilder.add(literal);
}
}
}
return literalParametersBuilder.build();
}
use of com.facebook.presto.spi.function.LiteralParameters in project presto by prestodb.
the class CharacterStringCasts method varcharToCharSaturatedFloorCast.
@ScalarOperator(OperatorType.SATURATED_FLOOR_CAST)
@SqlType("char(y)")
@LiteralParameters({ "x", "y" })
public static // Char(y) value that is smaller than the original Varchar(x) value. This is fine though for usage in TupleDomainTranslator.
Slice varcharToCharSaturatedFloorCast(@LiteralParameter("y") Long y, @SqlType("varchar(x)") Slice slice) {
Slice trimmedSlice = trimSpaces(slice);
int trimmedTextLength = countCodePoints(trimmedSlice);
int numberOfTrailingSpaces = slice.length() - trimmedSlice.length();
// if Varchar(x) value length (including spaces) is greater than y, we can just truncate it
if (trimmedTextLength + numberOfTrailingSpaces >= y) {
return truncateToLength(trimmedSlice, y.intValue());
}
if (trimmedTextLength == 0) {
return EMPTY_SLICE;
}
// and also remove one additional trailing character to get smaller Char(y) value
return trimmedSlice.slice(0, offsetOfCodePoint(trimmedSlice, trimmedTextLength - 1));
}
use of com.facebook.presto.spi.function.LiteralParameters in project presto by prestodb.
the class ColorFunctions method color.
@ScalarFunction
@LiteralParameters("x")
@SqlType(ColorType.NAME)
public static long color(@SqlType("varchar(x)") Slice color) {
int rgb = parseRgb(color);
if (rgb != -1) {
return rgb;
}
// encode system colors (0-15) as negative values, offset by one
try {
SystemColor systemColor = SystemColor.valueOf(upper(color).toStringUtf8());
int index = systemColor.getIndex();
return -(index + 1);
} catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid color: '%s'", color.toStringUtf8()), e);
}
}
use of com.facebook.presto.spi.function.LiteralParameters in project presto by prestodb.
the class JsonFunctions method jsonParse.
@ScalarFunction
@LiteralParameters("x")
@SqlType(StandardTypes.JSON)
public static Slice jsonParse(@SqlType("varchar(x)") Slice slice) {
try {
byte[] in = slice.getBytes();
SliceOutput dynamicSliceOutput = new DynamicSliceOutput(in.length);
SORTED_MAPPER.writeValue((OutputStream) 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()));
}
}
Aggregations