Skip to content

Commit cabc2cc

Browse files
author
hongwei.quhw
committed
kvSplit 配置化
1 parent d1fb813 commit cabc2cc

File tree

13 files changed

+267
-87
lines changed

13 files changed

+267
-87
lines changed

rdf-file-core/src/main/java/com/alipay/rdf/file/loader/TemplateLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ public static FileMeta load(String templatePath, String templateEncoding) {
209209
fileMeta.setRowCodecMode(templateConfig.getRowCodecMode());
210210
}
211211

212+
// 参数
213+
fileMeta.setParams(templateConfig.getParams());
214+
212215
CACHE.put(templatePath, fileMeta);
213216

214217
return fileMeta;

rdf-file-core/src/main/java/com/alipay/rdf/file/meta/FileMeta.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class FileMeta {
5959
private Boolean relationReadRowCompatibility;
6060
/**行序列化反序列化模式: 默认关系模式*/
6161
private String rowCodecMode = "relation";
62+
/**非通用参数,用于传递给插件*/
63+
private Map<String, String> params = new HashMap<String, String>();
6264

6365
public boolean isStartWithSplit(FileDataTypeEnum rowType) {
6466
Boolean startSplit = startWithSplit.get(rowType);
@@ -416,6 +418,14 @@ public void setRowCodecMode(String rowCodecMode) {
416418
this.rowCodecMode = rowCodecMode;
417419
}
418420

421+
public Map<String, String> getParams() {
422+
return params;
423+
}
424+
425+
public void setParams(Map<String, String> params) {
426+
this.params = params;
427+
}
428+
419429
@Override
420430
public String toString() {
421431
StringBuffer sb = new StringBuffer("FileMeta[");

rdf-file-core/src/main/java/com/alipay/rdf/file/meta/TemplateConfig.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.alipay.rdf.file.meta;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.List;
6+
import java.util.Map;
57

68
/**
79
* Copyright (C) 2013-2018 Ant Financial Services Group
@@ -44,6 +46,8 @@ public class TemplateConfig {
4446
private Boolean relationReadRowCompatibility;
4547
/**行序列化反序列化模式*/
4648
private String rowCodecMode;
49+
/**非通用参数,用于传递给插件*/
50+
private Map<String, String> params = new HashMap<String, String>();
4751

4852
public String getProtocol() {
4953
return protocol;
@@ -172,4 +176,12 @@ public String getRowCodecMode() {
172176
public void setRowCodecMode(String rowCodecMode) {
173177
this.rowCodecMode = rowCodecMode;
174178
}
179+
180+
public Map<String, String> getParams() {
181+
return params;
182+
}
183+
184+
public void setParams(Map<String, String> params) {
185+
this.params = params;
186+
}
175187
}

rdf-file-core/src/main/java/com/alipay/rdf/file/util/RdfFileUtil.java

Lines changed: 83 additions & 76 deletions
Large diffs are not rendered by default.

rdf-file-core/src/test/java/com/alipay/rdf/file/codec/RowNosqlKVCodecWriterTest.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,87 @@ public void test3() throws Exception {
308308
fileReader.close();
309309
}
310310

311+
@Test
312+
public void testKVSplit() throws Exception{
313+
String filePath = tf.getRoot().getAbsolutePath();
314+
FileConfig config = new FileConfig(new File(filePath, "test.txt").getAbsolutePath(),
315+
"/codec/kv/template/template6.json", new StorageConfig("nas"));
316+
317+
FileWriter fileWriter = FileFactory.createWriter(config);
318+
319+
Map<String, Object> head = new HashMap<String, Object>();
320+
head.put("totalCount", 2);
321+
head.put("totalAmount", new BigDecimal("23.22"));
322+
fileWriter.writeHead(head);
323+
324+
Map<String, Object> body = new HashMap<String, Object>();
325+
326+
Date testDate = DateUtil.parse("2017-01-03 12:22:33", "yyyy-MM-dd HH:mm:ss");
327+
328+
body.put("seq", "");
329+
body.put("instSeq", "303");
330+
body.put("gmtApply", testDate);
331+
body.put("date", testDate);
332+
body.put("dateTime", testDate);
333+
body.put("applyNumber", 12);
334+
body.put("amount", new BigDecimal("1.22"));
335+
body.put("age", new Integer(33));
336+
body.put("longN", new Long(33));
337+
body.put("bol", null);
338+
body.put("memo", " ");
339+
fileWriter.writeRow(body);
340+
341+
testDate = DateUtil.parse("2016-02-03 12:22:33", "yyyy-MM-dd HH:mm:ss");
342+
343+
body = new HashMap<String, Object>();
344+
body.put("seq", "seq234568");
345+
body.put("instSeq", "505");
346+
body.put("gmtApply", testDate);
347+
//body.put("date", testDate);
348+
body.put("dateTime", testDate);
349+
//body.put("applyNumber", 12);
350+
body.put("amount", new BigDecimal("1.09"));
351+
body.put("age", 66);
352+
body.put("longN", 125);
353+
//body.put("bol", false);
354+
//body.put("memo", "memo2");
355+
fileWriter.writeRow(body);
356+
357+
fileWriter.writeTail(new HashMap<String, Object>());
358+
359+
fileWriter.close();
360+
361+
//校验文件
362+
BufferedReader reader = new BufferedReader(
363+
new InputStreamReader(new FileInputStream(new File(config.getFilePath())), "UTF-8"));
364+
Assert.assertEquals("|totalCount_@_2|totalAmount_@_23.22", reader.readLine());
365+
Assert.assertEquals(
366+
"|seq_@_|instSeq_@_303|gmtApply_@_2017-01-03 12:22:33|date_@_20170103|dateTime_@_20170103 12:22:33|applyNumber_@_12|amount_@_1.22|age_@_33|longN_@_33|memo_@_|",
367+
reader.readLine());
368+
369+
Assert.assertEquals(
370+
"|seq_@_seq234568|instSeq_@_505|gmtApply_@_2016-02-03 12:22:33|dateTime_@_20160203 12:22:33|amount_@_1.09|age_@_66|longN_@_125|",
371+
reader.readLine());
372+
373+
Assert.assertEquals("|fileEnd_@_OFDCFEND|",reader.readLine());
374+
375+
Assert.assertNull(reader.readLine());
376+
reader.close();
377+
378+
FileReader fileReader = FileFactory.createReader(config);
379+
head = fileReader.readHead(HashMap.class);
380+
Assert.assertEquals(2L, head.get("totalCount"));
381+
382+
body = fileReader.readRow(HashMap.class);
383+
Assert.assertNull(body.get("seq"));
384+
Assert.assertEquals("303", body.get("instSeq"));
385+
Assert.assertNull(body.get("memo"));
386+
387+
Map<String, Object> tail = fileReader.readTail(HashMap.class);
388+
Assert.assertEquals("OFDCFEND", tail.get("fileEnd"));
389+
fileReader.close();
390+
}
391+
311392
@After
312393
public void after() {
313394
tf.delete();

rdf-file-core/src/test/java/com/alipay/rdf/file/meta/TemplateLoaderTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/**
1717
* 模板加载测试
18-
*
18+
*
1919
* @author hongwei.quhw
2020
* @version $Id: TemplateLoaderTest.java, v 0.1 2016-12-22 下午2:01:39 hongwei.quhw Exp $
2121
*/
@@ -186,4 +186,13 @@ public void testSummary_condition() {
186186

187187
TemplateLoader.load("/meta/template9.json", "UTF-8");
188188
}
189+
190+
@Test
191+
public void testParam() {
192+
FileMeta fileMeta = TemplateLoader.load("/meta/template10.json", "UTF-8");
193+
Assert.assertEquals(2, fileMeta.getParams().size());
194+
Assert.assertEquals("v1", fileMeta.getParams().get("k1"));
195+
Assert.assertEquals("v2", fileMeta.getParams().get("k2"));
196+
}
197+
189198
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"head":[
3+
"totalCount|总笔数|Required|Long",
4+
"totalAmount|总金额|BigDecimal|Required"
5+
],
6+
"body":[
7+
"seq|流水号",
8+
"instSeq|基金公司订单号|Required",
9+
"gmtApply|订单申请时间|Date:yyyy-MM-dd HH:mm:ss",
10+
"date|普通日期|Date:yyyyMMdd",
11+
"dateTime|普通日期时间|Date:yyyyMMdd HH:mm:ss",
12+
"applyNumber|普通数字|Integer",
13+
"addcolumn1|多余字段1",
14+
"amount|金额|BigDecimal",
15+
"age|年龄|Integer",
16+
"longN|长整型|Long",
17+
"bol|布尔值|Boolean",
18+
"memo|备注",
19+
"addcolumn2|多余字段2"
20+
],
21+
"tail":["fileEnd|数据文件尾部字符|default:OFDCFEND|[8,0]"],
22+
"rowCodecMode":"kv",
23+
"protocol":"sp",
24+
"startWithSplit": "head|body|tail",
25+
"endWithSplit": "body|tail",
26+
"params": {
27+
"rowCodecKVSplit":"_@_"
28+
}
29+
}

rdf-file-core/src/test/resources/meta/de-gbk.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"mfundAccountNo|货币基金份额账户|BigDecimal",
1010
"date|日期类型|Date:yyyy-MM-dd HH:mm:ss",
1111
"count|金额|BigDecimal|[10,2]",
12-
"name|姓名|REQUIRED|DEFAULT:jack"
12+
"name|姓名|REQUIRED|DEFAULT:jack",
1313
"test|所有|REQUIRED:false|DEFAULT:jack|String|[20,23]"
1414
],
1515
"totalCountKey": "totalCountKeyTest",
@@ -18,4 +18,4 @@
1818
"recordId|contractNo"
1919
],
2020
"protocol": "test"
21-
}
21+
}

