Skip to content

Commit

Permalink
Merge branch 'stackql:main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Iqbalabdi authored Nov 26, 2023
2 parents b858190 + c8f46c3 commit 8b6722b
Show file tree
Hide file tree
Showing 24 changed files with 235,820 additions and 97 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
github: [stackql]
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@
"CREATE MATERIALIZED VIEW vw_ec2_instance_types AS SELECT memoryInfo, hypervisor, autoRecoverySupported, instanceType, SPLIT_PART(processorInfo, '\n', 3) as processorArch, currentGeneration, freeTierEligible, hibernationSupported, SPLIT_PART(vCpuInfo, '\n', 2) as vCPUs, bareMetal, burstablePerformanceSupported, dedicatedHostsSupported, region FROM aws.ec2.instance_types WHERE region = 'us-east-1'; SELECT i.instanceId, i.instanceType, it.vCPUs, it.memoryInfo FROM aws.ec2.instances i INNER JOIN vw_ec2_instance_types it ON i.instanceType = it.instanceType WHERE i.region = 'us-east-1';",
"create materialized view vw_aws_usr as select * from aws.iam.users where region = 'us-east-1'; select u1.Arn, u2.UserName, u1.region from aws.iam.users u1 inner join vw_aws_usr u2 on u1.Arn = u2.Arn where u1.region = 'us-east-1' and u2.region = 'us-east-1' ;",
"create materialized view org_celebrity_contributors as ( select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'go-openapistackql' UNION ALL select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'stackql' UNION ALL select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'stackql-provider-registry') ;",
"create materialized view org_celeb_contributors as select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'go-openapistackql' UNION ALL select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'stackql' UNION ALL select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'stackql-provider-registry' ;"
"create materialized view org_celeb_contributors as select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'go-openapistackql' UNION ALL select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'stackql' UNION ALL select login, contributions FROM github.repos.contributors WHERE owner = 'stackql' AND repo = 'stackql-provider-registry' ;",
"SELECT f.url, f.login FROM ( SELECT clone_url as url, SPLIT_PART(clone_url, '/', -2) as login FROM github.repos.forks WHERE owner = 'stackql' AND repo = 'stackql' ) f LEFT OUTER JOIN github.activity.repo_stargazers s ON s.login = f.login WHERE owner = 'stackql' AND repo = 'stackql' ;",
"select u1.UserName, u.UserId, u.Arn, u1.region from ( select Arn, UserName, UserId from aws.iam.users where region = 'us-east-1' ) u inner join aws.iam.users u1 on u1.Arn = u.Arn where region = 'us-east-1' order by u1.UserName desc;",
],
"default": "show providers;"
},
Expand Down
13 changes: 13 additions & 0 deletions internal/stackql/astanalysis/annotatedast/annotated_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type AnnotatedAst interface {
SetSelectIndirect(selNode *sqlparser.Select, indirect astindirect.Indirect)
GetExecIndirect(selNode *sqlparser.Exec) (astindirect.Indirect, bool)
SetExecIndirect(selNode *sqlparser.Exec, indirect astindirect.Indirect)
GetSubequeryTableCount() int
}

type standardAnnotatedAst struct {
Expand All @@ -69,6 +70,18 @@ func (aa *standardAnnotatedAst) GetExecIndirect(selNode *sqlparser.Exec) (astind
return rv, ok
}

func (aa *standardAnnotatedAst) GetSubequeryTableCount() int {
var rv int
for _, indirect := range aa.tableIndirects {
switch t := indirect.(type) {
case *astindirect.Subquery:
rv += t.GetCtrlColumnRepeats()
default:
}
}
return rv
}

func (aa *standardAnnotatedAst) SetExecIndirect(selNode *sqlparser.Exec, indirect astindirect.Indirect) {
aa.execIndirectCache[selNode] = indirect
}
Expand Down
12 changes: 6 additions & 6 deletions internal/stackql/astindirect/indirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
)

var (
_ Indirect = &view{}
_ Indirect = &subquery{}
_ Indirect = &materializedView{}
_ Indirect = &View{}
_ Indirect = &Subquery{}
_ Indirect = &MaterializedView{}
)

type IndirectType int
Expand All @@ -33,15 +33,15 @@ const (
)

