public JavaFunctionHelper(IExternalFunctionInfo finfo, IDataOutputProvider outputProvider, List<String> parameters) { this.finfo = finfo; this.outputProvider = outputProvider; this.pointableVisitor = new JObjectPointableVisitor(); this.pointableAllocator = new PointableAllocator(); this.arguments = new IJObject[finfo.getArgumentList().size()]; int index = 0; for (IAType param : finfo.getArgumentList()) { this.arguments[index++] = objectPool.allocate(param); } this.resultHolder = objectPool.allocate(finfo.getReturnType()); this.poolTypeInfo = new HashMap<>(); this.parameters = parameters; }
public void setArguments(IFrameTupleReference tuple) throws AlgebricksException, IOException { for (int i = 0; i < evaluatorFactories.length; i++) { argumentEvaluators[i].evaluate(tuple, inputVal); // Type-cast the source array based on the input type that this function wants to receive. ATypeTag targetTypeTag = finfo.getArgumentList().get(i).getTypeTag(); ATypeTag sourceTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER .deserialize(inputVal.getByteArray()[inputVal.getStartOffset()]); if (sourceTypeTag != targetTypeTag) { castBuffer.reset(); ATypeHierarchy.convertNumericTypeByteArray(inputVal.getByteArray(), inputVal.getStartOffset(), inputVal.getLength(), targetTypeTag, castBuffer.getDataOutput(), true); functionHelper.setArgument(i, castBuffer); } else { functionHelper.setArgument(i, inputVal); } } }
public void setArgument(int index, IValueReference valueReference) throws IOException, AsterixException { IVisitablePointable pointable = null; IJObject jObject = null; IAType type = finfo.getArgumentList().get(index); switch (type.getTypeTag()) { case OBJECT: pointable = pointableAllocator.allocateRecordValue(type); pointable.set(valueReference); jObject = pointableVisitor.visit((ARecordVisitablePointable) pointable, getTypeInfo(index, type)); break; case ARRAY: case MULTISET: pointable = pointableAllocator.allocateListValue(type); pointable.set(valueReference); jObject = pointableVisitor.visit((AListVisitablePointable) pointable, getTypeInfo(index, type)); break; case ANY: throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_FUNCTION_HELPER_CANNOT_HANDLE_ARGU_TYPE, type.getTypeTag()); default: pointable = pointableAllocator.allocateFieldValue(type); pointable.set(valueReference); jObject = pointableVisitor.visit((AFlatValuePointable) pointable, getTypeInfo(index, type)); break; } arguments[index] = jObject; }