infobloxopen / seal

Apache License 2.0
16 stars 11 forks source link

Add SQL JSONB-predicate support; refactor SQL API to be more adaptable/flexible #132

Closed rchowinfoblox closed 3 years ago

rchowinfoblox commented 3 years ago
$ go test -v
=== RUN   TestCompileCondition
    sql_condition_test.go:193: Test#0: success: expected error and got err=no prefix condition parse function for IDENT found
    sql_condition_test.go:195: Test#1: success: where=(foobar.qwerty = 'there''s a single-quote in this string')
    sql_condition_test.go:195: Test#2: success: where=(mytable.nbf < 123 AND (mytable.description = 'string with subject. in it'))
    sql_condition_test.go:195: Test#3: success: where=((NOT (mytable.iss = 'string with ctx. in it')) AND (mytable.name ~ '.*goofy.*'))
    sql_condition_test.go:193: Test#4: success: expected error and got err=Replacer 0 on identifier 'ctx.tags["endangered"]' failed: Dialect DialectUnknown does not support JSONB conversion of id: ctx.tags["endangered"]
    sql_condition_test.go:195: Test#5: success: where=(mytable.tags->'endangered' = 'true')
    sql_condition_test.go:195: Test#6: success: where=(mytable.tags->>'endangered' = 'true')
    sql_condition_test.go:193: Test#7: success: expected error and got err=Replacer 0 on identifier 'ctx.tags["zero"]' failed: Index key is not unsigned-integer: ctx.tags["zero"]
    sql_condition_test.go:193: Test#8: success: expected error and got err=no prefix condition parse function for IDENT found
    sql_condition_test.go:193: Test#9: success: expected error and got err=no prefix condition parse function for IDENT found
    sql_condition_test.go:195: Test#10: success: where=(mytable.tags->'endangered' = 123)
    sql_condition_test.go:193: Test#11: success: expected error and got err=no prefix condition parse function for IDENT found
    sql_condition_test.go:193: Test#12: success: expected error and got err=Do not know how to SQL-convert indexed-identifier: mytable.tagz["endangered"]
    sql_condition_test.go:193: Test#13: success: expected error and got err=IN operator not supported yet: (ctx.id in "tag-manage")
    sql_condition_test.go:195: Test#14: success: where=(mytable.tags->'endangered' = 'bar in the barbar')
    sql_condition_test.go:195: Test#15: success: where=(mytable.tags->'endangered' = 271828)
--- PASS: TestCompileCondition (0.00s)
=== RUN   TestJSONBReplacer
    sql_jsonb_test.go:138: Test#0: success: expected error and got err=Dialect DialectUnknown does not support JSONB conversion of id: ctx.tags["endangered"]
    sql_jsonb_test.go:140: Test#1: success: replaced=ctx.tags->'endangered'
    sql_jsonb_test.go:140: Test#2: success: replaced=ctx.tags->'endangered'
    sql_jsonb_test.go:140: Test#3: success: replaced=ctx.tags->>'endangered'
    sql_jsonb_test.go:140: Test#4: success: replaced=ctx.tags?'endangered'
    sql_jsonb_test.go:140: Test#5: success: replaced=ctx.tags->'0'
    sql_jsonb_test.go:140: Test#6: success: replaced=ctx.tags->0
    sql_jsonb_test.go:140: Test#7: success: replaced=ctx.tags->0
    sql_jsonb_test.go:138: Test#8: success: expected error and got err=Index key is not unsigned-integer: ctx.tags["non_numeric_index"]
    sql_jsonb_test.go:138: Test#9: success: expected error and got err=Index key is not unsigned-integer: ctx.tags[non_numeric_index]
    sql_jsonb_test.go:138: Test#10: success: expected error and got err=Index key is not unsigned-integer: ctx.tags[3.14]
    sql_jsonb_test.go:138: Test#11: success: expected error and got err=Index key is not unsigned-integer: ctx.tags[-1]
--- PASS: TestJSONBReplacer (0.00s)
PASS
ok      github.com/infobloxopen/seal/pkg/compiler/sql   0.006s
$ go test -v
=== RUN   TestNextToken
--- PASS: TestNextToken (0.00s)
=== RUN   TestContextToken
--- PASS: TestContextToken (0.00s)
=== RUN   TestNextTokenComment
--- PASS: TestNextTokenComment (0.00s)
=== RUN   TestIsIndexedIdentifier
    lexer_test.go:322: Test#0: success: actual=true
    lexer_test.go:322: Test#1: success: actual=true
    lexer_test.go:322: Test#2: success: actual=false
    lexer_test.go:322: Test#3: success: actual=true
    lexer_test.go:322: Test#4: success: actual=true
    lexer_test.go:322: Test#5: success: actual=false
--- PASS: TestIsIndexedIdentifier (0.00s)
PASS
ok      github.com/infobloxopen/seal/pkg/lexer  0.002s
wplu commented 3 years ago

using mysqltable in test looks weird for DialectPostgres - LGTM otherwise

rchowinfoblox commented 3 years ago

@daniel-garcia requested less cumbersome SQL API, this PR replaced by https://github.com/infobloxopen/seal/pull/134