func NewViewIndirect(viewDTO internaldto.RelationDTO) (Indirect, error) {
rv := &view{
rv := &View{
viewDTO: viewDTO,
underlyingSymbolTable: symtab.NewHashMapTreeSymTab(),
}
return rv, nil
}

func NewMaterializedViewIndirect(viewDTO internaldto.RelationDTO, sqlSystem sql_system.SQLSystem) (Indirect, error) {
rv := &materializedView{
rv := &MaterializedView{
viewDTO: viewDTO,
underlyingSymbolTable: symtab.NewHashMapTreeSymTab(),
sqlSystem: sqlSystem,
Expand Down Expand Up @@ -89,7 +89,7 @@ func NewSubqueryIndirect(subQueryDTO internaldto.SubqueryDTO) (Indirect, error)
if subQueryDTO == nil {
return nil, fmt.Errorf("cannot accomodate nil subquery")
}
rv := &subquery{
rv := &Subquery{
subQueryDTO: subQueryDTO,
subQuery: subQueryDTO.GetSubquery(),
selectStmt: subQueryDTO.GetSubquery().Select,
Expand Down
46 changes: 23 additions & 23 deletions internal/stackql/astindirect/materialized_view_indirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,47 @@ import (
"github.com/stackql/stackql/internal/stackql/typing"
)

type materializedView struct {
type MaterializedView struct {
viewDTO internaldto.RelationDTO
selectStmt sqlparser.SelectStatement
paramCollection internaldto.TableParameterCollection
sqlSystem sql_system.SQLSystem
underlyingSymbolTable symtab.SymTab
}

func (v *materializedView) GetType() IndirectType {
func (v *MaterializedView) GetType() IndirectType {
return MaterializedViewType
}

func (v *materializedView) GetAssignedParameters() (internaldto.TableParameterCollection, bool) {
func (v *MaterializedView) GetAssignedParameters() (internaldto.TableParameterCollection, bool) {
return v.paramCollection, v.paramCollection != nil
}

func (v *materializedView) SetAssignedParameters(paramCollection internaldto.TableParameterCollection) {
func (v *MaterializedView) SetAssignedParameters(paramCollection internaldto.TableParameterCollection) {
v.paramCollection = paramCollection
}

func (v *materializedView) GetUnderlyingSymTab() symtab.SymTab {
func (v *MaterializedView) GetUnderlyingSymTab() symtab.SymTab {
return v.underlyingSymbolTable
}

func (v *materializedView) SetUnderlyingSymTab(symbolTable symtab.SymTab) {
func (v *MaterializedView) SetUnderlyingSymTab(symbolTable symtab.SymTab) {
v.underlyingSymbolTable = symbolTable
}

func (v *materializedView) GetName() string {
func (v *MaterializedView) GetName() string {
return v.viewDTO.GetName()
}

func (v *materializedView) GetColumns() []typing.ColumnMetadata {
func (v *MaterializedView) GetColumns() []typing.ColumnMetadata {
return nil
}

func (v *materializedView) GetRelationalColumns() []typing.RelationalColumn {
func (v *MaterializedView) GetRelationalColumns() []typing.RelationalColumn {
return v.viewDTO.GetColumns()
}

func (v *materializedView) GetRelationalColumnByIdentifier(name string) (typing.RelationalColumn, bool) {
func (v *MaterializedView) GetRelationalColumnByIdentifier(name string) (typing.RelationalColumn, bool) {
for _, col := range v.viewDTO.GetColumns() {
if col.GetName() == name {
return col, true
Expand All @@ -65,47 +65,47 @@ func (v *materializedView) GetRelationalColumnByIdentifier(name string) (typing.
return nil, false
}

func (v *materializedView) GetOptionalParameters() map[string]openapistackql.Addressable {
func (v *MaterializedView) GetOptionalParameters() map[string]openapistackql.Addressable {
return nil
}

func (v *materializedView) GetRequiredParameters() map[string]openapistackql.Addressable {
func (v *MaterializedView) GetRequiredParameters() map[string]openapistackql.Addressable {
return nil
}

func (v *materializedView) GetColumnByName(_ string) (typing.ColumnMetadata, bool) {
func (v *MaterializedView) GetColumnByName(_ string) (typing.ColumnMetadata, bool) {
return nil, false
}

func (v *materializedView) SetSelectContext(_ drm.PreparedStatementCtx) {
func (v *MaterializedView) SetSelectContext(_ drm.PreparedStatementCtx) {
//
}

func (v *materializedView) GetSelectContext() drm.PreparedStatementCtx {
func (v *MaterializedView) GetSelectContext() drm.PreparedStatementCtx {
return nil
}

func (v *materializedView) GetTables() sqlparser.TableExprs {
func (v *MaterializedView) GetTables() sqlparser.TableExprs {
return nil
}

func (v *materializedView) getAST() (sqlparser.Statement, error) {
func (v *MaterializedView) getAST() (sqlparser.Statement, error) {
sqlParser, err := parser.NewParser()
if err != nil {
return nil, err
}
return sqlParser.ParseQuery(v.viewDTO.GetRawQuery())
}

func (v *materializedView) GetSelectAST() sqlparser.SelectStatement {
func (v *MaterializedView) GetSelectAST() sqlparser.SelectStatement {
return v.selectStmt
}

func (v *materializedView) GetSelectionCtx() (drm.PreparedStatementCtx, error) {
func (v *MaterializedView) GetSelectionCtx() (drm.PreparedStatementCtx, error) {
return nil, fmt.Errorf("materialized view does not have select context")
}

func (v *materializedView) Parse() error {
func (v *MaterializedView) Parse() error {
parseResult, err := v.getAST()
if err != nil {
return err
Expand All @@ -114,7 +114,7 @@ func (v *materializedView) Parse() error {
case *sqlparser.DDL:
v.selectStmt = pr.SelectStatement
default:
return fmt.Errorf("materializedView of type '%T' not yet supported", pr)
return fmt.Errorf("MaterializedView of type '%T' not yet supported", pr)
}
for _, col := range v.viewDTO.GetColumns() {
colID := col.GetIdentifier()
Expand All @@ -132,10 +132,10 @@ func (v *materializedView) Parse() error {
return nil
}

func (v *materializedView) GetTranslatedDDL() (string, bool) {
func (v *MaterializedView) GetTranslatedDDL() (string, bool) {
return "", false
}

func (v *materializedView) GetLoadDML() (string, bool) {
func (v *MaterializedView) GetLoadDML() (string, bool) {
return "", false
}
46 changes: 25 additions & 21 deletions internal/stackql/astindirect/subquery_indirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stackql/stackql/internal/stackql/typing"
)

type subquery struct {
type Subquery struct {
subQueryDTO internaldto.SubqueryDTO
subQuery *sqlparser.Subquery
selectStmt sqlparser.SelectStatement
Expand All @@ -18,51 +18,55 @@ type subquery struct {
underlyingSymbolTable symtab.SymTab
}

func (v *subquery) GetType() IndirectType {
func (v *Subquery) GetType() IndirectType {
return SubqueryType
}

func (v *subquery) GetAssignedParameters() (internaldto.TableParameterCollection, bool) {
func (v *Subquery) GetAssignedParameters() (internaldto.TableParameterCollection, bool) {
return v.paramCollection, v.paramCollection != nil
}

func (v *subquery) SetAssignedParameters(paramCollection internaldto.TableParameterCollection) {
func (v *Subquery) SetAssignedParameters(paramCollection internaldto.TableParameterCollection) {
v.paramCollection = paramCollection
}

func (v *subquery) GetRelationalColumns() []typing.RelationalColumn {
func (v *Subquery) GetRelationalColumns() []typing.RelationalColumn {
return nil
}

func (v *subquery) GetRelationalColumnByIdentifier(_ string) (typing.RelationalColumn, bool) {
func (v *Subquery) GetRelationalColumnByIdentifier(_ string) (typing.RelationalColumn, bool) {
return nil, false
}

func (v *subquery) GetUnderlyingSymTab() symtab.SymTab {
func (v *Subquery) GetUnderlyingSymTab() symtab.SymTab {
return v.underlyingSymbolTable
}

func (v *subquery) SetUnderlyingSymTab(symbolTable symtab.SymTab) {
func (v *Subquery) SetUnderlyingSymTab(symbolTable symtab.SymTab) {
v.underlyingSymbolTable = symbolTable
}

func (v *subquery) GetName() string {
func (v *Subquery) GetName() string {
return v.subQueryDTO.GetAlias().GetRawVal()
}

func (v *subquery) GetColumns() []typing.ColumnMetadata {
func (v *Subquery) GetCtrlColumnRepeats() int {
return v.selCtx.GetCtrlColumnRepeats()
}

func (v *Subquery) GetColumns() []typing.ColumnMetadata {
return v.selCtx.GetNonControlColumns()
}

func (v *subquery) GetOptionalParameters() map[string]openapistackql.Addressable {
func (v *Subquery) GetOptionalParameters() map[string]openapistackql.Addressable {
return nil
}

func (v *subquery) GetRequiredParameters() map[string]openapistackql.Addressable {
func (v *Subquery) GetRequiredParameters() map[string]openapistackql.Addressable {
return nil
}

func (v *subquery) GetColumnByName(name string) (typing.ColumnMetadata, bool) {
func (v *Subquery) GetColumnByName(name string) (typing.ColumnMetadata, bool) {
for _, col := range v.selCtx.GetNonControlColumns() {
if col.GetIdentifier() == name {
return col, true
Expand All @@ -71,34 +75,34 @@ func (v *subquery) GetColumnByName(name string) (typing.ColumnMetadata, bool) {
return nil, false
}

func (v *subquery) SetSelectContext(selCtx drm.PreparedStatementCtx) {
func (v *Subquery) SetSelectContext(selCtx drm.PreparedStatementCtx) {
v.selCtx = selCtx
}

func (v *subquery) GetSelectContext() drm.PreparedStatementCtx {
func (v *Subquery) GetSelectContext() drm.PreparedStatementCtx {
return v.selCtx
}

func (v *subquery) GetTables() sqlparser.TableExprs {
func (v *Subquery) GetTables() sqlparser.TableExprs {
return nil
}

func (v *subquery) GetSelectAST() sqlparser.SelectStatement {
func (v *Subquery) GetSelectAST() sqlparser.SelectStatement {
return v.selectStmt
}

func (v *subquery) GetSelectionCtx() (drm.PreparedStatementCtx, error) {
func (v *Subquery) GetSelectionCtx() (drm.PreparedStatementCtx, error) {
return v.selCtx, nil
}

func (v *subquery) Parse() error {
func (v *Subquery) Parse() error {
return nil
}

func (v *subquery) GetTranslatedDDL() (string, bool) {
func (v *Subquery) GetTranslatedDDL() (string, bool) {
return "", false
}

func (v *subquery) GetLoadDML() (string, bool) {
func (v *Subquery) GetLoadDML() (string, bool) {
return "", false
}
Loading

0 comments on commit 8b6722b

Please sign in to comment.