package compute
import (
"fmt"
"strings"
"github.com/xlab/treeprint"
"github.com/daviszhen/plan/pkg/storage"
)
func WriteMapTree[K comparable, V any](tree treeprint.Tree, m map[K]V) {
for k, v := range m {
tree.AddNode(fmt.Sprintf("%v : %v", k, v))
}
}
func WriteExprsTree(tree treeprint.Tree, exprs []*Expr) {
for i, e := range exprs {
p := tree.AddBranch(fmt.Sprintf("%d", i))
p.AddNode(e.String())
}
}
func WriteExprTree(tree treeprint.Tree, expr *Expr) {
tree.AddNode(expr.String())
}
func listColDefsToTree(tree treeprint.Tree, colDefs []*storage.ColumnDefinition) {
for _, colDef := range colDefs {
consStrs := make([]string, 0)
for _, cons := range colDef.Constraints {
consStrs = append(consStrs, cons.String())
}
tree.AddMetaNode(
fmt.Sprintf("%v %v", colDef.Name, colDef.Type),
strings.Join(consStrs, ","),
)
}
}