@@ -111,4 +111,108 @@ struct CatalogTests {
111
111
await spark. stop ( )
112
112
}
113
113
#endif
114
+
115
+ @Test
116
+ func cacheTable( ) async throws {
117
+ let spark = try await SparkSession . builder. getOrCreate ( )
118
+ let tableName = " TABLE_ " + UUID( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
119
+ try await SQLHelper . withTable ( spark, tableName) ( {
120
+ try await spark. range ( 1 ) . write. saveAsTable ( tableName)
121
+ try await spark. catalog. cacheTable ( tableName)
122
+ #expect( try await spark. catalog. isCached ( tableName) )
123
+ try await spark. catalog. cacheTable ( tableName, StorageLevel . MEMORY_ONLY)
124
+ } )
125
+
126
+ try await #require( throws: Error . self) {
127
+ try await spark. catalog. cacheTable ( " not_exist_table " )
128
+ }
129
+ await spark. stop ( )
130
+ }
131
+
132
+ @Test
133
+ func isCached( ) async throws {
134
+ let spark = try await SparkSession . builder. getOrCreate ( )
135
+ let tableName = " TABLE_ " + UUID( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
136
+ try await SQLHelper . withTable ( spark, tableName) ( {
137
+ try await spark. range ( 1 ) . write. saveAsTable ( tableName)
138
+ #expect( try await spark. catalog. isCached ( tableName) == false )
139
+ try await spark. catalog. cacheTable ( tableName)
140
+ #expect( try await spark. catalog. isCached ( tableName) )
141
+ } )
142
+
143
+ try await #require( throws: Error . self) {
144
+ try await spark. catalog. isCached ( " not_exist_table " )
145
+ }
146
+ await spark. stop ( )
147
+ }
148
+
149
+ @Test
150
+ func refreshTable( ) async throws {
151
+ let spark = try await SparkSession . builder. getOrCreate ( )
152
+ let tableName = " TABLE_ " + UUID( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
153
+ try await SQLHelper . withTable ( spark, tableName) ( {
154
+ try await spark. range ( 1 ) . write. saveAsTable ( tableName)
155
+ try await spark. catalog. refreshTable ( tableName)
156
+ #expect( try await spark. catalog. isCached ( tableName) == false )
157
+
158
+ try await spark. catalog. cacheTable ( tableName)
159
+ #expect( try await spark. catalog. isCached ( tableName) )
160
+ try await spark. catalog. refreshTable ( tableName)
161
+ #expect( try await spark. catalog. isCached ( tableName) )
162
+ } )
163
+
164
+ try await #require( throws: Error . self) {
165
+ try await spark. catalog. refreshTable ( " not_exist_table " )
166
+ }
167
+ await spark. stop ( )
168
+ }
169
+
170
+ @Test
171
+ func refreshByPath( ) async throws {
172
+ let spark = try await SparkSession . builder. getOrCreate ( )
173
+ let tableName = " TABLE_ " + UUID( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
174
+ try await SQLHelper . withTable ( spark, tableName) ( {
175
+ try await spark. range ( 1 ) . write. saveAsTable ( tableName)
176
+ try await spark. catalog. refreshByPath ( " / " )
177
+ #expect( try await spark. catalog. isCached ( tableName) == false )
178
+
179
+ try await spark. catalog. cacheTable ( tableName)
180
+ #expect( try await spark. catalog. isCached ( tableName) )
181
+ try await spark. catalog. refreshByPath ( " / " )
182
+ #expect( try await spark. catalog. isCached ( tableName) )
183
+ } )
184
+ await spark. stop ( )
185
+ }
186
+
187
+ @Test
188
+ func uncacheTable( ) async throws {
189
+ let spark = try await SparkSession . builder. getOrCreate ( )
190
+ let tableName = " TABLE_ " + UUID( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
191
+ try await SQLHelper . withTable ( spark, tableName) ( {
192
+ try await spark. range ( 1 ) . write. saveAsTable ( tableName)
193
+ try await spark. catalog. cacheTable ( tableName)
194
+ #expect( try await spark. catalog. isCached ( tableName) )
195
+ try await spark. catalog. uncacheTable ( tableName)
196
+ #expect( try await spark. catalog. isCached ( tableName) == false )
197
+ } )
198
+
199
+ try await #require( throws: Error . self) {
200
+ try await spark. catalog. uncacheTable ( " not_exist_table " )
201
+ }
202
+ await spark. stop ( )
203
+ }
204
+
205
+ @Test
206
+ func clearCache( ) async throws {
207
+ let spark = try await SparkSession . builder. getOrCreate ( )
208
+ let tableName = " TABLE_ " + UUID( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
209
+ try await SQLHelper . withTable ( spark, tableName) ( {
210
+ try await spark. range ( 1 ) . write. saveAsTable ( tableName)
211
+ try await spark. catalog. cacheTable ( tableName)
212
+ #expect( try await spark. catalog. isCached ( tableName) )
213
+ try await spark. catalog. clearCache ( )
214
+ #expect( try await spark. catalog. isCached ( tableName) == false )
215
+ } )
216
+ await spark. stop ( )
217
+ }
114
218
}
0 commit comments