Skip to content

Commit 18c6020

Browse files
author
a13519
committed
revise readme
1 parent 5540c94 commit 18c6020

File tree

5 files changed

+207
-115
lines changed

5 files changed

+207
-115
lines changed

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,27 @@ A handy tool named **Bold/CompressedComparator** can compare two tables to figur
1414

1515
## Concept
1616

17+
### Headers
18+
When the data is parsed, the first row (after ignored rows before it) is treated as headers. And the columns referenced by this header.
19+
20+
### Compressed
21+
The Data carried by Table can be compressed to reduce the size of execution profile. Also it can be disabled by setting
22+
```java
23+
CompressedTableFactory
24+
.build("csv")
25+
.compressed(false)
26+
.build();
27+
```
28+
This is useful in handling large data set.
29+
1730
### Table Type
1831
* CSV: the source type of CSV file to parse
1932
* Excel: the source type of Excel file to parse
2033

21-
### Keys
34+
### Key Sets
2235
When a Table is parsed, the key set need to be set to Table thus table knows how to index the content and later those data can be queried. Each KeySet contains one or multiple columns which are represended by headers.
36+
To understand multiple Key Sets, you can imagine the name card, one person(Row in the case) could have multiple name cards, one is business card the other may be a social name card or family card, the name or identification on the card could be different but the purpose is to reveal to link it to the real human identity.
37+
Here, in Table, a Row could have multiple Keys to represent itself.
2338

2439
One **Bold/KeySet** contains:
2540
* One or Multiple headers or Columns
@@ -34,11 +49,24 @@ The **Bold/KeyHeadersList** represents the KeySets.
3449
### Delimeter
3550
This is for CSV parsing, a delimeter can be specified if it is other than comma
3651

52+
## Comparison
53+
The Compressed Comparator is to compare two Tables to find out the disparities.
54+
55+
### ComparatorListener
56+
This is a call back interface usd by comparator to let outside world known what's happened during the process.
3757

58+
### CompressedComparatorFactory
59+
This is the factory to initialize the Comparator you prefer.
60+
* before() and after() to specify two tables
61+
* ignoredFields() to set the Fields/Columns you don't want to compare thus fields won't appear in result
62+
* comparatorListener() to set the call back listener
63+
* trim() is to let the process trim the data fields or not
64+
* strictMissed() this is the switch in case the columns are missed in before or after, and it is to enable the comparison on this column. If it is true, then any rows in the tables will be mismatch if there are any missed columns in table.
3865

3966
## Examples
4067

