Skip to content

Commit

Permalink
feat: support sets in partial evaluation (#13)
Browse files Browse the repository at this point in the history
Support sets in partial evaluation and translation to sql.
  • Loading branch information
tanmaykm authored May 2, 2024
1 parent 223345f commit 7b014b1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OpenPolicyAgent"
uuid = "8f257efb-743c-4ebc-8197-d291a1f743b4"
authors = ["JuliaHub Inc.", "Tanmay Mohapatra <tanmaykm@gmail.com>"]
version = "0.3.1"
version = "0.3.2"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function visit(visitor::SQLVisitor, ref::AST.OPARef)
return nothing
end

function visit(visitor::SQLVisitor, arr::AST.OPAArray)
function visit(visitor::SQLVisitor, arr::Union{AST.OPAArray,AST.OPASet})
push!(visitor.result_stack, string("(", join([walk(visitor, v) for v in arr.value], ", "), ")"))
return nothing
end
Expand Down
2 changes: 1 addition & 1 deletion test/sql_translate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function to_sql(ref::OPARef)
end
end

function to_sql(arr::OPAArray)
function to_sql(arr::Union{OPAArray,OPASet})
return string("(", join(to_sql.(arr.value), ", "), ")")
end

Expand Down
19 changes: 19 additions & 0 deletions test/test_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ const PARTIAL_COMPILE_CASES = [
unknowns = ["data.reports"],
sql = "( ( public.juliahub_reports.clearance_level - 4 ) >= 0 )",
),
(
policy = """package example
import future.keywords.in
allow {
data.reports[_].category in {"public"}
}
""",
query = "data.example.allow == true",
input = Dict{String,Any}(
"subject" => Dict{String,Any}(
"clearance_level" => 4
)
),
options = Dict{String,Any}(
"disableInlining" => []
),
unknowns = ["data.reports"],
sql = "( public.juliahub_reports.category in ('public') )",
),
]

const EXAMPLE_QUERY = """input.servers[i].ports[_] = "p2"; input.servers[i].name = name"""
Expand Down

2 comments on commit 7b014b1

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105996

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" 7b014b142328b74368139a00f8dde6668ad4e29d
git push origin v0.3.2

Please sign in to comment.