getDistinctTable - Takes input table, and returns new one without any duplicates
()
| 40 | |
| 41 | // getDistinctTable - Takes input table, and returns new one without any duplicates |
| 42 | func (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 |
| 74 | func (table *Table) ToString() string { |
no test coverage detected