@Override public List<Object> deserialize(ByteBuffer ser) { try { String data = new String(Utils.toByteArray(ser), StandardCharsets.UTF_8); CSVParser parser = CSVParser.parse(data, CSVFormat.RFC4180); CSVRecord record = parser.getRecords().get(0); Preconditions.checkArgument(record.size() == fieldNames.size(), "Invalid schema"); ArrayList<Object> list = new ArrayList<>(fieldNames.size()); for (int i = 0; i < record.size(); i++) { list.add(record.get(i)); } return list; } catch (IOException e) { throw new RuntimeException(e); } }
if (csvRecord == null || csvRecord.size() == 0) { throw new KsqlException("Deserialization error in the delimited line: " + recordCsvString); if (csvRecord.size() != schema.fields().size()) { throw new KsqlException( String.format( "Unexpected field count, csvFields:%d schemaFields:%d line: %s", csvRecord.size(), schema.fields().size(), recordCsvString for (int i = 0; i < csvRecord.size(); i++) { if (csvRecord.get(i) == null) { columns.add(null);
if (record.size() == 3)
for (int i = 0; i < csvRecord.size(); i++) { final String rawValue = csvRecord.get(i);
@Override protected void execute(CSVRecord csvRecord) { try { if (csvRecord.size() < conversionFunctions.size()) { String message = String.format("CSV record does not have enough values (has %d, but needs %d)", csvRecord.size(), conversionFunctions.size()); throw new IllegalArgumentException(message); } for (int fieldIndex = 0; fieldIndex < conversionFunctions.size(); fieldIndex++) { Object sqlValue = conversionFunctions.get(fieldIndex).apply(csvRecord.get(fieldIndex)); if (sqlValue != null) { preparedStatement.setObject(fieldIndex + 1, sqlValue); } else { preparedStatement.setNull(fieldIndex + 1, dataTypes.get(fieldIndex).getSqlType()); } } preparedStatement.execute(); upsertListener.upsertDone(++upsertCount); } catch (Exception e) { if (LOG.isDebugEnabled()) { // Even though this is an error we only log it with debug logging because we're notifying the // listener, and it can do its own logging if needed LOG.debug("Error on CSVRecord " + csvRecord, e); } upsertListener.errorOnRecord(csvRecord, e); } }
private List<String[]> getRecords(String content, CSVFormat format) throws IOException { List<String[]> records = new ArrayList<>(); CSVParser parser = CSVParser.parse(content, format); for (CSVRecord record : parser.getRecords()) { String[] line = new String[record.size()]; for (int i = 0; i < line.length; i++) { line[i] = record.get(i); } records.add(line); } return records; } }
CSVRecord record = iterator.next(); String field = record.get(0); if ((field.toUpperCase(Locale.ENGLISH).equals(field)) && (record.size() == 1)) { investigationSection = Arrays.asList(sections).contains(field); studySection = (studyFileName != null) && (field.equals(studySectionField));
@Override public boolean apply(CSVRecord record) { return record.size() == size; } }
if (iterator.hasNext()) { CSVRecord record = iterator.next(); for (int i = 0; i < record.size(); i++) { xhtml.startElement("th"); xhtml.characters(record.get(i)); CSVRecord record = iterator.next(); xhtml.startElement("tr"); for (int j = 0; j < record.size(); j++) { xhtml.startElement("td"); xhtml.characters(record.get(j));
if (iterator.hasNext()) { CSVRecord record = iterator.next(); for (int i = 0; i < record.size(); i++) { xhtml.startElement("th"); xhtml.characters(record.get(i)); CSVRecord record = iterator.next(); xhtml.startElement("tr"); for (int j = 0; j < record.size(); j++) { xhtml.startElement("td"); xhtml.characters(record.get(j));
final int count = record.size(); assertEquals(testName, readTestData(), count + ":" + parsed);
assertTrue(phoenixResultSet.next()); int i = 0; int size = record.size(); for (String value : record) { assertEquals(value, phoenixResultSet.getObject(i + 1)
final int count = record.size(); assertEquals(testName, readTestData(), count + ":" + parsed);
@Override public String get(int index) { if (index < 0 || index > record.size() - 1) { return null; } return record.get(index); } }
@Override protected void eval() { evaluatedValues.clear(); CSVRecord record = iterator.next(); for (int i = 0; i < record.size(); i++) { String value = record.get(i); evaluatedValues.put("c" + i, value); } val = evaluatedValues; }
public List<String> getHeader(){ List<String> headers = new LinkedList<>(); if(firstRecord != null){ for(int i =0; i<firstRecord.size();i++){ headers.add(firstRecord.get(i)); } } return headers; }
public List<Tuple> read(InputStream is) throws IOException { CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(delim.charAt(0)); CSVParser csvParser = new CSVParser(new InputStreamReader(is), format); List<CSVRecord> records = csvParser.getRecords(); header = csvParser.getHeaderMap().entrySet().stream() .sorted((e1, e2) -> e1.getValue().compareTo(e2.getValue())) .map(Map.Entry::getKey).toArray(String[]::new); labelCol = labelCol == -1 ? records.get(0).size() - 1 : labelCol; List<Tuple> ds = records.stream().parallel().map(this::extractValuedFeat).collect(Collectors.toList()); return ds; }