dumpTable converts the cells in a SQL table into RDF entries, and sends entries to the m.dataWriter
(table string)
| 88 | // dumpTable converts the cells in a SQL table into RDF entries, |
| 89 | // and sends entries to the m.dataWriter |
| 90 | func (m *dumpMeta) dumpTable(table string) error { |
| 91 | tableGuide := m.tableGuides[table] |
| 92 | tableInfo := m.tableInfos[table] |
| 93 | |
| 94 | escapedColNames := escapeColumnNames(tableInfo.columnNames) |
| 95 | |
| 96 | query := fmt.Sprintf(`select %s from %s`, strings.Join(escapedColNames, ","), table) |
| 97 | rows, err := m.sqlPool.Query(query) |
| 98 | if err != nil { |
| 99 | return err |
| 100 | } |
| 101 | defer rows.Close() |
| 102 | |
| 103 | // populate the predNames |
| 104 | for _, column := range tableInfo.columnNames { |
| 105 | tableInfo.predNames = append(tableInfo.predNames, |
| 106 | predicateName(tableInfo, column)) |
| 107 | } |
| 108 | |
| 109 | row := &sqlRow{ |
| 110 | tableInfo: tableInfo, |
| 111 | } |
| 112 | |
| 113 | for rows.Next() { |
| 114 | // step 1: read the row's column values |
| 115 | colValues, err := getColumnValues(tableInfo.columnNames, tableInfo.columnDataTypes, rows) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | row.values = colValues |
| 120 | |
| 121 | // step 2: output the column values in RDF format |
| 122 | row.blankNodeLabel = tableGuide.blankNode.generate(tableInfo, colValues) |
| 123 | m.outputRow(row, tableInfo) |
| 124 | |
| 125 | // step 3: record mappings to the blankNodeLabel so that future tables can look up the |
| 126 | // blankNodeLabel |
| 127 | tableGuide.valuesRecorder.record(tableInfo, colValues, row.blankNodeLabel) |
| 128 | } |
| 129 | |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | // dumpTableConstraints reads data from a table, and then generate RDF entries |
| 134 | // from a row to another row in a foreign table by following columns with foreign key constraints. |
no test coverage detected