-
Notifications
You must be signed in to change notification settings - Fork 27
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
fix: Use empty dict for schema of JSON/JSONB columns #239
fix: Use empty dict for schema of JSON/JSONB columns #239
Conversation
Hmm but you still want the target to know this is an object right? Are you saying all of the values here
Don't currently work? If so that's surprising to me! If they don't work the
Which at least lets the target know that the data should be an object and can be put into the target system (database etc) as a By just returning |
I think it's actually true because according to the spec,
But a JSON/JSONB column can have not just objects, but also arrays, strings and numbers.
I'd want the target to know this can be any JSON stuff. The target should be able to handle that in a similar manner to MeltanoLabs/target-postgres#183. Wdyt @visch? |
Thanks for the lesson in JSON Schema :D I didn't realize that for objects. Implementation makes sense :D |
That was it 🎉 |
9301bf0
to
7281442
Compare
…for-columns-of-type-jsonjsonb
Tried testing this locally and hit an issue
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment on PR
…for-columns-of-type-jsonjsonb
I'm confused though as my local
Trying to understand this maybe it's a local setup thing hmm |
@visch You might need to do |
Since the tests pass this seems good, merging |
Hello @edgarrmondragon, I tried the tap with your new changes but I get an error when extracting a table with a JSONB column containing only arrays of objects : singer_sdk.helpers._typing.EmptySchemaTypeError: Could not detect type from empty type_dict. Did you forget to define a property in the stream schema? Full stack trace
Traceback (most recent call last):
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/bin/tap-postgres", line 8, in <module>
sys.exit(TapPostgres.cli())
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/tap_base.py", line 501, in invoke
tap.sync_all()
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/tap_base.py", line 460, in sync_all
stream.sync()
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/streams/core.py", line 1194, in sync
raise ex
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/streams/core.py", line 1187, in sync
for _ in self._sync_records(context=context):
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/streams/core.py", line 1109, in _sync_records
self._write_record_message(record)
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/streams/core.py", line 851, in _write_record_message
for record_message in self._generate_record_messages(record):
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/streams/core.py", line 827, in _generate_record_messages
record = conform_record_data_types(
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/helpers/_typing.py", line 383, in conform_record_data_types
rec, unmapped_properties = _conform_record_data_types(record, schema, level, None)
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/helpers/_typing.py", line 423, in _conform_record_data_types
if isinstance(elem, list) and is_uniform_list(property_schema):
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/helpers/_typing.py", line 128, in is_uniform_list
is_array_type(property_schema) is True
File "/Users/luis/projects/entropeak/tap-postgres/.meltano/extractors/tap-postgres/venv/lib/python3.10/site-packages/singer_sdk/helpers/_typing.py", line 242, in is_array_type
raise EmptySchemaTypeError
singer_sdk.helpers._typing.EmptySchemaTypeError: Could not detect type from empty type_dict. Did you forget to define a property in the stream schema? My test table can be created and populated with the following SQL script: CREATE TABLE public.test_meltano (
id int4 NOT NULL,
packagings jsonb NOT NULL,
CONSTRAINT test_meltano_pkey PRIMARY KEY (id)
);
INSERT INTO public.test_meltano (id, packagings) VALUES(1, '[{"type": "DEPOT_BAG", "other": "", "quantity": 1}]'::jsonb);
INSERT INTO public.test_meltano (id, packagings) VALUES(2, '[{"type": "BIG_BAG", "other": "", "quantity": 2}, {"type": "DEPOT_BAG", "other": "", "quantity": 1}]'::jsonb);
INSERT INTO public.test_meltano (id, packagings) VALUES(3, '[]'::jsonb); Do you have any clue ? |
@Lawiss Thanks for trying it out. I think we need a guard upstream to end early if the property schema is empty: https://github.com/meltano/sdk/blob/039c06f8b6c07a3cb33028759ca65e806226a6ad/singer_sdk/helpers/_typing.py#L424. I might get to it at some point this week, but feel free to send us a PR is you wish. Another option is to revert this PR and think of a better approach. |
No description provided.