ModelConverterUtils { static Tuple2<Params, Iterable<String>> extractModelMetaAndData(List<Row> rows) { Integer[] order = orderModelRows(rows); List<String> metaSegments = new ArrayList<>(); for (int i = 0; i < order.length; i++) { long id = (Long) rows.get(order[i]).getField(0); int currStringId = getStringIndex(id); if (currStringId == 0) { metaSegments.add((String) rows.get(order[i]).getField(1)); } else { break; } } String metaStr = mergeString(metaSegments); return Tuple2.of(Params.fromJson(metaStr), new StringDataIterable(rows, order)); }    }
@Test public void testExtractModelMetaAndData() throws Exception { Params meta = new Params().set(SOME_PARAM, "value"); List<String> stringList = new ArrayList<>(); stringList.add("apple"); stringList.add("banana"); MockCollector collector = new MockCollector(); ModelConverterUtils.appendMetaRow(meta, collector, 2); ModelConverterUtils.appendDataRows(stringList, collector, 2); Tuple2<Params, Iterable<String>> metaAndData = ModelConverterUtils.extractModelMetaAndData(collector.buffer); Assert.assertEquals(metaAndData.f0.toJson(), meta.toJson()); Iterator<String> stringIterator = metaAndData.f1.iterator(); Assert.assertTrue(stringIterator.hasNext()); Assert.assertEquals(stringIterator.next(), "apple"); Assert.assertTrue(stringIterator.hasNext()); Assert.assertEquals(stringIterator.next(), "banana"); }