private void write(final Record record, final OutputStream out, final List<String> columnNames) throws IOException { final int numCols = columnNames.size(); final Map<String, String> values = new HashMap<>(numCols); for (int i = 0; i < numCols; i++) { final String columnName = columnNames.get(i); final String columnValue = record.getAsString(columnName); values.put(columnName, columnValue); } final String evaluated = propertyValue.evaluateAttributeExpressions(values).getValue(); out.write(evaluated.getBytes(charset)); out.write(NEW_LINE); }
@Override public WriteResult write(Record record) throws IOException { if (++recordCount > failAfterN && failAfterN > -1) { throw new IOException("Unit Test intentionally throwing IOException after " + failAfterN + " records were written"); } if (header != null && !headerWritten) { out.write(header.getBytes()); out.write("\n".getBytes()); headerWritten = true; } final int numCols = record.getSchema().getFieldCount(); int i = 0; for (final String fieldName : record.getSchema().getFieldNames()) { final String val = record.getAsString(fieldName); if (val != null) { if (quoteValues) { out.write("\"".getBytes()); out.write(val.getBytes()); out.write("\"".getBytes()); } else { out.write(val.getBytes()); } } if (i++ < numCols - 1) { out.write(",".getBytes()); } } out.write("\n".getBytes()); return WriteResult.of(1, Collections.emptyMap()); }
final String val = record.getAsString(fieldName); if (val != null) { if (quoteValues) {
private byte[] handleComplexField(Record record, String field, String complexFieldStrategy) throws PutCreationFailedInvokedException { switch (complexFieldStrategy) { case FAIL_VALUE: getLogger().error("Complex value found for {}; routing to failure", new Object[]{field}); throw new PutCreationFailedInvokedException(String.format("Complex value found for %s; routing to failure", field)); case WARN_VALUE: getLogger().warn("Complex value found for {}; skipping", new Object[]{field}); return null; case TEXT_VALUE: final String value = record.getAsString(field); return clientService.toBytes(value); case IGNORE_VALUE: // silently skip return null; default: return null; } }
@Override public WriteResult writeRawRecord(final Record record) throws IOException { // If we are not writing an active record set, then we need to ensure that we write the // schema information. if (!isActiveRecordSet()) { schemaWriter.writeHeader(recordSchema, getOutputStream()); } includeHeaderIfNecessary(record, false); final String[] fieldNames = getFieldNames(record); // Avoid creating a new Object[] for every Record if we can. But if the record has a different number of columns than does our // schema, we don't have a lot of options here, so we just create a new Object[] in that case. final Object[] recordFieldValues = (fieldNames.length == this.fieldValues.length) ? this.fieldValues : new String[fieldNames.length]; int i = 0; for (final String fieldName : fieldNames) { final Optional<RecordField> recordField = recordSchema.getField(fieldName); if (recordField.isPresent()) { recordFieldValues[i++] = record.getAsString(fieldName, getFormat(recordField.get())); } else { recordFieldValues[i++] = record.getAsString(fieldName); } } printer.printRecord(recordFieldValues); final Map<String, String> attributes = schemaWriter.getAttributes(recordSchema); return WriteResult.of(incrementRecordCount(), attributes); }
final String key = messageKeyField == null ? null : record.getAsString(messageKeyField); final byte[] messageKey = (key == null) ? null : key.getBytes(StandardCharsets.UTF_8);
final String key = messageKeyField == null ? null : record.getAsString(messageKeyField); final byte[] messageKey = (key == null) ? null : key.getBytes(StandardCharsets.UTF_8);
final String key = messageKeyField == null ? null : record.getAsString(messageKeyField); final byte[] messageKey = (key == null) ? null : key.getBytes(StandardCharsets.UTF_8);
final String key = messageKeyField == null ? null : record.getAsString(messageKeyField); final byte[] messageKey = (key == null) ? null : key.getBytes(StandardCharsets.UTF_8);
break; case BINARY: row.addBinary(colIdx, record.getAsString(colName).getBytes()); break; case INT8: break; case STRING: row.addString(colIdx, record.getAsString(colName)); break; case DECIMAL32: case DECIMAL64: case DECIMAL128: row.addDecimal(colIdx, new BigDecimal(record.getAsString(colName))); break; default:
@Override public Map<String, String> writeRecord(final Record record) throws IOException { // If we are not writing an active record set, then we need to ensure that we write the // schema information. if (!isActiveRecordSet()) { schemaWriter.writeHeader(recordSchema, getOutputStream()); } includeHeaderIfNecessary(record, true); int i = 0; for (final RecordField recordField : recordSchema.getFields()) { fieldValues[i++] = record.getAsString(recordField, getFormat(recordField)); } printer.printRecord(fieldValues); return schemaWriter.getAttributes(recordSchema); }
String rowIdValue = record.getAsString(rowFieldName); if (rowIdValue == null) { throw new PutCreationFailedInvokedException(String.format("Row ID was null for flowfile with ID %s", flowFile.getAttribute("uuid")));
break; default: final String value = record.getAsString(field); retVal = clientService.toBytes(value); break; break; default: final String value = record.getAsString(field); retVal = clientService.toBytes(value); break;
case VARCHAR: case CHAR: val = record.getAsString(fieldName); break; case BINARY:
final String key = messageKeyField == null ? null : record.getAsString(messageKeyField); final byte[] messageKey = (key == null) ? null : key.getBytes(StandardCharsets.UTF_8);
final String key = messageKeyField == null ? null : record.getAsString(messageKeyField); final byte[] messageKey = (key == null) ? null : key.getBytes(StandardCharsets.UTF_8);
final String key = messageKeyField == null ? null : record.getAsString(messageKeyField); final byte[] messageKey = (key == null) ? null : key.getBytes(StandardCharsets.UTF_8);