0

Question: I am trying SQL query as the image showed below,I want it to be grouped by the same timestamp enter image description here

expected output:

[  
   {
      "tag1": {
        "TagName": "PV1-input-power-L(10W)",
        "Value": 0
       },
       "tag2": {
        "TagName": "Sunshine-Display-Value",
        "Value": 0
       },
       "tag3": {
        "TagName": "TotalEnergy-(100kWh)_1",
        "Value": 0
       },
      "timestamp": "2020-03-27T02:40:18Z"
    }
 ]

sample document:

document structure

tag

3
  • I think this will be easier to accomplish if you will create a sproc. Commented Apr 6, 2020 at 13:25
  • @HasanSavran My Collection is kinda unusal due to IoThub 4K file limit , one document is split into two. As you refer sproc , just wonder if it can make two document into one before any other operation? Commented Apr 7, 2020 at 1:31
  • I don't believe sproc can do that. Commented Apr 7, 2020 at 13:27

1 Answer 1

1

You can use User Defined Functions.

Here is the data from my containers My Data in Cosmos

Here is the function I have created. I named it CustomArray.

function userDefinedFunction(input){
var obj={};
input.forEach(function(element,index){ 
obj["tag"+index] = {
    TagName :element.TagName,
    Value: element.Value
};
}); return obj;}

Here, I run the UDF with my select statement enter image description here

It returns the following data.

enter image description here

Schema is very close to what you are looking for. I think you can make it better by changing some jscript in UDF. I hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.