b-slim commented on a change in pull request #1386: URL: https://github.com/apache/samza/pull/1386#discussion_r444587569
########## File path: samza-sql/src/main/java/org/apache/samza/sql/translator/MessageStreamCollector.java ########## @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.samza.sql.translator; + +import java.io.Closeable; +import java.io.Serializable; +import java.time.Duration; +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Deque; +import java.util.function.Function; +import org.apache.samza.context.Context; +import org.apache.samza.operators.KV; +import org.apache.samza.operators.MessageStream; +import org.apache.samza.operators.OutputStream; +import org.apache.samza.operators.functions.AsyncFlatMapFunction; +import org.apache.samza.operators.functions.ClosableFunction; +import org.apache.samza.operators.functions.FilterFunction; +import org.apache.samza.operators.functions.FlatMapFunction; +import org.apache.samza.operators.functions.JoinFunction; +import org.apache.samza.operators.functions.MapFunction; +import org.apache.samza.operators.functions.SinkFunction; +import org.apache.samza.operators.functions.StreamTableJoinFunction; +import org.apache.samza.operators.windows.Window; +import org.apache.samza.operators.windows.WindowPane; +import org.apache.samza.serializers.KVSerde; +import org.apache.samza.serializers.Serde; +import org.apache.samza.sql.data.SamzaSqlRelMessage; +import org.apache.samza.table.Table; + + +/** + * Collector of Map and Filter Samza Function, used to collect current call stack and trigger it when applying the join function. + * + * @TODO This class is a work around here to minimize the amount of code changes, but in an ideal world, + * @TODO where we use Calcite planner in conventional way we can combine function when via translation of RelNodes. + */ +class MessageStreamCollector implements MessageStream<SamzaSqlRelMessage>, Serializable, Closeable { + + private final Deque<MapFunction<? super SamzaSqlRelMessage, ? extends SamzaSqlRelMessage>> _mapFnCallQueue = + new ArrayDeque<>(); + private final Deque<ClosableFunction> _closingStack = new ArrayDeque<>(); + + @Override + public <OM> MessageStream<OM> map(MapFunction<? super SamzaSqlRelMessage, ? extends OM> mapFn) { + _mapFnCallQueue.offer((MapFunction<? super SamzaSqlRelMessage, ? extends SamzaSqlRelMessage>) mapFn); + return (MessageStream<OM>) this; + } + + @Override + public MessageStream<SamzaSqlRelMessage> filter(FilterFunction<? super SamzaSqlRelMessage> filterFn) { + _mapFnCallQueue.offer(new FilterMapAdapter(filterFn)); + return this; + } + + Function<SamzaSqlRelMessage, SamzaSqlRelMessage> getFunction(Context context) { + Function<SamzaSqlRelMessage, SamzaSqlRelMessage> tailFn = null; + while (!_mapFnCallQueue.isEmpty()) { Review comment: @srinipunuru added comments at the top of the class let me know if this still unclear. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
