Struggling to get a simpler mapper to work ```sing...
# troubleshooting
r
Struggling to get a simpler mapper to work
Copy code
singer_sdk.exceptions.MapExpressionError: Failed to evaluate simpleeval expressions 1 if company_industry == -1 else company_industry
Thoughts on what looks wrong?
Copy code
stream_maps:
        users:
          company_industry: 1 if company_industry == -1 else company_industry
Trying this in a separate REPL using
simpleeval
, it works fine
Ah, turns out
company_industry
is really
attributes['company_industry']
. Can I use stream_maps on nested fields?
e
Yeah you should able to do
company_industry: "1 if attributes['company_industry'] == -1 else attributes['company_industry']"
. But note that you can't write back to the nested field you're denesting
company_industry
.
r
That’s what I was looking for exactly – writing back to the nested field (I’d rather not mess with the structure). Cheers @Edgar Ramírez (Arch.dev), I’ll have a think on how else to approach this
e
Hmm I think you could use a dict wrapping a list comprehension to preserve the structure:
Copy code
stream_maps:
        users:
          attributes: "dict([(k, 1 if k == 'company_industry' and v == -1 else v) for k, v in attributes.items()])"
r
That’s actually really clever