Skip to content

Commit a4db986

Browse files
authored
Updated README (#11)
Added instructions for how to use the DQDL parser library.
1 parent 9b61841 commit a4db986

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,70 @@
22

33
This package contains the grammar in Antlr g4 format for the Data Quality Definition Language (DQDL).
44

5+
## Example
6+
7+
The first step is to add a dependency to DQDL. DQDL uses logging and requires an implementation of Slf4j to be available on the classpath. If you are using Maven, then the required dependencies can be added as following.
8+
9+
```
10+
<dependencies>
11+
<dependency>
12+
<groupId>software.amazon.glue</groupId>
13+
<artifactId>dqdl</artifactId>
14+
<version>1.0.0</version>
15+
</dependency>
16+
<dependency>
17+
<groupId>org.slf4j</groupId>
18+
<artifactId>slf4j-log4j12</artifactId>
19+
<version>2.0.16</version>
20+
</dependency>
21+
</dependencies>
22+
```
23+
24+
Once the dependencies are added, you can start using the `DQDLParser` class which allows you to parse a DQDL ruleset in the form of a string into a modeled `DQRuleset` object. The following snippet of code provides an example for how to do so.
25+
26+
```
27+
import software.amazon.glue.dqdl.exception.InvalidDataQualityRulesetException;
28+
import software.amazon.glue.dqdl.model.DQRuleset;
29+
import software.amazon.glue.dqdl.parser.DQDLParser;
30+
31+
public class App {
32+
public static void main(String[] args) throws InvalidDataQualityRulesetException {
33+
String ruleset = "Rules = [ RowCount > 1, ColumnCount > max(avg(last(10))) ]";
34+
DQDLParser parser = new DQDLParser();
35+
36+
DQRuleset dqRuleset = parser.parse(ruleset);
37+
System.out.println("--- Printing out ruleset ---");
38+
System.out.println(dqRuleset);
39+
40+
System.out.println("--- Printing out number of rules in the ruleset ---");
41+
System.out.println(dqRuleset.getRules().size());
42+
43+
System.out.println("--- Printing out individual rules ---");
44+
for (int i = 0; i < dqRuleset.getRules().size(); i++) {
45+
System.out.printf("Rule #%d - %s%n", i+1, dqRuleset.getRules().get(i));
46+
}
47+
}
48+
}
49+
```
50+
51+
The output of the code above is as following.
52+
53+
```
54+
55+
--- Printing out ruleset ---
56+
Rules = [
57+
RowCount > 1,
58+
ColumnCount > max(avg(last(10)))
59+
]
60+
61+
--- Printing out number of rules in the ruleset ---
62+
2
63+
64+
--- Printing out individual rules ---
65+
Rule #1 - RowCount > 1
66+
Rule #2 - ColumnCount > max(avg(last(10)))
67+
```
68+
569
## Security
670

771
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

0 commit comments

Comments
 (0)