-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from liuxtq/dev-fix-network
feat(interpreter): add tree graph to display the results of the Show Columns cmd
- Loading branch information
Showing
8 changed files
with
477 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
51 changes: 51 additions & 0 deletions
51
v8/src/main/java/org/apache/zeppelin/iginx/util/HighchartsTreeNode.java
This file contains 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,51 @@ | ||
package org.apache.zeppelin.iginx.util; | ||
|
||
public class HighchartsTreeNode { | ||
private String id; | ||
private String name; | ||
private String parent; | ||
private int depth; | ||
|
||
public HighchartsTreeNode(String id, String name, String parent, int depth) { | ||
this.id = id; | ||
this.name = name; | ||
this.depth = depth; | ||
if (depth == 0) { | ||
this.parent = "undefined"; | ||
} else { | ||
this.parent = parent; | ||
} | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getParent() { | ||
return parent; | ||
} | ||
|
||
public void setParent(String parent) { | ||
this.parent = parent; | ||
} | ||
|
||
public int getDepth() { | ||
return depth; | ||
} | ||
|
||
public void setDepth(int depth) { | ||
this.depth = depth; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
v8/src/main/java/org/apache/zeppelin/iginx/util/MultiwayTree.java
This file contains 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,92 @@ | ||
package org.apache.zeppelin.iginx.util; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class MultiwayTree { | ||
public static final String ROOT_NODE_NAME = "数据资产"; | ||
public static final String ROOT_NODE_PATH = "rootId"; | ||
|
||
public TreeNode getRoot() { | ||
return root; | ||
} | ||
|
||
public void setRoot(TreeNode root) { | ||
this.root = root; | ||
} | ||
|
||
TreeNode root; | ||
|
||
public TreeNode insert(TreeNode parenNode, TreeNode newNode) { | ||
TreeNode childNode = findNode(parenNode, newNode); | ||
if (childNode != null) { | ||
System.out.println("node already exists"); | ||
} else { | ||
parenNode.children.add(newNode); | ||
return newNode; | ||
} | ||
return childNode; | ||
} | ||
|
||
// 查找节点操作 | ||
private TreeNode findNode(TreeNode node, TreeNode nodeToFind) { | ||
if (node == null) { | ||
return null; | ||
} | ||
for (TreeNode child : node.children) { | ||
if (child.value.equals(nodeToFind.value)) { | ||
return child; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* 广度优先遍历树,转换为Highcharts节点数组 | ||
* | ||
* @param root | ||
* @param nodeList | ||
*/ | ||
public int traverseToHighchartsTreeNodes(TreeNode root, List<HighchartsTreeNode> nodeList) { | ||
if (root == null) { | ||
return 0; | ||
} | ||
|
||
Queue<TreeNode> queue = new LinkedList<>(); | ||
queue.offer(root); | ||
int depth = 0; | ||
|
||
while (!queue.isEmpty()) { | ||
int levelSize = queue.size(); // 当前层的节点数 | ||
for (int i = 0; i < levelSize; i++) { | ||
TreeNode node = queue.poll(); | ||
nodeList.add( | ||
new HighchartsTreeNode( | ||
node.path, node.value, StringUtils.substringBeforeLast(node.path, "."), depth)); | ||
for (TreeNode child : node.children) { | ||
queue.offer(child); | ||
} | ||
} | ||
depth++; | ||
} | ||
return depth; | ||
} | ||
|
||
public static MultiwayTree getMultiwayTree() { | ||
MultiwayTree tree = new MultiwayTree(); | ||
tree.root = new TreeNode(ROOT_NODE_PATH, ROOT_NODE_NAME); // 初始化 | ||
return tree; | ||
} | ||
|
||
public static void addTreeNodeFromString(MultiwayTree tree, String nodeString) { | ||
String[] nodes = nodeString.split("\\."); | ||
TreeNode newNode = tree.root; | ||
for (int i = 0; i < nodes.length; i++) { | ||
newNode = | ||
tree.insert( | ||
newNode, new TreeNode(StringUtils.join(newNode.path, ".", nodes[i]), nodes[i])); | ||
} | ||
} | ||
} |
Oops, something went wrong.