-
Notifications
You must be signed in to change notification settings - Fork 208
LIHADOOP-86205: Add view dependency tracking to capture full view lineage chain #577
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
thejdeep
wants to merge
4
commits into
linkedin:master
Choose a base branch
from
thejdeep:LIHADOOP-86205
base: master
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
55e1798
LIHADOOP-86205: Add view dependency tracking to capture full view lin…
thejdeep 588161f
Address comments - add validation for exited view
thejdeep b502f1c
Prevent too many caller interfaces, introduce withViewExpansion
thejdeep 991908e
Store catalog information in deps
thejdeep 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 |
|---|---|---|
|
|
@@ -18,4 +18,5 @@ ligradle | |
| .DS_Store | ||
| *.patch | ||
| */metastore_db | ||
| .pyc | ||
| .pyc | ||
| __pycache__/ | ||
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
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
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
56 changes: 56 additions & 0 deletions
56
coral-common/src/main/java/com/linkedin/coral/common/ViewDependency.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,56 @@ | ||
| /** | ||
| * Copyright 2017-2026 LinkedIn Corporation. All rights reserved. | ||
| * Licensed under the BSD-2 Clause license. | ||
| * See LICENSE in the project root for license information. | ||
| */ | ||
| package com.linkedin.coral.common; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
|
|
||
| /** | ||
| * Represents a single node in the view dependency chain. | ||
| * Names are in "catalog.db.table" format (e.g. "hive.db.v1", "openhouse.db.t1"). | ||
| * For a view "hive.db.v1" that depends on "hive.db.v2" and "openhouse.db.t1", | ||
| * this would be: ViewDependency("hive.db.v1", ["hive.db.v2", "openhouse.db.t1"]) | ||
| */ | ||
| public class ViewDependency { | ||
| private final String viewName; | ||
| private final List<String> dependencies; | ||
|
|
||
| public ViewDependency(String viewName, List<String> dependencies) { | ||
| this.viewName = viewName; | ||
| this.dependencies = dependencies; | ||
| } | ||
|
|
||
| public String getViewName() { | ||
| return viewName; | ||
| } | ||
|
|
||
| public List<String> getDependencies() { | ||
| return dependencies; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| ViewDependency that = (ViewDependency) o; | ||
| return Objects.equals(viewName, that.viewName) && Objects.equals(dependencies, that.dependencies); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(viewName, dependencies); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "ViewDependency{view=" + viewName + ", deps=" + dependencies + "}"; | ||
| } | ||
| } |
87 changes: 87 additions & 0 deletions
87
coral-common/src/main/java/com/linkedin/coral/common/ViewDependencyTracker.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,87 @@ | ||
| /** | ||
| * Copyright 2017-2026 LinkedIn Corporation. All rights reserved. | ||
| * Licensed under the BSD-2 Clause license. | ||
| * See LICENSE in the project root for license information. | ||
| */ | ||
| package com.linkedin.coral.common; | ||
|
|
||
| import java.util.ArrayDeque; | ||
| import java.util.ArrayList; | ||
| import java.util.Deque; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Supplier; | ||
|
|
||
|
|
||
| /** | ||
| * Thread-local tracker that records view to [immediate dependencies] mappings | ||
| * during Calcite view expansion. | ||
| */ | ||
| public class ViewDependencyTracker { | ||
| public static final String HIVE_CATALOG = "hive"; | ||
| public static final String OPENHOUSE_CATALOG = "openhouse"; | ||
|
|
||
| private static final ThreadLocal<ViewDependencyTracker> INSTANCE = | ||
| ThreadLocal.withInitial(ViewDependencyTracker::new); | ||
|
|
||
| private final Map<String, List<String>> viewDeps = new LinkedHashMap<>(); | ||
|
|
||
| private final Deque<String> expansionStack = new ArrayDeque<>(); | ||
|
|
||
| public static ViewDependencyTracker get() { | ||
| return INSTANCE.get(); | ||
| } | ||
|
|
||
| public static void reset() { | ||
| INSTANCE.remove(); | ||
| } | ||
|
|
||
| /** | ||
| * Tracks a view expansion, recording the view as a dependency of any parent view | ||
| * currently being expanded, then executing the supplied work within the scope of | ||
| * this view. The expansion stack is managed automatically. | ||
| */ | ||
| public <T> T withViewExpansion(String catalog, String dbName, String tableName, Supplier<T> work) { | ||
| String qualifiedName = catalog + "." + dbName + "." + tableName; | ||
| if (!expansionStack.isEmpty()) { | ||
| String parent = expansionStack.peek(); | ||
| viewDeps.computeIfAbsent(parent, k -> new ArrayList<>()).add(qualifiedName); | ||
| } | ||
| expansionStack.push(qualifiedName); | ||
| try { | ||
| return work.get(); | ||
| } finally { | ||
| expansionStack.pop(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Records a base table (non-view) as a dependency of the view currently being expanded. | ||
| */ | ||
| public void recordBaseTableDependency(String catalog, String dbName, String tableName) { | ||
| String qualifiedName = catalog + "." + dbName + "." + tableName; | ||
| if (!expansionStack.isEmpty()) { | ||
| String parent = expansionStack.peek(); | ||
| // Skip self-dependency: this occurs when convertView is called on a base table, | ||
| // which pushes the table name onto the stack and then resolves itself. | ||
| if (!qualifiedName.equals(parent)) { | ||
| viewDeps.computeIfAbsent(parent, k -> new ArrayList<>()).add(qualifiedName); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the collected view dependency chain. | ||
| * Each entry represents a view and its immediate dependencies (both views and base tables). | ||
| */ | ||
| public List<ViewDependency> getViewDependencies() { | ||
| List<ViewDependency> result = new ArrayList<>(); | ||
| for (Map.Entry<String, List<String>> entry : viewDeps.entrySet()) { | ||
| if (!entry.getValue().isEmpty()) { | ||
| result.add(new ViewDependency(entry.getKey(), entry.getValue())); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
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
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
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
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.
After each resolution, the state needs to be cleared - not just in tests, but also for 'regular' use
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.
I agree, this method will be invoked from the caller who invokes the rel converter of Coral