use of org.apache.samza.system.descriptors.InputDescriptor in project samza by apache.
the class ScanTranslator method translate.
// ScanMapFunction
void translate(final TableScan tableScan, final String queryLogicalId, final String logicalOpId, final TranslatorContext context, Map<String, DelegatingSystemDescriptor> systemDescriptors, Map<String, MessageStream<SamzaSqlInputMessage>> inputMsgStreams) {
StreamApplicationDescriptor streamAppDesc = context.getStreamAppDescriptor();
List<String> tableNameParts = tableScan.getTable().getQualifiedName();
String sourceName = SqlIOConfig.getSourceFromSourceParts(tableNameParts);
Validate.isTrue(relMsgConverters.containsKey(sourceName), String.format("Unknown source %s", sourceName));
SqlIOConfig sqlIOConfig = systemStreamConfig.get(sourceName);
final String systemName = sqlIOConfig.getSystemName();
final String streamId = sqlIOConfig.getStreamId();
final String source = sqlIOConfig.getSource();
final boolean isRemoteTable = sqlIOConfig.getTableDescriptor().isPresent() && (sqlIOConfig.getTableDescriptor().get() instanceof RemoteTableDescriptor || sqlIOConfig.getTableDescriptor().get() instanceof CachingTableDescriptor);
// descriptor to load the local table.
if (isRemoteTable) {
return;
}
// set the wrapper input transformer (SamzaSqlInputTransformer) in system descriptor
DelegatingSystemDescriptor systemDescriptor = systemDescriptors.get(systemName);
if (systemDescriptor == null) {
systemDescriptor = new DelegatingSystemDescriptor(systemName, new SamzaSqlInputTransformer());
systemDescriptors.put(systemName, systemDescriptor);
} else {
/* in SamzaSQL, there should be no systemDescriptor setup by user, so this branch happens only
* in case of Fan-OUT (i.e., same input stream used in multiple sql statements), or when same input
* used twice in same sql statement (e.g., select ... from input as i1, input as i2 ...), o.w., throw error */
if (systemDescriptor.getTransformer().isPresent()) {
InputTransformer existingTransformer = systemDescriptor.getTransformer().get();
if (!(existingTransformer instanceof SamzaSqlInputTransformer)) {
throw new SamzaException("SamzaSQL Exception: existing transformer for " + systemName + " is not SamzaSqlInputTransformer");
}
}
}
InputDescriptor inputDescriptor = systemDescriptor.getInputDescriptor(streamId, new NoOpSerde<>());
if (!inputMsgStreams.containsKey(source)) {
MessageStream<SamzaSqlInputMessage> inputMsgStream = streamAppDesc.getInputStream(inputDescriptor);
inputMsgStreams.put(source, inputMsgStream.map(new SystemMessageMapperFunction(source, queryId)));
}
MessageStream<SamzaSqlRelMessage> samzaSqlRelMessageStream = inputMsgStreams.get(source).filter(new FilterSystemMessageFunction(sourceName, queryId)).map(new ScanMapFunction(sourceName, queryId, queryLogicalId, logicalOpId));
context.registerMessageStream(tableScan.getId(), samzaSqlRelMessageStream);
}
use of org.apache.samza.system.descriptors.InputDescriptor in project beam by apache.
the class TranslationContext method createDummyStreamDescriptor.
/**
* The dummy stream created will only be used in Beam tests.
*/
private static InputDescriptor<OpMessage<String>, ?> createDummyStreamDescriptor(String id) {
final GenericSystemDescriptor dummySystem = new GenericSystemDescriptor(id, InMemorySystemFactory.class.getName());
final GenericInputDescriptor<OpMessage<String>> dummyInput = dummySystem.getInputDescriptor(id, new NoOpSerde<>());
dummyInput.withOffsetDefault(SystemStreamMetadata.OffsetType.OLDEST);
final Config config = new MapConfig(dummyInput.toConfig(), dummySystem.toConfig());
final SystemFactory factory = new InMemorySystemFactory();
final StreamSpec dummyStreamSpec = new StreamSpec(id, id, id, 1);
factory.getAdmin(id, config).createStream(dummyStreamSpec);
final SystemProducer producer = factory.getProducer(id, config, null);
final SystemStream sysStream = new SystemStream(id, id);
final Consumer<Object> sendFn = (msg) -> {
producer.send(id, new OutgoingMessageEnvelope(sysStream, 0, null, msg));
};
final WindowedValue<String> windowedValue = WindowedValue.timestampedValueInGlobalWindow("dummy", new Instant());
sendFn.accept(OpMessage.ofElement(windowedValue));
sendFn.accept(new WatermarkMessage(BoundedWindow.TIMESTAMP_MAX_VALUE.getMillis()));
sendFn.accept(new EndOfStreamMessage(null));
return dummyInput;
}
use of org.apache.samza.system.descriptors.InputDescriptor in project samza by apache.
the class TestStreamApplicationDescriptorImpl method testGetInputStreamWithExpandingSystem.
@Test
public void testGetInputStreamWithExpandingSystem() {
String streamId = "test-stream-1";
String expandedStreamId = "expanded-stream";
AtomicInteger expandCallCount = new AtomicInteger();
StreamExpander expander = (sg, isd) -> {
expandCallCount.incrementAndGet();
InputDescriptor expandedISD = new GenericSystemDescriptor("expanded-system", "mockFactoryClass").getInputDescriptor(expandedStreamId, new IntegerSerde());
return sg.getInputStream(expandedISD);
};
MockExpandingSystemDescriptor sd = new MockExpandingSystemDescriptor("mock-system", expander);
MockInputDescriptor isd = sd.getInputDescriptor(streamId, new IntegerSerde());
StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> {
appDesc.getInputStream(isd);
}, getConfig());
InputOperatorSpec inputOpSpec = streamAppDesc.getInputOperators().get(expandedStreamId);
assertEquals(OpCode.INPUT, inputOpSpec.getOpCode());
assertEquals(1, expandCallCount.get());
assertFalse(streamAppDesc.getInputOperators().containsKey(streamId));
assertFalse(streamAppDesc.getInputDescriptors().containsKey(streamId));
assertTrue(streamAppDesc.getInputDescriptors().containsKey(expandedStreamId));
assertEquals(expandedStreamId, inputOpSpec.getStreamId());
}
Aggregations