Skip to content

Commit 7989030

Browse files
authored
Merge pull request #1548 from cloudsufi/cherry-pick/9673a9e8ef253f3c03e215e1282ccf8266da8071
[🍒][Plugin-1730] Adding XLS UI elements for gcs file source
2 parents dcc8517 + 89a1f08 commit 7989030

File tree

3 files changed

+116
-3
lines changed

3 files changed

+116
-3
lines changed

docs/GCSFile-batchsource.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,44 @@ You also can use the macro function ${conn(connection-name)}.
3333
**Project ID:** Google Cloud Project ID, which uniquely identifies a project.
3434
It can be found on the Dashboard in the Google Cloud Platform Console.
3535

36+
**Service Account Type:** Service account type, file path where the service account is located or the JSON content of
37+
the service account.
38+
39+
**Service Account File Path:** Path on the local file system of the service account key. Can be set to 'auto-detect'.
40+
41+
**Service Account JSON:** Contents of the service account JSON file.
42+
3643
**Path:** Path to file(s) to be read. If a directory is specified, terminate the path name with a '/'.
3744
For example, `gs://<bucket>/path/to/directory/`.
3845
An asterisk ("\*") can be used as a wildcard to match a filename pattern.
3946
If no files are found or matched, the pipeline will fail.
4047

4148
**Format:** Format of the data to read.
42-
The format must be one of 'avro', 'blob', 'csv', 'delimited', 'json', 'parquet', 'text', 'tsv', or the
49+
The format must be one of 'avro', 'blob', 'csv', 'delimited', 'json', 'parquet', 'text', 'tsv', 'xls', or the
4350
name of any format plugin that you have deployed to your environment.
4451
If the format is a macro, only the pre-packaged formats can be used.
4552
If the format is 'blob', every input file will be read into a separate record.
4653
The 'blob' format also requires a schema that contains a field named 'body' of type 'bytes'.
4754
If the format is 'text', the schema must contain a field named 'body' of type 'string'.
4855

56+
**Get Schema:** Auto-detects schema from file. Supported formats are: avro, parquet, csv, delimited, tsv, blob, text, and xls.
57+
58+
**Sample Size:** The maximum number of rows that will get investigated for automatic data type detection.
59+
The default value is 1000. This is only used when the format is 'xls'.
60+
61+
**Override:** A list of columns with the corresponding data types for whom the automatic data type detection gets
62+
skipped. This is only used when the format is 'xls'.
63+
64+
**Terminate Reading After Empty Row:** Specify whether to stop reading after encountering the first empty row. Defaults to false. When false the reader will read all rows in the sheet. This is only used when the format is 'xls'.
65+
66+
**Select Sheet Using:** Select the sheet by name or number. Default is 'Sheet Number'. This is only used when the format is 'xls'.
67+
68+
**Sheet Value:** The name/number of the sheet to read from. If not specified, the first sheet will be read.
69+
Sheet Numbers are 0 based, ie first sheet is 0. This is only used when the format is 'xls'.
70+
4971
**Delimiter:** Delimiter to use when the format is 'delimited'. This will be ignored for other formats.
5072

51-
**Use First Row as Header:** Whether to use first row as header. Supported formats are 'text', 'csv', 'tsv', 'delimited'.
73+
**Use First Row as Header:** Whether to use first row as header. Supported formats are 'text', 'csv', 'tsv', 'delimited', 'xls'.
5274

5375
**Enable Quoted Values:** Whether to treat content between quotes as a value. This value will only be used if the format
5476
is 'csv', 'tsv' or 'delimited'. For example, if this is set to true, a line that looks like `1, "a, b, c"` will output two fields.

src/main/java/io/cdap/plugin/gcp/gcs/source/GCSSource.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ public static class GCSSourceConfig extends AbstractFileSourceConfig implements
166166
private static final String NAME_FILE_SYSTEM_PROPERTIES = "fileSystemProperties";
167167
private static final String NAME_FILE_REGEX = "fileRegex";
168168
private static final String NAME_DELIMITER = "delimiter";
169+
private static final String NAME_SHEET = "sheet";
170+
private static final String NAME_SHEET_VALUE = "sheetValue";
171+
private static final String NAME_TERMINATE_IF_EMPTY_ROW = "terminateIfEmptyRow";
169172

170173
private static final String DEFAULT_ENCRYPTED_METADATA_SUFFIX = ".metadata";
171174

@@ -220,6 +223,25 @@ public static class GCSSourceConfig extends AbstractFileSourceConfig implements
220223
@Description("The existing connection to use.")
221224
private GCPConnectorConfig connection;
222225

226+
@Name(NAME_SHEET)
227+
@Macro
228+
@Nullable
229+
@Description("Select the sheet by name or number. Default is 'Sheet Number'.")
230+
private String sheet;
231+
232+
@Name(NAME_SHEET_VALUE)
233+
@Macro
234+
@Nullable
235+
@Description("The name/number of the sheet to read from. If not specified, the first sheet will be read." +
236+
"Sheet Numbers are 0 based, ie first sheet is 0.")
237+
private String sheetValue;
238+
239+
@Name(NAME_TERMINATE_IF_EMPTY_ROW)
240+
@Macro
241+
@Nullable
242+
@Description("Specify whether to stop reading after encountering the first empty row. Defaults to false.")
243+
private String terminateIfEmptyRow;
244+
223245
@Override
224246
public void validate() {
225247
// no-op

widgets/GCSFile-batchsource.json

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,42 @@
187187
"label": "False"
188188
}
189189
}
190+
},
191+
{
192+
"widget-type": "toggle",
193+
"label": "Terminate Reading After Empty Row",
194+
"name": "terminateIfEmptyRow",
195+
"widget-attributes": {
196+
"default": "false",
197+
"on": {
198+
"value": "true",
199+
"label": "True"
200+
},
201+
"off": {
202+
"value": "false",
203+
"label": "False"
204+
}
205+
}
206+
},
207+
{
208+
"widget-type": "select",
209+
"label": "Select Sheet Using",
210+
"name": "sheet",
211+
"widget-attributes": {
212+
"values": [
213+
"Sheet Name",
214+
"Sheet Number"
215+
],
216+
"default": "Sheet Number"
217+
}
218+
},
219+
{
220+
"widget-type": "textbox",
221+
"label": "Sheet Value",
222+
"name": "sheetValue",
223+
"widget-attributes": {
224+
"default": "0"
225+
}
190226
}
191227
]
192228
},
@@ -673,13 +709,46 @@
673709
{
674710
"name": "skipHeader",
675711
"condition": {
676-
"expression": "format == 'delimited' || format == 'csv' || format == 'tsv'"
712+
"expression": "format == 'delimited' || format == 'csv' || format == 'tsv' || format == 'xls'"
677713
},
678714
"show": [
679715
{
680716
"name": "skipHeader"
681717
}
682718
]
719+
},
720+
{
721+
"name": "sheet",
722+
"condition": {
723+
"expression": "format == 'xls'"
724+
},
725+
"show": [
726+
{
727+
"name": "sheet"
728+
}
729+
]
730+
},
731+
{
732+
"name": "sheetValue",
733+
"condition": {
734+
"expression": "format == 'xls'"
735+
},
736+
"show": [
737+
{
738+
"name": "sheetValue"
739+
}
740+
]
741+
},
742+
{
743+
"name": "terminateIfEmptyRow",
744+
"condition": {
745+
"expression": "format == 'xls'"
746+
},
747+
"show": [
748+
{
749+
"name": "terminateIfEmptyRow"
750+
}
751+
]
683752
}
684753
],
685754
"outputs": [

0 commit comments

Comments
 (0)