@@ -55,6 +55,7 @@ public class SQLCursor implements FrameIterator {
5555 private ExecutorService exec2 = SQLJoinThreadPool .getThreadPool2 ();
5656 private ExecutorService remotepool = Executors .newCachedThreadPool ();
5757 private ExecutorService streampool = Executors .newCachedThreadPool ();
58+ private ExecutorService groupspool = Executors .newCachedThreadPool ();
5859 private List <FrameApiJoin > tasks ;
5960 private List <FrameApiJoin > tasks_ ;
6061 private FrameData bdnext ;
@@ -229,6 +230,7 @@ public void build() throws InternalException, IOException, ClassNotFoundExceptio
229230
230231 public void stream () throws Exception {
231232 final Queue <FrameApi > q = sfmap .get (lbi .getObjectId ());
233+ final Table gtable = Instance .getInstance ().getTableById (lbi .getObjectId ());
232234 if (!cur .isStream ()) {
233235 logger .error ("wrong stream method call: SQL statement is not a stream" );
234236 }
@@ -242,14 +244,27 @@ public void stream() throws Exception {
242244 Runnable r = new Runnable () {
243245 @ Override
244246 public void run () {
247+ Thread .currentThread ().setName ("Stream SQL thread " +Thread .currentThread ().getId ());
245248 try {
249+ final ConcurrentLinkedQueue <Object > q_in = new ConcurrentLinkedQueue <>();
250+ FrameGroupTask group = null ;
246251 while (((StreamQueue ) target ).isRunning ()) {
247252 FrameApi f = q .poll ();
248253 if (f != null ) {
249254 FrameJoinTask task = new FrameJoinTask (cur , f , null , target , rscols , nc , id , Config .getConfig ().LOCAL_NODE_ID , last , lbi .isLeftfs (), null , s );
250255 final Future <List <Object >> ft = exec .submit (task );
251- for (Object o : ft .get ()) {
252- target .persist (o , s );
256+ if (cur .getSqlStmt ().isGroupedResult ()) {
257+ if (group == null ) {
258+ group = new FrameGroupTask (cur , q_in , target , gtable , s );
259+ groupspool .submit (group );
260+ }
261+ for (Object o : ft .get ()) {
262+ q_in .add (o );
263+ }
264+ } else {
265+ for (Object o : ft .get ()) {
266+ target .persist (o , s );
267+ }
253268 }
254269 }
255270 if (q .peek () == null ) {
0 commit comments