jboss 函数调用期间TEIID中的转换错误

piwo6bdm  于 2022-11-08  发布在  其他
关注(0)|答案(1)|浏览(147)

我在vdb文件夹内的java jar文件中定义了以下函数:

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)
}

这就是我在DDL中声明UDF的方式

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');

当我从SQL客户端调用函数时,我得到以下错误。我还尝试了object和object[]

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

谢谢你的帮助
谢谢

afdcj2ne

afdcj2ne1#

问题出在这一行

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

如果不起作用,请尝试将方法签名更改为使用double[] depthArray,或者尝试强制转换为ArrayImpl,如

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

以上解决方案之一应该有效!

相关问题