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

Multicorn agg pushdown v2 #613

Merged
merged 20 commits into from
Jan 21, 2022
Merged

Conversation

gruuya
Copy link
Contributor

@gruuya gruuya commented Jan 17, 2022

Extend the engine's upperrel pushdown capabilities (#581) with the new features, via splitgraph/Multicorn#2 and splitgraph/postgres-elasticsearch-fdw#2:

  • support for qual/restriction pushdown, i.e. WHERE clauses in combination with aggregations
  • add support for COUNT(*) pushdown
  • add end-to-end testing of the new functionality

CU-1z461e4

@gruuya gruuya requested a review from mildbyte January 17, 2022 12:42
@gruuya gruuya self-assigned this Jan 17, 2022
Copy link
Contributor

@mildbyte mildbyte left a comment

Choose a reason for hiding this comment

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

Tests look good apart from minor nitpicks! I'll move on to reviewing the other two PRs now.

query = "SELECT COUNT(*) FROM es.account"

# Ensure query is going to be aggregated on the foreign server
result = get_engine().run_sql("EXPLAIN " + query)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use the local_engine_empty fixture here (and in other places) instead of get_engine(). The former rolls back when the test is finished whereas the latter holds open a transaction that might eventually influence other tests. In this case, get_engine() would return the same global engine object as local_engine_empty but it's best to be explicit.

assert len(result) == 1

# Assert aggregation result
assert result[0] == (Decimal("24.439862542955325"), 49795.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use something like assert math.isclose(result[0][0], 24.4399, rel_tol=1e-05) here just in case this slightly shifts with different versions of ES to make maintenance easier

test/splitgraph/commands/test_es_aggregation_pushdown.py Outdated Show resolved Hide resolved
assert _extract_queries_from_explain(result)[0] == {
"query": {
"bool": {
"must": [
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the should nested inside of must -- is it so that ES treats the should clauses as "one of these must match"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is correct (note that I actually didn't change this logic, it just got exposed in the tests now). The ANY qual is broken up into logical ORs (i.e. shoulds in ES) and those are ANDed with the first qual through the must.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. I have this weird memory of Multicorn not supporting OR clauses, but ANY bypasses that.

test/splitgraph/commands/test_es_aggregation_pushdown.py Outdated Show resolved Hide resolved
@@ -28,6 +29,84 @@ def _extract_queries_from_explain(result):
_bare_sequential_scan = {"query": {"bool": {"must": []}}}


@pytest.mark.mounting
def test_patern_matching_queries(local_engine_empty):
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: pattern

@gruuya gruuya merged commit 190fe80 into master Jan 21, 2022
@gruuya gruuya deleted the multicorn-agg-pushdown-v2-cu-1z461e4 branch January 21, 2022 11:24
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

Successfully merging this pull request may close these issues.

None yet

2 participants