Skip to content

Commit d128a27

Browse files
committed
Update memory management
1 parent ccb3066 commit d128a27

File tree

11 files changed

+1436
-56
lines changed

11 files changed

+1436
-56
lines changed

builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,10 @@ func (b *DBBuilder) createTableFromXLSXSheet(ctx context.Context, db *sql.DB, ta
626626
}
627627

628628
// Create records for type inference
629-
records := make([]record, len(dataRows))
629+
records := make([]Record, len(dataRows))
630630
for i, row := range dataRows {
631631
// Pad row with empty strings if necessary
632-
paddedRow := make(record, len(headers))
632+
paddedRow := make(Record, len(headers))
633633
for j := range headers {
634634
if j < len(row) {
635635
paddedRow[j] = row[j]
@@ -677,7 +677,7 @@ func (b *DBBuilder) createSQLiteTable(ctx context.Context, db *sql.DB, tableName
677677
}
678678

679679
// insertDataIntoTable inserts records into the specified table
680-
func (b *DBBuilder) insertDataIntoTable(ctx context.Context, db *sql.DB, tableName string, headers []string, records []record) error {
680+
func (b *DBBuilder) insertDataIntoTable(ctx context.Context, db *sql.DB, tableName string, headers []string, records []Record) error {
681681
placeholders := make([]string, len(headers))
682682
for i := range placeholders {
683683
placeholders[i] = "?"

file.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type file struct {
101101
type tableChunk struct {
102102
tableName string
103103
headers header
104-
records []record
104+
records []Record
105105
columnInfo []columnInfo
106106
}
107107

@@ -116,7 +116,7 @@ func (tc *tableChunk) getHeaders() header {
116116
}
117117

118118
// getRecords returns the records in this chunk
119-
func (tc *tableChunk) getRecords() []record {
119+
func (tc *tableChunk) getRecords() []Record {
120120
return tc.records
121121
}
122122

@@ -130,9 +130,11 @@ type chunkProcessor func(chunk *tableChunk) error
130130

131131
// streamingParser represents a parser that can read from io.Reader directly
132132
type streamingParser struct {
133-
fileType FileType
134-
tableName string
135-
chunkSize ChunkSize
133+
fileType FileType
134+
tableName string
135+
chunkSize ChunkSize
136+
memoryPool *MemoryPool // Pool for reusable memory allocations
137+
memoryLimit *MemoryLimit // Configurable memory limits
136138
}
137139

138140
// newFile creates a new file
@@ -471,7 +473,7 @@ func (f *file) parseDelimitedFile(delimiter rune) (*table, error) {
471473
return nil, err
472474
}
473475

474-
tableRecords := make([]record, 0, len(records)-1)
476+
tableRecords := make([]Record, 0, len(records)-1)
475477
for i := 1; i < len(records); i++ {
476478
tableRecords = append(tableRecords, newRecord(records[i]))
477479
}
@@ -542,9 +544,9 @@ func (f *file) parseLTSV() (*table, error) {
542544
header = append(header, key)
543545
}
544546

545-
tableRecords := make([]record, 0, len(records))
547+
tableRecords := make([]Record, 0, len(records))
546548
for _, recordMap := range records {
547-
var row record
549+
var row Record
548550
for _, key := range header {
549551
if val, exists := recordMap[key]; exists {
550552
row = append(row, val)
@@ -624,9 +626,9 @@ func (f *file) parseXLSX() (*table, error) {
624626

625627
// convertXLSXRowsToTable converts XLSX rows to table headers and records
626628
// First row becomes headers, remaining rows become records with padding
627-
func convertXLSXRowsToTable(rows [][]string) (header, []record) {
629+
func convertXLSXRowsToTable(rows [][]string) (header, []Record) {
628630
var headers header
629-
var records []record
631+
var records []Record
630632

631633
// First row as headers
632634
if len(rows) > 0 {
@@ -636,9 +638,9 @@ func convertXLSXRowsToTable(rows [][]string) (header, []record) {
636638

637639
// Remaining rows as records
638640
if len(rows) > 1 {
639-
records = make([]record, len(rows)-1)
641+
records = make([]Record, len(rows)-1)
640642
for i, row := range rows[1:] {
641-
record := make(record, len(headers))
643+
record := make(Record, len(headers))
642644
for j := range headers {
643645
if j < len(row) {
644646
record[j] = row[j]

file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Bob,35,Kyoto`
233233

234234
assert.Len(t, table.getRecords(), 3, "Record count mismatch")
235235

236-
expectedFirstRecord := record{"John", "25", "Tokyo"}
236+
expectedFirstRecord := Record{"John", "25", "Tokyo"}
237237
assert.True(t, table.getRecords()[0].equal(expectedFirstRecord), "First record mismatch")
238238
}
239239

@@ -260,7 +260,7 @@ Bob 35 Kyoto`
260260

261261
assert.Len(t, table.getRecords(), 3, "Record count mismatch")
262262

263-
expectedFirstRecord := record{"John", "25", "Tokyo"}
263+
expectedFirstRecord := Record{"John", "25", "Tokyo"}
264264
assert.True(t, table.getRecords()[0].equal(expectedFirstRecord), "First record mismatch")
265265
}
266266

filesql.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func (f *file) parseParquet() (*table, error) {
469469
}
470470
defer table.Release()
471471

472-
var allRecords []record
472+
var allRecords []Record
473473
var headerSlice header
474474

475475
if table.NumRows() == 0 {
@@ -493,7 +493,7 @@ func (f *file) parseParquet() (*table, error) {
493493
// Convert each row in the batch
494494
numRows := batch.NumRows()
495495
for i := range numRows {
496-
row := make(record, batch.NumCols())
496+
row := make(Record, batch.NumCols())
497497
for j, col := range batch.Columns() {
498498
value := extractValueFromArrowArray(col, i)
499499
row[j] = value
@@ -556,7 +556,7 @@ func (f *file) parseCompressedParquet() (*table, error) {
556556
}
557557
defer table.Release()
558558

559-
var allRecords []record
559+
var allRecords []Record
560560
var headerSlice header
561561

562562
if table.NumRows() == 0 {
@@ -580,7 +580,7 @@ func (f *file) parseCompressedParquet() (*table, error) {
580580
// Convert each row in the batch
581581
numRows := batch.NumRows()
582582
for i := range numRows {
583-
row := make(record, batch.NumCols())
583+
row := make(Record, batch.NumCols())
584584
for j, col := range batch.Columns() {
585585
value := extractValueFromArrowArray(col, i)
586586
row[j] = value

0 commit comments

Comments
 (0)