@ProcessElement public void processElement(ProcessContext ctx) { GenericRecord genericRecord = ctx.element(); Schema schema = new Schema.Parser().parse(schemaJson); StringBuilder row = new StringBuilder(); for (Schema.Field field : schema.getFields()) { String fieldType = field.schema().getType().toString().toLowerCase(); if (!acceptedTypes.contains(fieldType)) { LOG.error("Data transformation doesn't support: " + fieldType); throw new IllegalArgumentException("Field type " + fieldType + " is not supported."); } if (row.length() > 0) { row.append(delimiter); } row.append(genericRecord.get(field.name())); } ctx.output(row.toString()); } }
@ProcessElement public void processElement(ProcessContext c) { String[] columns = c.element().split(DELIMITER); try { Long singerId = Long.parseLong(columns[0].trim()); Long albumId = Long.parseLong(columns[1].trim()); String albumTitle = columns[2].trim(); c.output(new Album(singerId, albumId, albumTitle)); } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { LOG.info("ParseAlbum: parse error on '" + c.element() + "': " + e.getMessage()); } } }
@ProcessElement public void processElement(ProcessContext c) { String[] columns = c.element().split(DELIMITER); try { Long singerId = Long.parseLong(columns[0].trim()); String firstName = columns[1].trim(); String lastName = columns[2].trim(); c.output(new Singer(singerId, firstName, lastName)); } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { LOG.info("ParseSinger: parse error on '" + c.element() + "': " + e.getMessage()); } } }
@ProcessElement public void processElement(ProcessContext c) throws Exception { Transaction tx = c.sideInput(txView); ReadOperation op = c.element(); BatchReadOnlyTransaction context = spannerAccessor.getBatchClient().batchReadOnlyTransaction(tx.transactionId()); try (ResultSet resultSet = execute(op, context)) { while (resultSet.next()) { c.output(resultSet.getCurrentRowAsStruct()); } } }