private static ColumnData findColumnValue(StreamData tupleData, String name) { for (ColumnData val : tupleData.getColumnList()) { if (val.getName().equals(name)) { return val; } } return null; }
private WebSocketReplyData processPublishRequest( WebSocketDecodeContext ctx, WebSocketDecoder decoder) throws WebSocketException { YarchDatabase ydb = YarchDatabase.getInstance(processor.getInstance()); StreamData req = decoder.decodeMessageData(ctx, SchemaArchive.StreamData.MERGE).build(); Stream stream = ydb.getStream(req.getStream()); if (stream == null) { throw new WebSocketException( ctx.getRequestId(), "Cannot find stream '" + req.getStream() + "'"); } TupleDefinition tdef = stream.getDefinition(); List<Object> tupleColumns = new ArrayList<>(); // 'fixed' colums for (ColumnDefinition cdef : stream.getDefinition().getColumnDefinitions()) { ColumnData providedField = findColumnValue(req, cdef.getName()); if (providedField == null) continue; if (!providedField.hasValue()) { throw new WebSocketException( ctx.getRequestId(), "No value was provided for column " + cdef.getName()); } Object column = makeTupleColumn(ctx, cdef.getName(), providedField.getValue(), cdef.getType()); tupleColumns.add(column); } // 'dynamic' columns for (ColumnData val : req.getColumnList()) { if (stream.getDefinition().getColumn(val.getName()) == null) { DataType type = dataTypeFromValue(val.getValue()); tdef.addColumn(val.getName(), type); Object column = makeTupleColumn(ctx, val.getName(), val.getValue(), type); tupleColumns.add(column); } } Tuple t = new Tuple(tdef, tupleColumns); log.info("Emitting tuple {} to {}", t, stream.getName()); stream.emitTuple(t); return toAckReply(ctx.getRequestId()); }