|
| 1 | + |
| 2 | + |
| 3 | +# Analytics with stackql |
| 4 | + |
| 5 | +The canonical pattern is a postgres backend. To meaningfully develop analytics capability, **real** authenticated access to providers plus a postgres backend is needed. Therefore for local development: |
| 6 | + |
| 7 | +- Ensure that all env var secrets are exported from the `.gitignore`d file `cicd/vol/vendor-secrets/secrets.sh`. |
| 8 | +- Run and kill development containers with `docker compose -f docker-compose-live.yml down --volumes` / `docker compose -f docker-compose-live.yml up --force-recreate`. |
| 9 | +- Connect and develop queries with `psql "postgresql://stackql:[email protected]:8632/stackql"`. |
| 10 | + |
| 11 | + |
| 12 | +## TODO |
| 13 | + |
| 14 | +Robot tests for: |
| 15 | + |
| 16 | +- Support for `current_date`. |
| 17 | +- Support for `current_timestamp`. |
| 18 | +- Support for multi-layered table valued functions in subqueries with outside filters, per Figure MLS-01. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +```sql |
| 23 | + |
| 24 | +-- sqlite version |
| 25 | + |
| 26 | +CREATE OR REPLACE MATERIALIZED VIEW gcp_compute_public_ip_exposure AS |
| 27 | +select |
| 28 | + resource_type, |
| 29 | + resource_id, |
| 30 | + resource_name, |
| 31 | + cloud, |
| 32 | + region, |
| 33 | + protocol, |
| 34 | + from_port, |
| 35 | + to_port, |
| 36 | + cidr, |
| 37 | + direction, |
| 38 | + public_access_type, |
| 39 | + public_principal, |
| 40 | + access_mechanism |
| 41 | +from |
| 42 | +( |
| 43 | +SELECT |
| 44 | + 'compute' AS resource_type, |
| 45 | + vms.id AS resource_id, |
| 46 | + vms.name AS resource_name, |
| 47 | + 'google' AS cloud, |
| 48 | + split_part(vms.zone, '/', -1) AS region, |
| 49 | + NULL AS protocol, |
| 50 | + NULL AS from_port, |
| 51 | + NULL AS to_port, |
| 52 | + NULL AS cidr, |
| 53 | + NULL AS direction, |
| 54 | + NULL AS public_access_type, |
| 55 | + NULL AS public_principal, |
| 56 | + NULL AS access_mechanism, |
| 57 | + json_extract(ac.value, '$.natIP') as external_ip |
| 58 | +FROM google.compute.instances vms, |
| 59 | + json_each(vms.networkInterfaces) AS ni, |
| 60 | + json_each(json_extract(ni.value, '$.accessConfigs')) AS ac |
| 61 | +WHERE |
| 62 | + vms.project in ( |
| 63 | + 'testing-project' |
| 64 | + ) |
| 65 | + ) foo |
| 66 | + where external_ip != '' |
| 67 | +; |
| 68 | + |
| 69 | + |
| 70 | +-- postgres version |
| 71 | + |
| 72 | +CREATE OR REPLACE MATERIALIZED VIEW gcp_compute_public_ip_exposure AS |
| 73 | +select |
| 74 | + resource_type, |
| 75 | + resource_id, |
| 76 | + resource_name, |
| 77 | + cloud, |
| 78 | + region, |
| 79 | + protocol, |
| 80 | + from_port, |
| 81 | + to_port, |
| 82 | + cidr, |
| 83 | + direction, |
| 84 | + public_access_type, |
| 85 | + public_principal, |
| 86 | + access_mechanism |
| 87 | +from |
| 88 | +( |
| 89 | +SELECT |
| 90 | + 'compute' AS resource_type, |
| 91 | + vms.id AS resource_id, |
| 92 | + vms.name AS resource_name, |
| 93 | + 'google' AS cloud, |
| 94 | + split_part(vms.zone, '/', -1) AS region, |
| 95 | + NULL AS protocol, |
| 96 | + NULL AS from_port, |
| 97 | + NULL AS to_port, |
| 98 | + NULL AS cidr, |
| 99 | + NULL AS direction, |
| 100 | + NULL AS public_access_type, |
| 101 | + NULL AS public_principal, |
| 102 | + NULL AS access_mechanism, |
| 103 | + json_extract_path_text(ac.value, 'natIP') as external_ip |
| 104 | +FROM google.compute.instances vms, |
| 105 | + json_array_elements_text(vms.networkInterfaces) AS ni, |
| 106 | + json_array_elements_text(json_extract_path_text(ni.value, 'accessConfigs')) AS ac |
| 107 | +WHERE |
| 108 | + vms.project in ( |
| 109 | + 'stackql-interesting' |
| 110 | + ) |
| 111 | + ) foo |
| 112 | + where external_ip != '' |
| 113 | +; |
| 114 | + |
| 115 | +``` |
| 116 | + |
| 117 | +**Figure MLS-01**: Multi-layered table valued functions in subqueries with outside filters. |
| 118 | + |
| 119 | +--- |
| 120 | + |
0 commit comments