forcedotcom / phoenix

BSD 3-Clause "New" or "Revised" License
558 stars 227 forks source link

Add built-in function that returns ARRAY length #662

Closed jtaylor-sfdc closed 10 years ago

jtaylor-sfdc commented 10 years ago

Add a built-in function (see step-by-step instructions here) called ARRAY_LENGTH that returns the length of an array.

ramkrish86 commented 10 years ago

I have done this implementation. But facing an interesting issue. Currently my no of elements (array length) is stored as Vint in the serialization format. So what should be the return type of the built in function? Since Vint it may occupy one byte or 2 bytes to represent the integer. Bases on the number of bytes occupied should we change the return type? If we change the return type like {code} // Array length will return an Vint if(elementSize == Bytes.SIZEOF_BYTE) { // If Vnt occupies only one byte return tinyint return PDataType.TINYINT; } else { // If not return short return PDataType.SMALLINT; } {code} From the REsultSet, it is ideallly rs.getInt(). But internally it is not getInt. So can we change the vInt to Integer only so that the implementation becomes simple?

jtaylor-sfdc commented 10 years ago

Implemented by @ramkrish86. Thanks for the contributions!