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

Add support for skip history (write last state to sink) #26

Open
gkorland opened this issue May 25, 2020 · 7 comments
Open

Add support for skip history (write last state to sink) #26

gkorland opened this issue May 25, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@gkorland
Copy link
Contributor

In case when only the last key state is relevant we should be able to skip updates.

e.g.

HSET person:1 name v1
HSET person:1 name v2
HSET person:1 name v3

Only one call to the DB should sent

UPDATE person SET name = v3 WHERE id=1; 
@K-Jo
Copy link
Collaborator

K-Jo commented May 25, 2020

@gkorland could this be generalised as a feature of streams?

@mcazzador
Copy link

Hi, is it possible to write only first key occurrence (in final database table) and dont' make a "REPLACE INTO" if a replicated key is inserted in redis?
Thanks

@MeirShpilraien
Copy link
Collaborator

@mcazzador Theoretically, it's possible but requires some code changes, if you describe a little more the usecase and why you need it maybe we can come up with a solution.

@mcazzador
Copy link

Hi, "REPLACE INTO" is not the best solution for me because i need to flag every DB records inserted on backend. REPLACE INTO in case of duplicate key (I want to protect myself from a possible case of this type without bloking error), erase my previous update fields. Maybe i can change REPLACE INTO with something like that:

INSERT INTO tablename (id, value...)
VALUES('$id', '$value',....)
ON DUPLICATE KEY UPDATE ....

I thought it was already implemented in the code.

@MeirShpilraien
Copy link
Collaborator

MeirShpilraien commented Oct 18, 2020

@mcazzador you can easily change the add query by inheriting the MySqlConnector (for example in case of mysql backend) and override def PrepereQueries(self, mappings):

def PrepereQueries(self, mappings):

Then you can use your new connector as it was MySql connector.

Is this helps?

@mcazzador
Copy link

Thank's a lot

@mcazzador
Copy link

I do that, maybe it could be doing better, thanks

def GetUpdateQuery_noreplace(tableName, mappings, pk):
query = 'INSERT INTO %s' % tableName
values = [val for kk, val in mappings.items() if not kk.startswith('_')]
values = [self.pk] + values
values.sort()
query = '%s(%s) values(%s) ON DUPLICATE KEY UPDATE %s=:%s' % (query, ','.join(values), ','.join([':%s' % a for a in values]),pk,pk)
return query

@gkorland gkorland added the enhancement New feature or request label Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants