transferwise / pipelinewise-target-postgres

Singer.io Target for PostgreSQL - PipelineWise compatible
https://transferwise.github.io/pipelinewise/
Other
21 stars 39 forks source link

Integer type not being recognized, everything being forced to Numeric #84

Closed Vaslo closed 2 years ago

Vaslo commented 2 years ago

I am running the spreadsheets-anywhere tap to pull in some CSV data. I am using the Meltano schema override to ensure that a month number is typed as an integer. When your target picks it up, it can't seem to recognize it as one of the other int types and insists on it being a numeric, which is just much too big. Because of this, it creates an extra column with the number as a numeric and leaves my original column as null. I've tried smallint, integer, and bigint types and despite your code having the ability to recognize a maximum, it refuses to do it. Any idea why?

image

This is one of the ways I have set my schema in the tap, for what it's worth:

   schema:
      accounts:
        acct_number:
          type: ["null","string"]
      gl_transactions:
        account:
          type: ["null","string"]
        future:
          type: ["null","string"]
        intercompany_segment:
          type: ["null","string"]
        project:
          type: ["null","string"]  
        effective_year:
          type: ["integer"]
        effective_month:
          type: ["integer"]
Samira-El commented 2 years ago

Using numeric is the expected behavior when the provided schema doesn't contain info on the maximum value of the integer property, so the target errs on the safe side and picks the biggest numeric column. See the code here.

To make the target use small int for the effective_month column, add a maximum property with value <= 32767.

Vaslo commented 2 years ago

Such an easy fix, thanks for the quick reply. I am very new to JSON so didn't quite know how to set it up even after reading the code. I didn't realize I also had to pass a maximum property but now it totally makes sense. This did the trick:

effective_year:
          type: ["integer"]
          maximum: 3000
        effective_month:
          type: ["integer"]
          maximum: 12