Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support sets in partial evaluation #13

Merged
merged 1 commit into from
May 2, 2024
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
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
Loading