richardstartin commented on code in PR #8535: URL: https://github.com/apache/pinot/pull/8535#discussion_r849750848
########## pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java: ########## @@ -32,6 +36,46 @@ public class DataTypeConversionFunctions { private DataTypeConversionFunctions() { } + @ScalarFunction + public static Object cast(Object value, String targetTypeLiteral) { + try { + Class<?> clazz = value.getClass(); + boolean isMultiValue = clazz.isArray() & clazz != byte[].class; + PinotDataType sourceType = isMultiValue + ? PinotDataType.getMultiValueType(clazz) + : PinotDataType.getSingleValueType(clazz); + PinotDataType targetDataType = convertTypeLiteralToDataType(targetTypeLiteral); + if (sourceType == STRING && EnumSet.of(INTEGER, LONG, INTEGER_ARRAY, LONG_ARRAY) + .contains(targetDataType)) { + // convert integers via double to avoid parse errors + if (isMultiValue) { + return targetDataType.convert(DOUBLE_ARRAY.convert(value, sourceType), DOUBLE_ARRAY); + } + return targetDataType.convert(DOUBLE.convert(value, sourceType), DOUBLE); + } + return targetDataType.convert(value, sourceType); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("Unknown data type: " + targetTypeLiteral); + } + } Review Comment: @Jackie-Jiang just to pre-empt lots of very helpful suggestions to optimise this, I haven't even tried. The basic premise is that the transform function will be used when this is on the hot path, and this already makes my query >100x faster by allowing metadata to be used. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org