<commit_before>package main

import (
	"fmt"
	"sort"
	"strings"
)

func DisplayForceSobjects(sobjects []ForceSobject) {
	names := make([]string, len(sobjects))
	for i, sobject := range sobjects {
		names[i] = sobject["name"].(string)
	}
	sort.Strings(names)
	for _, name := range names {
		fmt.Println(name)
	}
}

func DisplayForceRecords(records []ForceRecord) {
	var keys []string
	if len(records) > 0 {
		for key, _ := range records[0] {
			if key != "attributes" {
				keys = append(keys, key)
			}
		}
		lengths := make([]int, len(keys))
		separators := make([]string, len(keys))
		for i, key := range keys {
			lengths[i] = len(key)
			for _, record := range records {
				l := len(fmt.Sprintf("%v", record[key]))
				if l > lengths[i] {
					lengths[i] = l
				}
			}
			separators[i] = strings.Repeat("-", lengths[i]+2)
		}
		formatter_parts := make([]string, len(keys))
		for i, length := range lengths {
			formatter_parts[i] = fmt.Sprintf(" %%-%ds ", length)
		}
		formatter := strings.Join(formatter_parts, "|")
		fmt.Printf(formatter+"\n", StringSliceToInterfaceSlice(keys)...)
		fmt.Printf(strings.Join(separators, "+") + "\n")
		for _, record := range records {
			values := make([]string, len(keys))
			for i, key := range keys {
				values[i] = fmt.Sprintf("%v", record[key])
			}
			fmt.Printf(formatter+"\n", StringSliceToInterfaceSlice(values)...)
		}
		fmt.Printf(strings.Join(separators, "+") + "\n")
	}
	fmt.Printf(" (%d records)\n", len(records))
}

func DisplayForceRecord(record ForceRecord) {<commit_msg>Add support for parent relationship SOQL queries<commit_after>package main

import (
	"fmt"
	"sort"
	"strings"
)

func DisplayForceSobjects(sobjects []ForceSobject) {
	names := make([]string, len(sobjects))
	for i, sobject := range sobjects {
		names[i] = sobject["name"].(string)
	}
	sort.Strings(names)
	for _, name := range names {
		fmt.Println(name)
	}
}

func DisplayForceRecords(records []ForceRecord) {
	var keys []string
	var flattenedRecords []map[string]interface{}
	for _, record := range records {
		flattenedRecord := FlattenForceRecord(record)
		flattenedRecords = append(flattenedRecords, flattenedRecord)
		for key, _ := range flattenedRecord {
			if !StringSliceContains(keys, key) {
				keys = append(keys, key)
			}
		}
	}
	keys = RemoveTransientRelationships(keys)

	if len(records) > 0 {
		lengths := make([]int, len(keys))
		separators := make([]string, len(keys))
		for i, key := range keys {
			lengths[i] = len(key)
			for _, record := range flattenedRecords {
				l := len(fmt.Sprintf("%v", record[key]))
				if l > lengths[i] {
					lengths[i] = l
				}
			}
			separators[i] = strings.Repeat("-", lengths[i]+2)
		}
		formatter_parts := make([]string, len(keys))
		for i, length := range lengths {
			formatter_parts[i] = fmt.Sprintf(" %%-%ds ", length)
		}
		formatter := strings.Join(formatter_parts, "|")
		fmt.Printf(formatter+"\n", StringSliceToInterfaceSlice(keys)...)
		fmt.Printf(strings.Join(separators, "+") + "\n")
		for _, record := range flattenedRecords {
			values := make([]string, len(keys))
			for i, key := range keys {
				values[i] = fmt.Sprintf("%v", record[key])
			}
			fmt.Printf(formatter+"\n", StringSliceToInterfaceSlice(values)...)
		}
		fmt.Printf(strings.Join(separators, "+") + "\n")
	}
	fmt.Printf(" (%d records)\n", len(records))
}

func FlattenForceRecord(record ForceRecord) map[string]interface{} {
	fieldValues := make(map[string]interface{})
	for key, _ := range record {
		value := record[key]
		if key == "attributes" {
			continue
		} else if relationship, isRelationship := value.(map[string]interface{}); isRelationship {
			for subKey, subValue := range FlattenForceRecord(relationship) {
				fieldValues[key+"."+subKey] = subValue
			}
		} else {
			fieldValues[key] = value
		}
	}
	return fieldValues
}

func StringSliceContains(slice []string, e string) bool {
	for _, s := range slice {
		if s == e {
			return true
		}
	}
	return false
}

func RemoveTransientRelationships(slice []string) []string {
	var transientRelationships []string
	for _, s1 := range slice {
		for _, s2 := range slice {
			if strings.HasPrefix(s1, s2+".") {
				transientRelationships = append(transientRelationships, s2)
			}
		}
	}

	var flattened []string
	for _, s := range slice {
		if !StringSliceContains(transientRelationships, s) {
			flattened = append(flattened, s)
		}
	}
	return flattened
}

func DisplayForceRecord(record ForceRecord) {
{'fraction_non_alphanumeric': 0.16264380780509813, 'fraction_numerical': 0.0022558087074216106, 'mean_word_length': 4.032917139614075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3332136', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1508, 'n_words': 339}