ASAFDAR
ASAFDAR

Reputation: 19

Conversion Error in TEIID during function call

I have following function defined in a java jar file within the vdb folder:

public static Blob createSampleLogCurve(String indexType, String indexUnit, String curveName, String curveUnit, String curveDataType, Object depthArray, Object valueArray) throws BulkDataException, SQLException { NullValueDef nullDef = new NullValueDef();
      byte[] bytes = null;
      nullDef.setNullFloat(-98765.0F);
      double[] depths = (double[])((double[])depthArray);
      int totalsamples = depths.length;
      String dataType = DataType.FLOAT.toString();
      double increment = depths[1] - depths[0];

      for(int i = 0; i < totalsamples - 1; ++i) {
         if (increment != depths[i + 1] - depths[i]) {
            increment = 0.0D;
            break;
         }
      }

      if (curveDataType.equalsIgnoreCase("INT")) {
         dataType = DataType.INT.toString();
      } else if (curveDataType.equalsIgnoreCase("DOUBLE")) {
         dataType = DataType.DOUBLE.toString();
      } else {
         dataType = DataType.FLOAT.toString();
      }

      CurveIndexProtoBuf indexProtobuf = new CurveIndexProtoBuf(depths[0], increment, totalsamples, indexType, indexUnit, depths);
      List<CurveValueProtoBuf> values = new ArrayList();
      values.add(new CurveValueProtoBuf(SampleType.VALUE.toString(), dataType, (String)null, curveUnit, 1, 1, (List)null, curveName, (Index)null, (Index)null, valueArray));
      LogCurveProtoBuf logCurveProtobuf = new LogCurveProtoBuf(indexType.equals("DEPTH") ? IndexType.DEPTH.toString() : IndexType.TIME.toString(), indexProtobuf, values);
      PipedInputStream in = new PipedInputStream(1024);
      PipedOutputStream out = null;

      try {
         out = new PipedOutputStream(in);
         logCurveProtobuf.build().writeDelimitedTo(out);
         out.close();
         bytes = IOUtils.toByteArray(in);
      } catch (Exception var29) {
         System.out.println(var29);
      } finally {
         try {
            out.close();
            in.close();
         } catch (IOException var28) {
            var28.printStackTrace();
         }

      }

      return new SerialBlob(bytes)
}

This is how I have declared the UDF in DDL

CREATE VIRTUAL FUNCTION createSampleLogCurve(indexType string,  indexUnit string,  curveName string, curveUnit string,  curveDataType string,  depthArray double[],  valueArray float[]) returns Blob
                OPTIONS(JAVA_CLASS 'com.common.udf.ProtoBufFunctions', JAVA_METHOD 'createSampleLogCurve');

When I call the function from SQL client, I get below error. I also tried object and object[]

java.lang.ClassCastException: org.teiid.core.types.ArrayImpl cannot be cast to [D

Appreciate any help on this

Thanks

Upvotes: 0

Views: 77

Answers (1)

Ramesh Reddy
Ramesh Reddy

Reputation: 574

The issue is with this line

double[] depths = (double[])((double[])depthArray);

Either try changing the method signature to use double[] depthArray if that does not work, try casting to ArrayImpl like


either one of the above solutions will work!
    if (depthArray instanceof ArrayImpl) {
        ArrayImpl array = (ArrayImpl) depth array;
        Object[] arrayVals = array.getValues();
        for (int i = 0; i < arrayVals.length; i++) {
            double val = arrayVals[i];
            // do 
        }
    }

one of the above solutions should work!

Upvotes: 0

Related Questions