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

Record Accessor does not support direct array access notation #9958

Open
niedbalski opened this issue Feb 19, 2025 · 0 comments
Open

Record Accessor does not support direct array access notation #9958

niedbalski opened this issue Feb 19, 2025 · 0 comments

Comments

@niedbalski
Copy link
Collaborator

Bug Report

The Record Accessor API currently cannot handle direct array access patterns like $[0] or $array[0]. It requires the array to be nested within a map first, like $data.array[0].

# This doesn't work
pipeline:
  inputs:
    - name: dummy
      dummy: '{"array": ["a", "b", "c"]}'
  outputs:
    - name: stdout
      match: "*"
      processors:
        logs:
          - name: calyptia
            actions:
              - type: put
                opts:
                  key: "worked"
                  value: "true"
                condition:
                  operator: AND
                  rules:
                    - field: "$array[0]"  # Returns empty
                      operator: eq
                      value: "a"

# This works
pipeline:
  inputs:
    - name: dummy
      dummy: '{"data": {"array": ["a", "b", "c"]}}'
  outputs:
    - name: stdout
      match: "*"
      processors:
        logs:
          - name: calyptia
            actions:
              - type: put
                opts:
                  key: "worked"
                  value: "true"
                condition:
                  operator: AND
                  rules:
                    - field: "$data.array[0]"  # Works correctly
                      operator: eq
                      value: "a"

The record accessor implementation in flb_ra_key_to_value requires a map lookup first through ra_key_val_id before handling any array access. This makes it impossible to access array elements directly without first having a map key.

Proposed Solution:

Modify the record accessor code to:

  1. Check if the root object is an array when direct array access is attempted
  2. Add handling for array access without requiring an initial map lookup
  3. Parse and validate array indices directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant