MCPcopy Index your code
hub / github.com/LissaGreense/GO4SQL / getDistinctTable

Method getDistinctTable

engine/table.go:42–71  ·  view source on GitHub ↗

getDistinctTable - Takes input table, and returns new one without any duplicates

()

Source from the content-addressed store, hash-verified

40
41// getDistinctTable - Takes input table, and returns new one without any duplicates
42func (table *Table) getDistinctTable() *Table {
43 distinctTable := getCopyOfTableWithoutRows(table)
44
45 rowsCount := len(table.Columns[0].Values)
46
47 checksumSet := map[uint32]struct{}{}
48
49 for iRow := 0; iRow < rowsCount; iRow++ {
50
51 mergedColumnValues := ""
52 for iColumn := range table.Columns {
53 fieldValue := table.Columns[iColumn].Values[iRow].ToString()
54 if table.Columns[iColumn].Type.Literal == token.TEXT {
55 fieldValue = "'" + fieldValue + "'"
56 }
57 mergedColumnValues += fieldValue
58 }
59 checksum := adler32.Checksum([]byte(mergedColumnValues))
60
61 _, exist := checksumSet[checksum]
62 if !exist {
63 checksumSet[checksum] = struct{}{}
64 for i, column := range distinctTable.Columns {
65 column.Values = append(column.Values, table.Columns[i].Values[iRow])
66 }
67 }
68 }
69
70 return distinctTable
71}
72
73// ToString - Return string contain all values and Column names in Table
74func (table *Table) ToString() string {

Callers 1

getSelectResponseMethod · 0.95

Calls 2

ToStringMethod · 0.65

Tested by

no test coverage detected