41-
### Parse a table
68+
### Parse a table with single key set
69+
In this case, the key is composition keys of two columns of "Customer Id" and "First Name":
4270
```java
4371
CompressedTable beforetable = CompressedTableFactory
4472
.build("csv")
@@ -53,3 +81,32 @@ CompressedTable beforetable = CompressedTableFactory
5381
.toAbsolutePath()
5482
.toString());
5583
```
84+
85+
### Parse a table with multiple key sets
86+
In this case, there are two key sets used to identify a row by one set of {"Customer Id", "First Name"}, the other key set is {"Phone 1", "Phone 2", "Email"}
87+
```java
88+
CompressedTable beforetable = CompressedTableFactory
89+
.build("csv")
90+
.keyHeaderList(new KeyHeadersList()
91+
.addHeaders(new String[]{"First Name", "Last Name"})
92+
.addHeaders(new String[]{"Phone 1", "Phone 2", "Email"})
93+
)
94+
.ignoredLines(0)
95+
.delimeter(',')
96+
.parse(Paths.get("customers-1000b.csv")
97+
.toAbsolutePath()
98+
.toString());
99+
```
100+
101+
### Compare two tables
102+
103+
```java
104+
CompressedComparatorFactory.builder()
105+
.before(beforetable)
106+
.after(aftertable)
107+
.comparatorListener(listener)
108+
.strictMissed(false)
109+
.ignoredFields(new HashSet(Arrays.asList(new String[]{})))
110+
.build().create()
111+
.compare();
112+
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package samples;
2+
3+
import lombok.extern.log4j.Log4j2;
4+
import net.zousys.compressedtable.CompressedComparatorFactory;
5+
import net.zousys.compressedtable.CompressedTableFactory;
6+
import net.zousys.compressedtable.impl.CompressedTable;
7+
import net.zousys.compressedtable.impl.KeyHeadersList;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Paths;
11+
import java.util.Arrays;
12+
import java.util.HashSet;
13+
import java.util.zip.DataFormatException;
14+
15+
@Log4j2
16+
public class CompareTwoTables {
17+
/**
18+
*
19+
* @param args
20+
* @throws IOException
21+
* @throws DataFormatException
22+
*/
23+
public static void main(String[] args) throws IOException, DataFormatException {
24+
CompareListener listener = new CompareListener();
25+
26+
CompressedTable beforetable = CompressedTableFactory
27+
.build("csv")
28+
.keyHeaderList(new KeyHeadersList()
29+
.addHeaders(new String[]{"Customer Id", "First Name"})
30+
)
31+
.compressed(true)
32+
.ignoredLines(0)
33+
.delimeter(',')
34+
.parse(Paths.get("customers-1000b.csv")
35+
.toAbsolutePath()
36+
.toString());
37+
listener.handleBeforeLoaded(beforetable);
38+
log.info("Before size: " + beforetable.getContents().size() + " " + beforetable.getHeaders() + " Mode: " + beforetable.getMode());
39+
40+
CompressedTable aftertable = CompressedTableFactory
41+
.build("csv")
42+
.keyHeaderList(new KeyHeadersList()
43+
.addHeaders(new String[]{"Customer Id", "First Name"})
44+
)
45+
.compressed(true)
46+
.ignoredLines(0)
47+
.delimeter(',')
48+
.parse(Paths.get("customers-1000a.csv")
49+
.toAbsolutePath()
50+
.toString());
51+
listener.handleAfterLoaded(aftertable);
52+
log.info("After size: " + aftertable.getContents().size() + " " + aftertable.getHeaders() + " Mode: " + beforetable.getMode());
53+
54+
CompressedComparatorFactory.builder()
55+
.before(beforetable)
56+
.after(aftertable)
57+
.comparatorListener(listener)
58+
.ignoredFields(new HashSet(Arrays.asList(new String[]{})))
59+
.strictMissed(true)
60+
.build().create()
61+
.compare();
62+
63+
}
64+
65+
}

src/main/java/samples/Main.java

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package samples;
2+
3+
import lombok.extern.log4j.Log4j2;
4+
import net.zousys.compressedtable.CompressedComparatorFactory;
5+
import net.zousys.compressedtable.CompressedTableFactory;
6+
import net.zousys.compressedtable.impl.CompressedTable;
7+
import net.zousys.compressedtable.impl.KeyHeadersList;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Paths;
11+
import java.util.Arrays;
12+
import java.util.HashSet;
13+
import java.util.zip.DataFormatException;
14+
15+
@Log4j2
16+
public class ParseMultipleKeySets {
17+
/**
18+
* Default the Table is compressed. This is to parse a CSV file to compressed table.
19+
*
20+
* @param args
21+
* @throws IOException
22+
* @throws DataFormatException
23+
*/
24+
public static void main(String[] args) throws IOException, DataFormatException {
25+
CompareListener k = new CompareListener();
26+
27+
CompressedTable beforetable = CompressedTableFactory
28+
.build("csv")
29+
.keyHeaderList(new KeyHeadersList()
30+
.addHeaders(new String[]{"First Name", "Last Name"})
31+
.addHeaders(new String[]{"Phone 1", "Phone 2", "Email"})
32+
)
33+
.ignoredLines(0)
34+
.delimeter(',')
35+
.parse(Paths.get("customers-1000b.csv")
36+
.toAbsolutePath()
37+
.toString());
38+
k.handleBeforeLoaded(beforetable);
39+
log.info("Before size: " + beforetable.getContents().size() + " " + beforetable.getHeaders());
40+
}
41+
42+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package samples;
2+
3+
import lombok.extern.log4j.Log4j2;
4+
import net.zousys.compressedtable.CompressedComparatorFactory;
5+
import net.zousys.compressedtable.CompressedTableFactory;
6+
import net.zousys.compressedtable.impl.CompressedTable;
7+
import net.zousys.compressedtable.impl.KeyHeadersList;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Paths;
11+
import java.util.Arrays;
12+
import java.util.HashSet;
13+
import java.util.zip.DataFormatException;
14+
15+
@Log4j2
16+
public class ParseSingleKeySet {
17+
/**
18+
* This is to parse a Single Key Set CSV file to an un-compressed table
19+
* @param args
20+
* @throws IOException
21+
* @throws DataFormatException
22+
*/
23+
public static void main(String[] args) throws IOException, DataFormatException {
24+
CompareListener listener = new CompareListener();
25+
26+
CompressedTable beforetable = CompressedTableFactory
27+
.build("csv")
28+
.keyHeaderList(new KeyHeadersList()
29+
.addHeaders(new String[]{"Customer Id", "First Name"})
30+
)
31+
.compressed(false)
32+
.ignoredLines(0)
33+
.delimeter(',')
34+
.parse(Paths.get("customers-1000b.csv")
35+
.toAbsolutePath()
36+
.toString());
37+
listener.handleBeforeLoaded(beforetable);
38+
log.info("Before size: " + beforetable.getContents().size() + " " + beforetable.getHeaders() + " Mode: " + beforetable.getMode());
39+
40+
}
41+
}

0 commit comments

Comments
 (0)