use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class QuantileDigestFunctions method valuesAtQuantilesBigint.
@ScalarFunction("values_at_quantiles")
@Description("For each input q between [0, 1], find the value whose rank in the sorted sequence of the n values represented by the qdigest is qn.")
@SqlType("array(bigint)")
public static Block valuesAtQuantilesBigint(@SqlType("qdigest(bigint)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock) {
QuantileDigest digest = new QuantileDigest(input);
BlockBuilder output = BIGINT.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
BIGINT.writeLong(output, digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i)));
}
return output.build();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class TDigestFunctions method quantilesAtValuesDouble.
@ScalarFunction(value = "quantiles_at_values", visibility = EXPERIMENTAL)
@Description("For each input x between min/max values of t-digest, find which quantile is represented by that value")
@SqlType("array(double)")
public static Block quantilesAtValuesDouble(@SqlType("tdigest(double)") Slice input, @SqlType("array(double)") Block valuesArrayBlock) {
TDigest tDigest = createTDigest(input);
BlockBuilder output = DOUBLE.createBlockBuilder(null, valuesArrayBlock.getPositionCount());
for (int i = 0; i < valuesArrayBlock.getPositionCount(); i++) {
DOUBLE.writeDouble(output, tDigest.getCdf(DOUBLE.getDouble(valuesArrayBlock, i)));
}
return output.build();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class DataSizeFunctions method parsePrestoDataSize.
@Description("converts data size string to bytes")
@ScalarFunction("parse_presto_data_size")
@LiteralParameters("x")
@SqlType("decimal(38,0)")
public static Slice parsePrestoDataSize(@SqlType("varchar(x)") Slice input) {
String dataSize = input.toStringUtf8();
int valueLength = 0;
for (int i = 0; i < dataSize.length(); i++) {
char c = dataSize.charAt(i);
if (isDigit(c) || c == '.') {
valueLength++;
} else {
break;
}
}
if (valueLength == 0) {
throw invalidDataSize(dataSize);
}
BigDecimal value = parseValue(dataSize.substring(0, valueLength), dataSize);
Unit unit = Unit.parse(dataSize.substring(valueLength), dataSize);
BigInteger bytes = value.multiply(unit.getFactor()).toBigInteger();
try {
return encodeUnscaledValue(bytes);
} catch (ArithmeticException e) {
throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("Value out of range: '%s' ('%sB')", dataSize, bytes));
}
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class DateTimeFunctions method addFieldValueTimeWithTimeZone.
@Description("add the specified amount of time to the given time")
@LiteralParameters("x")
@ScalarFunction("date_add")
@SqlType(StandardTypes.TIME_WITH_TIME_ZONE)
public static long addFieldValueTimeWithTimeZone(@SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone) {
ISOChronology chronology = unpackChronology(timeWithTimeZone);
long millis = modulo24Hour(chronology, getTimeField(chronology, unit).add(unpackMillisUtc(timeWithTimeZone), toIntExact(value)));
return updateMillisUtc(millis, timeWithTimeZone);
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class DateTimeFunctions method currentDate.
@Description("current date")
@ScalarFunction
@SqlType(StandardTypes.DATE)
public static long currentDate(SqlFunctionProperties properties) {
ISOChronology chronology = getChronology(properties.getTimeZoneKey());
// It is ok for this method to use the Object interfaces because it is constant folded during
// plan optimization
LocalDate currentDate = new DateTime(properties.getSessionStartTime(), chronology).toLocalDate();
return Days.daysBetween(new LocalDate(1970, 1, 1), currentDate).getDays();
}
Aggregations