use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class TeradataStringFunctions method char2HexInt.
@Description("Returns the hexadecimal representation of the UTF-16BE encoding of the argument")
@ScalarFunction("char2hexint")
@SqlType(StandardTypes.VARCHAR)
public static Slice char2HexInt(@SqlType(StandardTypes.VARCHAR) Slice string) {
Slice utf16 = Slices.wrappedBuffer(UTF_16BE.encode(string.toStringUtf8()));
String encoded = BaseEncoding.base16().encode(utf16.getBytes());
return Slices.utf8Slice(encoded);
}
use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class CreateHll method createHll.
@ScalarFunction
@SqlType(StandardTypes.HYPER_LOG_LOG)
public static Slice createHll(@SqlType(StandardTypes.BIGINT) long value) {
HyperLogLog hll = HyperLogLog.newInstance(4096);
hll.add(value);
return hll.serialize();
}
use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
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 io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class DateTimeFunctions method toUnixTimeFromTimestampWithTimeZone.
@ScalarFunction("to_unixtime")
@SqlType(StandardTypes.DOUBLE)
public static double toUnixTimeFromTimestampWithTimeZone(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) {
ISOChronology localChronology = getChronology(session.getTimeZoneKey());
long localMillis = localChronology.getZone().convertUTCToLocal(unpackMillisUtc(timestampWithTimeZone));
ISOChronology zoneChronology = unpackChronology(timestampWithTimeZone);
long zoneMillis = zoneChronology.getZone().convertLocalToUTC(localMillis, false);
return zoneMillis / 1000.0;
}
use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class DateTimeFunctions method toISO8601FromTimestampWithTimeZone.
@ScalarFunction("to_iso8601")
@SqlType("varchar(35)")
public static // the maximum year represented by 64bits timestamp is ~584944387 it may require up to 35 characters.
Slice toISO8601FromTimestampWithTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) {
long millisUtc = unpackMillisUtc(timestampWithTimeZone);
DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withChronology(getChronology(unpackZoneKey(timestampWithTimeZone)));
return utf8Slice(formatter.print(millisUtc));
}
Aggregations