3838public class RoutineTest {
3939
4040 private static final RoutineId ROUTINE_ID = RoutineId .of ("dataset" , "routine" );
41+ private static final RoutineId ROUTINE_ID_TVF = RoutineId .of ("dataset" , "tvf_routine" );
4142 private static final String DETERMINISM_LEVEL = "DETERMINISTIC" ;
4243 private static final String ETAG = "etag" ;
4344 private static final String ROUTINE_TYPE = "SCALAR_FUNCTION" ;
45+ private static final String ROUTINE_TYPE_TVF = "TABLE_VALUED_FUNCTION" ;
4446 private static final Long CREATION_TIME = 10L ;
4547 private static final Long LAST_MODIFIED_TIME = 20L ;
4648 private static final String LANGUAGE = "SQL" ;
@@ -56,6 +58,18 @@ public class RoutineTest {
5658 private static final StandardSQLDataType RETURN_TYPE =
5759 StandardSQLDataType .newBuilder ("FLOAT64" ).build ();
5860
61+ private static final StandardSQLField COLUMN_1 =
62+ StandardSQLField .newBuilder ("COLUMN_1" , StandardSQLDataType .newBuilder ("STRING" ).build ())
63+ .build ();
64+ private static final StandardSQLField COLUMN_2 =
65+ StandardSQLField .newBuilder ("COLUMN_2" , StandardSQLDataType .newBuilder ("FLOAT64" ).build ())
66+ .build ();
67+
68+ private static final List <StandardSQLField > COLUMN_LIST = ImmutableList .of (COLUMN_1 , COLUMN_2 );
69+
70+ private static final StandardSQLTableType RETURN_TABLE_TYPE =
71+ StandardSQLTableType .newBuilder (COLUMN_LIST ).build ();
72+
5973 private static final List <String > IMPORTED_LIBRARIES =
6074 ImmutableList .of ("gs://foo" , "gs://bar" , "gs://baz" );
6175
@@ -75,11 +89,19 @@ public class RoutineTest {
7589 .setBody (BODY )
7690 .build ();
7791
92+ private static final RoutineInfo ROUTINE_INFO_TVF =
93+ RoutineInfo .newBuilder (ROUTINE_ID_TVF )
94+ .setBody (BODY )
95+ .setRoutineType (ROUTINE_TYPE_TVF )
96+ .setReturnTableType (RETURN_TABLE_TYPE )
97+ .build ();
98+
7899 @ Rule public MockitoRule rule ;
79100
80101 private BigQuery bigquery ;
81102 private BigQueryOptions mockOptions ;
82103 private Routine expectedRoutine ;
104+ private Routine expectedRoutineTvf ;
83105 private Routine routine ;
84106
85107 @ Before
@@ -88,6 +110,7 @@ public void setUp() {
88110 mockOptions = mock (BigQueryOptions .class );
89111 when (bigquery .getOptions ()).thenReturn (mockOptions );
90112 expectedRoutine = new Routine (bigquery , new RoutineInfo .BuilderImpl (ROUTINE_INFO ));
113+ expectedRoutineTvf = new Routine (bigquery , new RoutineInfo .BuilderImpl (ROUTINE_INFO_TVF ));
91114 routine = new Routine (bigquery , new RoutineInfo .BuilderImpl (ROUTINE_INFO ));
92115 }
93116
@@ -114,6 +137,7 @@ public void testBuilder() {
114137 @ Test
115138 public void testToBuilder () {
116139 compareRoutineInfo (expectedRoutine , expectedRoutine .toBuilder ().build ());
140+ compareRoutineInfo (expectedRoutineTvf , expectedRoutineTvf .toBuilder ().build ());
117141 }
118142
119143 @ Test
@@ -200,6 +224,7 @@ public void compareRoutineInfo(RoutineInfo expected, RoutineInfo value) {
200224 assertEquals (expected .getLanguage (), value .getLanguage ());
201225 assertEquals (expected .getArguments (), value .getArguments ());
202226 assertEquals (expected .getReturnType (), value .getReturnType ());
227+ assertEquals (expected .getReturnTableType (), value .getReturnTableType ());
203228 assertEquals (expected .getImportedLibraries (), value .getImportedLibraries ());
204229 assertEquals (expected .getBody (), value .getBody ());
205230 assertEquals (expected .hashCode (), value .hashCode ());
0 commit comments