use of io.prestosql.spi.function.LiteralParameters in project hetu-core by openlookeng.
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 io.prestosql.spi.function.LiteralParameters in project hetu-core by openlookeng.
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 io.prestosql.spi.function.LiteralParameters in project hetu-core by openlookeng.
the class DateTimeFunctions method fromISO8601Date.
@ScalarFunction("from_iso8601_date")
@LiteralParameters("x")
@SqlType(StandardTypes.DATE)
public static long fromISO8601Date(ConnectorSession session, @SqlType("varchar(x)") Slice iso8601DateTime) {
DateTimeFormatter formatter = ISODateTimeFormat.dateElementParser().withChronology(UTC_CHRONOLOGY);
DateTime dateTime = parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8());
return MILLISECONDS.toDays(dateTime.getMillis());
}
use of io.prestosql.spi.function.LiteralParameters in project hetu-core by openlookeng.
the class IpAddressOperators method castFromVarcharToIpAddress.
@LiteralParameters("x")
@ScalarOperator(CAST)
@SqlType(StandardTypes.IPADDRESS)
public static Slice castFromVarcharToIpAddress(@SqlType("varchar(x)") Slice slice) {
byte[] address;
try {
address = InetAddresses.forString(slice.toStringUtf8()).getAddress();
} catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Cannot cast value to IPADDRESS: " + slice.toStringUtf8());
}
byte[] bytes;
if (address.length == 4) {
bytes = new byte[16];
bytes[10] = (byte) 0xff;
bytes[11] = (byte) 0xff;
arraycopy(address, 0, bytes, 12, 4);
} else if (address.length == 16) {
bytes = address;
} else {
throw new PrestoException(GENERIC_INTERNAL_ERROR, "Invalid InetAddress length: " + address.length);
}
return wrappedBuffer(bytes);
}
use of io.prestosql.spi.function.LiteralParameters in project hetu-core by openlookeng.
the class UrlFunctions method urlExtractParameter.
@SqlNullable
@Description("extract query parameter from url")
@ScalarFunction
@LiteralParameters({ "x", "y" })
@SqlType("varchar(x)")
public static Slice urlExtractParameter(@SqlType("varchar(x)") Slice url, @SqlType("varchar(y)") 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;
}
Aggregations