2121import org .apache .flink .configuration .Configuration ;
2222import org .apache .flink .table .api .DataTypes ;
2323import org .apache .flink .table .api .Schema ;
24+ import org .apache .flink .table .catalog .CatalogBaseTable ;
2425import org .apache .flink .table .catalog .CatalogDescriptor ;
2526import org .apache .flink .table .catalog .CatalogMaterializedTable ;
2627import org .apache .flink .table .catalog .CatalogMaterializedTable .LogicalRefreshMode ;
5354import static org .assertj .core .api .Assertions .assertThat ;
5455
5556/** Test {@link ShowCreateUtil}. */
56- public class ShowCreateUtilTest {
57+ class ShowCreateUtilTest {
5758 private static final ObjectIdentifier TABLE_IDENTIFIER =
5859 ObjectIdentifier .of ("catalogName" , "dbName" , "tableName" );
5960 private static final ObjectIdentifier VIEW_IDENTIFIER =
@@ -69,30 +70,38 @@ public class ShowCreateUtilTest {
6970 Column .physical ("id" , DataTypes .INT ()),
7071 Column .physical ("name" , DataTypes .STRING ()));
7172
72- @ ParameterizedTest (name = "{index}: {1 }" )
73+ @ ParameterizedTest (name = "{index}: {2 }" )
7374 @ MethodSource ("argsForShowCreateTable" )
74- void showCreateTable (ResolvedCatalogTable resolvedCatalogTable , String expected ) {
75+ void showCreateTable (
76+ ResolvedCatalogTable resolvedCatalogTable , boolean isTemporary , String expected ) {
7577 final String createTableString =
7678 ShowCreateUtil .buildShowCreateTableRow (
77- resolvedCatalogTable , TABLE_IDENTIFIER , false , DefaultSqlFactory .INSTANCE );
79+ resolvedCatalogTable ,
80+ TABLE_IDENTIFIER ,
81+ isTemporary ,
82+ DefaultSqlFactory .INSTANCE );
7883 assertThat (createTableString ).isEqualTo (expected );
7984 }
8085
81- @ ParameterizedTest (name = "{index}: {1 }" )
86+ @ ParameterizedTest (name = "{index}: {2 }" )
8287 @ MethodSource ("argsForShowCreateView" )
83- void showCreateView (ResolvedCatalogView resolvedCatalogView , String expected ) {
88+ void showCreateView (
89+ ResolvedCatalogView resolvedCatalogView , boolean isTemporary , String expected ) {
8490 final String createViewString =
85- ShowCreateUtil .buildShowCreateViewRow (resolvedCatalogView , VIEW_IDENTIFIER , false );
91+ ShowCreateUtil .buildShowCreateViewRow (
92+ resolvedCatalogView , VIEW_IDENTIFIER , isTemporary );
8693 assertThat (createViewString ).isEqualTo (expected );
8794 }
8895
89- @ ParameterizedTest (name = "{index}: {1 }" )
96+ @ ParameterizedTest (name = "{index}: {2 }" )
9097 @ MethodSource ("argsForShowCreateMaterializedTable" )
9198 void showCreateMaterializedTable (
92- ResolvedCatalogMaterializedTable materializedTable , String expected ) {
99+ ResolvedCatalogMaterializedTable materializedTable ,
100+ boolean isTemporary ,
101+ String expected ) {
93102 final String createMaterializedTableString =
94103 ShowCreateUtil .buildShowCreateMaterializedTableRow (
95- materializedTable , MATERIALIZED_TABLE_IDENTIFIER , false );
104+ materializedTable , MATERIALIZED_TABLE_IDENTIFIER , isTemporary );
96105 assertThat (createMaterializedTableString ).isEqualTo (expected );
97106 }
98107
@@ -137,168 +146,186 @@ private static Collection<Arguments> argsForShowCreateCatalog() {
137146 }
138147
139148 private static Collection <Arguments > argsForShowCreateView () {
140- Collection <Arguments > argList = new ArrayList <>();
141- argList . add (
142- Arguments . of (
143- createResolvedView (ONE_COLUMN_SCHEMA , "SELECT 1" , "SELECT 1" , null ),
144- "CREATE VIEW `catalogName`.`dbName`.`viewName` (\n "
145- + " `id`\n "
146- + ")\n "
147- + "AS SELECT 1\n " ) );
149+ final Collection <Arguments > argList = new ArrayList <>();
150+ addTemporaryAndPermanent (
151+ argList ,
152+ createResolvedView (ONE_COLUMN_SCHEMA , "SELECT 1" , "SELECT 1" , null ),
153+ "CREATE %sVIEW `catalogName`.`dbName`.`viewName` (\n "
154+ + " `id`\n "
155+ + ")\n "
156+ + "AS SELECT 1\n " );
148157
149- argList . add (
150- Arguments . of (
151- createResolvedView (
152- TWO_COLUMNS_SCHEMA ,
153- "SELECT id, name FROM tbl_a" ,
154- "SELECT id, name FROM `catalogName`.`dbName`.`tbl_a`" ,
155- "View comment" ),
156- "CREATE VIEW `catalogName`.`dbName`.`viewName` (\n "
157- + " `id`,\n "
158- + " `name`\n "
159- + ")\n "
160- + "COMMENT 'View comment'\n "
161- + "AS SELECT id, name FROM `catalogName`.`dbName`.`tbl_a`\n " ) );
158+ addTemporaryAndPermanent (
159+ argList ,
160+ createResolvedView (
161+ TWO_COLUMNS_SCHEMA ,
162+ "SELECT id, name FROM tbl_a" ,
163+ "SELECT id, name FROM `catalogName`.`dbName`.`tbl_a`" ,
164+ "View comment" ),
165+ "CREATE %sVIEW `catalogName`.`dbName`.`viewName` (\n "
166+ + " `id`,\n "
167+ + " `name`\n "
168+ + ")\n "
169+ + "COMMENT 'View comment'\n "
170+ + "AS SELECT id, name FROM `catalogName`.`dbName`.`tbl_a`\n " );
162171 return argList ;
163172 }
164173
165174 private static Collection <Arguments > argsForShowCreateTable () {
166- Collection <Arguments > argList = new ArrayList <>();
167- argList .add (
168- Arguments .of (
169- createResolvedTable (
170- ONE_COLUMN_SCHEMA ,
171- Collections .emptyMap (),
172- Collections .emptyList (),
173- TableDistribution .of (
174- TableDistribution .Kind .HASH ,
175- 2 ,
176- Arrays .asList ("key1" , "key2" )),
177- null ),
178- "CREATE TABLE `catalogName`.`dbName`.`tableName` (\n "
179- + " `id` INT\n "
180- + ")\n "
181- + "DISTRIBUTED BY HASH(`key1`, `key2`) INTO 2 BUCKETS\n " ));
175+ final Collection <Arguments > argList = new ArrayList <>();
176+ addTemporaryAndPermanent (
177+ argList ,
178+ createResolvedTable (
179+ ONE_COLUMN_SCHEMA ,
180+ Collections .emptyMap (),
181+ Collections .emptyList (),
182+ TableDistribution .of (
183+ TableDistribution .Kind .HASH , 2 , Arrays .asList ("key1" , "key2" )),
184+ null ),
185+ "CREATE %sTABLE `catalogName`.`dbName`.`tableName` (\n "
186+ + " `id` INT\n "
187+ + ")\n "
188+ + "DISTRIBUTED BY HASH(`key1`, `key2`) INTO 2 BUCKETS\n " );
182189
183- argList . add (
184- Arguments . of (
185- createResolvedTable (
186- ONE_COLUMN_SCHEMA ,
187- Collections .emptyMap (),
188- Collections .emptyList (),
189- TableDistribution .of (
190- TableDistribution .Kind .RANGE , 2 , Arrays .asList ("1" , "10" )),
191- "Table comment" ),
192- "CREATE TABLE `catalogName`.`dbName`.`tableName` (\n "
193- + " `id` INT\n "
194- + ")\n "
195- + "COMMENT 'Table comment'\n "
196- + "DISTRIBUTED BY RANGE(`1`, `10`) INTO 2 BUCKETS\n " ) );
190+ addTemporaryAndPermanent (
191+ argList ,
192+ createResolvedTable (
193+ ONE_COLUMN_SCHEMA ,
194+ Collections .emptyMap (),
195+ Collections .emptyList (),
196+ TableDistribution .of (
197+ TableDistribution .Kind .RANGE , 2 , Arrays .asList ("1" , "10" )),
198+ "Table comment" ),
199+ "CREATE %sTABLE `catalogName`.`dbName`.`tableName` (\n "
200+ + " `id` INT\n "
201+ + ")\n "
202+ + "COMMENT 'Table comment'\n "
203+ + "DISTRIBUTED BY RANGE(`1`, `10`) INTO 2 BUCKETS\n " );
197204
198205 final Map <String , String > options = new HashMap <>();
199206 options .put ("option_key_a" , "option_value_a" );
200207 options .put ("option_key_b" , "option_value_b" );
201208 options .put ("option_key_c" , "option_value_c" );
202209
203- argList . add (
204- Arguments . of (
205- createResolvedTable (
206- TWO_COLUMNS_SCHEMA ,
207- options ,
208- Collections .emptyList (),
209- null ,
210- "Another table comment" ),
211- "CREATE TABLE `catalogName`.`dbName`.`tableName` (\n "
212- + " `id` INT,\n "
213- + " `name` VARCHAR(2147483647)\n "
214- + ")\n "
215- + "COMMENT 'Another table comment'\n "
216- + "WITH (\n "
217- + " 'option_key_a' = 'option_value_a',\n "
218- + " 'option_key_b' = 'option_value_b',\n "
219- + " 'option_key_c' = 'option_value_c'\n "
220- + ")\n " ) );
210+ addTemporaryAndPermanent (
211+ argList ,
212+ createResolvedTable (
213+ TWO_COLUMNS_SCHEMA ,
214+ options ,
215+ Collections .emptyList (),
216+ null ,
217+ "Another table comment" ),
218+ "CREATE %sTABLE `catalogName`.`dbName`.`tableName` (\n "
219+ + " `id` INT,\n "
220+ + " `name` VARCHAR(2147483647)\n "
221+ + ")\n "
222+ + "COMMENT 'Another table comment'\n "
223+ + "WITH (\n "
224+ + " 'option_key_a' = 'option_value_a',\n "
225+ + " 'option_key_b' = 'option_value_b',\n "
226+ + " 'option_key_c' = 'option_value_c'\n "
227+ + ")\n " );
221228
222- argList . add (
223- Arguments . of (
224- createResolvedTable (
225- ONE_COLUMN_SCHEMA ,
226- Collections .emptyMap (),
227- Arrays .asList ("key1" , "key2" ),
228- null ,
229- "comment" ),
230- "CREATE TABLE `catalogName`.`dbName`.`tableName` (\n "
231- + " `id` INT\n "
232- + ")\n "
233- + "COMMENT 'comment'\n "
234- + "PARTITIONED BY (`key1`, `key2`)\n " ) );
229+ addTemporaryAndPermanent (
230+ argList ,
231+ createResolvedTable (
232+ ONE_COLUMN_SCHEMA ,
233+ Collections .emptyMap (),
234+ Arrays .asList ("key1" , "key2" ),
235+ null ,
236+ "comment" ),
237+ "CREATE %sTABLE `catalogName`.`dbName`.`tableName` (\n "
238+ + " `id` INT\n "
239+ + ")\n "
240+ + "COMMENT 'comment'\n "
241+ + "PARTITIONED BY (`key1`, `key2`)\n " );
235242
236- argList .add (
237- Arguments .of (
238- createResolvedTable (
239- TWO_COLUMNS_SCHEMA ,
240- options ,
241- Arrays .asList ("key1" , "key2" ),
242- TableDistribution .of (
243- TableDistribution .Kind .UNKNOWN ,
244- 3 ,
245- Arrays .asList ("1" , "2" , "3" )),
246- "table comment" ),
247- "CREATE TABLE `catalogName`.`dbName`.`tableName` (\n "
248- + " `id` INT,\n "
249- + " `name` VARCHAR(2147483647)\n "
250- + ")\n "
251- + "COMMENT 'table comment'\n "
252- + "DISTRIBUTED BY (`1`, `2`, `3`) INTO 3 BUCKETS\n "
253- + "PARTITIONED BY (`key1`, `key2`)\n "
254- + "WITH (\n "
255- + " 'option_key_a' = 'option_value_a',\n "
256- + " 'option_key_b' = 'option_value_b',\n "
257- + " 'option_key_c' = 'option_value_c'\n "
258- + ")\n " ));
243+ addTemporaryAndPermanent (
244+ argList ,
245+ createResolvedTable (
246+ TWO_COLUMNS_SCHEMA ,
247+ options ,
248+ Arrays .asList ("key1" , "key2" ),
249+ TableDistribution .of (
250+ TableDistribution .Kind .UNKNOWN , 3 , Arrays .asList ("1" , "2" , "3" )),
251+ "table comment" ),
252+ "CREATE %sTABLE `catalogName`.`dbName`.`tableName` (\n "
253+ + " `id` INT,\n "
254+ + " `name` VARCHAR(2147483647)\n "
255+ + ")\n "
256+ + "COMMENT 'table comment'\n "
257+ + "DISTRIBUTED BY (`1`, `2`, `3`) INTO 3 BUCKETS\n "
258+ + "PARTITIONED BY (`key1`, `key2`)\n "
259+ + "WITH (\n "
260+ + " 'option_key_a' = 'option_value_a',\n "
261+ + " 'option_key_b' = 'option_value_b',\n "
262+ + " 'option_key_c' = 'option_value_c'\n "
263+ + ")\n " );
259264 return argList ;
260265 }
261266
262267 private static Collection <Arguments > argsForShowCreateMaterializedTable () {
263- Collection <Arguments > argList = new ArrayList <>();
264- argList . add (
265- Arguments . of (
266- createResolvedMaterialized (
267- ONE_COLUMN_SCHEMA ,
268- null ,
269- List .of (),
270- IntervalFreshness .ofMinute ("1" ),
271- RefreshMode .CONTINUOUS ,
272- "SELECT 1" ),
273- "CREATE MATERIALIZED TABLE `catalogName`.`dbName`.`materializedTableName` (\n "
274- + " `id` INT\n "
275- + ")\n "
276- + "FRESHNESS = INTERVAL '1' MINUTE\n "
277- + "REFRESH_MODE = CONTINUOUS\n "
278- + "AS SELECT 1\n " ) );
268+ final Collection <Arguments > argList = new ArrayList <>();
269+ addTemporaryAndPermanent (
270+ argList ,
271+ createResolvedMaterialized (
272+ ONE_COLUMN_SCHEMA ,
273+ null ,
274+ List .of (),
275+ IntervalFreshness .ofMinute ("1" ),
276+ RefreshMode .CONTINUOUS ,
277+ "SELECT 1" ),
278+ "CREATE %sMATERIALIZED TABLE `catalogName`.`dbName`.`materializedTableName` (\n "
279+ + " `id` INT\n "
280+ + ")\n "
281+ + "FRESHNESS = INTERVAL '1' MINUTE\n "
282+ + "REFRESH_MODE = CONTINUOUS\n "
283+ + "AS SELECT 1\n " );
279284
280- argList .add (
281- Arguments .of (
282- createResolvedMaterialized (
283- TWO_COLUMNS_SCHEMA ,
284- "Materialized table comment" ,
285- List .of ("id" ),
286- IntervalFreshness .ofMinute ("3" ),
287- RefreshMode .FULL ,
288- "SELECT id, name FROM tbl_a" ),
289- "CREATE MATERIALIZED TABLE `catalogName`.`dbName`.`materializedTableName` (\n "
290- + " `id` INT,\n "
291- + " `name` VARCHAR(2147483647)\n "
292- + ")\n "
293- + "COMMENT 'Materialized table comment'\n "
294- + "PARTITION BY (`id`)\n "
295- + "FRESHNESS = INTERVAL '3' MINUTE\n "
296- + "REFRESH_MODE = FULL\n "
297- + "AS SELECT id, name FROM tbl_a\n " ));
285+ addTemporaryAndPermanent (
286+ argList ,
287+ createResolvedMaterialized (
288+ ONE_COLUMN_SCHEMA ,
289+ null ,
290+ List .of (),
291+ IntervalFreshness .ofMinute ("1" ),
292+ RefreshMode .CONTINUOUS ,
293+ "SELECT 1" ),
294+ "CREATE %sMATERIALIZED TABLE `catalogName`.`dbName`.`materializedTableName` (\n "
295+ + " `id` INT\n "
296+ + ")\n "
297+ + "FRESHNESS = INTERVAL '1' MINUTE\n "
298+ + "REFRESH_MODE = CONTINUOUS\n "
299+ + "AS SELECT 1\n " );
300+
301+ addTemporaryAndPermanent (
302+ argList ,
303+ createResolvedMaterialized (
304+ TWO_COLUMNS_SCHEMA ,
305+ "Materialized table comment" ,
306+ List .of ("id" ),
307+ IntervalFreshness .ofMinute ("3" ),
308+ RefreshMode .FULL ,
309+ "SELECT id, name FROM tbl_a" ),
310+ "CREATE %sMATERIALIZED TABLE `catalogName`.`dbName`.`materializedTableName` (\n "
311+ + " `id` INT,\n "
312+ + " `name` VARCHAR(2147483647)\n "
313+ + ")\n "
314+ + "COMMENT 'Materialized table comment'\n "
315+ + "PARTITION BY (`id`)\n "
316+ + "FRESHNESS = INTERVAL '3' MINUTE\n "
317+ + "REFRESH_MODE = FULL\n "
318+ + "AS SELECT id, name FROM tbl_a\n " );
298319
299320 return argList ;
300321 }
301322
323+ private static void addTemporaryAndPermanent (
324+ Collection <Arguments > argList , CatalogBaseTable catalogBaseTable , String sql ) {
325+ argList .add (Arguments .of (catalogBaseTable , false , String .format (sql , "" )));
326+ argList .add (Arguments .of (catalogBaseTable , true , String .format (sql , "TEMPORARY " )));
327+ }
328+
302329 private static ResolvedCatalogTable createResolvedTable (
303330 ResolvedSchema resolvedSchema ,
304331 Map <String , String > options ,
0 commit comments