rdf-file-core/src/test/resources/meta/de-utf-8.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"mfundAccountNo|货币基金份额账户|BigDecimal",
1010
"date|日期类型|Date:yyyy-MM-dd HH:mm:ss",
1111
"count|金额|BigDecimal|[10,2]",
12-
"name|姓名|REQUIRED|DEFAULT:jack"
12+
"name|姓名|REQUIRED|DEFAULT:jack",
1313
"test|所有|REQUIRED:false|DEFAULT:jack|String|[20,23]"
1414
],
1515
"totalCountKey": "totalCountKeyTest",
@@ -18,4 +18,4 @@
1818
"acctRef|name"
1919
],
2020
"protocol":"DE"
21-
}
21+
}

rdf-file-core/src/test/resources/meta/template1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"mfundAccountNo|货币基金份额账户|BigDecimal",
1010
"date|日期类型|Date:yyyy-MM-dd HH:mm:ss",
1111
"count|金额|BigDecimal|[10,2]",
12-
"name|姓名|REQUIRED|DEFAULT:jack"
12+
"name|姓名|REQUIRED|DEFAULT:jack",
1313
"test|所有|REQUIRED:false|DEFAULT:jack|String|[20,23]"
1414
],
1515
"summaryColumnPairs": [
@@ -22,4 +22,4 @@
2222
"lineBreak": "\r",
2323
"startWithSplit": "head|body|tail",
2424
"endWithSplit": "head|body|tail"
25-
}
25+
}

0 commit comments

Comments
 (0)