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

Add bulk prefix and suffix string collection matching. #4997

Merged
merged 1 commit into from
Aug 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 45 additions & 1 deletion ast/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ var DefaultBuiltins = [...]*Builtin{
Union,

// Strings
AnyPrefixMatch,
AnySuffixMatch,
Concat,
FormatInt,
IndexOf,
Expand Down Expand Up @@ -269,7 +271,7 @@ var DefaultBuiltins = [...]*Builtin{
// UUIDs
UUIDRFC4122,

//SemVers
// SemVers
SemVerIsValid,
SemVerCompare,

Expand Down Expand Up @@ -959,6 +961,48 @@ The set of regex symbols is limited for this builtin: only ` + "`.`, `*`, `+`, `
*/
var stringsCat = category("strings")

var AnyPrefixMatch = &Builtin{
Name: "strings.any_prefix_match",
Description: "Returns true if any of the search strings begins with any of the base strings.",
Decl: types.NewFunction(
types.Args(
types.Named("search", types.NewAny(
types.S,
types.NewSet(types.S),
types.NewArray(nil, types.S),
)).Description("search string(s)"),
types.Named("base", types.NewAny(
types.S,
types.NewSet(types.S),
types.NewArray(nil, types.S),
)).Description("base string(s)"),
),
types.Named("result", types.B).Description("result of the prefix check"),
anderseknert marked this conversation as resolved.
Show resolved Hide resolved
),
Categories: stringsCat,
}

var AnySuffixMatch = &Builtin{
Name: "strings.any_suffix_match",
Description: "Returns true if any of the search strings ends with any of the base strings.",
Decl: types.NewFunction(
types.Args(
types.Named("search", types.NewAny(
types.S,
types.NewSet(types.S),
types.NewArray(nil, types.S),
)).Description("search string(s)"),
types.Named("base", types.NewAny(
types.S,
types.NewSet(types.S),
types.NewArray(nil, types.S),
)).Description("base string(s)"),
),
types.Named("result", types.B).Description("result of the suffix check"),
),
Categories: stringsCat,
}

var Concat = &Builtin{
Name: "concat",
Description: "Joins a set or array of strings with a delimiter.",
Expand Down
52 changes: 52 additions & 0 deletions builtin_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
"split",
"sprintf",
"startswith",
"strings.any_prefix_match",
"strings.any_suffix_match",
"strings.replace_n",
"strings.reverse",
"substring",
Expand Down Expand Up @@ -10973,6 +10975,56 @@
},
"wasm": true
},
"strings.any_prefix_match": {
"args": [
{
"description": "search string(s)",
"name": "search",
"type": "any\u003cstring, array[string], set[string]\u003e"
},
{
"description": "base string(s)",
"name": "base",
"type": "any\u003cstring, array[string], set[string]\u003e"
}
],
"available": [
"edge"
],
"description": "Returns true if any of the search strings begins with any of the base strings.",
"introduced": "edge",
"result": {
"description": "result of the prefix check",
"name": "result",
"type": "boolean"
},
"wasm": false
},
"strings.any_suffix_match": {
"args": [
{
"description": "search string(s)",
"name": "search",
"type": "any\u003cstring, array[string], set[string]\u003e"
},
{
"description": "base string(s)",
"name": "base",
"type": "any\u003cstring, array[string], set[string]\u003e"
}
],
"available": [
"edge"
],
"description": "Returns true if any of the search strings ends with any of the base strings.",
"introduced": "edge",
"result": {
"description": "result of the suffix check",
"name": "result",
"type": "boolean"
},
"wasm": false
},
"strings.replace_n": {
"args": [
{
Expand Down
102 changes: 102 additions & 0 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,108 @@
"type": "function"
}
},
{
"name": "strings.any_prefix_match",
"decl": {
"args": [
{
"of": [
{
"type": "string"
},
{
"dynamic": {
"type": "string"
},
"type": "array"
},
{
"of": {
"type": "string"
},
"type": "set"
}
],
"type": "any"
},
{
"of": [
{
"type": "string"
},
{
"dynamic": {
"type": "string"
},
"type": "array"
},
{
"of": {
"type": "string"
},
"type": "set"
}
],
"type": "any"
}
],
"result": {
"type": "boolean"
},
"type": "function"
}
},
{
"name": "strings.any_suffix_match",
"decl": {
"args": [
{
"of": [
{
"type": "string"
},
{
"dynamic": {
"type": "string"
},
"type": "array"
},
{
"of": {
"type": "string"
},
"type": "set"
}
],
"type": "any"
},
{
"of": [
{
"type": "string"
},
{
"dynamic": {
"type": "string"
},
"type": "array"
},
{
"of": {
"type": "string"
},
"type": "set"
}
],
"type": "any"
}
],
"result": {
"type": "boolean"
},
"type": "function"
}
},
{
"name": "strings.replace_n",
"decl": {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
github.com/tchap/go-patricia/v2 v2.3.1
github.com/vektah/gqlparser/v2 v2.4.6
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
github.com/yashtewari/glob-intersection v0.1.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,10 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tchap/go-patricia v2.2.6+incompatible h1:JvoDL7JSoIP2HDE8AbDH3zC8QBPxmzYe32HHy5yQ+Ck=
github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
github.com/tchap/go-patricia/v2 v2.3.1 h1:6rQp39lgIYZ+MHmdEq4xzuk1t7OdC35z/xm0BGhTkes=
github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
13 changes: 13 additions & 0 deletions internal/compiler/wasm/opa/callgraph.csv
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,19 @@ opa_sets_union,opa_value_type
opa_sets_union,opa_set
opa_sets_union,opa_set_add
opa_sets_union,opa_value_free
opa_strings_any_prefix_match,opa_value_type
opa_strings_any_prefix_match,opa_value_iter
opa_strings_any_prefix_match,opa_value_get
opa_strings_any_prefix_match,opa_strings_any_prefix_match
opa_strings_any_prefix_match,opa_value_free
opa_strings_any_prefix_match,opa_strncmp
opa_strings_any_prefix_match,opa_boolean
opa_strings_any_suffix_match,opa_value_type
opa_strings_any_suffix_match,opa_value_iter
opa_strings_any_suffix_match,opa_value_get
opa_strings_any_suffix_match,opa_strings_any_suffix_match
opa_strings_any_suffix_match,opa_value_free
opa_strings_any_suffix_match,opa_boolean
opa_strings_concat,opa_value_type
opa_strings_concat,opa_malloc
opa_strings_concat,memcpy
Expand Down
5 changes: 3 additions & 2 deletions internal/compiler/wasm/opa/opa.go

Large diffs are not rendered by default.

Binary file modified internal/compiler/wasm/opa/opa.wasm
Binary file not shown.