Repository: GreenmaskIO/greenmask (go)

Issue:
bug: restoring partitioned tables fails
Given the following configuration file, and the schema from the partitoned table example https://docs.greenmask.io/latest/built_in_transformers/transformation_inheritance/?h=partitioned#example-1-partitioned-tables
```
common:
  tmp_dir: '/tmp'

log:
  level: debug

storage:
  directory:
    path: /tmp/dumps

dump:
  pg_dump_options:
    load-via-partition-root: true

  transformation:
    - schema: public
      name: sales
      apply_for_inherited: true
      transformers:
        - name: RandomDate
          params:
            min: "2023-01-01"
            max: "2023-03-01"
            column: "sale_date"
            engine: "random"
```

`greenmask restore` fails with
```
> fatal error="data stage restoration error: at least one worker exited with error: unable to perform restoration task (worker 1 restoring table \"public\".\"sales\"): cannot open dump file: open /tmp/dumps/1731395980666/3400.dat.gz: no such file or directory" pid=14714
```

It seems the dump only contains data for the partitions, not for the root table.

This is not related to the `apply_for_inherited` configuration option, because the error happens even if I don't apply any transformations to the table.

This regression seems to have appeared in `v0.2.1`

Pull request:
Fix: Corrected naming in template context objects
Closes #238

* Renamed methods according to the documentation: `GetColumnRawValue` is now `GetRawColumnValue`, and `SetColumnRawValue` is now `SetRawColumnValue`.

Patch:
diff --git a/internal/db/postgres/transformers/column_context.go b/internal/db/postgres/transformers/column_context.go
index dbc6f45..a8d1891 100644
--- a/internal/db/postgres/transformers/column_context.go
+++ b/internal/db/postgres/transformers/column_context.go
@@ -49,15 +49,15 @@ func (cc *ColumnContext) GetValue() (any, error) {
 }
 
 func (cc *ColumnContext) GetRawValue() (any, error) {
-	return cc.rc.GetColumnRawValue(cc.columnName)
+	return cc.rc.GetRawColumnValue(cc.columnName)
 }
 
 func (cc *ColumnContext) GetColumnValue(name string) (any, error) {
 	return cc.rc.GetColumnValue(name)
 }
 
