Skip to content

Commit 91bcc5a

Browse files
author
hongwei.quhw
committed
columninfo 支持
1 parent c101de7 commit 91bcc5a

File tree

5 files changed

+32
-36
lines changed

5 files changed

+32
-36
lines changed

rdf-file-core/src/main/java/com/alipay/rdf/file/codec/AbstractColumnInfoCodec.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,4 @@ protected static List<FileColumnMeta> getColumnMetas(FileConfig config, FileData
5454
RdfErrorEnum.UNSUPPORTED_OPERATION);
5555
}
5656
}
57-
58-
protected static void checkRelationRowCodecMode(FileConfig fileConfig) {
59-
if (!RdfFileUtil.isRelationCodecMode(fileConfig)) {
60-
throw new RdfFileException("rdf-file#ColumnInfoCodec.checkRelationRowCodecMode protocol=" + TemplateLoader.load(fileConfig).getProtocol() +" unsupported rowCodecMode="
61-
+ RdfFileUtil.getRowCodecMode(fileConfig), RdfErrorEnum.UNSUPPORTED_OPERATION);
62-
}
63-
}
6457
}

rdf-file-core/src/main/java/com/alipay/rdf/file/codec/ColumnInfoHorizontalCodec.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class ColumnInfoHorizontalCodec extends AbstractColumnInfoCodec {
2727

2828
public static void serialize(FileDataTypeEnum layoutType, FileDataTypeEnum dataType, FileConfig config, FileWriter writer,
2929
String method) {
30-
checkRelationRowCodecMode(config);
3130
FileMeta fileMeta = TemplateLoader.load(config);
3231
List<FileColumnMeta> colMetas = getColumnMetas(config, dataType);
3332
StringBuilder colHead = new StringBuilder();
@@ -51,7 +50,6 @@ public static void serialize(FileDataTypeEnum layoutType, FileDataTypeEnum dataT
5150
public static <T> T deserialize(FileDataTypeEnum layoutType, FileDataTypeEnum dataType, FileConfig config,
5251
FileReader reader,
5352
String method) {
54-
checkRelationRowCodecMode(config);
5553
String line = reader.readLine();
5654
RdfFileUtil.assertNotBlank(line, "文件=" + config.getFilePath() + ", " + layoutType.name() + " 内容缺失");
5755

rdf-file-core/src/main/java/com/alipay/rdf/file/codec/ColumnInfoVerticalCodec.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class ColumnInfoVerticalCodec extends AbstractColumnInfoCodec {
2424

2525
public static void serialize(FileDataTypeEnum layoutType, FileDataTypeEnum dataType, FileConfig fileConfig,
2626
FileWriter writer, String method) {
27-
checkRelationRowCodecMode(fileConfig);
2827
//按行写入column字段
2928
for (FileColumnMeta colMeta : getColumnMetas(fileConfig, dataType)) {
3029
writer.writeLine(getValue(colMeta, method));
@@ -33,7 +32,6 @@ public static void serialize(FileDataTypeEnum layoutType, FileDataTypeEnum dataT
3332

3433
public static <T> T deserialize(FileDataTypeEnum layoutType, FileDataTypeEnum dataType, FileConfig fileConfig,
3534
FileReader reader, String method) {
36-
checkRelationRowCodecMode(fileConfig);
3735
for (FileColumnMeta colMeta : getColumnMetas(fileConfig, dataType)) {
3836
String columnName = RdfFileUtil.assertTrimNotBlank(reader.readLine());
3937
RdfFileUtil.assertNotBlank(columnName, "文件=" + fileConfig.getFilePath() + ", " + layoutType.name() + " 内容缺失");

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ public void setUp() throws IOException {
3030
tf.create();
3131
}
3232

33-
// 文件有body column描述 失败
34-
@Test(expected = RdfFileException.class)
35-
public void test1() throws Exception {
36-
String filePath = File.class.getResource("/codec/kv/data/data1.txt").getPath();
37-
38-
FileConfig config = new FileConfig(filePath, "/codec/kv/template/template1.json", new StorageConfig("nas"));
39-
40-
FileReader fileReader = FileFactory.createReader(config);
41-
42-
fileReader.readHead(HashMap.class);
43-
}
44-
4533
// 模板有多余字段
4634
@Test
4735
public void test2() throws Exception {

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.alipay.rdf.file.codec;
22

3-
import com.alipay.rdf.file.exception.RdfFileException;
43
import com.alipay.rdf.file.interfaces.FileFactory;
54
import com.alipay.rdf.file.interfaces.FileReader;
65
import com.alipay.rdf.file.interfaces.FileWriter;
@@ -31,9 +30,9 @@ public void setUp() throws IOException {
3130
}
3231

3332
/**
34-
* de 有columnInfo的序列化与反序列化不支持
33+
* de 有columnInfo的序列化与反序列化
3534
*/
36-
@Test(expected = RdfFileException.class)
35+
@Test
3736
public void test() throws Exception {
3837
String filePath = tf.getRoot().getAbsolutePath();
3938
FileConfig config = new FileConfig(new File(filePath, "test.txt").getAbsolutePath(),
@@ -55,7 +54,7 @@ public void test() throws Exception {
5554
body.put("gmtApply", testDate);
5655
body.put("date", testDate);
5756
body.put("dateTime", testDate);
58-
body.put("applyNumber", 12);
57+
body.put("applyNumber", new BigDecimal("12"));
5958
body.put("amount", new BigDecimal("1.22"));
6059
body.put("age", new Integer(33));
6160
body.put("longN", new Long(33));
@@ -64,14 +63,14 @@ public void test() throws Exception {
6463
fileWriter.writeRow(body);
6564

6665
testDate = DateUtil.parse("2016-02-03 12:22:33", "yyyy-MM-dd HH:mm:ss");
67-
66+
body = new HashMap<String, Object>();
6867
body.put("seq", "seq234567");
6968
body.put("instSeq", "505");
7069
body.put("gmtApply", testDate);
7170
body.put("date", testDate);
7271
body.put("dateTime", testDate);
73-
body.put("applyNumber", 12);
74-
body.put("amount", new BigDecimal("1.09"));
72+
body.put("applyNumber", new BigDecimal("12"));
73+
//body.put("amount", new BigDecimal("1.09"));
7574
body.put("age", 66);
7675
body.put("longN", 125);
7776
body.put("bol", false);
@@ -83,17 +82,37 @@ public void test() throws Exception {
8382
//校验文件
8483
BufferedReader reader = new BufferedReader(
8584
new InputStreamReader(new FileInputStream(new File(config.getFilePath())), "UTF-8"));
86-
Assert.assertEquals("总笔数:2|总金额:23.22", reader.readLine());
85+
Assert.assertEquals("totalCount:总笔数:2|totalAmount:总金额:23.22", reader.readLine());
8786
Assert.assertEquals("流水号|基金公司订单号|订单申请时间|普通日期|普通日期时间|普通数字|金额|年龄|长整型|布尔值|备注",
8887
reader.readLine());
8988
Assert.assertEquals(
90-
"seq12345|303|2017-01-03 12:22:33|20170103|20170103 12:22:33|12|1.22|33|33|true|memo1",
89+
"seq:seq12345|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|bol:true|memo:memo1",
9190
reader.readLine());
9291
Assert.assertEquals(
93-
"seq234567|505|2016-02-03 12:22:33|20160203|20160203 12:22:33|12|1.09|66|125|false|memo2",
92+
"seq:seq234567|instSeq:505|gmtApply:2016-02-03 12:22:33|date:20160203|dateTime:20160203 12:22:33|applyNumber:12|age:66|longN:125|bol:false|memo:memo2",
9493
reader.readLine());
9594

9695
reader.close();
96+
97+
FileReader fileReader = FileFactory.createReader(config);
98+
head = fileReader.readHead(HashMap.class);
99+
Assert.assertEquals(2L, head.get("totalCount"));
100+
Assert.assertEquals(new BigDecimal("23.22"), head.get("totalAmount"));
101+
102+
body = fileReader.readRow(HashMap.class);
103+
body = fileReader.readRow(HashMap.class);
104+
105+
Assert.assertEquals("seq234567", body.get("seq"));
106+
Assert.assertEquals("505", body.get("instSeq"));
107+
Assert.assertEquals("2016-02-03 12:22:33", DateUtil.format((Date) body.get("gmtApply"), "yyyy-MM-dd HH:mm:ss"));
108+
Assert.assertEquals(new BigDecimal("12"), body.get("applyNumber"));
109+
Assert.assertEquals(null, body.get("amount"));
110+
Assert.assertEquals(66, body.get("age"));
111+
Assert.assertEquals(125L, body.get("longN"));
112+
Assert.assertEquals(false, body.get("bol"));
113+
Assert.assertEquals("memo2", body.get("memo"));
114+
115+
fileReader.close();
97116
}
98117

99118
@Test
@@ -289,7 +308,7 @@ public void test3() throws Exception {
289308
"|instSeq:999|gmtApply:2016-02-03 12:22:33|dateTime:20160203 12:22:33|amount:1.09|age:66|longN:125|",
290309
reader.readLine());
291310

292-
Assert.assertEquals("|fileEnd:OFDCFEND|",reader.readLine());
311+
Assert.assertEquals("|fileEnd:OFDCFEND|", reader.readLine());
293312

294313
Assert.assertNull(reader.readLine());
295314
reader.close();
@@ -309,7 +328,7 @@ public void test3() throws Exception {
309328
}
310329

311330
@Test
312-
public void testKVSplit() throws Exception{
331+
public void testKVSplit() throws Exception {
313332
String filePath = tf.getRoot().getAbsolutePath();
314333
FileConfig config = new FileConfig(new File(filePath, "test.txt").getAbsolutePath(),
315334
"/codec/kv/template/template6.json", new StorageConfig("nas"));
@@ -370,7 +389,7 @@ public void testKVSplit() throws Exception{
370389
"|seq_@_seq234568|instSeq_@_505|gmtApply_@_2016-02-03 12:22:33|dateTime_@_20160203 12:22:33|amount_@_1.09|age_@_66|longN_@_125|",
371390
reader.readLine());
372391

373-
Assert.assertEquals("|fileEnd_@_OFDCFEND|",reader.readLine());
392+
Assert.assertEquals("|fileEnd_@_OFDCFEND|", reader.readLine());
374393

375394
Assert.assertNull(reader.readLine());
376395
reader.close();

0 commit comments

Comments
 (0)