Question about types for Currency Amounts. Questi...
# singer-tap-development
a
Question about types for Currency Amounts. Question about genson. I don't see it creating useful types, am I missing something with the command? or is it simply that that api throws out strings e.g. total_price I'm exploring genson as an alternative to defining customer json schema types, 'total_price' is not acceptable as an IntegerType or NumberType of course
Copy code
genson -i 2 ./orders.json
where orders.json is
Copy code
{
    "orders": [
        {
            "id": 4673406632095,
            "admin_graphql_api_id": "<gid://shopify/Order/4673406632095>",
            "app_id": 580111,
            "browser_ip": "82.9.68.231",
            "buyer_accepts_marketing": false,
            "cancel_reason": null,
            "cancelled_at": null,
            "cart_token": null,
            "checkout_id": 24167827865759,
            "checkout_token": "dc6f6a96f31cf73e99b1f92e243c1279",
            "client_details": {
                "accept_language": "en-GB,en-US;q=0.9,en;q=0.8",
                "browser_height": 948,
                "browser_ip": "82.9.68.231",
                "browser_width": 1848,
                "session_hash": null,
                "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36"
            },
            "closed_at": null,
            "confirmed": true,
            "contact_email": "<mailto:aaron.phethean@gmail.com|aaron.phethean@gmail.com>",
            "created_at": "2022-02-23T19:18:02+00:00",
            "currency": "GBP",
            "current_subtotal_price": "99.00",
            "current_total_tax": "0.00",
            "customer_locale": "en",
            "device_id": null,
            "discount_codes": [],
            "email": "<mailto:aaron.phethean@gmail.com|aaron.phethean@gmail.com>",
            "estimated_taxes": false,
            "financial_status": "paid",
            "fulfillment_status": null,
            "gateway": "bogus",
            "landing_site": "/wallets/checkouts.json",
            "landing_site_ref": null,
            "location_id": null,
            "name": "#1004",
            "note": null,
            "note_attributes": [],
            "number": 4,
            "order_number": 1004,
            "order_status_url": "<https://matatika-shop.myshopify.com/60689580191/orders/67d4bd5f3b8307a6fb9af38ec06f874b/authenticate?key=157b435b68011953a83f87a3f720b685>",
            "original_total_duties_set": null,
            "payment_gateway_names": [
                "bogus"
            ],
            "phone": null,
            "presentment_currency": "GBP",
            "processed_at": "2022-02-23T19:18:00+00:00",
            "processing_method": "direct",
            "reference": null,
            "referring_site": "<https://matatika-shop.myshopify.com/products/tap-google-analytics>",
            "source_identifier": null,
            "source_name": "web",
            "source_url": null,
            "subtotal_price": "99.00",
            "tags": "",
            "total_outstanding": "0.00",
            "total_price": "99.00",
        }
    ]
}
v
You're trying to infer type based on the name of the key it sounds like? Curious but yeah that's not what
genson
does, maybe a tool you could write would do that but you'll have to make assumptions based on names
a
Not trying to do anything clever! Let me ask a simpler question. With the SDK, how would you create a type for currency amounts? Simply TypeNumber? Assuming that's the case, the total_price response is a string, so do I post process the response perhaps?
v
My first thought is a string and convert in the target. My point is in your example a price is
Copy code
"subtotal_price": "99.00"
That's a string
The big question I think you're asking is about Data Mappings like
What's the best representation for currency. It get's fairly curious, as things like NUMBER from Oracle, the tap-oracle tap uses
multipleOf
and other indicators like max / min, but is that actually correct? It depends In your case with the JSON the way it is from your source system I'd pass it as a string.
Have to be very careful with imprecision with floating point stuff if you go that route, and I think I'd only think about that route if I was pulling from a DB with forced typing
a
Thanks Derek. Actually I'm fairly used to working with currency amounts and precision issues. Although it's been awhile…. Not so clear how to do what I want in the SDK / with json schema. Taking the string all the way through to the db and a dbt transform to clean up the types sounds nasty for everyone. I think I'd rather remove the floating point, and document the precision. Have to think more about this.
I think this is what I’m after. Json schema has a ‘format’ that acts as an annotation. So ‘date-time’ and ‘singer.decimal’ will give the target an opportunity to create columns of the right type. https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times. Our before SDK taps must have been doing this somehow…
v
Did you end up going with the string formatter for currency? I personally think String is totally ok in the example you have as the data is coming from the source as a String.
a
In short, I’ve not quite figured it out yet.  I haven’t figured out how to get the decimal type into postgres with the ‘transferwise’ variant.  Bumping this specific question up to the top of this channel.