somandal commented on code in PR #9296: URL: https://github.com/apache/pinot/pull/9296#discussion_r959964142
########## pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java: ########## @@ -47,40 +49,51 @@ public void init(List<TransformFunction> arguments, Map<String, DataSource> data _transformFunction = arguments.get(0); TransformFunction castFormatTransformFunction = arguments.get(1); + boolean isSVCol = _transformFunction.getResultMetadata().isSingleValue(); if (castFormatTransformFunction instanceof LiteralTransformFunction) { String targetType = ((LiteralTransformFunction) castFormatTransformFunction).getLiteral().toUpperCase(); switch (targetType) { case "INT": case "INTEGER": - _resultMetadata = INT_SV_NO_DICTIONARY_METADATA; + _resultMetadata = isSVCol ? INT_SV_NO_DICTIONARY_METADATA : INT_MV_NO_DICTIONARY_METADATA; break; case "LONG": - _resultMetadata = LONG_SV_NO_DICTIONARY_METADATA; + _resultMetadata = isSVCol ? LONG_SV_NO_DICTIONARY_METADATA : LONG_MV_NO_DICTIONARY_METADATA; break; case "FLOAT": - _resultMetadata = FLOAT_SV_NO_DICTIONARY_METADATA; + _resultMetadata = isSVCol ? FLOAT_SV_NO_DICTIONARY_METADATA : FLOAT_MV_NO_DICTIONARY_METADATA; break; case "DOUBLE": - _resultMetadata = DOUBLE_SV_NO_DICTIONARY_METADATA; + _resultMetadata = isSVCol ? DOUBLE_SV_NO_DICTIONARY_METADATA : DOUBLE_MV_NO_DICTIONARY_METADATA; break; case "DECIMAL": case "BIGDECIMAL": case "BIG_DECIMAL": + // TODO: MV cast to BIG_DECIMAL type Review Comment: just curious, why not throw an exception here like you do for other types which don't have support for MV such as BOOLEAN/TIMESTAMP? ########## pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java: ########## @@ -96,6 +109,204 @@ public TransformResultMetadata getResultMetadata() { return _resultMetadata; } + @Override + public double[][] transformToDoubleValuesMV(ProjectionBlock projectionBlock) { + DataType resultStoredType = _resultMetadata.getDataType().getStoredType(); + if (resultStoredType == DataType.DOUBLE) { + return _transformFunction.transformToDoubleValuesMV(projectionBlock); + } else { + int length = projectionBlock.getNumDocs(); + if (_doubleValuesMV == null || _doubleValuesMV.length < length) { + _doubleValuesMV = new double[length][]; + } + switch (resultStoredType) { + case INT: + int[][] intValues = _transformFunction.transformToIntValuesMV(projectionBlock); + ArrayCopyUtils.copy(intValues, _doubleValuesMV, length); + break; + case LONG: + long[][] longValues = _transformFunction.transformToLongValuesMV(projectionBlock); + ArrayCopyUtils.copy(longValues, _doubleValuesMV, length); + break; + case FLOAT: + float[][] floatValues = _transformFunction.transformToFloatValuesMV(projectionBlock); + ArrayCopyUtils.copy(floatValues, _doubleValuesMV, length); + break; + case STRING: + String[][] stringValues = _transformFunction.transformToStringValuesMV(projectionBlock); + ArrayCopyUtils.copy(stringValues, _doubleValuesMV, length); + break; + default: + throw new IllegalStateException(); + } + } + return _doubleValuesMV; + } + + @Override + public String[][] transformToStringValuesMV(ProjectionBlock projectionBlock) { + DataType resultDataType = _resultMetadata.getDataType(); + DataType resultStoredType = resultDataType.getStoredType(); + int length = projectionBlock.getNumDocs(); + if (resultStoredType == DataType.STRING) { + // Specialize BOOLEAN and TIMESTAMP when casting to STRING + DataType inputDataType = _transformFunction.getResultMetadata().getDataType(); + if (inputDataType.getStoredType() != inputDataType) { + if (_stringValuesMV == null || _stringValuesMV.length < length) { + _stringValuesMV = new String[length][]; + } + if (inputDataType == DataType.BOOLEAN) { + int[][] intValues = _transformFunction.transformToIntValuesMV(projectionBlock); + for (int i = 0; i < length; i++) { + int rowLen = intValues[i].length; + for (int j = 0; j < rowLen; j++) { + _stringValuesMV[i][j] = Boolean.toString(intValues[i][j] == 1); + } + } Review Comment: nit: I know you only call this once, but might still be good to put this into a separate private method for easier code readability. same for DataType.TIMESTAMP handled next. -- 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