Skip to content

Commit 046e5a8

Browse files
boolean-comparisons (#653)
* boolean-comparisons Summary: - Support for boolean comparisons. - Added robot test `AWS EC2 Volumes Boolean Predicate Literal and String Equivalence`. * linting-fix
1 parent 93d989b commit 046e5a8

6 files changed

Lines changed: 52 additions & 8 deletions

File tree

internal/stackql/astvisit/param_extract.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,16 @@ func (v *standardParserParamAstVisitor) Visit(node sqlparser.SQLNode) error {
722722
rt,
723723
v.getNextOrdinal(),
724724
))
725+
case sqlparser.BoolVal:
726+
k, err := parserutil.NewUnknownTypeColumnarReference(lt)
727+
if err != nil {
728+
return err
729+
}
730+
v.params.Set(k, parserutil.NewComparisonParameterMetadata(
731+
node,
732+
rt,
733+
v.getNextOrdinal(),
734+
))
725735
case *sqlparser.ColName:
726736
k, err := parserutil.NewUnknownTypeColumnarReference(lt)
727737
if err != nil {

internal/stackql/astvisit/placeholder_param_extract.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,16 @@ func (v *standardParserPlaceholderParamAstVisitor) Visit(node sqlparser.SQLNode)
742742
rt,
743743
0,
744744
))
745+
case sqlparser.BoolVal:
746+
k, err := parserutil.NewUnknownTypeColumnarReference(lt)
747+
if err != nil {
748+
return err
749+
}
750+
v.params.SetIntolerant(k, parserutil.NewComparisonParameterMetadata(
751+
node,
752+
rt,
753+
0,
754+
))
745755
default:
746756
}
747757
default:

internal/stackql/primitivegenerator/statement_analyzer.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"regexp"
7+
"strconv"
78
"strings"
89
"time"
910

@@ -444,9 +445,14 @@ func (pb *standardPrimitiveGenerator) whereComparisonExprCopyAndReWrite(
444445
}
445446
if symTabErr == nil && symTabEntry.In != "server" {
446447
if !(requiredParamPresent || optionalParamPresent) {
448+
rightExpr := expr.Right
449+
if boolVal, boolOk := expr.Right.(sqlparser.BoolVal); boolOk {
450+
// Provider-backed rows are often materialized as text, so normalize bool literals.
451+
rightExpr = &sqlparser.SQLVal{Type: sqlparser.StrVal, Val: []byte(strconv.FormatBool(bool(boolVal)))}
452+
}
447453
return &sqlparser.ComparisonExpr{
448454
Left: expr.Left,
449-
Right: expr.Right,
455+
Right: rightExpr,
450456
Operator: expr.Operator,
451457
Escape: expr.Escape,
452458
}, colName, nil

internal/stackql/util/plan_utility.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ func ExtractSQLNodeParams(
151151
case *sqlparser.SQLVal:
152152
val := string(r.Val)
153153
paramMap[key] = val
154+
case sqlparser.BoolVal:
155+
paramMap[key] = strconv.FormatBool(bool(r))
154156
case *sqlparser.ColName:
155157
kr := r.Name.GetRawVal()
156158
paramMap[key] = kr
@@ -198,6 +200,8 @@ func TransformSQLRawParameters(input map[string]interface{}, ignoreTuples bool)
198200

199201
func extractRaw(raw interface{}, ignoreTuples bool) (interface{}, error) {
200202
switch r := raw.(type) {
203+
case sqlparser.BoolVal:
204+
return strconv.FormatBool(bool(r)), nil
201205
case *sqlparser.SQLVal:
202206
switch r.Type { //nolint:exhaustive // TODO: review
203207
case sqlparser.StrVal:

test/python/stackql_test_tooling/stackql_context.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
_BUILD_MINOR_VERSION = os.environ.get('BUILDMINORVERSION', '1')
2727
_BUILD_PATCH_VERSION = os.environ.get('BUILDPATCHVERSION', '1')
2828

29-
_SHELL_WELCOME_MSG = """
30-
""" + f"stackql Command Shell {_BUILD_MAJOR_VERSION}.{_BUILD_MINOR_VERSION}.{_BUILD_PATCH_VERSION}" + """
31-
Copyright (c) 2021, stackql studios. All rights reserved.
32-
Welcome to the interactive shell for running stackql commands.
33-
---
34-
"""
35-
3629
def get_shell_welcome_stdout(env: str) -> str:
3730
return ''
3831

test/robot/functional/stackql_mocked_from_cmd_line.robot

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@ AWS EC2 Volumes Select Simple
179179
... ${SELECT_AWS_VOLUMES}
180180
... ${SELECT_AWS_VOLUMES_ASC_EXPECTED}
181181

182+
AWS EC2 Volumes Boolean Predicate Literal and String Equivalence
183+
${inputStr} = Catenate
184+
... select volumeId, encrypted, size from aws.ec2.volumes where region = 'ap-southeast-1' and encrypted = false order by volumeId asc;
185+
... select volumeId, encrypted, size from aws.ec2.volumes where region = 'ap-southeast-1' and encrypted = 'false' order by volumeId asc;
186+
${outputStr} = Catenate SEPARATOR=\n
187+
... ${SELECT_AWS_VOLUMES_ASC_EXPECTED}
188+
... ${SELECT_AWS_VOLUMES_ASC_EXPECTED}
189+
Should Stackql Exec Inline Equal Both Streams
190+
... ${STACKQL_EXE}
191+
... ${OKTA_SECRET_STR}
192+
... ${GITHUB_SECRET_STR}
193+
... ${K8S_SECRET_STR}
194+
... ${REGISTRY_NO_VERIFY_CFG_STR}
195+
... ${AUTH_CFG_STR}
196+
... ${SQL_BACKEND_CFG_STR_CANONICAL}
197+
... ${inputStr}
198+
... ${outputStr}
199+
... ${EMPTY}
200+
... stdout=${CURDIR}/tmp/AWS-EC2-Volumes-Boolean-Predicate-Literal-and-String-Equivalence-stdout.tmp
201+
... stderr=${CURDIR}/tmp/AWS-EC2-Volumes-Boolean-Predicate-Literal-and-String-Equivalence-stderr.tmp
202+
182203
AWS IAM Users Select Simple
183204
Should Horrid Query StackQL Inline Equal
184205
... ${STACKQL_EXE}

0 commit comments

Comments
 (0)