yupeng9 commented on a change in pull request #6941:
URL: https://github.com/apache/incubator-pinot/pull/6941#discussion_r634922225



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java
##########
@@ -94,51 +94,157 @@ public TransformResultMetadata getResultMetadata() {
 
   @Override
   public int[] transformToIntValuesSV(ProjectionBlock projectionBlock) {
-    return _transformFunction.transformToIntValuesSV(projectionBlock);
+    // When casting to FLOAT, need to first read as the result type then 
convert to int values
+    DataType resultStoredType = _resultMetadata.getDataType().getStoredType();
+    if (resultStoredType != DataType.FLOAT) {
+      return _transformFunction.transformToIntValuesSV(projectionBlock);
+    } else {
+      if (_intValuesSV == null) {
+        _intValuesSV = new int[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      }
+      int numDocs = projectionBlock.getNumDocs();
+      float[] floatValues = 
_transformFunction.transformToFloatValuesSV(projectionBlock);
+      ArrayCopyUtils.copy(floatValues, _intValuesSV, numDocs);
+      return _intValuesSV;
+    }
   }
 
   @Override
   public long[] transformToLongValuesSV(ProjectionBlock projectionBlock) {
-    return _transformFunction.transformToLongValuesSV(projectionBlock);
+    // When casting to INT/FLOAT/DOUBLE, need to first read as the result type 
then convert to long values
+    DataType resultStoredType = _resultMetadata.getDataType().getStoredType();
+    if (resultStoredType != DataType.INT && resultStoredType != DataType.FLOAT 
&& resultStoredType != DataType.DOUBLE) {
+      return _transformFunction.transformToLongValuesSV(projectionBlock);
+    } else {
+      if (_longValuesSV == null) {
+        _longValuesSV = new long[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      }
+      int numDocs = projectionBlock.getNumDocs();
+      if (resultStoredType == DataType.INT) {
+        int[] intValues = 
_transformFunction.transformToIntValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(intValues, _longValuesSV, numDocs);
+      } else if (resultStoredType == DataType.FLOAT) {
+        float[] floatValues = 
_transformFunction.transformToFloatValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(floatValues, _longValuesSV, numDocs);
+      } else {
+        double[] doubleValues = 
_transformFunction.transformToDoubleValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(doubleValues, _longValuesSV, numDocs);
+      }
+      return _longValuesSV;
+    }
   }
 
   @Override
   public float[] transformToFloatValuesSV(ProjectionBlock projectionBlock) {
-    return _transformFunction.transformToFloatValuesSV(projectionBlock);
+    // When casting to INT/LONG, need to first read as the result type then 
convert to float values
+    DataType resultStoredType = _resultMetadata.getDataType().getStoredType();
+    if (resultStoredType != DataType.INT && resultStoredType != DataType.LONG) 
{
+      return _transformFunction.transformToFloatValuesSV(projectionBlock);
+    } else {
+      if (_floatValuesSV == null) {
+        _floatValuesSV = new float[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      }
+      int numDocs = projectionBlock.getNumDocs();
+      if (resultStoredType == DataType.INT) {

Review comment:
       do we need handling of long type?

##########
File path: 
pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CastTransformFunctionTest.java
##########
@@ -40,21 +40,21 @@ public void testCastTransformFunction() {
     testTransformFunction(transformFunction, expectedValues);
 
     expression = RequestContextUtils.getExpressionFromSQL(
-        String.format("CAST(ADD(CAST(%s AS INT), %s) AS STRING)", 
STRING_SV_COLUMN, DOUBLE_SV_COLUMN));
+        String.format("CAST(ADD(CAST(%s AS LONG), %s) AS STRING)", 
DOUBLE_SV_COLUMN, LONG_SV_COLUMN));

Review comment:
       can you add more test coverage? There are quite a few special handling 
logic added.

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CastTransformFunction.java
##########
@@ -94,51 +94,157 @@ public TransformResultMetadata getResultMetadata() {
 
   @Override
   public int[] transformToIntValuesSV(ProjectionBlock projectionBlock) {
-    return _transformFunction.transformToIntValuesSV(projectionBlock);
+    // When casting to FLOAT, need to first read as the result type then 
convert to int values
+    DataType resultStoredType = _resultMetadata.getDataType().getStoredType();
+    if (resultStoredType != DataType.FLOAT) {
+      return _transformFunction.transformToIntValuesSV(projectionBlock);
+    } else {
+      if (_intValuesSV == null) {
+        _intValuesSV = new int[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      }
+      int numDocs = projectionBlock.getNumDocs();
+      float[] floatValues = 
_transformFunction.transformToFloatValuesSV(projectionBlock);
+      ArrayCopyUtils.copy(floatValues, _intValuesSV, numDocs);
+      return _intValuesSV;
+    }
   }
 
   @Override
   public long[] transformToLongValuesSV(ProjectionBlock projectionBlock) {
-    return _transformFunction.transformToLongValuesSV(projectionBlock);
+    // When casting to INT/FLOAT/DOUBLE, need to first read as the result type 
then convert to long values
+    DataType resultStoredType = _resultMetadata.getDataType().getStoredType();
+    if (resultStoredType != DataType.INT && resultStoredType != DataType.FLOAT 
&& resultStoredType != DataType.DOUBLE) {
+      return _transformFunction.transformToLongValuesSV(projectionBlock);
+    } else {
+      if (_longValuesSV == null) {
+        _longValuesSV = new long[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      }
+      int numDocs = projectionBlock.getNumDocs();
+      if (resultStoredType == DataType.INT) {
+        int[] intValues = 
_transformFunction.transformToIntValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(intValues, _longValuesSV, numDocs);
+      } else if (resultStoredType == DataType.FLOAT) {
+        float[] floatValues = 
_transformFunction.transformToFloatValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(floatValues, _longValuesSV, numDocs);
+      } else {
+        double[] doubleValues = 
_transformFunction.transformToDoubleValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(doubleValues, _longValuesSV, numDocs);
+      }
+      return _longValuesSV;
+    }
   }
 
   @Override
   public float[] transformToFloatValuesSV(ProjectionBlock projectionBlock) {
-    return _transformFunction.transformToFloatValuesSV(projectionBlock);
+    // When casting to INT/LONG, need to first read as the result type then 
convert to float values
+    DataType resultStoredType = _resultMetadata.getDataType().getStoredType();
+    if (resultStoredType != DataType.INT && resultStoredType != DataType.LONG) 
{
+      return _transformFunction.transformToFloatValuesSV(projectionBlock);
+    } else {
+      if (_floatValuesSV == null) {
+        _floatValuesSV = new float[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      }
+      int numDocs = projectionBlock.getNumDocs();
+      if (resultStoredType == DataType.INT) {
+        int[] intValues = 
_transformFunction.transformToIntValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(intValues, _floatValuesSV, numDocs);
+      } else {
+        long[] longValues = 
_transformFunction.transformToLongValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(longValues, _floatValuesSV, numDocs);
+      }
+      return _floatValuesSV;
+    }
   }
 
   @Override
   public double[] transformToDoubleValuesSV(ProjectionBlock projectionBlock) {
-    return _transformFunction.transformToDoubleValuesSV(projectionBlock);
+    // When casting to INT/LONG/FLOAT, need to first read as the result type 
then convert to double values
+    DataType resultStoredType = _resultMetadata.getDataType().getStoredType();
+    if (resultStoredType != DataType.INT && resultStoredType != DataType.LONG 
&& resultStoredType != DataType.FLOAT) {
+      return _transformFunction.transformToDoubleValuesSV(projectionBlock);
+    } else {
+      if (_doubleValuesSV == null) {
+        _doubleValuesSV = new double[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      }
+      int numDocs = projectionBlock.getNumDocs();
+      if (resultStoredType == DataType.INT) {
+        int[] intValues = 
_transformFunction.transformToIntValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(intValues, _doubleValuesSV, numDocs);
+      } else if (resultStoredType == DataType.LONG) {
+        long[] longValues = 
_transformFunction.transformToLongValuesSV(projectionBlock);
+        ArrayCopyUtils.copy(longValues, _doubleValuesSV, numDocs);
+      } else {

Review comment:
       do we need to handle float type?




-- 
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.

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

Reply via email to