-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(dsl): Add OpenMetadata DSL module for alert rules and governance #27605
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
Dev0907
wants to merge
1
commit into
open-metadata:main
Choose a base branch
from
Dev0907:feature/openmetadata-dsl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.open-metadata</groupId> | ||
| <artifactId>platform</artifactId> | ||
| <version>1.12.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>openmetadata-dsl</artifactId> | ||
| <name>OpenMetadata DSL</name> | ||
| <description> | ||
| OpenMetadata DSL (Domain-Specific Language) enables users to create sophisticated | ||
| alert rules, governance policies, and automation workflows using natural, expressive syntax. | ||
| </description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.open-metadata</groupId> | ||
| <artifactId>openmetadata-spec</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.open-metadata</groupId> | ||
| <artifactId>openmetadata-service</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.antlr</groupId> | ||
| <artifactId>antlr4-runtime</artifactId> | ||
| <version>4.9.3</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-core</artifactId> | ||
| <version>6.1.14</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
gitar-bot[bot] marked this conversation as resolved.
|
||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
36 changes: 36 additions & 0 deletions
36
openmetadata-dsl/src/main/java/org/openmetadata/dsl/DSLContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright 2026 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.openmetadata.dsl; | ||
|
|
||
| import java.util.List; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import org.openmetadata.schema.EntityInterface; | ||
| import org.openmetadata.schema.type.ChangeEvent; | ||
|
|
||
| /** | ||
| * DSL Evaluation Context - holds the data needed to evaluate DSL expressions. | ||
| */ | ||
| @Data | ||
| @Builder | ||
| public class DSLContext { | ||
|
|
||
| /** The entity being evaluated */ | ||
| private EntityInterface entity; | ||
|
|
||
| /** Change event if this is triggered by an entity change */ | ||
| private ChangeEvent changeEvent; | ||
|
|
||
| /** Additional variables defined in the expression */ | ||
| private List<DSLVariable> variables; | ||
| } |
207 changes: 207 additions & 0 deletions
207
openmetadata-dsl/src/main/java/org/openmetadata/dsl/DSLExamples.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| /* | ||
| * Copyright 2026 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.openmetadata.dsl; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| /** | ||
| * Examples demonstrating OpenMetadata DSL usage. | ||
| */ | ||
| @Slf4j | ||
| public class DSLExamples { | ||
|
|
||
| public static void main(String[] args) { | ||
| log.info("=== OpenMetadata DSL Examples ===\n"); | ||
|
|
||
| OpenMetadataDSL dsl = new OpenMetadataDSL(); | ||
|
|
||
| // Example 1: Basic entity check | ||
| exampleBasicEntityCheck(dsl); | ||
|
|
||
| // Example 2: Data quality monitoring | ||
| exampleDataQualityMonitoring(dsl); | ||
|
|
||
| // Example 3: Compliance check | ||
| exampleComplianceCheck(dsl); | ||
|
|
||
| // Example 4: Security monitoring | ||
| exampleSecurityMonitoring(dsl); | ||
|
|
||
| log.info("\n=== Examples Complete ==="); | ||
| } | ||
|
|
||
| private static void exampleBasicEntityCheck(OpenMetadataDSL dsl) { | ||
| log.info("--- Example 1: Basic Entity Check ---"); | ||
|
|
||
| String rule = "entity.entityType == 'table' AND hasTag('Business-Critical')"; | ||
|
|
||
| DSLContext context = DSLContext.builder() | ||
| .entity(createMockEntity("users", "table")) | ||
| .build(); | ||
|
|
||
| boolean result = dsl.evaluateCondition(rule, context); | ||
| log.info("Rule: {}", rule); | ||
| log.info("Result: {}", result); | ||
| log.info(""); | ||
| } | ||
|
|
||
| private static void exampleDataQualityMonitoring(OpenMetadataDSL dsl) { | ||
| log.info("--- Example 2: Data Quality Monitoring ---"); | ||
|
|
||
| String rule = "entity.entityType == 'table' " + | ||
| "AND contains(entity.service.name, 'prod') " + | ||
| "AND (isEmpty(entity.description) OR length(entity.owners) == 0)"; | ||
|
|
||
| DSLContext context = DSLContext.builder() | ||
| .entity(createMockEntity("orders", "table")) | ||
| .build(); | ||
|
|
||
| boolean result = dsl.evaluateCondition(rule, context); | ||
| log.info("Rule: {}", rule); | ||
| log.info("Result: {}", result); | ||
| log.info(""); | ||
| } | ||
|
|
||
| private static void exampleComplianceCheck(OpenMetadataDSL dsl) { | ||
| log.info("--- Example 3: Compliance & Governance ---"); | ||
|
|
||
| String rule = "contains(entity.name, 'customer') " + | ||
| "AND NOT hasTag('GDPR-Compliant') " + | ||
| "AND entity.entityType == 'table'"; | ||
|
|
||
| DSLContext context = DSLContext.builder() | ||
| .entity(createMockEntity("customer_data", "table")) | ||
| .build(); | ||
|
|
||
| boolean result = dsl.evaluateCondition(rule, context); | ||
| log.info("Rule: {}", rule); | ||
| log.info("Result: {}", result); | ||
| log.info(""); | ||
| } | ||
|
|
||
| private static void exampleSecurityMonitoring(OpenMetadataDSL dsl) { | ||
| log.info("--- Example 4: Security Monitoring ---"); | ||
|
|
||
| String rule = "contains(entity.name, 'ssn') " + | ||
| "AND NOT hasTag('Security-Classified') " + | ||
| "AND entity.entityType == 'table'"; | ||
|
|
||
| DSLContext context = DSLContext.builder() | ||
| .entity(createMockEntity("employee_ssn", "table")) | ||
| .build(); | ||
|
|
||
| boolean result = dsl.evaluateCondition(rule, context); | ||
| log.info("Rule: {}", rule); | ||
| log.info("Result: {}", result); | ||
| log.info(""); | ||
| } | ||
|
|
||
| private static EntityInterface createMockEntity(String name, String type) { | ||
| return new EntityInterface() { | ||
| @Override | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public String getFullyQualifiedName() { | ||
| return "prod." + name; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public org.openmetadata.schema.type.EntityReference getEntityReference() { | ||
| return org.openmetadata.schema.type.EntityReference.builder() | ||
| .id(java.util.UUID.randomUUID()) | ||
| .name(name) | ||
| .type(type) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public org.openmetadata.schema.type.EntityReference getService() { | ||
| return org.openmetadata.schema.type.EntityReference.builder() | ||
| .name("prod_mysql") | ||
| .type("databaseService") | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public java.util.List<org.openmetadata.schema.type.TagLabel> getTags() { | ||
| return java.util.List.of( | ||
| org.openmetadata.schema.type.TagLabel.builder() | ||
| .tagFQN("Business-Critical") | ||
| .build() | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public java.util.List<org.openmetadata.schema.type.EntityReference> getOwners() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Long getUpdatedAt() { | ||
| return System.currentTimeMillis(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getId() { | ||
| return java.util.UUID.randomUUID().toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public org.openmetadata.schema.type.EntityStatus getStatus() { | ||
| return org.openmetadata.schema.type.EntityStatus.ACTIVE; | ||
| } | ||
|
|
||
| @Override | ||
| public org.openmetadata.schema.type.Include getInclude() { | ||
| return org.openmetadata.schema.type.Include.ALL; | ||
| } | ||
|
|
||
| @Override | ||
| public java.util.Map<String, Object> getExtension() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setExtension(java.util.Map<String, Object> extension) {} | ||
|
|
||
| @Override | ||
| public org.openmetadata.schema.type.ChangeDescription getChangeDescription() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setChangeDescription(org.openmetadata.schema.type.ChangeDescription changeDescription) {} | ||
|
|
||
| @Override | ||
| public org.openmetadata.schema.type.Domain getDomain() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setDomain(org.openmetadata.schema.type.Domain domain) {} | ||
|
|
||
| @Override | ||
| public java.util.List<org.openmetadata.schema.type.DataProduct> getDataProducts() { | ||
| return null; | ||
| } | ||
| }; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
openmetadata-dsl/src/main/java/org/openmetadata/dsl/DSLExpression.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright 2026 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
gitar-bot[bot] marked this conversation as resolved.
|
||
| package org.openmetadata.dsl; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| /** | ||
| * Represents a parsed DSL expression node. | ||
| */ | ||
| @Data | ||
| @Builder | ||
| public class DSLExpression { | ||
|
|
||
| public enum ExpressionType { | ||
| BOOLEAN, | ||
| NUMBER, | ||
| STRING, | ||
| FIELD, | ||
| FUNCTION, | ||
| BINARY_EXPR, | ||
| VARIABLE, | ||
| CONDITIONAL | ||
| } | ||
|
|
||
| private ExpressionType type; | ||
| private Boolean booleanValue; | ||
| private Number numberValue; | ||
| private String stringValue; | ||
| private String fieldName; | ||
| private String functionName; | ||
| private List<DSLExpression> arguments; | ||
| private DSLExpression left; | ||
| private DSLExpression right; | ||
| private String operator; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
openmetadata-dsl/pom.xmldeclares dependencies onantlr4-runtime:4.9.3andspring-core:6.1.14, but neither is imported or used anywhere in the module's source code. The parser is hand-written usingjava.util.regex. Additionally, these hardcoded versions conflict with the parent POM's managed versions (antlr:4.13.2,spring:6.2.11), which could cause classpath issues at runtime if the module is included in a larger build. Remove unused dependencies or, if they are planned for future use, at least use${antlr.version}/${spring.version}from the parent POM.Suggested fix:
Was this helpful? React with 👍 / 👎 | Reply
gitar fixto apply this suggestion