diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0c9f0d1..27a6540 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Change Log
+## Version 1.17.6
+
+Released on Jun 30, 2022
+
+- Fix a bug in REPLACE query. ([GitHub #79](https://github.com/mithrandie/csvq/issues/79))
+
## Version 1.17.5
Released on Jun 26, 2022
diff --git a/docs/changelog.md b/docs/changelog.md
index 72aeb6c..dd60e69 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -5,6 +5,12 @@ title: Change Log - csvq
# Change Log
+## Version 1.17.6
+
+Released on Jun 30, 2022
+
+- Fix a bug in REPLACE query. ([GitHub #79](https://github.com/mithrandie/csvq/issues/79))
+
## Version 1.17.5
Released on Jun 26, 2022
diff --git a/docs/index.md b/docs/index.md
index 20c46e2..22bd4e9 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -13,10 +13,10 @@ In the multiple operations, you can use variables, cursors, temporary tables, an
## Latest Release
-Version 1.17.5
-: Released on Jun 26, 2022
+Version 1.17.6
+: Released on Jun 30, 2022
-
+
file_downloaddownload
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index 992acd7..770eb06 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -6,7 +6,7 @@
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
https://mithrandie.github.io/csvq/
- 2022-06-26T02:35:14+00:00
+ 2022-06-30T13:40:41+00:00
https://mithrandie.github.io/csvq/reference.html
@@ -178,7 +178,7 @@
https://mithrandie.github.io/csvq/changelog.html
- 2022-06-26T02:35:14+00:00
+ 2022-06-30T13:40:41+00:00
https://mithrandie.github.io/csvq/license.html
diff --git a/lib/query/main_test.go b/lib/query/main_test.go
index 9234d44..e8cfc38 100644
--- a/lib/query/main_test.go
+++ b/lib/query/main_test.go
@@ -145,6 +145,7 @@ func setup() {
_ = copyfile(filepath.Join(TestDir, "rename_column.csv"), filepath.Join(TestDataDir, "table1.csv"))
_ = copyfile(filepath.Join(TestDir, "updated_file_1.csv"), filepath.Join(TestDataDir, "table1.csv"))
_ = copyfile(filepath.Join(TestDir, "dup_name.csv"), filepath.Join(TestDataDir, "dup_name.csv"))
+ _ = copyfile(filepath.Join(TestDir, "table_empty.csv"), filepath.Join(TestDataDir, "table_empty.csv"))
_ = copyfile(filepath.Join(TestDir, "table3.tsv"), filepath.Join(TestDataDir, "table3.tsv"))
_ = copyfile(filepath.Join(TestDir, "dup_name.tsv"), filepath.Join(TestDataDir, "dup_name.tsv"))
diff --git a/lib/query/query_test.go b/lib/query/query_test.go
index 5d0b1d1..e590648 100644
--- a/lib/query/query_test.go
+++ b/lib/query/query_test.go
@@ -2426,6 +2426,57 @@ var replaceTests = []struct {
},
}),
},
+ {
+ Name: "Replace Query to Empty Table",
+ Query: parser.ReplaceQuery{
+ Table: parser.Table{Object: parser.Identifier{Literal: "table_empty"}},
+ Fields: []parser.QueryExpression{
+ parser.FieldReference{Column: parser.Identifier{Literal: "column1"}},
+ parser.FieldReference{Column: parser.Identifier{Literal: "column2"}},
+ },
+ Keys: []parser.QueryExpression{
+ parser.FieldReference{Column: parser.Identifier{Literal: "column1"}},
+ },
+ ValuesList: []parser.QueryExpression{
+ parser.RowValue{
+ Value: parser.ValueList{
+ Values: []parser.QueryExpression{
+ parser.NewIntegerValueFromString("4"),
+ parser.NewStringValue("str4"),
+ },
+ },
+ },
+ },
+ },
+ ResultFile: &FileInfo{
+ Path: GetTestFilePath("table_empty.csv"),
+ Delimiter: ',',
+ NoHeader: false,
+ Encoding: text.UTF8,
+ LineBreak: text.LF,
+ ForUpdate: true,
+ },
+ UpdateCount: 1,
+ ViewCache: GenerateViewMap([]*View{
+ {
+ FileInfo: &FileInfo{
+ Path: GetTestFilePath("table_empty.csv"),
+ Delimiter: ',',
+ NoHeader: false,
+ Encoding: text.UTF8,
+ LineBreak: text.LF,
+ ForUpdate: true,
+ },
+ Header: NewHeader("table_empty", []string{"column1", "column2"}),
+ RecordSet: []Record{
+ NewRecord([]value.Primary{
+ value.NewInteger(4),
+ value.NewString("str4"),
+ }),
+ },
+ },
+ }),
+ },
{
Name: "Replace Query For Temporary View",
Query: parser.ReplaceQuery{
diff --git a/lib/query/version.go b/lib/query/version.go
index 4584519..ac7b27d 100644
--- a/lib/query/version.go
+++ b/lib/query/version.go
@@ -1,3 +1,3 @@
package query
-var Version = "v1.17.5"
+var Version = "v1.17.6"
diff --git a/lib/query/view.go b/lib/query/view.go
index f2384db..ee95b5f 100644
--- a/lib/query/view.go
+++ b/lib/query/view.go
@@ -2222,7 +2222,7 @@ func (view *View) replace(ctx context.Context, flags *cmd.Flags, fields []parser
return 0, err
}
- sortValuesInInsertRecords := make([]SortValues, view.RecordLen())
+ sortValuesInInsertRecords := make([]SortValues, len(records))
if err := NewGoroutineTaskManager(len(records), -1, flags.CPU).Run(ctx, func(index int) error {
sortValues := make(SortValues, len(keyIndices))
for j, idx := range keyIndices {
diff --git a/testdata/csv/table_empty.csv b/testdata/csv/table_empty.csv
new file mode 100644
index 0000000..18288ad
--- /dev/null
+++ b/testdata/csv/table_empty.csv
@@ -0,0 +1 @@
+column1,column2