-func (cc *ColumnContext) GetColumnRawValue(name string) (any, error) {
-	return cc.rc.GetColumnRawValue(name)
+func (cc *ColumnContext) GetRawColumnValue(name string) (any, error) {
+	return cc.rc.GetRawColumnValue(name)
 }
 
 func (cc *ColumnContext) EncodeValue(v any) (any, error) {
diff --git a/internal/db/postgres/transformers/email.go b/internal/db/postgres/transformers/email.go
index 887f971..7de4799 100644
--- a/internal/db/postgres/transformers/email.go
+++ b/internal/db/postgres/transformers/email.go
@@ -150,7 +150,7 @@ func NewEmailTransformer(ctx context.Context, driver *toolkit.Driver, parameters
 		for _, c := range driver.Table.Columns {
 			funcMap[c.Name] = func(name string) func() (any, error) {
 				return func() (any, error) {
-					return rrctx.GetColumnRawValue(name)
+					return rrctx.GetRawColumnValue(name)
 				}
 			}(c.Name)
 		}
diff --git a/internal/db/postgres/transformers/json_context.go b/internal/db/postgres/transformers/json_context.go
index f26862c..f2d72c4 100644
--- a/internal/db/postgres/transformers/json_context.go
+++ b/internal/db/postgres/transformers/json_context.go
@@ -46,8 +46,8 @@ func (jc *JsonContext) GetColumnValue(name string) (any, error) {
 	return jc.rc.GetColumnValue(name)
 }
 
-func (jc *JsonContext) GetColumnRawValue(name string) (any, error) {
-	return jc.rc.GetColumnRawValue(name)
+func (jc *JsonContext) GetRawColumnValue(name string) (any, error) {
+	return jc.rc.GetRawColumnValue(name)
 }
 
 func (jc *JsonContext) EncodeValueByColumn(name string, v any) (any, error) {
diff --git a/pkg/toolkit/dynamic_parameter.go b/pkg/toolkit/dynamic_parameter.go
index 846ec8d..a6ce34a 100644
--- a/pkg/toolkit/dynamic_parameter.go
+++ b/pkg/toolkit/dynamic_parameter.go
@@ -53,15 +53,15 @@ func (dpc *DynamicParameterContext) GetValue() (any, error) {
 }
 
 func (dpc *DynamicParameterContext) GetRawValue() (any, error) {
-	return dpc.rc.GetColumnRawValue(dpc.column.Name)
+	return dpc.rc.GetRawColumnValue(dpc.column.Name)
 }
 
 func (dpc *DynamicParameterContext) GetColumnValue(name string) (any, error) {
 	return dpc.rc.GetColumnValue(name)
 }
 
-func (dpc *DynamicParameterContext) GetColumnRawValue(name string) (any, error) {
-	return dpc.rc.GetColumnRawValue(name)
+func (dpc *DynamicParameterContext) GetRawColumnValue(name string) (any, error) {
+	return dpc.rc.GetRawColumnValue(name)
 }
 
 func (dpc *DynamicParameterContext) EncodeValue(v any) (any, error) {
diff --git a/pkg/toolkit/expr.go b/pkg/toolkit/expr.go
index 0e3db56..8ead7a4 100644
--- a/pkg/toolkit/expr.go
+++ b/pkg/toolkit/expr.go
@@ -157,7 +157,7 @@ func newRecordContext(driver *Driver) (*RecordContext, []expr.Option) {
 			fmt.Sprintf("__raw__%s", c.Name),
 			func(name string) func(params ...any) (any, error) {
 				return func(params ...any) (any, error) {
-					return rctx.GetColumnRawValue(name)
+					return rctx.GetRawColumnValue(name)
 				}
 			}(c.Name),
 		)
diff --git a/pkg/toolkit/template_record_context.go b/pkg/toolkit/template_record_context.go
index 10daa7f..e3a0da0 100644
--- a/pkg/toolkit/template_record_context.go
+++ b/pkg/toolkit/template_record_context.go
@@ -61,7 +61,7 @@ func (rc *RecordContext) GetColumnValue(name string) (any, error) {
 	return v.Value, nil
 }
 
-func (rc *RecordContext) GetColumnRawValue(name string) (any, error) {
+func (rc *RecordContext) GetRawColumnValue(name string) (any, error) {
 	v, err := rc.record.GetRawColumnValueByName(name)
 	if err != nil {
 		return nil, err
@@ -87,7 +87,7 @@ func (rc *RecordContext) SetColumnValue(name string, v any) (bool, error) {
 	return true, nil
 }
 
-func (rc *RecordContext) SetColumnRawValue(name string, v any) (bool, error) {
+func (rc *RecordContext) SetRawColumnValue(name string, v any) (bool, error) {
 	var val *RawValue
 	switch vv := v.(type) {
 	case NullType:


Test patch:
diff --git a/internal/db/postgres/transformers/template_record_test.go b/internal/db/postgres/transformers/template_record_test.go
index e8b8866..7e739f9 100644
--- a/internal/db/postgres/transformers/template_record_test.go
+++ b/internal/db/postgres/transformers/template_record_test.go
@@ -86,7 +86,7 @@ func TestTemplateRecordTransformer_Transform_date(t *testing.T) {
 func TestTemplateRecordTransformer_Transform_json(t *testing.T) {
 	var columnName = "doc"
 	var template = `
-	  {{ $val := .GetColumnRawValue "doc" }}
+	  {{ $val := .GetRawColumnValue "doc" }}
 	  {{ jsonSet "name" "hello" $val | jsonValidate | .SetColumnValue "doc" }}
 	`