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

Index Children only with based Condition #514

Open
kundankumarcasio opened this issue Dec 26, 2023 · 7 comments
Open

Index Children only with based Condition #514

kundankumarcasio opened this issue Dec 26, 2023 · 7 comments

Comments

@kundankumarcasio
Copy link

PGSync version: latest

Postgres version: 15.2

Elasticsearch/OpenSearch version: 7.17.13

Redis version: 7.2

Python version: 3.8

Problem Description:
I want to index children with given condition
[
{
"database": "databaseName",
"index": "indexName",
"nodes": {
"table": "parentTable",
"columns": [],
"children": [
{
"table": "childTable",
"columns": [],
"relationship": {
"variant": "object",
"type": "one_to_many",
"foreign_key": {
"child": [
"parent_id"
],
"parent": [
"id"
],
"condition": {
"child_column1": "some Value" //need help here
}
}
}
}
]
}
}
]

Equivalent SQL Query:
select * from parentTable join childTable where parentTable.id=childTable.parent_id where child_column1="some Value"

Error Message (if any):



@jvanderen1
Copy link

jvanderen1 commented Jan 5, 2024

I wonder if this could also be achieved within PGSync's plugin API? That way, conditions can be more expressive. Something like:

from pgsync import plugin


class FooPlugin(plugin.Plugin):
    name = 'FooPlugin'

    def transform(self, doc, **kwargs):
       ...

    def should_index(self, doc, **kwargs):
        return doc['childTable']['parent_id'] == 'someValue'

@kundankumarcasio
Copy link
Author

thank you very much.
i will try this.

@jvanderen1
Copy link

I don't think an API exists today for something like this. However, it could be an enhancement.

@kundankumarcasio
Copy link
Author

yes.
Any work around for this ?

@jvanderen1
Copy link

You can probably write a plugin like the following:

from pgsync import plugin


class FooPlugin(plugin.Plugin):
    name = 'FooPlugin'

    def transform(self, doc, **kwargs):
      return doc if doc['childTable']['parent_id'] == 'someValue' else None

But I am concerned that depending on the condition, this won't necessarily insert/delete documents as expected. It may work for your use case though.

@kundankumarcasio
Copy link
Author

I tried this and it worked, but this creates some sync inconsistencies.

@jvanderen1
Copy link

This would be a great enhancement to add for things like soft-deleted or archived records.

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