@@ -219,35 +219,16 @@ public void testCreateGlobalFunction() throws Exception {
219219 Assert .assertNotNull (db );
220220
221221 //2. create global function
222- String createFuncStr = "create global function my_add(VARCHAR(1024)) RETURNS BOOLEAN properties\n "
223- + "(\n "
224- + "\" symbol\" = \" _ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_9StringValE\" ,\n "
225- + "\" prepare_fn\" = \" _ZN9doris_udf13AddUdfPrepareEPNS_15FunctionContextENS0_18FunctionStateScopeE\" ,\n "
226- + "\" close_fn\" = \" _ZN9doris_udf11AddUdfCloseEPNS_15FunctionContextENS0_18FunctionStateScopeE\" ,\n "
227- + "\" object_file\" = \" http://127.0.0.1:8008/libcmy_udf.so\" \n "
228- + ");" ;
229-
230- CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt ) UtFrameUtils .parseAndAnalyzeStmt (createFuncStr ,
231- ctx );
232- Env .getCurrentEnv ().createFunction (createFunctionStmt );
233-
234- List <Function > functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
235- Assert .assertEquals (1 , functions .size ());
236- Assert .assertTrue (functions .get (0 ).isUdf ());
237-
238- String queryStr = "select my_add(null)" ;
239- testFunctionQuery (ctx , queryStr , false );
240222
241- //3. create alias function
242- createFuncStr
223+ String createFuncStr
243224 = "create global alias function id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));" ;
244- createFunctionStmt = (CreateFunctionStmt ) UtFrameUtils .parseAndAnalyzeStmt (createFuncStr , ctx );
225+ CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt ) UtFrameUtils .parseAndAnalyzeStmt (createFuncStr , ctx );
245226 Env .getCurrentEnv ().createFunction (createFunctionStmt );
246227
247- functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
248- Assert .assertEquals (2 , functions .size ());
228+ List < Function > functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
229+ Assert .assertEquals (1 , functions .size ());
249230
250- queryStr = "select id_masking(13888888888);" ;
231+ String queryStr = "select id_masking(13888888888);" ;
251232 testFunctionQuery (ctx , queryStr , false );
252233
253234 queryStr = "select id_masking(k1) from db1.tbl1" ;
@@ -262,7 +243,7 @@ public void testCreateGlobalFunction() throws Exception {
262243 Env .getCurrentEnv ().createFunction (createFunctionStmt );
263244
264245 functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
265- Assert .assertEquals (3 , functions .size ());
246+ Assert .assertEquals (2 , functions .size ());
266247
267248 queryStr = "select decimal(333, 4, 1);" ;
268249 testFunctionQuery (ctx , queryStr , true );
@@ -281,7 +262,7 @@ public void testCreateGlobalFunction() throws Exception {
281262 Env .getCurrentEnv ().createFunction (createFunctionStmt );
282263
283264 functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
284- Assert .assertEquals (4 , functions .size ());
265+ Assert .assertEquals (3 , functions .size ());
285266
286267 queryStr = "select varchar(333, 4);" ;
287268 testFunctionQuery (ctx , queryStr , true );
@@ -296,7 +277,7 @@ public void testCreateGlobalFunction() throws Exception {
296277 Env .getCurrentEnv ().createFunction (createFunctionStmt );
297278
298279 functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
299- Assert .assertEquals (5 , functions .size ());
280+ Assert .assertEquals (4 , functions .size ());
300281
301282 queryStr = "select char(333, 4);" ;
302283 testFunctionQuery (ctx , queryStr , true );
@@ -305,6 +286,44 @@ public void testCreateGlobalFunction() throws Exception {
305286 Assert .assertTrue (dorisAssert .query (queryStr ).explainQuery ().contains ("CAST(`k1` AS CHARACTER)" ));
306287 }
307288
289+
290+
291+ @ Test
292+ public void testGlobalFunctionPersist () throws Exception {
293+ ConnectContext ctx = UtFrameUtils .createDefaultCtx ();
294+
295+ //1. create database db1、db2
296+ createDatabase (ctx , "create database db1;" );
297+
298+ createTable ("create table db1.tbl1(k1 int, k2 bigint, k3 varchar(10), k4 char(5)) duplicate key(k1) "
299+ + "distributed by hash(k2) buckets 1 properties('replication_num' = '1');" );
300+
301+ dorisAssert = new DorisAssert ();
302+ dorisAssert .useDatabase ("db1" );
303+
304+ Database db = Env .getCurrentInternalCatalog ().getDbNullable ("default_cluster:db1" );
305+ Assert .assertNotNull (db );
306+
307+ //2. create global function
308+ String createFuncStr
309+ = "create global alias function id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));" ;
310+ CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt ) UtFrameUtils .parseAndAnalyzeStmt (createFuncStr , ctx );
311+ Env .getCurrentEnv ().createFunction (createFunctionStmt );
312+
313+ List <Function > functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
314+ Assert .assertEquals (1 , functions .size ());
315+
316+ //3. validate persist
317+ String imageDir = ctx .getEnv ().getImageDir ();
318+ ctx .getEnv ().saveImage ();
319+ ctx .getEnv ().loadImage (imageDir );
320+ functions = Env .getCurrentEnv ().getGlobalFunctionMgr ().getFunctions ();
321+ Assert .assertEquals (1 , functions .size ());
322+ File file = new File (imageDir );
323+ file .delete ();
324+ }
325+
326+
308327 private void testFunctionQuery (ConnectContext ctx , String queryStr , Boolean isStringLiteral ) throws Exception {
309328 ctx .getState ().reset ();
310329 StmtExecutor stmtExecutor = new StmtExecutor (ctx , queryStr );
0 commit comments