private Map createParameterMap()

in asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ExecuteProcedureStatement.java [151:188]


    private Map<byte[], byte[]> createParameterMap(Procedure procedure) throws AsterixException, HyracksDataException {
        Map<byte[], byte[]> map = new HashMap<>();
        if (procedure.getParams().size() != argList.size()) {
            throw AsterixException.create(ErrorCode.COMPILATION_INVALID_PARAMETER_NUMBER,
                    procedure.getEntityId().getEntityName(), argList.size());
        }
        ArrayBackedValueStorage abvsKey = new ArrayBackedValueStorage();
        DataOutput dosKey = abvsKey.getDataOutput();
        ArrayBackedValueStorage abvsValue = new ArrayBackedValueStorage();
        DataOutput dosValue = abvsValue.getDataOutput();

        for (int i = 0; i < procedure.getParams().size(); i++) {
            if (!(argList.get(i) instanceof LiteralExpr)) {
                //TODO handle nonliteral arguments to procedure
                throw AsterixException.create(ErrorCode.TYPE_UNSUPPORTED, procedure.getEntityId().getEntityName(),
                        argList.get(i).getClass());
            }
            //Turn the argument name into a byte array
            IAObject str = new AString(procedure.getParams().get(i));
            abvsKey.reset();
            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(str.getType()).serialize(str, dosKey);
            //We do not save the type tag of the string key
            byte[] key = new byte[abvsKey.getLength() - 1];
            System.arraycopy(abvsKey.getByteArray(), 1, key, 0, abvsKey.getLength() - 1);

            //Turn the argument value into a byte array
            IAObject object = ConstantHelper.objectFromLiteral(((LiteralExpr) argList.get(i)).getValue());
            abvsValue.reset();
            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(object.getType()).serialize(object,
                    dosValue);
            byte[] value = new byte[abvsValue.getLength()];
            System.arraycopy(abvsValue.getByteArray(), abvsValue.getStartOffset(), value, 0, abvsValue.getLength());

            map.put(key, value);
        }

        return map;
    }