Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the date / Timestamp type range in the yaml config file #11

Open
ludsh2000 opened this issue Jan 10, 2023 · 1 comment
Open

Comments

@ludsh2000
Copy link

How to set the date / Timestamp type range in the yaml config file, is there some sample?
The target table column type is DATE or TimeStamp, I would like to generate the random value but between "2022-01-01" and "2022-12-31" or "2022-01-01:00-00-00" and "2022-12-31:00-00-00".

@techno-tanoC
Copy link

techno-tanoC commented Aug 27, 2024

I am facing the same issue. I couldn't figure out how to specify a range for the TIMESTAMP type. As a workaround, I am currently using the following patch.

diff --git a/pkg/generator/data/timestamp.go b/pkg/generator/data/timestamp.go
index e809fdf..1ec8603 100644
--- a/pkg/generator/data/timestamp.go
+++ b/pkg/generator/data/timestamp.go
@@ -48,6 +48,12 @@ func NewTimestampGenerator(cfg Config) (Generator, error) {
                        ret.min = min.Unix()
                case int64:
                        ret.min = min
+               case string:
+                       t, err := time.Parse(time.RFC3339, min)
+                       if err != nil {
+                               return nil, fmt.Errorf("minimum '%s' invalid string for timestamp generator", min)
+                       }
+                       ret.min = t.Unix()
                default:
                        return nil, fmt.Errorf("minimum '%s' of type '%T' invalid for timestamp generator", min, min)
                }
@@ -57,6 +63,12 @@ func NewTimestampGenerator(cfg Config) (Generator, error) {
                        ret.max = max.Unix()
                case int64:
                        ret.max = max
+               case string:
+                       t, err := time.Parse(time.RFC3339, max)
+                       if err != nil {
+                               return nil, fmt.Errorf("maximum '%s' invalid string for timestamp generator", max)
+                       }
+                       ret.max = t.Unix()
                default:
                        return nil, fmt.Errorf("maximum '%s' of type '%T' invalid for timestamp generator", max, max)
                }

Now, you can set a range like this:

tables:
  - name: users
    columns:
      - name: created_at
        generator:
          range:
            minimum: 2022-01-01T00:00:00Z
            maximum: 2022-12-31T00:00:00Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants