});
}
@Override
public Datum eval(Tuple params) {
Datum finding = params.get(0);
Datum textArray = params.get(1);
if (finding instanceof NullDatum || textArray instanceof NullDatum) {
return NullDatum.get();
}
byte[] searchBytes = finding.asByteArray();
// Returns 0 if the first argument has any commas.
for (int i = 0; i < finding.size(); i++) {
if (searchBytes[i] == ',') {
return DatumFactory.createInt4(0);
}
}
byte[] arrayData = textArray.asByteArray();
int findingLength = finding.size();
int posInTextArray = 0;
int curLengthOfCandidate = 0;
boolean matching = true;
for (int i = 0; i < textArray.size(); i++) {
if (arrayData[i] == ',') {
posInTextArray++;
if (matching && curLengthOfCandidate == findingLength) {
return DatumFactory.createInt4(posInTextArray);