3232import net .hydromatic .sqllogictest .TestStatistics ;
3333import net .hydromatic .sqllogictest .executors .SqlSltTestExecutor ;
3434import org .dbsp .sqlCompiler .circuit .DBSPCircuit ;
35+ import org .dbsp .sqlCompiler .circuit .operator .DBSPSinkOperator ;
3536import org .dbsp .sqlCompiler .compiler .CompilerOptions ;
3637import org .dbsp .sqlCompiler .compiler .DBSPCompiler ;
3738import org .dbsp .sqlCompiler .compiler .backend .rust .RustFileWriter ;
@@ -288,20 +289,28 @@ ProgramAndTester generateTestCase(
288289 }
289290 compiler .compileStatement (dbspQuery );
290291 compiler .throwIfErrorsOccurred ();
291- DBSPCircuit dbsp = compiler .getFinalCircuit (false );
292+ DBSPCircuit circuit = compiler .getFinalCircuit (false );
293+ circuit .setName ("circuit" + suffix );
292294 DBSPNode .done ();
293295
294- if (dbsp .getOutputCount () != 1 )
295- throw new RuntimeException (
296- "Didn't expect a query to have " + dbsp .getOutputCount () + " outputs" );
297- DBSPTypeZSet outputType = dbsp .getSingleOutputType ().to (DBSPTypeZSet .class );
296+ List <DBSPSinkOperator > sinks = Linq .list (circuit .sinkOperators .values ());
297+ int outputNumber = 0 ;
298+ DBSPSinkOperator sink = null ;
299+ for (; outputNumber < circuit .getOutputCount (); outputNumber ++) {
300+ sink = sinks .get (outputNumber );
301+ // Skip over system views if we are not checking these
302+ if (!sink .metadata .system )
303+ break ;
304+ }
305+ assert sink != null ;
306+ DBSPTypeZSet outputType = sink .outputType .to (DBSPTypeZSet .class );
298307 DBSPZSetLiteral expectedOutput = null ;
299308 if (testQuery .outputDescription .hash == null ) {
300309 expectedOutput = DBSPExecutor .convert (testQuery .outputDescription .getQueryResults (), outputType );
301310 }
302311
303312 return createTesterCode (
304- "tester" + suffix , dbsp ,
313+ "tester" + suffix , circuit , outputNumber ,
305314 gen .getInputFunction (),
306315 compiler .getTableContents (),
307316 expectedOutput , testQuery .outputDescription );
@@ -410,12 +419,14 @@ public TestStatistics execute(SltTestFile file, OptionsParser.SuppliedOptions op
410419 * @param circuit DBSP circuit that will be tested.
411420 * @param output Expected data from the circuit.
412421 * @param description Description of the expected outputs.
422+ * @param outputNumber Position of data output in output vector.
413423 * @return The code for a function that runs the circuit with the specified
414424 * input and tests the produced output.
415425 */
416426 static ProgramAndTester createTesterCode (
417427 String name ,
418428 DBSPCircuit circuit ,
429+ int outputNumber ,
419430 DBSPFunction inputGeneratingFunction ,
420431 TableContents contents ,
421432 @ Nullable DBSPZSetLiteral output ,
@@ -430,7 +441,9 @@ static ProgramAndTester createTesterCode(
430441 DBSPLetStatement streams = new DBSPLetStatement ("streams" , cas .getVarReference ().field (1 ));
431442 list .add (streams );
432443
433- DBSPType circuitOutputType = circuit .getSingleOutputType ();
444+ List <DBSPSinkOperator > sinks = Linq .list (circuit .sinkOperators .values ());
445+ DBSPSinkOperator sink = sinks .get (outputNumber );
446+ DBSPType circuitOutputType = sink .outputType ;
434447 // True if the output is a zset of vectors (generated for order by queries)
435448 boolean isVector = circuitOutputType .to (DBSPTypeZSet .class ).elementType .is (DBSPTypeVec .class );
436449
@@ -455,7 +468,7 @@ static ProgramAndTester createTesterCode(
455468 DBSPLetStatement outputStatement =
456469 new DBSPLetStatement ("out" ,
457470 new DBSPApplyExpression ("read_output_handle" , DBSPTypeAny .getDefault (),
458- streams .getVarReference ().field (circuit .getInputTables ().size ()).borrow ()));
471+ streams .getVarReference ().field (circuit .getInputTables ().size () + outputNumber ).borrow ()));
459472 list .add (outputStatement );
460473 DBSPExpression sort = new DBSPEnumValue ("SortOrder" , description .getOrder ().toString ());
461474
0 commit comments