-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from teamclairvoyant/REST-158-RB
[REST-158] Support for Excel
- Loading branch information
Showing
18 changed files
with
343 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Excel", | ||
"position": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Excel | ||
|
||
Restonomer can parse the api response of MS Excel file type. User need to configure the checkpoint in below | ||
format: | ||
|
||
```hocon | ||
name = "checkpoint_excel_response_dataframe_converter" | ||
data = { | ||
data-request = { | ||
url = "http://localhost:8080/excel-response-converter" | ||
} | ||
data-response = { | ||
body = { | ||
type = "Excel" | ||
excel-format = { | ||
data-address = "'Transactions Report'!A2:G4" | ||
} | ||
} | ||
persistence = { | ||
type = "LocalFileSystem" | ||
file-format = { | ||
type = "ParquetFileFormat" | ||
} | ||
file-path = "/tmp/response_body" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Excel Format Configurations | ||
|
||
User can provide below options to the `excel-format` instance: | ||
|
||
| Parameter Name | Default Value | Description | | ||
|:-----------------------------------|:---------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| header | true | Boolean flag to tell whether given excel sheet contains header names or not. | | ||
| data-address | A1 | The location of the data to read from. Following address styles are supported: <br/> `B3:` Start cell of the data. Returns all rows below and all columns to the right. <br/> `B3:F35:` Cell range of data. Reading will return only rows and columns in the specified range. <br/> `'My Sheet'!B3:F35:` Same as above, but with a specific sheet. <br/> `MyTable[#All]:` Table of data. Returns all rows and columns in this table. | | ||
| treat-empty-values-as-nulls | true | Treats empty values as null | | ||
| set-error-cells-to-fallback-values | false | If set false errors will be converted to null. If true, any ERROR cell values (e.g. #N/A) will be converted to the zero values of the column's data type. | | ||
| use-plain-number-format | false | If true, format the cells without rounding and scientific notations | | ||
| infer-schema | false | Infers the input schema automatically from data. | | ||
| add-color-columns | false | If it is set to true, adds field with coloured format | | ||
| timestamp-format | "yyyy-mm-dd hh:mm:ss" | String timestamp format | | ||
| excerpt-size | 10 | If set and if schema inferred, number of rows to infer schema from | | ||
| max-rows-in-memory | None | If set, uses a streaming reader which can help with big files (will fail if used with xls format files) | | ||
| max-byte-array-size | None | See https://poi.apache.org/apidocs/5.0/org/apache/poi/util/IOUtils.html#setByteArrayMaxOverride-int- | | ||
| temp-file-threshold | None | Number of bytes at which a zip entry is regarded as too large for holding in memory and the data is put in a temp file instead | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"label": "Text", | ||
"position": 1 | ||
"position": 2 | ||
} |
Binary file added
BIN
+15.2 KB
src/it/resources/mock_data/response_body/__files/sample_excel_response_body.xlsx
Binary file not shown.
20 changes: 20 additions & 0 deletions
20
src/it/resources/mock_data/response_body/expected_excel_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"Created": "2021-07-29 10:35:12", | ||
"Advertiser": "Zola", | ||
"Transaction ID": "1210730000580100000", | ||
"Earnings": "$0.68", | ||
"SID": "wlus9", | ||
"Status": "CONFIRMED", | ||
"ClickPage": "https://www.zola.com/" | ||
}, | ||
{ | ||
"Created": "2022-04-18 07:23:54", | ||
"Advertiser": "TradeInn", | ||
"Transaction ID": "1220419021230020000", | ||
"Earnings": "$12.48", | ||
"SID": "wles7", | ||
"Status": "CONFIRMED", | ||
"ClickPage": "https://www.tradeinn.com/" | ||
} | ||
] |
10 changes: 10 additions & 0 deletions
10
...resources/mock_data/response_body/mappings/mocked_excel_response_dataframe_converter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/excel-response-converter" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"bodyFileName": "sample_excel_response_body.xlsx" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...omer_context/checkpoints/response_body/checkpoint_excel_response_dataframe_converter.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name = "checkpoint_excel_response_dataframe_converter" | ||
|
||
data = { | ||
data-request = { | ||
url = "http://localhost:8080/excel-response-converter" | ||
} | ||
|
||
data-response = { | ||
body = { | ||
type = "Excel" | ||
excel-format = { | ||
data-address = "'Transactions Report'!A2:G4" | ||
} | ||
} | ||
|
||
persistence = { | ||
type = "LocalFileSystem" | ||
file-format = { | ||
type = "ParquetFileFormat" | ||
} | ||
file-path = "/tmp/response_body" | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...airvoyant/restonomer/response_body/ExcelResponseToDataFrameConverterIntegrationTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.clairvoyant.restonomer.response_body | ||
|
||
import com.clairvoyant.restonomer.common.{IntegrationTestDependencies, MockFileSystemPersistence} | ||
|
||
class ExcelResponseToDataFrameConverterIntegrationTest | ||
extends IntegrationTestDependencies | ||
with MockFileSystemPersistence { | ||
|
||
override val mappingsDirectory: String = "response_body" | ||
|
||
it should "convert the excel file response body into a dataframe" in { | ||
runCheckpoint(checkpointFileName = "checkpoint_excel_response_dataframe_converter.conf") | ||
outputDF should matchExpectedDataFrame("expected_excel_response.json") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.