@@ -717,6 +717,71 @@ abstract class SessionCatalogSuite extends AnalysisTest {
717717 }
718718 }
719719
720+ test(" list tables with pattern and includeLocalTempViews" ) {
721+ withEmptyCatalog { catalog =>
722+ catalog.createDatabase(newDb(" mydb" ), ignoreIfExists = false )
723+ catalog.createTable(newTable(" tbl1" , " mydb" ), ignoreIfExists = false )
724+ catalog.createTable(newTable(" tbl2" , " mydb" ), ignoreIfExists = false )
725+ val tempTable = Range (1 , 10 , 2 , 10 )
726+ catalog.createTempView(" temp_view1" , tempTable, overrideIfExists = false )
727+ catalog.createTempView(" temp_view4" , tempTable, overrideIfExists = false )
728+
729+ assert(catalog.listTables(" mydb" ).toSet == catalog.listTables(" mydb" , " *" ).toSet)
730+ assert(catalog.listTables(" mydb" ).toSet == catalog.listTables(" mydb" , " *" , true ).toSet)
731+ assert(catalog.listTables(" mydb" ).toSet ==
732+ catalog.listTables(" mydb" , " *" , false ).toSet ++ catalog.listLocalTempViews(" *" ))
733+ assert(catalog.listTables(" mydb" , " *" , true ).toSet ==
734+ Set (TableIdentifier (" tbl1" , Some (" mydb" )),
735+ TableIdentifier (" tbl2" , Some (" mydb" )),
736+ TableIdentifier (" temp_view1" ),
737+ TableIdentifier (" temp_view4" )))
738+ assert(catalog.listTables(" mydb" , " *" , false ).toSet ==
739+ Set (TableIdentifier (" tbl1" , Some (" mydb" )), TableIdentifier (" tbl2" , Some (" mydb" ))))
740+ assert(catalog.listTables(" mydb" , " tbl*" , true ).toSet ==
741+ Set (TableIdentifier (" tbl1" , Some (" mydb" )), TableIdentifier (" tbl2" , Some (" mydb" ))))
742+ assert(catalog.listTables(" mydb" , " tbl*" , false ).toSet ==
743+ Set (TableIdentifier (" tbl1" , Some (" mydb" )), TableIdentifier (" tbl2" , Some (" mydb" ))))
744+ assert(catalog.listTables(" mydb" , " temp_view*" , true ).toSet ==
745+ Set (TableIdentifier (" temp_view1" ), TableIdentifier (" temp_view4" )))
746+ assert(catalog.listTables(" mydb" , " temp_view*" , false ).toSet == Set .empty)
747+ }
748+ }
749+
750+ test(" list temporary view with pattern" ) {
751+ withBasicCatalog { catalog =>
752+ val tempTable = Range (1 , 10 , 2 , 10 )
753+ catalog.createTempView(" temp_view1" , tempTable, overrideIfExists = false )
754+ catalog.createTempView(" temp_view4" , tempTable, overrideIfExists = false )
755+ assert(catalog.listLocalTempViews(" *" ).toSet ==
756+ Set (TableIdentifier (" temp_view1" ), TableIdentifier (" temp_view4" )))
757+ assert(catalog.listLocalTempViews(" temp_view*" ).toSet ==
758+ Set (TableIdentifier (" temp_view1" ), TableIdentifier (" temp_view4" )))
759+ assert(catalog.listLocalTempViews(" *1" ).toSet == Set (TableIdentifier (" temp_view1" )))
760+ assert(catalog.listLocalTempViews(" does_not_exist" ).toSet == Set .empty)
761+ }
762+ }
763+
764+ test(" list global temporary view and local temporary view with pattern" ) {
765+ withBasicCatalog { catalog =>
766+ val tempTable = Range (1 , 10 , 2 , 10 )
767+ catalog.createTempView(" temp_view1" , tempTable, overrideIfExists = false )
768+ catalog.createTempView(" temp_view4" , tempTable, overrideIfExists = false )
769+ catalog.globalTempViewManager.create(" global_temp_view1" , tempTable, overrideIfExists = false )
770+ catalog.globalTempViewManager.create(" global_temp_view2" , tempTable, overrideIfExists = false )
771+ assert(catalog.listTables(catalog.globalTempViewManager.database, " *" ).toSet ==
772+ Set (TableIdentifier (" temp_view1" ),
773+ TableIdentifier (" temp_view4" ),
774+ TableIdentifier (" global_temp_view1" , Some (catalog.globalTempViewManager.database)),
775+ TableIdentifier (" global_temp_view2" , Some (catalog.globalTempViewManager.database))))
776+ assert(catalog.listTables(catalog.globalTempViewManager.database, " *temp_view1" ).toSet ==
777+ Set (TableIdentifier (" temp_view1" ),
778+ TableIdentifier (" global_temp_view1" , Some (catalog.globalTempViewManager.database))))
779+ assert(catalog.listTables(catalog.globalTempViewManager.database, " global*" ).toSet ==
780+ Set (TableIdentifier (" global_temp_view1" , Some (catalog.globalTempViewManager.database)),
781+ TableIdentifier (" global_temp_view2" , Some (catalog.globalTempViewManager.database))))
782+ }
783+ }
784+
720785 // --------------------------------------------------------------------------
721786 // Partitions
722787 // --------------------------------------------------------------------------
0 commit comments