@@ -10,7 +10,15 @@ This CLI tool reads a JSON file and produces BigQuery compatible SQL views from
10
10
## Usage
11
11
12
12
``` bash
13
- npx @nealwp/blobview@latest < filepath>
13
+ npx @nealwp/blobview [options] < filepath>
14
+
15
+ Arguments:
16
+ filepath path to valid JSON file
17
+
18
+ Options:
19
+ -t TABLE, --table=TABLE specify a table name to use in FROM clause. default: " <table>"
20
+ -d DATASET, --dataset=DATASET specify a dataset to use in FROM clause. default: " <dataset>"
21
+ -h, --help show help
14
22
```
15
23
16
24
## Examples:
@@ -19,6 +27,13 @@ Default output to STDOUT:
19
27
npx @nealwp/blobview@latest ./path/to/file.json
20
28
```
21
29
30
+ Dataset and table as input options:
31
+ ``` bash
32
+ npx @nealwp/blobview@latest --dataset=myDataset --table=myTable ./path/to/file.json
33
+ # shorthand options
34
+ npx @nealwp/blobview@latest -d myDataset -t myTable ./path/to/file.json
35
+ ```
36
+
22
37
Redirect output to file:
23
38
``` bash
24
39
npx @nealwp/blobview@latest ./path/to/file.json > my-view-file.sql
@@ -32,6 +47,7 @@ npx @nealwp/blobview@latest ./path/to/file.json > my-view-file.sql
32
47
* Auto-formats column names to snake_case from camelCase and PascalCase
33
48
* Detects deeply-nested objects and formats to JSON string
34
49
* Pre-populates FROM clause with BigQuery-style placeholders
50
+ * BigQuery dataset and table name can be supplied as input options
35
51
36
52
## Limitations
37
53
* Does not detect DATE or TIMESTAMP types, or other types like BOOLEAN
@@ -40,7 +56,7 @@ npx @nealwp/blobview@latest ./path/to/file.json > my-view-file.sql
40
56
* Does not create SQL views in any syntax other than BigQuery
41
57
* Requires a local JSON file to read
42
58
* Does not include option to write queries to separate files instead of STDOUT
43
- * BigQuery project, dataset, and datastream names cannot be supplied as input
59
+ * BigQuery project name cannot be supplied as input
44
60
45
61
## Example Output
46
62
@@ -100,20 +116,52 @@ SELECT
100
116
, CAST(JSON_VALUE(json_blob .integerField ) as INTEGER ) as integer_field
101
117
, CAST(JSON_VALUE(json_blob .decimalField ) as DECIMAL ) as decimal_field
102
118
, TO_JSON_STRING(json_blob .exampleGeoJson ) as example_geo_json
103
- FROM < project> .< datastream> .< dataset>
119
+ FROM < project> .< dataset> .< table>
120
+ /**/
121
+ SELECT
122
+ CAST(JSON_VALUE(json_blob .childField1 .gender) as STRING) as gender
123
+ , CAST(JSON_VALUE(json_blob .childField1 .latitude) as DECIMAL ) as latitude
124
+ FROM < project> .< dataset> .< table>
125
+ /**/
126
+ SELECT
127
+ CAST(JSON_VALUE(json_blob .childField2 .favoriteFruit) as STRING) as favorite_fruit
128
+ , CAST(JSON_VALUE(json_blob .childField2 .longitude) as DECIMAL ) as longitude
129
+ FROM < project> .< dataset> .< table>
130
+ /**/
131
+ SELECT
132
+ CAST(JSON_VALUE(json_blob .childWithNestedObject .isNormal) as STRING) as is_normal
133
+ , TO_JSON_STRING(json_blob .childWithNestedObject .nestedObject) as nested_object
134
+ FROM < project> .< dataset> .< table>
135
+ ```
136
+
137
+ ``` bash
138
+ # terminal command with input options
139
+ npx @nealwp/blobview --dataset=myDataset --table=myTable sample-data.json
140
+ ```
141
+
142
+ Will produce the following output:
143
+
144
+ ``` sql
145
+ /* stdout */
146
+ SELECT
147
+ CAST(JSON_VALUE(json_blob .stringField ) as STRING) as string_field
148
+ , CAST(JSON_VALUE(json_blob .integerField ) as INTEGER ) as integer_field
149
+ , CAST(JSON_VALUE(json_blob .decimalField ) as DECIMAL ) as decimal_field
150
+ , TO_JSON_STRING(json_blob .exampleGeoJson ) as example_geo_json
151
+ FROM < project> .myDataset .myTable
104
152
/**/
105
153
SELECT
106
154
CAST(JSON_VALUE(json_blob .childField1 .gender) as STRING) as gender
107
155
, CAST(JSON_VALUE(json_blob .childField1 .latitude) as DECIMAL ) as latitude
108
- FROM < project> .< datastream > . < dataset >
156
+ FROM < project> .myDataset . myTable
109
157
/**/
110
158
SELECT
111
159
CAST(JSON_VALUE(json_blob .childField2 .favoriteFruit) as STRING) as favorite_fruit
112
160
, CAST(JSON_VALUE(json_blob .childField2 .longitude) as DECIMAL ) as longitude
113
- FROM < project> .< datastream > . < dataset >
161
+ FROM < project> .myDataset . myTable
114
162
/**/
115
163
SELECT
116
164
CAST(JSON_VALUE(json_blob .childWithNestedObject .isNormal) as STRING) as is_normal
117
165
, TO_JSON_STRING(json_blob .childWithNestedObject .nestedObject) as nested_object
118
- FROM < project> .< datastream > . < dataset >
166
+ FROM < project> .myDataset . myTable
119
167
```
0 commit comments