@Test public void testAppendAuxiliaryData() throws Exception { List<String> stringList = new ArrayList<>(); stringList.add("apple"); stringList.add("banana"); MockCollector collector = new MockCollector(); ModelConverterUtils.appendAuxiliaryData(stringList, collector, 3); Row row1 = collector.buffer.get(0); Assert.assertEquals(row1.getArity(), 3); Assert.assertEquals(row1.getField(0), Integer.MAX_VALUE * ModelConverterUtils.MAX_NUM_SLICES); Assert.assertEquals(row1.getField(2), "apple"); Row row2 = collector.buffer.get(1); Assert.assertEquals(row2.getArity(), 3); Assert.assertEquals(row2.getField(0), Integer.MAX_VALUE * ModelConverterUtils.MAX_NUM_SLICES + 1L); Assert.assertEquals(row2.getField(2), "banana"); }
static <T> void appendAuxiliaryData(Iterable<T> auxData, Collector<Row> collector, final int numFields) { if (auxData == null) { return; } final int numAdditionalFields = numFields - 2; int sliceIndex = 0; for (T data : auxData) { int stringIndex = Integer.MAX_VALUE; long modelId = getModelId(stringIndex, sliceIndex); Row row = new Row(numFields); row.setField(0, modelId); if (data instanceof Row) { Row r = (Row) data; for (int j = 0; j < numAdditionalFields; j++) { row.setField(2 + j, r.getField(j)); } } else { row.setField(2, data); } collector.collect(row); sliceIndex++; } }
ModelConverterUtils { static <T> void appendAuxiliaryData(Iterable<T> auxData, Collector<Row> collector, final int numFields) { if (auxData == null) { return; } final int numAdditionalFields = numFields - 2; int sliceIndex = 0; for (T data : auxData) { int stringIndex = Integer.MAX_VALUE; long modelId = getModelId(stringIndex, sliceIndex); Row row = new Row(numFields); row.setField(0, modelId); if (data instanceof Row) { Row r = (Row) data; for (int j = 0; j < numAdditionalFields; j++) { row.setField(2 + j, r.getField(j)); } } else { row.setField(2, data); } collector.collect(row); sliceIndex++; } } }
ModelConverterUtils { static <T> void appendAuxiliaryData(Iterable<T> auxData, Collector<Row> collector, final int numFields) { if (auxData == null) { return; } final int numAdditionalFields = numFields - 2; int sliceIndex = 0; for (T data : auxData) { int stringIndex = Integer.MAX_VALUE; long modelId = getModelId(stringIndex, sliceIndex); Row row = new Row(numFields); row.setField(0, modelId); if (data instanceof Row) { Row r = (Row) data; for (int j = 0; j < numAdditionalFields; j++) { row.setField(2 + j, r.getField(j)); } } else { row.setField(2, data); } collector.collect(row); sliceIndex++; } }  }
ModelConverterUtils { static <T> void appendAuxiliaryData(Iterable<T> auxData, Collector<Row> collector, final int numFields) { if (auxData == null) { return; } final int numAdditionalFields = numFields - 2; int sliceIndex = 0; for (T data : auxData) { int stringIndex = Integer.MAX_VALUE; long modelId = getModelId(stringIndex, sliceIndex); Row row = new Row(numFields); row.setField(0, modelId); if (data instanceof Row) { Row r = (Row) data; for (int j = 0; j < numAdditionalFields; j++) { row.setField(2 + j, r.getField(j)); } } else { row.setField(2, data); } collector.collect(row); sliceIndex++; } }   }
ModelConverterUtils { static <T> void appendAuxiliaryData(Iterable<T> auxData, Collector<Row> collector, final int numFields) { if (auxData == null) { return; } final int numAdditionalFields = numFields - 2; int sliceIndex = 0; for (T data : auxData) { int stringIndex = Integer.MAX_VALUE; long modelId = getModelId(stringIndex, sliceIndex); Row row = new Row(numFields); row.setField(0, modelId); if (data instanceof Row) { Row r = (Row) data; for (int j = 0; j < numAdditionalFields; j++) { row.setField(2 + j, r.getField(j)); } } else { row.setField(2, data); } collector.collect(row); sliceIndex++; } }    }