Azure ADX - UpdatePolicy fails to insert data

Krishna Kumar, Sai Hariharan 5 Reputation points
2025-04-01T07:02:05.7166667+00:00

Hi Everyone,

 

I believe everyone is doing good and safe.

 

I am facing challenge with ADX. Please find the problem details below.

 

Problem statement: We are unable to insert a result data into a target table from source table using an UpdatePolicy

 

Description: We have written an UpdatePolicy on a table. This UpdatePolicy will accept query parameters as an ADX function. This function returns output result in the form of table. Further, This table output result received should be inserted into target table.

 

Additional Details:

  1. UpdatePolicy helps to update the data into a target table from source table dynamically/automatically.
  2. UpdatePolicy is almost equivalent to Triggers  in SQL Server to do dynamic insert into a target table.
  3. Syntax of UpdatePolicy is as below

  

.alter table TargetTable policy update


[

   {

       "IsEnabled": true,

       "Source": "SourceTable",

       "Query": "SourceTable                     

                 | extend Result = G3MS_ClearAlarm(Id, CountryCode, OccuredTime)

                 | project AlarmId = Result.AlarmId, ClearAlarmId = Result.ClearAlarmId, ClearTime = Result.ClearTime",

       "IsTransactional": true,

       "PropagateIngestionProperties": false

   }

]

 

Error Received when executed

Error during execution of a policy operation: Request is invalid and cannot be processed: Semantic error: SEM0085: Tabular expression is not expected in the current context.

 Error - snapshot

 

If anyone has any suggestions/thoughts on this will be very beneficial to complete the requirement. 

Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
561 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Krishna Kumar, Sai Hariharan 5 Reputation points
    2025-04-07T07:34:56.7166667+00:00

    Atlast i could get the solution from my colleague who was expert in finding solutions. Below is the way i could resolve this problem

    ADX Tables

    .create table ABC(CountryCode: string,  PlatformDeviceType: string, UnitState: string, SystemType: string, AttributeId: int, OccuredTime: datetime, ReceivedTime: datetime, SourceApplicationId: int,AlarmClearAttributes: string) 
    
    
    .create table AlarmClearDetails (AlarmId: string, ClearAlarmId: string, AlarmClearTime: datetime) 
    
    

    ADX Function:

    We need to mention all columns and below is syntax of the function

    .create-or-alter function with (
        docstring = "<Details abouve the function>",
        folder = "<FolderNAME>"
    )
    G3MS_ClearAlarm(input: (
    CountryCode: string,  PlatformDeviceType: string, UnitState: string, SystemType: string, AttributeId: int, OccuredTime: datetime, ReceivedTime: datetime, SourceApplicationId: int,AlarmClearAttributes: string
    ))
    {
    
    //WRITE logic you wanted to do as part of business.
    
    }
    

    ADX Update Policy

    .alter table AlarmClearDetails policy update
    @'[{"Source": "Alarm", "Query": "G3MS_ClearAlarm(ABC)", "IsEnabled": true}]'
    

    In this way we can solve the problem statement i had.


  2. Rakesh Govindula 965 Reputation points Microsoft External Staff
    2025-04-07T10:30:32.5133333+00:00

    Hi @Krishna Kumar, Sai Hariharan,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue:

    Unable to insert a result data into a target table from source table using an UpdatePolicy.

    When using the below code:

    
    alter table TargetTable policy update
    
    Copy
    
    [
    
       {
    
           "IsEnabled": true,
    
           "Source": "SourceTable",
    
           "Query": "SourceTable                     
    
                     | extend Result = G3MS_ClearAlarm(Id, CountryCode, OccuredTime)
    
                     | project AlarmId = Result.AlarmId, ClearAlarmId = Result.ClearAlarmId, ClearTime = Result.ClearTime",
    
           "IsTransactional": true,
    
           "PropagateIngestionProperties": false
    
       }
    
    ]
    
    

    Getting below error while trying the above query:

    
    Error during execution of a policy operation: Request is invalid and cannot be processed: Semantic error: SEM0085: Tabular expression is not expected in the current context.
    
    

    Solution:

    We need to mention all columns and below is syntax of the function

    Creation of ADX Tables:

    
    .create table ABC(CountryCode: string,  PlatformDeviceType: string, UnitState: string, SystemType: string, AttributeId: int, OccuredTime: datetime, ReceivedTime: datetime, SourceApplicationId: int,AlarmClearAttributes: string)
    
    
    
    .create table AlarmClearDetails (AlarmId: string, ClearAlarmId: string, AlarmClearTime: datetime) 
    
    

    ADX Function:

    We need to mention all columns and below is syntax of the function

    
    .create-or-alter function with (
    
        docstring = "<Details abouve the function>",
    
        folder = "<FolderNAME>"
    
    )
    
    G3MS_ClearAlarm(input: (
    
    CountryCode: string,  PlatformDeviceType: string, UnitState: string, SystemType: string, AttributeId: int, OccuredTime: datetime, ReceivedTime: datetime, SourceApplicationId: int,AlarmClearAttributes: string
    
    ))
    
    {
    
    //WRITE logic you wanted to do as part of business.
    
    }
    
    

    ADX Update Policy:

    
    .alter table AlarmClearDetails policy update
    
    @'[{"Source": "Alarm", "Query": "G3MS_ClearAlarm(ABC)", "IsEnabled": true}]'
    
    

    Please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.