Skip to content

Commit

Permalink
Add IsArray in the Attribute and constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
electron0zero committed Aug 29, 2024
1 parent 1df8375 commit 1371b8f
Show file tree
Hide file tree
Showing 27 changed files with 848 additions and 838 deletions.
8 changes: 6 additions & 2 deletions pkg/traceql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,15 +933,18 @@ type Attribute struct {
Parent bool
Name string
Intrinsic Intrinsic
IsArray bool
}

// NewAttribute creates a new attribute with the given identifier string.
func NewAttribute(att string) Attribute {
// this is same as NewScopedAttribute(AttributeScopeNone, false, att), so maybe we remove this method??
func NewAttribute(att string, isArray bool) Attribute {
return Attribute{
Scope: AttributeScopeNone,
Parent: false,
Name: att,
Intrinsic: IntrinsicNone,
IsArray: isArray,
}
}

Expand Down Expand Up @@ -999,7 +1002,7 @@ func (Attribute) referencesSpan() bool {

// NewScopedAttribute creates a new scopedattribute with the given identifier string.
// this handles parent, span, and resource scopes.
func NewScopedAttribute(scope AttributeScope, parent bool, att string) Attribute {
func NewScopedAttribute(scope AttributeScope, parent bool, att string, isArray bool) Attribute {
intrinsic := IntrinsicNone
// if we are explicitly passed a resource or span scopes then we shouldn't parse for intrinsic
if scope == AttributeScopeNone && !parent {
Expand All @@ -1011,6 +1014,7 @@ func NewScopedAttribute(scope AttributeScope, parent bool, att string) Attribute
Parent: parent,
Name: att,
Intrinsic: intrinsic,
IsArray: isArray,
}
}

Expand Down
46 changes: 23 additions & 23 deletions pkg/traceql/ast_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ func TestSpansetFilter_extractConditions(t *testing.T) {
{
query: `{ .foo = "bar" && "bzz" = .fzz }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("fzz"), OpEqual, NewStaticString("bzz")),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("fzz", false), OpEqual, NewStaticString("bzz")),
},
allConditions: true,
},
{
query: `{ .foo = "bar" || "bzz" = .fzz }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("fzz"), OpEqual, NewStaticString("bzz")),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("fzz", false), OpEqual, NewStaticString("bzz")),
},
allConditions: false,
},
Expand All @@ -37,38 +37,38 @@ func TestSpansetFilter_extractConditions(t *testing.T) {
{
query: `{ .foo = .bar }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpNone),
newCondition(NewAttribute("bar"), OpNone),
newCondition(NewAttribute("foo", false), OpNone),
newCondition(NewAttribute("bar", false), OpNone),
},
allConditions: true,
},
{
query: `{ (.foo = "bar") = true }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("bar")),
},
allConditions: true,
},
{
query: `{ true = (.foo = "bar") }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("bar")),
},
allConditions: true,
},
{
query: `{ (.foo = "bar") = .bar }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("bar"), OpNone),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("bar", false), OpNone),
},
allConditions: true,
},
{
query: `{ .bar = (.foo = "bar") }`,
conditions: []Condition{
newCondition(NewAttribute("bar"), OpNone),
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("bar", false), OpNone),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("bar")),
},
allConditions: true,
},
Expand All @@ -84,24 +84,24 @@ func TestSpansetFilter_extractConditions(t *testing.T) {
{
query: `{ (.foo = "bar") = !.bar }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("bar"), OpNone),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("bar")),
newCondition(NewAttribute("bar", false), OpNone),
},
allConditions: true,
},
{
query: `{ .foo = .bar + 1 }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpNone),
newCondition(NewAttribute("bar"), OpNone),
newCondition(NewAttribute("foo", false), OpNone),
newCondition(NewAttribute("bar", false), OpNone),
},
allConditions: true,
},
{
query: `{ (.foo = 2) && (.bar / 1 > 3) }`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticInt(2)),
newCondition(NewAttribute("bar"), OpNone),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticInt(2)),
newCondition(NewAttribute("bar", false), OpNone),
},
allConditions: true,
},
Expand Down Expand Up @@ -135,14 +135,14 @@ func TestScalarFilter_extractConditions(t *testing.T) {
{
query: `{ .foo = "a" } | count() > 10`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("a")),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("a")),
},
allConditions: false,
},
{
query: `{ .foo = "a" } | avg(duration) > 10ms`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("a")),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("a")),
newCondition(NewIntrinsic(IntrinsicDuration), OpNone),
},
allConditions: false,
Expand Down Expand Up @@ -225,10 +225,10 @@ func TestSelect_extractConditions(t *testing.T) {
{
query: `{ .foo = "a" } | select(resource.service.name)`,
conditions: []Condition{
newCondition(NewAttribute("foo"), OpEqual, NewStaticString("a")),
newCondition(NewAttribute("foo", false), OpEqual, NewStaticString("a")),
},
secondPassConditions: []Condition{
newCondition(NewScopedAttribute(AttributeScopeResource, false, "service.name"), OpNone),
newCondition(NewScopedAttribute(AttributeScopeResource, false, "service.name", false), OpNone),
},
allConditions: false,
},
Expand All @@ -238,7 +238,7 @@ func TestSelect_extractConditions(t *testing.T) {
newCondition(NewIntrinsic(IntrinsicSpanStartTime), OpNone),
},
secondPassConditions: []Condition{
newCondition(NewAttribute("name"), OpNone),
newCondition(NewAttribute("name", false), OpNone),
newCondition(NewIntrinsic(IntrinsicName), OpNone),
},
allConditions: false,
Expand Down
Loading

0 comments on commit 1371b8f

Please sign in to comment.