Skip to content

Clarification request on nested $match usage with $sm and $sme #448

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

Open
malakamgad24 opened this issue May 5, 2025 · 3 comments
Open

Comments

@malakamgad24
Copy link

malakamgad24 commented May 5, 2025

I'm currently implementing support for AAS Query Language and came across a query example whose logic I believe could benefit from further clarification. According to the spec:

If $aas and $sm are used together, only the submodels referenced by the matching $aas are searched by the $sm expression. The same search principle is used when combining $sm and $sme. In such case, only the SubmodelElements which are part of matching submodels by $sm expression are searched by the $sme expression. Several such hierarchical conditions may even be combined by $match expressions.

Here is an example query that seems to follow that pattern, but I find the usage of multiple $match blocks within the same $and a bit unclear:

{
  "$condition": {
    "$and": [
      { 
        "$match": [
          { "$eq": [
              { 
                  "$field": "$sm#idShort"
              },
              { 
                  "$strVal": "TechnicalData"
              }
            ]
          },
          { 
            "$eq": [
              {
                "$field":  "$sme.ProductClassifications[].ProductClassId#value"
              },
              {
                  "$strVal": "27-37-09-05"
              }
            ]
          }
        ]
      },
      { 
        "$match": [
          {
            "$eq": [
              { 
                 "$field": "$sm#idShort" 
              },
              { 
                  "$strVal": "TechnicalData" 
              }
            ]
          },
          {
            "$eq": [
              { 
                 "$field": "$sme#semanticId" 
              },
              { 
                 "$strVal": "0173-1#02-BAF016#006" 
              }
            ]
          },
          {
            "$lt": [
              {
                 "$field": "$sme#value"
              },
              { 
                 "$numVal": 100 
               }
            ]
          }
        ]
      }
    ]
  }
}

My questions:

  1. Since both $match blocks specify the same $sm#idShort ("TechnicalData"), is there a more concise or semantically clearer way to write this query—perhaps combining the $sme conditions under a single $match block?
  2. Would a simplified hierarchical structure without repeating $sm conditions be valid or recommended?
  3. Is the current example the only way to express multiple conditions under the same submodel context?

I’d really appreciate any clarification or pointers.

@sebbader-sap
Copy link
Contributor

Since both $match blocks specify the same $sm#idShort ("TechnicalData"), is there a more concise or semantically clearer way to write this query—perhaps combining the $sme conditions under a single $match block?

I would agree, there are certainly other ways how to formulate this query.

@sebbader-sap
Copy link
Contributor

sebbader-sap commented May 15, 2025

Would a simplified hierarchical structure without repeating $sm conditions be valid or recommended?

Depends on what how you express it. Just be aware that there could be other submodels having a SME at ProductClassifications[].ProductClassId with value = "27-37-09-05" (for instance).

@sebbader-sap
Copy link
Contributor

Is the current example the only way to express multiple conditions under the same submodel context?

No, I am pretty sure there is quite a number of different query formulations that express the same content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants