@Override public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool) throws HyracksDataException { IJObject jObject = objectPool.allocate(BuiltinType.ASTRING); try { byte byteArray[] = pointable.getByteArray(); int len = pointable.getLength() - 3; int off = pointable.getStartOffset() + 3; baaos.reset(); if (off >= 0 && off <= byteArray.length && len >= 0 && off + len - byteArray.length <= 0) { baaos.write(byteArray, off, len); ((JString) jObject).setValue(JObjectUtil.getNormalizedString(baaos.toString("UTF-8"))); } else { ((JString) jObject).setValue(""); } } catch (IOException e) { e.printStackTrace(); } return jObject; }
@Override public void evaluate(IFunctionHelper functionHelper) throws Exception { list.clear(); JRecord inputRecord = (JRecord) functionHelper.getArgument(0); JString id = (JString) inputRecord.getValueByName("id"); JString text = (JString) inputRecord.getValueByName("text"); String[] tokens = text.getValue().split(" "); for (String tk : tokens) { if (tk.startsWith("#")) { JString newField = (JString) functionHelper.getObject(JTypeTag.STRING); newField.setValue(tk); list.add(newField); } } JRecord result = (JRecord) functionHelper.getResultObject(); result.setField("id", id); result.setField("username", inputRecord.getValueByName("username")); result.setField("location", inputRecord.getValueByName("location")); result.setField("text", text); result.setField("timestamp", inputRecord.getValueByName("timestamp")); result.setField("topics", list); functionHelper.setResult(result); }