Skip to content

Conversation

mdumandag
Copy link
Contributor

@mdumandag mdumandag commented Sep 20, 2021

Up until now, we were returning the SqlResult immediately after
initiating the query to the server, without waiting for the first
response.

The server might not be able to handle some consequences of such
an API. To align the behavior with the Java implementation and
make it more intuitive, we now wait for the initial response
in the execute and execute_statement methods.

With that change, the return types are changed from SqlResult to
Future[SqlResult]. Also, I got rid of the Futures in the return types
of the methods over the SqlResult except for the close, as the
close might in fact go to the server.

With this change, I cleaned up the implementation so that it reflects
the new behavior better.

Also, we now return a rejected Future immediately if the first execute
the request fails.

@codecov-commenter
Copy link

codecov-commenter commented Sep 22, 2021

Codecov Report

Merging #480 (cd83ee2) into master (61a7eae) will decrease coverage by 0.28%.
The diff coverage is 97.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #480      +/-   ##
==========================================
- Coverage   95.23%   94.95%   -0.29%     
==========================================
  Files         346      346              
  Lines       17734    17705      -29     
==========================================
- Hits        16889    16811      -78     
- Misses        845      894      +49     
Impacted Files Coverage Δ
hazelcast/sql.py 97.59% <97.87%> (+0.26%) ⬆️
...otocol/codec/client_authentication_custom_codec.py 50.00% <0.00%> (-23.81%) ⬇️
hazelcast/reactor.py 81.79% <0.00%> (-8.26%) ⬇️
hazelcast/connection.py 91.88% <0.00%> (-1.42%) ⬇️
hazelcast/listener.py 93.71% <0.00%> (-0.63%) ⬇️
hazelcast/invocation.py 95.78% <0.00%> (+0.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 61a7eae...cd83ee2. Read the comment docs.

Up until now, we were returning the `SqlResult` immediately after
initiating the query to the server, without waiting for the first
response.

The server might not be able to handle some consequences of such
an API. To align the behavior with the Java implementation and
make it more intuitive, we now wait for the initial response
in the `execute` and `execute_statement` methods.

With that change, the return types are changed from `SqlResult` to
`Future[SqlResult]`. Also, I got rid of the Futures in the return types
of the methods over the `SqlResult` except for the `close`, as the
`close` might in fact go to the server.

With this change, I cleaned up the implementation so that it reflects
the new behavior better.
@mdumandag mdumandag force-pushed the sql-wait-first-response branch from 0708c93 to efec85e Compare September 22, 2021 13:02
@mdumandag mdumandag changed the title Wait for the initial response in the SQL queries [API-900] Wait for the initial response in the SQL queries Sep 23, 2021
with client.sql.execute(mapping_query) as result:
# wait until query completes
result.update_count().result()
client.sql.execute(mapping_query).result():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client.sql.execute(mapping_query).result():
client.sql.execute(mapping_query).result()

*params: Query parameters that will be passed to
:func:`SqlStatement.add_parameter`.
Returns:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like in docstring, the code in "Usage" section needs to be updated too

:func:`update_count`. ::
update_count = client.sql.execute("SELECT ...").update_count().result()
update_count = client.sql.execute("UPDATE ...").result().update_count()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support UPDATE queries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know but I copied this from the Java side. I assume they did it like this because currently, we don't have any queries that return update count

hazelcast/sql.py Outdated
# There is nothing more we can get from the server.
self._closed = True
return (
execute_response.row_page is None # Just an update count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we check row_metadata to be null here? Java does that also we checked row_metadata in other places to check if result is a rowset or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same and more inline with the check below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a second look, the row page might be null, let me change that

@mdumandag mdumandag merged commit d98ffc9 into hazelcast:master Sep 23, 2021
@mdumandag mdumandag deleted the sql-wait-first-response branch September 23, 2021 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants