Skip to content

Commit 004e86d

Browse files
author
lexluo
committed
[enhancement] global operation persist (apache#16973)
1 parent 48c44ff commit 004e86d

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/persist/meta/MetaPersistMethod.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ public static MetaPersistMethod create(String name) throws NoSuchMethodException
203203
metaPersistMethod.writeMethod = Env.class.getDeclaredMethod("saveMTMVJobManager",
204204
CountingDataOutputStream.class, long.class);
205205
break;
206-
// case "globalFunction":
207-
// metaPersistMethod.readMethod = Env.class.getDeclaredMethod("loadGlobalFunction", DataInputStream.class,
208-
// long.class);
209-
// metaPersistMethod.writeMethod = Env.class.getDeclaredMethod("saveGlobalFunction",
210-
// CountingDataOutputStream.class, long.class);
211-
// break;
206+
case "globalFunction":
207+
metaPersistMethod.readMethod = Env.class.getDeclaredMethod("loadGlobalFunction", DataInputStream.class,
208+
long.class);
209+
metaPersistMethod.writeMethod = Env.class.getDeclaredMethod("saveGlobalFunction",
210+
CountingDataOutputStream.class, long.class);
211+
break;
212212
default:
213213
break;
214214
}

‎fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ public void test() throws Exception {
8686
Assert.assertNotNull(db);
8787

8888
// create alias function
89-
String createFuncStr = "create alias function db1.id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));";
90-
CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx);
89+
String createFuncStr
90+
= "create alias function db1.id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));";
91+
CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr,
92+
ctx);
9193
Env.getCurrentEnv().createFunction(createFunctionStmt);
9294

9395
List<Function> functions = db.getFunctions();
@@ -202,7 +204,7 @@ public void test() throws Exception {
202204
public void testCreateGlobalFunction() throws Exception {
203205
ConnectContext ctx = UtFrameUtils.createDefaultCtx();
204206

205-
//1. create database db1、db2
207+
// 1. create database db1、db2
206208
createDatabase(ctx, "create database db1;");
207209
createDatabase(ctx, "create database db2;");
208210

@@ -218,11 +220,12 @@ public void testCreateGlobalFunction() throws Exception {
218220
Database db = Env.getCurrentInternalCatalog().getDbNullable("default_cluster:db1");
219221
Assert.assertNotNull(db);
220222

221-
//2. create global function
223+
// 2. create global function
222224

223225
String createFuncStr
224226
= "create global alias function id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));";
225-
CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx);
227+
CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr,
228+
ctx);
226229
Env.getCurrentEnv().createFunction(createFunctionStmt);
227230

228231
List<Function> functions = Env.getCurrentEnv().getGlobalFunctionMgr().getFunctions();
@@ -235,7 +238,7 @@ public void testCreateGlobalFunction() throws Exception {
235238
Assert.assertTrue(
236239
dorisAssert.query(queryStr).explainQuery().contains("concat(left(`k1`, 3), '****', right(`k1`, 4))"));
237240

238-
//4. create alias function with cast
241+
// 4. create alias function with cast
239242
// cast any type to decimal with specific precision and scale
240243
createFuncStr = "create global alias function decimal(all, int, int) with parameter(col, precision, scale)"
241244
+ " as cast(col as decimal(precision, scale));";
@@ -255,7 +258,7 @@ public void testCreateGlobalFunction() throws Exception {
255258
Assert.assertTrue(dorisAssert.query(queryStr).explainQuery().contains("CAST(`k3` AS DECIMAL(4,1))"));
256259
}
257260

258-
//5. cast any type to varchar with fixed length
261+
// 5. cast any type to varchar with fixed length
259262
createFuncStr = "create global alias function db1.varchar(all, int) with parameter(text, length) as "
260263
+ "cast(text as varchar(length));";
261264
createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx);
@@ -270,7 +273,7 @@ public void testCreateGlobalFunction() throws Exception {
270273
queryStr = "select varchar(k1, 4) from db1.tbl1;";
271274
Assert.assertTrue(dorisAssert.query(queryStr).explainQuery().contains("CAST(`k1` AS CHARACTER)"));
272275

273-
//6. cast any type to char with fixed length
276+
// 6. cast any type to char with fixed length
274277
createFuncStr = "create global alias function db1.char(all, int) with parameter(text, length) as "
275278
+ "cast(text as char(length));";
276279
createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx);
@@ -287,12 +290,11 @@ public void testCreateGlobalFunction() throws Exception {
287290
}
288291

289292

290-
291293
@Test
292294
public void testGlobalFunctionPersist() throws Exception {
293295
ConnectContext ctx = UtFrameUtils.createDefaultCtx();
294296

295-
//1. create database db1、db2
297+
// 1. create database db1、db2
296298
createDatabase(ctx, "create database db1;");
297299

298300
createTable("create table db1.tbl1(k1 int, k2 bigint, k3 varchar(10), k4 char(5)) duplicate key(k1) "
@@ -304,16 +306,17 @@ public void testGlobalFunctionPersist() throws Exception {
304306
Database db = Env.getCurrentInternalCatalog().getDbNullable("default_cluster:db1");
305307
Assert.assertNotNull(db);
306308

307-
//2. create global function
309+
// 2. create global function
308310
String createFuncStr
309311
= "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);
312+
CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr,
313+
ctx);
311314
Env.getCurrentEnv().createFunction(createFunctionStmt);
312315

313316
List<Function> functions = Env.getCurrentEnv().getGlobalFunctionMgr().getFunctions();
314317
Assert.assertEquals(1, functions.size());
315318

316-
//3. validate persist
319+
// 3. validate persist
317320
String imageDir = ctx.getEnv().getImageDir();
318321
ctx.getEnv().saveImage();
319322
ctx.getEnv().loadImage(imageDir);

0 commit comments

Comments
 (0)