Skip to content

Commit 543d6a8

Browse files
view-uplift-phase-02 (#637)
Summary: - Amedned prepared statement argument miscount. - Supports 3 way indirect join. Ie: `view`, `materialized view`, suquery, user space table. - Added robot test `Three Way View Subquery Provider Table Join Returns Results`.
1 parent caf5f19 commit 543d6a8

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

docs/data_flow.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11

22
# Data flow analysis in stackql
33

4-
Data flow analysis is impplmented as multiple passes on:
4+
Data flow analysis is implemented as multiple passes on:
55

6-
- An inital abstract syntax tree (AST) from the parser.
6+
- An initial abstract syntax tree (AST) from the parser.
77
- Annotated derivatives of the AST.
88
- `any-sdk` `{ provider, service, resource, method, schema... }` graphs.
99
- `gonum` DAG adaptations with data flow dependencies representing edges.
1010

1111
Some other aspects of data flow analysis:
1212

1313
- Relational algebra is implemented in a coupled RDBMS (embedded `sqlite` or `postgres` over TCP). There is a query rewriting process to stringify "containers" for this.
14-
- There are `transaction control counter` objects and corresponding RDBMS columns to bound relational algebra "containers" and future proof for gargage collection. Some mutex protection is in place.
14+
- There are `transaction control counter` objects and corresponding RDBMS columns to bound relational algebra "containers" and future proof for garbage collection. Some mutex protection is in place.
1515
- Views in `stackql` permit clobbering of where clause arguments from outside the view. The canonical case is a document-based view in a provider document. A good example are in [test/registry/src/aws/v0.1.0/services/pseudo_s3.yaml](/test/registry/src/aws/v0.1.0/services/pseudo_s3.yaml)at `...s3_bucket_list_and_detail.config.views.select`; one can overwrite `region` here.
1616
- Views, subqueries, materialized views and user space tables are modelled as "indirections".
1717

1818

19-
## Open Issues
19+
## Reasonable expectations
2020

2121
## Indirection Data Flow Analysis and Query Execution
2222

23-
Data flow analysis for indirections is not composable:
23+
Data flow analysis for indirections ought to be composable:
2424

25-
- It it impossible to join heterogenous collections of these with each other or conventional resources. There is no recusrsive and stable data flow analysis.
26-
- While `stackql` does have a `max depth` parameter, I do not believe it is stable enfoced eagerly. Ie: queries too complex should fail at analysis time. Cannot remember param name of=r default.
25+
- It should be possible to join heterogeneous collections of these with each other or conventional resources. There should exist recursive and stable data flow analysis.
26+
- `stackql`'s `max depth` parameter should be stably enforced, eagerly. Ie: queries too complex should fail at analysis time.
2727

28-
The expected fix for this issue:
28+
In other words, the expected behaviour:
2929

3030
- Joins, unions etc on indirections work to arbitrary and configurable depth. For depth violations, failure is eager in the analysis phase and error message is plain and in the canonical err stream already widely used.
31-
- Data flow analysis includes assurance on reuired poarams and viability of projections, joins, etc.
31+
- Data flow analysis includes assurance on required params and viability of projections, joins, etc.
3232
- Support for CTEs internal to these indirections is in place.
33-
- Mocked robot tests are added to the canonical test suite, covering off this function.
33+
- Mocked robot tests are included in the canonical test suite, covering off this function.
3434

3535

3636
## Glossary of terms

docs/views.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Views are rendered as inline subqueries `( SELECT ... ) AS "alias"` in the final
6868

6969
**Not supported:**
7070
- Table-qualified parameter clobbering into views (e.g. `WHERE v1.region = 'us-east-1'` will not override the view's internal `region` parameter).
71-
- Joins of three or more heterogeneous indirections (e.g. `view JOIN subquery JOIN provider_table`). Binary joins work; three-way and beyond fail with parameter count mismatches in the SQL composition layer.
7271

7372
### Materialized views (eager evaluated)
7473

internal/stackql/drm/prepared_statement_args.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ func (ca *standardPreparedStatementArgs) Analyze() error {
8181

8282
func (ca *standardPreparedStatementArgs) compose() (childQueryComposition, error) {
8383
var varArgs []interface{}
84-
j := 0
8584
query := ca.GetQuery()
86-
var childQueryStrings []interface{} // dunno why
85+
var childQueryStrings []interface{}
8786
var keys []int
8887
for i := range ca.GetChildren() {
8988
keys = append(keys, i)
@@ -97,14 +96,11 @@ func (ca *standardPreparedStatementArgs) compose() (childQueryComposition, error
9796
}
9897
childQueryStrings = append(childQueryStrings, childResponse.GetQueryString())
9998
varArgs = append(varArgs, childResponse.GetVarArgs()...)
100-
j = k
10199
}
102100
if len(childQueryStrings) > 0 {
103101
query = fmt.Sprintf(ca.GetQuery(), childQueryStrings...)
104102
}
105-
if len(ca.GetArgs()) >= j {
106-
varArgs = append(varArgs, ca.GetArgs()[j:]...)
107-
}
103+
varArgs = append(varArgs, ca.GetArgs()...)
108104
return newChildQueryComposition(query, varArgs), nil
109105
}
110106

test/robot/functional/stackql_mocked_from_cmd_line.robot

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9580,6 +9580,23 @@ View JOIN Materialized View Returns Results
95809580
... stdout=${CURDIR}/tmp/View-JOIN-Materialized-View-Returns-Results-stdout.tmp
95819581
... stderr=${CURDIR}/tmp/View-JOIN-Materialized-View-Returns-Results-stderr.tmp
95829582

9583+
Three Way View Subquery Provider Table Join Returns Results
9584+
${inputStr} = Catenate
9585+
... create or replace view vw_repos as select name, url from stackql_repositories;
9586+
... select v1.name from vw_repos v1 inner join (select name from stackql_repositories) sq on v1.name = sq.name inner join github.repos.repos r on v1.name = r.name where r.org = 'stackql';
9587+
Should Stackql Exec Inline Contain
9588+
... ${STACKQL_EXE}
9589+
... ${OKTA_SECRET_STR}
9590+
... ${GITHUB_SECRET_STR}
9591+
... ${K8S_SECRET_STR}
9592+
... ${REGISTRY_NO_VERIFY_CFG_STR}
9593+
... ${AUTH_CFG_STR}
9594+
... ${SQL_BACKEND_CFG_STR_CANONICAL}
9595+
... ${inputStr}
9596+
... dummyapp.io
9597+
... stdout=${CURDIR}/tmp/Three-Way-View-Subquery-Provider-Table-Join-Returns-Results-stdout.tmp
9598+
... stderr=${CURDIR}/tmp/Three-Way-View-Subquery-Provider-Table-Join-Returns-Results-stderr.tmp
9599+
95839600
CTE Within View Returns Results
95849601
${inputStr} = Catenate
95859602
... create or replace view vw_cte as with sub as (select name from stackql_repositories) select name from sub;

0 commit comments

Comments
 (0)