Description
The NTree function is a hierarchical analysis function that can build and traverse tree structures on all worker machines. The function reads the data only once from the disk and creates the trees in memory.
Usage
td_ntree_mle (
data = NULL,
data.partition.column = "1",
data.order.column = NULL,
root.node = NULL,
node.id = NULL,
parent.id = NULL,
allow.cycles = FALSE,
starts.with = NULL,
mode = NULL,
output = NULL,
max.distance = 5,
logging = FALSE,
result = NULL,
data.sequence.column = NULL
)
Arguments
data |
Required Argument. |
data.partition.column |
Optional Argument. |
data.order.column |
Optional Argument. |
root.node |
Required Argument. |
node.id |
Required Argument. |
parent.id |
Required Argument. |
allow.cycles |
Optional Argument. |
starts.with |
Required Argument. |
mode |
Required Argument. |
output |
Required Argument. |
max.distance |
Optional Argument. |
logging |
Optional Argument. |
result |
Required Argument.
The default value is the string "operation(expression)" without the quotation
marks. For example, PATH(node_name).
Types: character |
data.sequence.column |
Optional Argument. |
Value
Function returns an object of class "td_ntree_mle" which is a named
list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator
using the name: result.
Examples
# Get the current context/connection.
con <- td_get_context()$connection
# Load example data
loadExampleData("ntree_example", "employee_table", "emp_table_by_dept")
# Create object(s) of class "tbl_teradata".
employee_table <- tbl(con, "employee_table")
emp_table_by_dept <- tbl(con, "emp_table_by_dept")
# Example 1 - This example finds the employees who report to employee
# 100 (either directly or indirectly) by traversing the tree
# of employees from employee 100 downward.
td_ntree_out1 <- td_ntree_mle(data=employee_table,
root.node = 'mgr_id is NULL',
node.id='emp_id',
parent.id='mgr_id',
starts.with='emp_id=100',
mode='down',
output='end',
result='PATH(emp_name) AS path'
)
# Example 2 - This example finds the reporting structure by department.
td_ntree_out2 <- td_ntree_mle(data=emp_table_by_dept,
data.partition.column='department',
root.node = "mgr_id = 'none'",
node.id='id',
parent.id='mgr_id',
starts.with='root',
mode='down',
output='all',
result='PATH(name) AS path, PATH(id) as path2'
)