Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zavoraad authored Mar 8, 2024
1 parent 909be3b commit b7853b8
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,50 @@ pip install git+https://github.com/databricks-industry-solutions/x12-edi-parser

### Reading in EDI Data

#### EDI Formats

Default used is AnsiX12 (* as a delim and ~ as segment separator)

```python
from databricksx12.format import *
ediFormat = AnsiX12Delim #specifying formats of data, ansi is also the default if nothing is specified
df = spark.read.text("sampledata/837/*", wholetext = True)

(df.rdd
.map(lambda x: x.asDict().get("value"))
.map(lambda x: EDI(x, delim_cls = ediFormat))
.map(lambda x: {"transaction_count": x.num_transactions()})
).toDF().show()
+-----------------+
|transaction_count|
+-----------------+
| 5|
| 1|
| 1|
| 1|
+-----------------+



#Building a dynamic/custom format
customFormat = type("", (), dict({'SEGMENT_DELIM': '~', 'ELEMENT_DELIM': '*', 'SUB_DELIM': ':'}))
(df.rdd
.map(lambda x: x.asDict().get("value"))
.map(lambda x: EDI(x, delim_cls = customFormat))
.map(lambda x: {"transaction_count": x.num_transactions()})
).toDF().show()
+-----------------+
|transaction_count|
+-----------------+
| 5|
| 1|
| 1|
| 1|
+-----------------+


```

```python
from databricksx12.edi import *

Expand Down Expand Up @@ -127,21 +171,6 @@ trxDF.filter(x.row_number == 0).show()
"""
```

### Different EDI Formats

Default used is AnsiX12 (* as a delim and ~ as segment separator)

```python
from databricksx12.format import *
ediFormat = AnsiX12Delim #specifying formats of data

(df.rdd
.map(lambda x: x.asDict().get("value"))
.map(lambda x: EDI(x), delim_cls = ediFormat)
.map(lambda x: {"transaction_count": x.num_transactions()})
).toDF().show()
```

###

## Project support
Expand Down

0 comments on commit b7853b8

Please sign in to comment.