Refine search
private static Tuple transformToTuple(List<?> objList, HCatSchema hs) throws Exception { if (objList == null) { return null; } Tuple t = tupFac.newTuple(objList.size()); List<HCatFieldSchema> subFields = hs.getFields(); for (int i = 0; i < subFields.size(); i++) { t.set(i, extractPigObject(objList.get(i), subFields.get(i))); } return t; }
Object object = entry.getValue(); if (object == null) { tuple.set(i++, null); continue; case DataType.BYTEARRAY: byte[] bytes = PDataType.fromTypeId(PBinary.INSTANCE.getSqlType()).toBytes(object); tuple.set(i, new DataByteArray(bytes, 0, bytes.length)); break; case DataType.CHARARRAY: tuple.set(i, DataType.toString(object)); break; case DataType.DOUBLE: tuple.set(i, DataType.toDouble(object)); break; case DataType.FLOAT: tuple.set(i, DataType.toFloat(object)); break; case DataType.INTEGER: tuple.set(i, DataType.toInteger(object)); break; case DataType.LONG: tuple.set(i, DataType.toLong(object)); break; case DataType.BOOLEAN: tuple.set(i, DataType.toBoolean(object)); break; case DataType.DATETIME: if (object instanceof java.sql.Timestamp)
/** * Test Use the udf to reserve multiple tuples * * @throws Exception */ @Test public void testMultipleTuples() throws Exception { Tuple tuple = tupleFactory.newTuple(2); tuple.set(0, 2L); tuple.set(1, SEQUENCE_NAME); final String tentantId = conn.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB); ReserveNSequence udf = new ReserveNSequence(zkQuorum, tentantId); for (int i = 0; i < 2; i++) { udf.exec(tuple); } long nextValue = getNextSequenceValue(conn); assertEquals(5L, nextValue); }
private void doTest(Connection conn, UDFTestProperties props) throws Exception { setCurrentValue(conn, props.getCurrentValue()); Tuple tuple = tupleFactory.newTuple(3); tuple.set(0, props.getNumToReserve()); tuple.set(1, props.getSequenceName()); tuple.set(2, zkQuorum); Long result = null; try { final String tenantId = conn.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB); ReserveNSequence udf = new ReserveNSequence(zkQuorum, tenantId); result = udf.exec(tuple); validateReservedSequence(conn, props.getCurrentValue(), props.getNumToReserve(), result); // Calling this to cleanup for the udf. To close the connection udf.finish(); } catch (Exception e) { if (props.isExceptionExpected()) { assertEquals(props.getExceptionClass(), e.getClass()); e.getMessage().contains(props.getErrorMessage()); } else { throw e; } } }
protected Tuple constructOutput(List<Result> resLst, Tuple value) throws ExecException{ // Construct key Object key; if (resLst.size() > 1) { Tuple t = mTupleFactory.newTuple(resLst.size()); int i = -1; for (Result res : resLst) { t.set(++i, res.result); } key = t; } else { key = resLst.get(0).result; } // Put key and value in a tuple and return output.set(0, key); output.set(1, value); return output; }
public HashMap<Object, List<Tuple>> insertNullTuples(HashMap<Object, List<Tuple>> groupedData, int tupleSize) throws ExecException { Tuple nullTuple = TupleFactory.getInstance().newTuple(tupleSize); for (int i=0; i<tupleSize; i++) { nullTuple.set(i, null); } for (Object key : joinData.keySet()) { if (!groupedData.containsKey(key)) { groupedData.put(key, Collections.singletonList(nullTuple)); } } return groupedData; }
private static Tuple transformToTuple(List<?> objList, HCatSchema hs) throws Exception { if (objList == null) { return null; } Tuple t = tupFac.newTuple(objList.size()); List<HCatFieldSchema> subFields = hs.getFields(); for (int i = 0; i < subFields.size(); i++) { t.set(i, extractPigObject(objList.get(i), subFields.get(i))); } return t; }
private static Tuple transformToTuple(List<?> objList, HCatSchema hs) throws Exception { if (objList == null) { return null; } Tuple t = tupFac.newTuple(objList.size()); List<HCatFieldSchema> subFields = hs.getFields(); for (int i = 0; i < subFields.size(); i++) { t.set(i, extractPigObject(objList.get(i), subFields.get(i))); } return t; }
Tuple GetJoinInput(Tuple group, List<Integer> groupCols, int numFields) throws ExecException { Tuple t = TupleFactory.getInstance().newTuple(numFields); if (groupCols.size() == 1) { // GroupLabel would be a data atom t.set(groupCols.get(0), group); } else { if (!(group instanceof Tuple)) throw new RuntimeException("Unrecognized group label!"); for (int i = 0; i < groupCols.size(); i++) { t.set(groupCols.get(i), group.get(i)); } } return t; }
Tuple GetGroupByInput(Object groupLabel, List<Integer> groupCols, int numFields) throws ExecException { Tuple t = TupleFactory.getInstance().newTuple(numFields); if (groupCols.size() == 1) { // GroupLabel would be a data atom t.set(groupCols.get(0), groupLabel); } else { if (!(groupLabel instanceof Tuple)) throw new RuntimeException("Unrecognized group label!"); Tuple group = (Tuple) groupLabel; for (int i = 0; i < groupCols.size(); i++) { t.set(groupCols.get(i), group.get(i)); } } return t; }
Tuple GetJoinInput(Tuple group, List<Integer> groupCols0, List<Integer> groupCols, int numFields) throws ExecException { Tuple t = TupleFactory.getInstance().newTuple(numFields); if (groupCols.size() == 1) { // GroupLabel would be a data atom t.set(groupCols.get(0), group.get(groupCols0.get(0))); } else { if (!(group instanceof Tuple)) throw new RuntimeException("Unrecognized group label!"); for (int i = 0; i < groupCols.size(); i++) { t.set(groupCols.get(i), group.get(groupCols0.get(i))); } } return t; }
public DataBag exec(Tuple input) throws IOException { DataBag outputBag = bagFactory.newDefaultBag(); String idBase = (String)input.get(0); for (int k=0; k < numKeys; k++) { String key = idBase+k; int key_bucket = random.nextInt(maxRandom); Tuple next = tupleFactory.newTuple(2); next.set(0, key); next.set(1, key_bucket); outputBag.add(next); } return outputBag; }
public static Tuple bytesToTuple(DataInput in) throws IOException { // Don't use Tuple.readFields, because it requires you to // create a tuple with no size and then append fields. // That's less efficient than allocating the tuple size up // front and then filling in the spaces. // Read the size. int sz = in.readInt(); // if sz == 0, we construct an "empty" tuple - // presumably the writer wrote an empty tuple! if (sz < 0) { throw new IOException("Invalid size " + sz + " for a tuple"); } Tuple t = mTupleFactory.newTuple(sz); for (int i = 0; i < sz; i++) { t.set(i, readDatum(in)); } return t; }