FindIdentityName Recursively walk a node looking for first Identity Field and combine with outermost expression to create an alias min(year) => "min_year" eq(min(year), max(month)) => "eq_year EXISTS url => "exists_url"
(depth int, node Node, prefix string)
| 444 | // eq(min(year), max(month)) => "eq_year |
| 445 | // EXISTS url => "exists_url" |
| 446 | func FindIdentityName(depth int, node Node, prefix string) string { |
| 447 | |
| 448 | switch n := node.(type) { |
| 449 | case *IdentityNode: |
| 450 | if prefix == "" { |
| 451 | return n.Text |
| 452 | } |
| 453 | return fmt.Sprintf("%s_%s", prefix, n.Text) |
| 454 | case *BinaryNode: |
| 455 | for _, arg := range n.Args { |
| 456 | return FindIdentityName(depth+1, arg, prefix) |
| 457 | } |
| 458 | case *FuncNode: |
| 459 | if depth > 10 { |
| 460 | return "" |
| 461 | } |
| 462 | for _, arg := range n.Args { |
| 463 | if prefix == "" { |
| 464 | prefix = strings.ToLower(n.F.Name) |
| 465 | switch prefix { |
| 466 | case "count": |
| 467 | prefix = "ct" |
| 468 | case "valuect", "mapct": |
| 469 | prefix = "cts" |
| 470 | case "todate", "toint", "tostring", "tofloat": |
| 471 | prefix = "" |
| 472 | default: |
| 473 | // use the name of function |
| 474 | } |
| 475 | } |
| 476 | return FindIdentityName(depth+1, arg, prefix) |
| 477 | } |
| 478 | } |
| 479 | return "" |
| 480 | } |
| 481 | |
| 482 | // ValueTypeFromNode Infer Value type from Node |
| 483 | func ValueTypeFromNode(n Node) value.ValueType { |
no outgoing calls