use of io.confluent.ksql.rest.entity.StreamedRow.Header in project ksql by confluentinc.
the class Console method formatFieldType.
private static String formatFieldType(final FieldInfo field, final Optional<WindowType> windowType, final boolean isTable) {
final FieldType possibleFieldType = field.getType().orElse(null);
if (possibleFieldType == FieldType.HEADER) {
final String headerType = field.getHeaderKey().map(k -> "(header('" + k + "'))").orElse("(headers)");
return String.format("%-16s %s", field.getSchema().toTypeString(), headerType);
}
if (possibleFieldType == FieldType.KEY) {
final String wt = windowType.map(v -> " (Window type: " + v + ")").orElse("");
final String keyType = isTable ? "(primary key)" : "(key)";
return String.format("%-16s %s%s", field.getSchema().toTypeString(), keyType, wt);
}
return field.getSchema().toTypeString();
}
use of io.confluent.ksql.rest.entity.StreamedRow.Header in project ksql by confluentinc.
the class HARouting method streamedRowsHandler.
private static Consumer<List<StreamedRow>> streamedRowsHandler(final KsqlNode owner, final PullQueryQueue pullQueryQueue, final BiFunction<List<?>, LogicalSchema, PullQueryRow> rowFactory, final LogicalSchema outputSchema, final Optional<ConsistencyOffsetVector> consistencyOffsetVector) {
final AtomicInteger processedRows = new AtomicInteger(0);
final AtomicReference<Header> header = new AtomicReference<>();
return streamedRows -> {
try {
if (streamedRows == null || streamedRows.isEmpty()) {
return;
}
final List<PullQueryRow> rows = new ArrayList<>();
// If this is the first row overall, skip the header
final int previousProcessedRows = processedRows.getAndAdd(streamedRows.size());
for (int i = 0; i < streamedRows.size(); i++) {
final StreamedRow row = streamedRows.get(i);
if (i == 0 && previousProcessedRows == 0) {
final Optional<Header> optionalHeader = row.getHeader();
optionalHeader.ifPresent(h -> validateSchema(outputSchema, h.getSchema(), owner));
optionalHeader.ifPresent(header::set);
continue;
}
if (row.getErrorMessage().isPresent()) {
// If we receive an error that's not a network error, we let that bubble up.
throw new KsqlException(row.getErrorMessage().get().getMessage());
}
if (!row.getRow().isPresent()) {
parseNonDataRows(row, i, consistencyOffsetVector);
continue;
}
final List<?> r = row.getRow().get().getColumns();
Preconditions.checkNotNull(header.get());
rows.add(rowFactory.apply(r, header.get().getSchema()));
}
if (!pullQueryQueue.acceptRows(rows)) {
LOG.error("Failed to queue all rows");
}
} catch (Exception e) {
throw new KsqlException(e.getMessage(), e);
}
};
}
Aggregations