Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions internal/stackql/astanalysis/earlyanalysis/ast_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/stackql/stackql/internal/stackql/astanalysis/annotatedast"
"github.com/stackql/stackql/internal/stackql/astindirect"
"github.com/stackql/stackql/internal/stackql/constants"
"github.com/stackql/stackql/internal/stackql/handler"
"github.com/stackql/stackql/internal/stackql/internal_data_transfer/internaldto"
"github.com/stackql/stackql/internal/stackql/logging"
Expand Down Expand Up @@ -40,6 +41,7 @@ type indirectExpandAstVisitor struct {
tcc internaldto.TxnControlCounters
primitiveGenerator primitivegenerator.PrimitiveGenerator
whereParams parserutil.ParameterMap
indirectionDepth int
}

func newIndirectExpandAstVisitor(
Expand All @@ -51,6 +53,7 @@ func newIndirectExpandAstVisitor(
namespaceCollection tablenamespace.TableNamespaceCollection,
whereParams parserutil.ParameterMap,
tcc internaldto.TxnControlCounters,
indirectionDepth int,
) (AstExpandVisitor, error) {
if whereParams == nil {
whereParams = parserutil.NewParameterMap()
Expand All @@ -64,6 +67,7 @@ func newIndirectExpandAstVisitor(
handlerCtx: handlerCtx,
tcc: tcc,
whereParams: whereParams,
indirectionDepth: indirectionDepth,
}
return rv, nil
}
Expand Down Expand Up @@ -601,7 +605,10 @@ func (v *indirectExpandAstVisitor) Visit(node sqlparser.SQLNode) error {

case sqlparser.TableExprs:
for _, n := range node {
n.Accept(v)
err := n.Accept(v)
if err != nil {
return err
}
}

case *sqlparser.AliasedTableExpr:
Expand Down Expand Up @@ -692,9 +699,10 @@ func (v *indirectExpandAstVisitor) Visit(node sqlparser.SQLNode) error {
if err != nil {
return err
}
childAnalyzer.SetIndirectionDepth(v.indirectionDepth + 1)
err = childAnalyzer.Analyze(indirect.GetSelectAST(), v.handlerCtx, v.tcc)
if err != nil {
return nil
return err
}
// Persist indirect for later retrieval
v.annotatedAST.SetIndirect(node, indirect)
Expand All @@ -703,6 +711,11 @@ func (v *indirectExpandAstVisitor) Visit(node sqlparser.SQLNode) error {
if err != nil {
return err
}
maxIndirectCount := childAnalyzer.GetIndirectionDepth()
if maxIndirectCount > constants.LimitsIndirectMaxChainLength {
return fmt.Errorf("query error: indirection chain length %d > %d and is therefore disallowed; please do not cite views from within views", maxIndirectCount, constants.LimitsIndirectMaxChainLength)
}
indirectPrimitiveGenerator.GetPrimitiveComposer().GetAst()
selCtx := indirectPrimitiveGenerator.GetPrimitiveComposer().GetIndirectSelectPreparedStatementCtx()
underlyingSymTab := indirectPrimitiveGenerator.GetPrimitiveComposer().GetSymTab()
colz := selCtx.GetNonControlColumns()
Expand Down
12 changes: 12 additions & 0 deletions internal/stackql/astanalysis/earlyanalysis/first_passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ type InitialPassesScreener interface {
GetInstructionType() InstructionType
GetPlanBuilderInput() planbuilderinput.PlanBuilderInput
GetStatementType() sqlparser.StatementType
GetIndirectionDepth() int
IsCacheExemptMaterialDetected() bool
SetIndirectionDepth(int)
}

type InitialPassesScreenerAnalyzer interface {
Expand Down Expand Up @@ -59,6 +61,15 @@ type standardInitialPasses struct {
primitiveGenerator primitivegenerator.PrimitiveGenerator
parentAnnotatedAST annotatedast.AnnotatedAst
parentWhereParams parserutil.ParameterMap
indirectionDepth int
}

func (sp *standardInitialPasses) GetIndirectionDepth() int {
return sp.indirectionDepth
}

func (sp *standardInitialPasses) SetIndirectionDepth(indirectionDepth int) {
sp.indirectionDepth = indirectionDepth
}

func (sp *standardInitialPasses) GetInstructionType() InstructionType {
Expand Down Expand Up @@ -142,6 +153,7 @@ func (sp *standardInitialPasses) initialPasses(statement sqlparser.Statement, ha
handlerCtx.GetNamespaceCollection(),
whereParams,
tcc,
sp.indirectionDepth,
)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions internal/stackql/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const (
SQLDataSourceSchemaDefault string = SQLDataSourceSchemaPostgresInfo
)

const (
LimitsIndirectMaxChainLength int = 1
)

type GCStatus int

const (
Expand Down
14 changes: 14 additions & 0 deletions test/robot/functional/stackql_mocked_from_cmd_line.robot
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,20 @@ Describe View of Cloud Control Resource Returns Expected Result
... RestrictPublicBuckets
... stdout=${CURDIR}/tmp/Describe-View-of-Cloud-Control-Resource-Returns-Expected-Result.tmp

View Depth Limitation Upheld
Should Stackql Exec Inline Contain Stderr
... ${STACKQL_EXE}
... ${OKTA_SECRET_STR}
... ${GITHUB_SECRET_STR}
... ${K8S_SECRET_STR}
... ${REGISTRY_NO_VERIFY_CFG_STR}
... ${AUTH_CFG_STR}
... ${SQL_BACKEND_CFG_STR_CANONICAL}
... create view zz1 as select name from stackql_repositories; select * from zz1;
... please do not cite views from within views
... stdout=${CURDIR}/tmp/View-Depth-Limitation-Upheld-stdout.tmp
... stderr=${CURDIR}/tmp/View-Depth-Limitation-Upheld-stderr.tmp

Weird ID WSL bug query
# ID cannot be handled as integer on WSL
Should Horrid Query StackQL Inline Equal
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MajorVersion=0
MinorVersion=2
MinorVersion=3